sistemazione partizioni

This commit is contained in:
cmaffio
2016-04-20 17:07:50 +02:00
parent e81bc965fc
commit c301904ebc

View File

@@ -87,7 +87,6 @@ sub inizializza {
} }
sub aggiorna { sub aggiorna {
my $dbmysql = shift; my $dbmysql = shift;
my $tabella = shift; my $tabella = shift;
my $campo = shift; my $campo = shift;
@@ -103,11 +102,11 @@ sub aggiorna {
my $ultimo = ""; my $ultimo = "";
foreach $riga (@risp) { foreach $riga (@risp) {
if ($riga =~ /^[\(\s]?PARTITION p(\d+) VALUES LESS THAN \((\d+)'\) .*$/) { if ($riga =~ /^[\(\s]?PARTITION p(\d{4})(\d{2})(\d{2}) VALUES LESS THAN \(\d+\) .*$/) {
my $p = "$1$2$3";
next if ($1 eq '19700101'); next if ($p eq '19700101');
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($2);
$ultimo = ($year+1900)."-".i($mon+1)."-".$mday; $ultimo = "$1-$2-$3";
my $diff = diffgg ($ultimo); my $diff = diffgg ($ultimo);
if ($diff > 365) { if ($diff > 365) {
@@ -128,9 +127,10 @@ sub aggiorna {
my @tmp0 = split / /, $ultimo; my @tmp0 = split / /, $ultimo;
my @tmp = split /-/, $tmp0[0]; my @tmp = split /-/, $tmp0[0];
my $p = $tmp[0].$tmp[1].$tmp[2]; my $p = $tmp[0].$tmp[1].$tmp[2];
$inquery .= "PARTITION p$p VALUES LESS THAN ('$ultimo'),\n"; $inquery .= "PARTITION p$p VALUES LESS THAN ( TO_DAYS('$ultimo') ),\n";
} }
$query = "$prequery$inquery$postquery"; $query = "$prequery$inquery$postquery";
print "$query\n" if ($messaggi);
$sts = $dbmysql->prepare($query); $sts = $dbmysql->prepare($query);
$sts->execute (); $sts->execute ();
@@ -159,5 +159,5 @@ sub addgg {
my @part = split /-/, $data; my @part = split /-/, $data;
my @tempo = (59, 59, 23, $part[2], $part[1]-1, $part[0]-1900); my @tempo = (59, 59, 23, $part[2], $part[1]-1, $part[0]-1900);
my $tempo = timelocal(@tempo) + 86400; my $tempo = timelocal(@tempo) + 86400;
return strftime('%Y-%m-%d %H:%M:%S',localtime($tempo)) return strftime('%Y-%m-%d',localtime($tempo))
} }