Test and quote all idents, including reserved words and those with spaces, in OSCCaptureSync.pm.

This commit is contained in:
Daniel Nichter
2012-02-20 11:09:36 -07:00
parent a6f9501fa8
commit 39fe787fdd
7 changed files with 120 additions and 63 deletions

View File

@@ -14,6 +14,7 @@ use Test::More;
use DSNParser;
use Sandbox;
use PerconaTest;
use Quoter;
use OSCCaptureSync;
use Data::Dumper;
@@ -30,72 +31,92 @@ if ( !$dbh ) {
}
else {
plan tests => 4;
plan tests => 10;
}
$sb->load_file("master", "t/lib/samples/osc/tbl001.sql");
$dbh->do("USE osc");
my $osc = new OSCCaptureSync();
my $q = new Quoter();
my $osc = new OSCCaptureSync(Quoter => $q);
my $msg = sub { print "$_[0]\n"; };
my $output;
my $output = output(
sub {
$osc->capture(
dbh => $dbh,
db => 'osc',
tbl => 't',
tmp_tbl => '__new_t',
columns => [qw(id c)],
chunk_column => 'id',
msg => $msg,
)
},
);
sub test_table {
my (%args) = @_;
my ($tbl, $col, $expect) = @args{qw(tbl col expect)};
ok(
no_diff(
$output,
"t/lib/samples/osc/capsync001.txt",
cmd_output => 1,
),
"SQL statments to create triggers"
);
$sb->load_file("master", "t/lib/samples/osc/$tbl");
PerconaTest::wait_for_table($dbh, "osc.t", "id=5");
$dbh->do("USE osc");
$dbh->do('insert into t values (6, "f")');
$dbh->do('update t set c="z" where id=1');
$dbh->do('delete from t where id=3');
my $rows = $dbh->selectall_arrayref("select id, c from __new_t order by id");
is_deeply(
$rows,
[
[1, 'z'], # update t set c="z" where id=1
[6, 'f'], # insert into t values (6, "f")
],
"Triggers work"
) or print Dumper($rows);
output(sub {
$osc->cleanup(
dbh => $dbh,
db => 'osc',
msg => $msg,
ok(
no_diff(
sub {
$osc->capture(
dbh => $dbh,
db => 'osc',
tbl => 't',
tmp_tbl => '__new_t',
columns => ['id', $col],
chunk_column => 'id',
msg => $msg,
)
},
"t/lib/samples/osc/$expect",
stderr => 1,
),
"$tbl: SQL statments to create triggers"
);
});
$rows = $dbh->selectall_arrayref("show triggers from `osc` like 't'");
is_deeply(
$rows,
[],
"Cleanup removes the triggers"
$dbh->do("insert into t values (6, 'f')");
$dbh->do("update t set `$col`='z' where id=1");
$dbh->do("delete from t where id=3");
my $rows = $dbh->selectall_arrayref("select id, `$col` from __new_t order by id");
is_deeply(
$rows,
[
[1, 'z'], # update t set c="z" where id=1
[6, 'f'], # insert into t values (6, "f")
],
"$tbl: Triggers work"
) or print Dumper($rows);
output(sub {
$osc->cleanup(
dbh => $dbh,
db => 'osc',
msg => $msg,
);
});
$rows = $dbh->selectall_arrayref("show triggers from `osc` like 't'");
is_deeply(
$rows,
[],
"$tbl: Cleanup removes the triggers"
);
}
test_table(
tbl => "tbl001.sql",
col => "c",
expect => "capsync001.txt",
);
test_table(
tbl => "tbl002.sql",
col => "default",
expect => "capsync002.txt",
);
test_table(
tbl => "tbl003.sql",
col => "space col",
expect => "capsync003.txt",
);
# #############################################################################
# Done.
# #############################################################################
$output = '';
{
local *STDERR;
open STDERR, '>', \$output;