I've heard Class::DBI described as many things before... but never "complex whirlygig" :-)

(SPOPS or Alzabo on the other hand ;-)

update: above removed because I was foolish and misread the message hierarchy. Bad Adrian.

For example, to create the rows (assuming the DB table exists) you would just need something like (untested code):

#! /usr/bin/perl use strict; use warnings; package BackupJob; use base 'Class::DBI'; use CLASS; # the DB where you job table is CLASS->set_db('Main', 'dbi:mysql', 'username', 'password'); # the name of your job table CLASS->table('jobs'); # the columns in your table, primary key first CLASS->columns(All => qw( jobid class classtype client compression elapsed ended filelistcount files fileslastwritten group jobid jobpid jobtype kbytes kbyteslastwritten masterserver operation owner path percent priority retentionperiod retentionunits schedule schedule_type server started state status stunit subtype try try_1_elapsed try_1_ended try_1_fileswritten try_1_kbyteswritten try_1_pid try_1_server try_1_started try_1_status try_1_statuscoun +t try_1_statusdescription try_1_statuslines try_1_stunit trycount )); package main; # If we assume %JOBS us a has mapping # jobid => {column => value, column => value ...} # then the following will create a DB row for each # entry my ($jobid, $values); while ( ($jobid, $values) = each %JOBS ) { BackupJob->create({ jobid => $jobid, %$values }) or die };

The BackupJob object also gives you lots of other nice things like searching, accessors, etc for free. Nice Class::DBI :-)

(of course, one of the things that Class::DBI doesn't support is tables with multi-column primary keys - so its not a lot of use for the table example I gave earlier :-)


In reply to Re^2: MySQL Table Creation using DBI by adrianh
in thread MySQL Table Creation using DBI by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.