TT#71051 sync-db sync timezone delimiter

* add support for MariaDB timezones sync sql
      delimiter as now in the generated sql stream output
      there are sections with '\d' changing the delimiter behaviour.

Change-Id: If226db7018f431ff4248dcf6ff5a614ff96a45c7
changes/92/35392/2
Kirill Solomko 6 years ago
parent 549d2c71a2
commit 406b4cb645

@ -203,7 +203,6 @@ sub sync_db_timezones {
chomp $tzinfo_version; chomp $tzinfo_version;
my $sql = ''; my $sql = '';
my $p_rs = $RS;
eval { eval {
$dbh->begin_work() or die "Cannot start tx: $DBI::errstr\n"; $dbh->begin_work() or die "Cannot start tx: $DBI::errstr\n";
my ($cur_tzinfo_version) = $dbh->selectrow_array(<<SQL) my ($cur_tzinfo_version) = $dbh->selectrow_array(<<SQL)
@ -217,13 +216,24 @@ SQL
open(my $sql_stream, "<", \$out) open(my $sql_stream, "<", \$out)
or die "Cannot open sql stream: $ERRNO\n"; or die "Cannot open sql stream: $ERRNO\n";
binmode($sql_stream); binmode($sql_stream);
local $RS = ";\n";
$dbh->do('USE mysql') $dbh->do('USE mysql')
or die "Cannot use mysql database: $DBI::errstr\n"; or die "Cannot use mysql database: $DBI::errstr\n";
my $batch;
my $delim = ';';
while ($sql = <$sql_stream>) { while ($sql = <$sql_stream>) {
map { if ($sql =~ m#^\s*\\d\s+(\S+)#) {
$dbh->do($_) or die "Cannot insert timezone data: $DBI::errstr\n"; $delim = $1;
} split /;\s+/, $sql; # multiple one line statements } else {
if ($sql =~ /^(.*)\Q$delim\E\s*$/) {
if ($1) {
$batch .= $1;
}
$dbh->do($batch) or die "Cannot insert timezone data: $DBI::errstr\n";
$batch = undef;
} else {
$batch .= $sql;
}
}
} }
close $sql_stream; close $sql_stream;
$dbh->do(<<SQL, undef, $tzinfo_version, $tzinfo_version) $dbh->do(<<SQL, undef, $tzinfo_version, $tzinfo_version)
@ -232,10 +242,9 @@ INSERT INTO ngcp.tzinfo_version SET version = ?
SQL SQL
or die "Cannot insert into ngcp.tzinfo_version: $DBI::errstr\n"; or die "Cannot insert into ngcp.tzinfo_version: $DBI::errstr\n";
}; };
local $RS = $p_rs;
$err = $EVAL_ERROR; $err = $EVAL_ERROR;
if ($err) { if ($err) {
print $err,"sql: $sql\n"; print $err;
$dbh->rollback(); $dbh->rollback();
return; return;
} }

Loading…
Cancel
Save