summaryrefslogtreecommitdiff
path: root/ext/sqlite3/tests
diff options
context:
space:
mode:
authorBohwaZ <bohwaz@github.com>2019-06-17 23:28:30 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2019-06-17 23:34:51 +0200
commitce22ccc77b1cfe3d922ebe485069afc61d784916 (patch)
tree59f884de2a58c9f651052dc6ade3ff796d3f9aa7 /ext/sqlite3/tests
parentd924b426c90a16b954b9f17e239a105e7697a1fc (diff)
downloadphp-git-ce22ccc77b1cfe3d922ebe485069afc61d784916.tar.gz
Implement SQLite3 backup API
Diffstat (limited to 'ext/sqlite3/tests')
-rw-r--r--ext/sqlite3/tests/sqlite3_38_backup.phpt58
1 files changed, 58 insertions, 0 deletions
diff --git a/ext/sqlite3/tests/sqlite3_38_backup.phpt b/ext/sqlite3/tests/sqlite3_38_backup.phpt
new file mode 100644
index 0000000000..8ff5189fdc
--- /dev/null
+++ b/ext/sqlite3/tests/sqlite3_38_backup.phpt
@@ -0,0 +1,58 @@
+--TEST--
+SQLite3::backup test
+--SKIPIF--
+<?php require_once(__DIR__ . '/skipif.inc'); ?>
+--FILE--
+<?php
+
+require_once(__DIR__ . '/new_db.inc');
+
+echo "Creating table\n";
+$db->exec('CREATE TABLE test (a, b);');
+$db->exec('INSERT INTO test VALUES (42, \'php\');');
+
+echo "Checking if table has been created\n";
+var_dump($db->querySingle('SELECT COUNT(*) FROM sqlite_master;'));
+
+$db2 = new SQLite3(':memory:');
+
+echo "Backup to DB2\n";
+var_dump($db->backup($db2));
+
+echo "Checking if table has been copied\n";
+var_dump($db2->querySingle('SELECT COUNT(*) FROM sqlite_master;'));
+
+echo "Checking backup contents\n";
+var_dump($db2->querySingle('SELECT a FROM test;'));
+var_dump($db2->querySingle('SELECT b FROM test;'));
+
+echo "Resetting DB2\n";
+
+$db2->close();
+$db2 = new SQLite3(':memory:');
+
+echo "Locking DB1\n";
+var_dump($db->exec('BEGIN EXCLUSIVE;'));
+
+echo "Backup to DB2 (should fail)\n";
+var_dump($db->backup($db2));
+
+?>
+--EXPECTF--
+Creating table
+Checking if table has been created
+int(1)
+Backup to DB2
+bool(true)
+Checking if table has been copied
+int(1)
+Checking backup contents
+int(42)
+string(3) "php"
+Resetting DB2
+Locking DB1
+bool(true)
+Backup to DB2 (should fail)
+
+Warning: SQLite3::backup(): Backup failed: source database is busy in %s on line %d
+bool(false) \ No newline at end of file