use strict;
use warnings;
use DBI;
use Data::Dumper;
my $dbh = DBI->connect() or die DBI->errstr;
my $tables = [@ARGV];
$tables =$dbh->selectcol_arrayref("show tables;") unless defined @$tables;
for my $table (@$tables) {
print "Checking $table ... ";
my $cols = $dbh->selectall_arrayref("describe $table",{Slice=>{}});
my @dates = grep { $_->{Type} =~ /date/ } @$cols;
# print Dumper(@dates);
for my $col (@dates) {
my $field = $col->{Field};
my $count = $dbh->do("UPDATE `$table` SET `$field` = NULL WHERE `$field` = '0000-00-00';");
print "fixed '$field' ($count) ... ";
}
print " done.\n";
# die;
}
####
use strict;
use warnings;
use DBI;
use Data::Dumper;
my $dbh = DBI->connect() or die DBI->errstr;
my $tables = [@ARGV];
$tables =$dbh->selectcol_arrayref("show tables;") unless defined @$tables;
for my $table (@$tables) {
print "Checking $table ... ";
my $cols = $dbh->selectall_arrayref("describe $table",{Slice=>{}});
my @dates = grep { $_->{Type} =~ /timestamp/ } @$cols;
# print Dumper(@dates);
for my $col (@dates) {
my $field = $col->{Field};
my $count = $dbh->do("UPDATE `$table` SET `$field` = NOW() WHERE `$field` = '0000-00-00 00:00:00';");
print "fixed '$field' ($count) ... " if $count > 0;
}
print " done.\n";
# die;
}
####
use strict;
use warnings;
use DBI;
use Data::Dumper;
my $dbh = DBI->connect() or die DBI->errstr;
my $tables = [@ARGV];
$tables =$dbh->selectcol_arrayref("show tables;") unless defined @$tables;
for my $table (@$tables) {
print "Checking $table ... ";
my $cols = $dbh->selectall_arrayref("describe $table",{Slice=>{}});
my @dates = grep { $_->{Type} =~ /timestamp/ } @$cols;
# print Dumper(@dates);
for my $col (@dates) {
my $field = $col->{Field};
my $count = $dbh->do("UPDATE `$table` SET `$field` = NOW() WHERE `$field` = '0000-00-00 00:00:00';");
print "fixed '$field' ($count) ... " if $count > 0;
}
print " done.\n";
# die;
}