public void PagedBackup(int stepSize) { const int expected = 2 << 16; var sqlite = new Sqlite3(); using (var source = (Database)sqlite.OpenTest("CREATE TABLE t1(id INTEGER PRIMARY KEY)")) using (var dest = (Database)sqlite.OpenTest()) { source.Execute("BEGIN TRANSACTION"); foreach (var i in Enumerable.Range(1, expected)) { source.Execute($"INSERT INTO t1(id) VALUES({i})"); } source.Execute("COMMIT"); source.BackupTo(dest, stepSize, this); var actual = 0; using (var stmt = dest.Prepare("SELECT * FROM t1")) while (stmt.Step() == Status.Row) { actual++; } Assert.AreEqual(expected, actual); } }
public void InvokesBusyHandler(int busyCallCount) { var called = false; var path = Path.GetTempFileName(); var sqlite = new Sqlite3(); using (var db1 = sqlite.OpenTest(path, OpenFlags.ReadWrite | OpenFlags.Create, "BEGIN IMMEDIATE TRANSACTION")) using (var db2 = sqlite.OpenTest(path, OpenFlags.ReadWrite)) { db2.Hooks.Busy = busyHandler; using (var stms = db2.Prepare("BEGIN IMMEDIATE TRANSACTION")) Assert.AreEqual(Status.Busy, stms.Step()); } Assert.IsTrue(called); File.Delete(path); int busyHandler(int callCount) { if (callCount < busyCallCount) { return(1); } called = true; return(0); } }
public void SimpleBackup() { const string expected = "fizzbuzz"; var sqlite = new Sqlite3(); using (var source = (Database)sqlite.OpenTest("CREATE TABLE t1(id INTEGER PRIMARY KEY, name TEXT)", $"INSERT INTO t1(name) VALUES('{expected}')")) using (var dest = (Database)sqlite.OpenTest()) { source.BackupTo(dest); using (var stmt = dest.Prepare("SELECT name FROM t1")) { Assert.AreEqual(Status.Row, stmt.Step()); Assert.AreEqual(expected, stmt.Columns.GetText(0)); } } }