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 :-) |