1 package BackupPC::Config::Db::MySQL;
3 use base 'BackupPC::Config::Db';
10 %BackupPC::Config::Db::gConfigTypeField =
11 (BOOLEAN => 'valueBit',
13 FLOAT => 'valueFloat',
14 STRING => 'valueString',
21 my $dsn = 'DBI:mysql:database=backuppc;host=reagan';
22 $self->{dbh} = DBI->connect($dsn, 'root', undef, {RaiseError => 1,
29 my $cmd = "SHOW TABLE STATUS LIKE 'Config'";
30 my $sth = $self->{dbh}->prepare($cmd);
33 my $row = $sth->fetchrow_hashref || return time();
36 if (defined($mtime = $row->{'Update_time'})) {
37 $mtime =~ m/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/
39 return &Date_SecsSince1970($2,$3,$1,$4,$5,$6);
48 my $cmd = "SHOW TABLE STATUS LIKE 'Client'";
49 my $sth = $self->{dbh}->prepare($cmd);
52 my $row = $sth->fetchrow_hashref || return time();
55 if (defined($mtime = $row->{'Update_time'})) {
56 return &Date_SecsSince1970($mtime);
62 # Date subs borrowed from Date::Manip.
63 # Copyright (c) 1995-2001 Sullivan Beck. All rights reserved.
64 # This program is free software; you can redistribute it and/or modify it
65 # under the same terms as Perl itself.
67 sub Date_SecsSince1970 {
69 $mysqlDate =~ m/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/
71 my($y,$m,$d,$h,$mn,$s) = ($1,$2,$3,$4,$5,$6);
72 my($sec_now,$sec_70,$Ny,$N4,$N100,$N400,$dayofyear,$days)=();
75 $y=~ /(\d{2})(\d{2})/;
87 $N400=($N100-1)/4 + 1;
90 my(@days) = ( 0, 31, 59, 90,120,151,181,212,243,273,304,334,365);
92 $ly=1 if ($m>2 && &Date_LeapYear($y));
94 $dayofyear=$days[$m-1]+$d+$ly;
95 $days= $Ny*365 + $N4 - $N100 + $N400 + $dayofyear;
96 $sec_now=($days-1)*24*3600 + $h*3600 + $mn*60 + $s;
98 return ($sec_now-$sec_70);
104 return 1 if $y % 100;
105 return 0 if $y % 400;