diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2012-09-24 10:15:50 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-26 13:46:46 +0000 |
commit | 485b97be9f2f2abf5a40923b5fd85f75714a8c02 (patch) | |
tree | ca05cb0ecf3828d909a898c3e5805804a0aff5f8 /t/34_online_backup.t | |
download | perl-dbd-sqlite-tarball-baserock/morph.tar.gz |
Imported from /srv/lorry/lorry-area/perl-dbd-sqlite-tarball/DBD-SQLite-1.38_01.tar.gz.HEADDBD-SQLite-1.38_01masterbaserock/morph
Diffstat (limited to 't/34_online_backup.t')
-rw-r--r-- | t/34_online_backup.t | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/t/34_online_backup.t b/t/34_online_backup.t new file mode 100644 index 0000000..0675f2e --- /dev/null +++ b/t/34_online_backup.t @@ -0,0 +1,76 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More; +use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS/; + +BEGIN { + use DBD::SQLite; + unless ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= 3006011) { + plan skip_all => "this test requires SQLite 3.6.11 and newer"; + exit; + } +} + +use Test::NoWarnings; +use DBI; + +plan tests => 6 * @CALL_FUNCS + 1; + +foreach my $call_func (@CALL_FUNCS) { + # Connect to the test db and add some stuff: + my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 ); + my $dbfile = dbfile('foo'); + $foo->do( + 'CREATE TABLE online_backup_test( id INTEGER PRIMARY KEY, foo INTEGER )' + ); + $foo->do("INSERT INTO online_backup_test (foo) VALUES ($$)"); + + # That should be in the "foo" database on disk now, so disconnect and try to + # back it up: + + $foo->disconnect; + + my $dbh = DBI->connect( + 'dbi:SQLite:dbname=:memory:', + undef, undef, + { RaiseError => 1 } + ); + + ok($dbh->$call_func($dbfile, 'backup_from_file')); + + { + my ($count) = $dbh->selectrow_array( + "SELECT count(foo) FROM online_backup_test WHERE foo=$$" + ); + is($count, 1, "Found our process ID in backed-up table"); + } + + # Add more data then attempt to copy it back to file: + $dbh->do( + 'CREATE TABLE online_backup_test2 ( id INTEGER PRIMARY KEY, foo INTEGER )' + ); + $dbh->do("INSERT INTO online_backup_test2 (foo) VALUES ($$)"); + + # backup to file (foo): + ok($dbh->$call_func($dbfile, 'backup_to_file')); + + $dbh->disconnect; + + # Reconnect to foo db and check data made it over: + { + my $foo = connect_ok( dbfile => 'foo', RaiseError => 1 ); + + my ($count) = $foo->selectrow_array( + "SELECT count(foo) FROM online_backup_test2 WHERE foo=$$" + ); + is($count, 1, "Found our process ID in table back on disk"); + + $foo->disconnect; + } + $dbh->disconnect; + + unlink $dbfile; +} |