/// <summary> /// This tests the SQLite in-memory DB by creating some data and then selecting it /// </summary> public static void TestDatabase() { var watch = new DiagnosticTimer(); var db = new SQLiteDatabase(":memory:"); watch.Checkpoint("Create DB"); db.ExecuteNonQuery("CREATE TABLE Root (intIndex INTEGER PRIMARY KEY, strIndex TEXT, nr REAL)"); watch.Checkpoint("Create table 1"); db.ExecuteNonQuery("CREATE TABLE This (intIndex INTEGER PRIMARY KEY, strIndex TEXT, nr REAL)"); watch.Checkpoint("Create table 2"); db.ExecuteNonQuery("CREATE INDEX RootStrIndex ON Root (strIndex)"); const string insertCommand = "INSERT INTO Root VALUES (?,?,?)"; int i; var stmt = new SQLiteVdbe(db, insertCommand); long key = 1999; for (i = 0; i < 10000; i++) { key = (3141592621L * key + 2718281829L) % 1000000007L; stmt.Reset(); stmt.BindLong(1, key); stmt.BindText(2, key.ToString()); stmt.BindDouble(3, 12.34); stmt.ExecuteStep(); } stmt.Close(); watch.Checkpoint("Insert 10000 rows"); i = 0; var c1 = new SQLiteVdbe(db, "SELECT * FROM Root ORDER BY intIndex LIMIT 5000"); while (c1.ExecuteStep() != Sqlite3.SQLITE_DONE) { long intKey = c1.Result_Long(0); key = intKey; i += 1; } c1.Close(); var diagnostic = watch.LastCheckpoint("Select 5000 sorted rows"); MessageBox.Show(diagnostic); }