Beispiel #1
0
        public void test_hooks()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                work w = new work();
                Assert.AreEqual(w.count_commits, 0);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 0);
                Assert.AreEqual(w.count_profiles, 0);

                db.commit_hook(my_commit_hook, w);
                db.rollback_hook(my_rollback_hook, w);
                db.update_hook(my_update_hook, w);
                db.trace(my_trace_hook, w);
                db.profile(my_profile_hook, w);

                GC.Collect();

                db.exec("CREATE TABLE foo (x int);");

                Assert.AreEqual(w.count_commits, 1);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 1);
                Assert.AreEqual(w.count_profiles, 1);

                db.exec("INSERT INTO foo (x) VALUES (1);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 2);
                Assert.AreEqual(w.count_profiles, 2);

                db.exec("BEGIN TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 3);
                Assert.AreEqual(w.count_profiles, 3);

                db.exec("INSERT INTO foo (x) VALUES (2);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 4);
                Assert.AreEqual(w.count_profiles, 4);

                db.exec("ROLLBACK TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 1);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 5);
                Assert.AreEqual(w.count_profiles, 5);
            }
        }
Beispiel #2
0
        public void test_error()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int UNIQUE);");
                db.exec("INSERT INTO foo (x) VALUES (3);");
                bool fail = false;
                try
                {
                    db.exec("INSERT INTO foo (x) VALUES (3);");
                }
                catch (ugly.sqlite3_exception e)
                {
                    fail = true;

                    int errcode = db.errcode();
                    Assert.AreEqual(errcode, e.errcode);
                    Assert.AreEqual(errcode, raw.SQLITE_CONSTRAINT);

                    Assert.AreEqual(db.extended_errcode(), raw.SQLITE_CONSTRAINT_UNIQUE, "Extended error codes for SQLITE_CONSTRAINT were added in 3.7.16");

                    string errmsg = db.errmsg();
                    Assert.IsTrue(errmsg != null);
                    Assert.IsTrue(errmsg.Length > 0);
                }
                Assert.IsTrue(fail);

                Assert.IsTrue(raw.sqlite3_errstr(raw.SQLITE_CONSTRAINT) != null);
            }
        }
Beispiel #3
0
        public void test_column_origin()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int, v int, t text, d real, b blob, q blob);");
                byte[] blob = db.query_scalar <byte[]>("SELECT randomblob(5);");
                db.exec("INSERT INTO foo (x,v,t,d,b,q) VALUES (?,?,?,?,?,?)", 32, 44, "hello", 3.14, blob, null);
#if not
                // maybe we should just let this fail so we can
                // see the differences between running against the built-in
                // sqlite vs a recent version?
                if (1 == raw.sqlite3_compileoption_used("ENABLE_COLUMN_METADATA"))
#endif
                {
                    using (sqlite3_stmt stmt = db.prepare("SELECT x AS mario FROM foo;"))
                    {
                        stmt.step();

                        Assert.IsTrue(stmt.stmt_readonly() != 0);

                        Assert.AreEqual(stmt.column_database_name(0), "main");
                        Assert.AreEqual(stmt.column_table_name(0), "foo");
                        Assert.AreEqual(stmt.column_origin_name(0), "x");
                        Assert.AreEqual(stmt.column_name(0), "mario");
                        Assert.AreEqual(stmt.column_decltype(0), "int");
                    }
                }
            }
        }
        public void test_total_changes()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                Assert.AreEqual(db.total_changes(), 0);
                Assert.AreEqual(db.changes(), 0);

                db.exec("CREATE TABLE foo (x int);");
                Assert.AreEqual(db.total_changes(), 0);
                Assert.AreEqual(db.changes(), 0);

                db.exec("INSERT INTO foo (x) VALUES (1);");
                Assert.AreEqual(db.total_changes(), 1);
                Assert.AreEqual(db.changes(), 1);

                db.exec("INSERT INTO foo (x) VALUES (2);");
                db.exec("INSERT INTO foo (x) VALUES (3);");
                Assert.AreEqual(db.total_changes(), 3);
                Assert.AreEqual(db.changes(), 1);

                db.exec("UPDATE foo SET x=5;");
                Assert.AreEqual(db.total_changes(), 6);
                Assert.AreEqual(db.changes(), 3);
            }
        }
Beispiel #5
0
        public void test_stmt_busy()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int);");
                db.exec("INSERT INTO foo (x) VALUES (1);");
                db.exec("INSERT INTO foo (x) VALUES (2);");
                db.exec("INSERT INTO foo (x) VALUES (3);");
                const string sql = "SELECT x FROM foo";
                using (sqlite3_stmt stmt = db.prepare(sql))
                {
                    Assert.AreEqual(sql, stmt.sql());

                    Assert.AreEqual(stmt.stmt_busy(), 0);
                    stmt.step();
                    Assert.IsTrue(stmt.stmt_busy() != 0);
                    stmt.step();
                    Assert.IsTrue(stmt.stmt_busy() != 0);
                    stmt.step();
                    Assert.IsTrue(stmt.stmt_busy() != 0);
                    stmt.step();
                    Assert.IsTrue(stmt.stmt_busy() == 0);
                }
            }
        }
Beispiel #6
0
 public void test_last_insert_rowid()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x text);");
         db.exec("INSERT INTO foo (x) VALUES ('b')");
         Assert.AreEqual(db.last_insert_rowid(), 1);
     }
 }
Beispiel #7
0
 public void test_count()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x int);");
         db.exec("INSERT INTO foo (x) VALUES (1);");
         db.exec("INSERT INTO foo (x) VALUES (2);");
         db.exec("INSERT INTO foo (x) VALUES (3);");
         int c = db.query_scalar <int>("SELECT COUNT(*) FROM foo");
         Assert.AreEqual(c, 3);
     }
 }
Beispiel #8
0
        public void test_blob_write_with_byte_array_offset()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                const int len = 100;

                db.exec("CREATE TABLE foo (b blob);");
                db.exec("INSERT INTO foo (b) VALUES (zeroblob(?))", len);
                long rowid = db.last_insert_rowid();

                byte[] blob = db.query_scalar <byte[]>("SELECT b FROM foo;");
                Assert.AreEqual(blob.Length, len);

                for (int i = 0; i < 100; i++)
                {
                    Assert.AreEqual(blob[i], 0);
                }

                using (sqlite3_blob bh = db.blob_open("main", "foo", "b", rowid, 1))
                {
                    int len2 = bh.bytes();
                    Assert.AreEqual(len, len2);

                    byte[] blob2 = new byte[len];
                    for (int i = 0; i < 100; i++)
                    {
                        blob2[i] = 73;
                    }

                    bh.write(blob2, 40, 20, 50);
                }

                byte[] blob3 = db.query_scalar <byte[]>("SELECT b FROM foo;");
                Assert.AreEqual(blob3.Length, len);

                for (int i = 0; i < 50; i++)
                {
                    Assert.AreEqual(blob3[i], 0);
                }

                for (int i = 50; i < 70; i++)
                {
                    Assert.AreEqual(blob3[i], 73);
                }

                for (int i = 70; i < 100; i++)
                {
                    Assert.AreEqual(blob3[i], 0);
                }
            }
        }
Beispiel #9
0
 public void test_sum_plus_count()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.create_function("sum_plus_count", 1, null, sum_plus_count_step, sum_plus_count_final);
         db.exec("CREATE TABLE foo (x int);");
         for (int i = 0; i < 5; i++)
         {
             db.exec("INSERT INTO foo (x) VALUES (?);", i);
         }
         long c = db.query_scalar <long>("SELECT sum_plus_count(x) FROM foo;");
         Assert.AreEqual(c, (0 + 1 + 2 + 3 + 4) + 5);
     }
 }
        public void test_result_errors()
        {
            int code = 10;
            delegate_function_scalar errorcode_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_code(ctx, code);

            delegate_function_scalar toobig_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_toobig(ctx);

            delegate_function_scalar nomem_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_nomem(ctx);

            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.create_function("errorcode", 0, null, errorcode_func);
                db.create_function("toobig", 0, null, toobig_func);
                db.create_function("nomem", 0, null, nomem_func);

                try
                {
                    db.exec("select errorcode();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, code);
                }

                try
                {
                    db.exec("select toobig();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, raw.SQLITE_TOOBIG);
                }

                try
                {
                    db.exec("select nomem();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, raw.SQLITE_NOMEM);
                }
            }
        }
Beispiel #11
0
        public void test_row()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int, v int, t text, d real, b blob, q blob);");
                byte[] blob = db.query_scalar <byte[]>("SELECT randomblob(5);");
                db.exec("INSERT INTO foo (x,v,t,d,b,q) VALUES (?,?,?,?,?,?)", 32, 44, "hello", 3.14, blob, null);
                foreach (row r in db.query <row>("SELECT x,v,t,d,b,q FROM foo;"))
                {
                    Assert.AreEqual(r.x, 32);
                    Assert.AreEqual(r.v, 44);
                    Assert.AreEqual(r.t, "hello");
                    Assert.AreEqual(r.d, 3.14);
                    Assert.AreEqual(r.b.Length, blob.Length);
                    for (int i = 0; i < blob.Length; i++)
                    {
                        Assert.AreEqual(r.b[i], blob[i]);
                    }
                    Assert.AreEqual(r.q, null);
                }
                using (sqlite3_stmt stmt = db.prepare("SELECT x,v,t,d,b,q FROM foo;"))
                {
                    stmt.step();

                    Assert.AreEqual(stmt.db_handle(), db);

                    Assert.AreEqual(stmt.column_int(0), 32);
                    Assert.AreEqual(stmt.column_int64(1), 44);
                    Assert.AreEqual(stmt.column_text(2), "hello");
                    Assert.AreEqual(stmt.column_double(3), 3.14);
                    Assert.AreEqual(stmt.column_bytes(4), blob.Length);
                    byte[] b2 = stmt.column_blob(4);
                    Assert.AreEqual(b2.Length, blob.Length);
                    for (int i = 0; i < blob.Length; i++)
                    {
                        Assert.AreEqual(b2[i], blob[i]);
                    }

                    Assert.AreEqual(stmt.column_type(5), raw.SQLITE_NULL);

                    Assert.AreEqual(stmt.column_name(0), "x");
                    Assert.AreEqual(stmt.column_name(1), "v");
                    Assert.AreEqual(stmt.column_name(2), "t");
                    Assert.AreEqual(stmt.column_name(3), "d");
                    Assert.AreEqual(stmt.column_name(4), "b");
                    Assert.AreEqual(stmt.column_name(5), "q");
                }
            }
        }
Beispiel #12
0
        public void test_bind_parameter_index()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int, v int, t text, d real, b blob, q blob);");
                using (sqlite3_stmt stmt = db.prepare("INSERT INTO foo (x,v,t,d,b,q) VALUES (:x,:v,:t,:d,:b,:q)"))
                {
                    Assert.IsTrue(stmt.stmt_readonly() == 0);

                    Assert.AreEqual(stmt.bind_parameter_count(), 6);

                    Assert.AreEqual(stmt.bind_parameter_index(":m"), 0);

                    Assert.AreEqual(stmt.bind_parameter_index(":x"), 1);
                    Assert.AreEqual(stmt.bind_parameter_index(":v"), 2);
                    Assert.AreEqual(stmt.bind_parameter_index(":t"), 3);
                    Assert.AreEqual(stmt.bind_parameter_index(":d"), 4);
                    Assert.AreEqual(stmt.bind_parameter_index(":b"), 5);
                    Assert.AreEqual(stmt.bind_parameter_index(":q"), 6);

                    Assert.AreEqual(stmt.bind_parameter_name(1), ":x");
                    Assert.AreEqual(stmt.bind_parameter_name(2), ":v");
                    Assert.AreEqual(stmt.bind_parameter_name(3), ":t");
                    Assert.AreEqual(stmt.bind_parameter_name(4), ":d");
                    Assert.AreEqual(stmt.bind_parameter_name(5), ":b");
                    Assert.AreEqual(stmt.bind_parameter_name(6), ":q");
                }
            }
        }
Beispiel #13
0
        public void test_create_table_explicit_close()
        {
            sqlite3 db = ugly.open(":memory:");

            db.exec("CREATE TABLE foo (x int);");
            db.close();
        }
Beispiel #14
0
 public void test_open_v2()
 {
     using (sqlite3 db = ugly.open_v2(":memory:", raw.SQLITE_OPEN_READWRITE | raw.SQLITE_OPEN_CREATE, null))
     {
         db.exec("CREATE TABLE foo (x int);");
     }
 }
Beispiel #15
0
 public void test_create_table_memory_db()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x int);");
     }
 }
        public void test_table_column_metadata()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                // out string dataType, out string collSeq, out int notNull, out int primaryKey, out int autoInc
                db.exec("CREATE TABLE foo (rowid integer primary key asc autoincrement, x int not null);");

                string dataType;
                string collSeq;
                int    notNull;
                int    primaryKey;
                int    autoInc;

                raw.sqlite3_table_column_metadata(db, "main", "foo", "x", out dataType, out collSeq, out notNull, out primaryKey, out autoInc);
                Assert.AreEqual(dataType, "int");
                Assert.AreEqual(collSeq, "BINARY");
                Assert.IsTrue(notNull > 0);
                Assert.AreEqual(primaryKey, 0);
                Assert.AreEqual(autoInc, 0);

                raw.sqlite3_table_column_metadata(db, "main", "foo", "rowid", out dataType, out collSeq, out notNull, out primaryKey, out autoInc);
                Assert.AreEqual(dataType, "integer");
                Assert.AreEqual(collSeq, "BINARY");
                Assert.AreEqual(notNull, 0);
                Assert.IsTrue(primaryKey > 0);
                Assert.IsTrue(primaryKey > 0);
            }
        }
Beispiel #17
0
 public void test_get_autocommit()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         Assert.AreEqual(db.get_autocommit(), 1);
         db.exec("BEGIN TRANSACTION;");
         Assert.IsTrue(db.get_autocommit() == 0);
     }
 }
Beispiel #18
0
 public void test_exec_two_with_tail()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         string errmsg;
         db.exec("CREATE TABLE foo (x int);INSERT INTO foo (x) VALUES (1);", null, null, out errmsg);
         int c = db.query_scalar <int>("SELECT COUNT(*) FROM foo");
         Assert.AreEqual(c, 1);
     }
 }
Beispiel #19
0
 private static void CreateTables(sqlite3 db)
 {
     db.exec("DROP TABLE IF EXISTS categories");
     db.exec("CREATE TABLE IF NOT EXISTS categories (id INTEGER PRIMARY KEY, name TEXT NOT NULL)");
     db.exec("CREATE TABLE IF NOT EXISTS items (" +
             "release_date TEXT NOT NULL," +
             "hash TEXT NOT NULL," +
             "topic INTEGER NOT NULL," +
             "post INTEGER NOT NULL," +
             "author TEXT NOT NULL," +
             "title TEXT NOT NULL," +
             "description TEXT NOT NULL," +
             "size INTEGER NOT NULL," +
             "category INTEGER NOT NULL," +
             "magnet TEXT DEFAULT NULL," +
             "disabled INTEGER DEFAULT 0" +
             ")");
     db.exec("CREATE TABLE IF NOT EXISTS metadata (key TEXT NOT NULL, value TEXT)");
     db.exec("INSERT OR REPLACE INTO metadata (key, value) VALUES ('version', '1')");
 }
 public void test_bernt()
 {
     using (sqlite3 db = ugly.open(""))
     {
         db.exec("CREATE TABLE places_dat (resource_handle TEXT PRIMARY KEY, data BLOB) WITHOUT ROWID;");
         byte[] buf1 = db.query_scalar <byte[]>("SELECT randomblob(16);");
         db.exec("INSERT INTO places_dat VALUES (?,?)", "foo", buf1);
         Assert.AreEqual(1, db.changes());
         int c1 = db.query_scalar <int>("SELECT COUNT(*) FROM places_dat WHERE resource_handle='foo';");
         Assert.AreEqual(1, c1);
         byte[] buf2 = new byte[2];
         buf2[0] = 42;
         buf2[1] = 73;
         db.exec("UPDATE places_dat SET data=? WHERE resource_handle=?;", buf2, "foo");
         Assert.AreEqual(1, db.changes());
         byte[] buf3 = db.query_scalar <byte[]>("SELECT data FROM places_dat WHERE resource_handle='foo';");
         Assert.AreEqual(2, buf3.Length);
         Assert.AreEqual(buf2[0], buf3[0]);
         Assert.AreEqual(buf2[1], buf3[1]);
     }
 }
Beispiel #21
0
        private static void SeedDb(sqlite3 db, List <CsvItem> csvItems)
        {
            db.exec("DELETE FROM items");
            db.exec("BEGIN TRANSACTION");
            using (var stmt = db.prepare("INSERT INTO items (release_date, hash, topic, post, author, title, description, size, category, magnet) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"))
            {
                for (var i = 0; i < csvItems.Count; i++)
                {
                    if (i % 100 == 0)
                    {
                        Console.Write('.');
                    }

                    if (i % 5000 == 0)
                    {
                        Console.WriteLine();
                    }

                    var item = csvItems[i];
                    stmt.reset();

                    stmt.bind_text(1, item.ReleaseDate);
                    stmt.bind_text(2, item.Hash);
                    stmt.bind_int(3, item.Topic);
                    stmt.bind_int(4, item.Post);
                    stmt.bind_text(5, item.Author);
                    stmt.bind_text(6, item.Title);
                    stmt.bind_text(7, item.Description);
                    stmt.bind_int64(8, item.Size);
                    stmt.bind_int(9, item.Category);
                    stmt.bind_text(10, BuildMagnetUri(item));

                    stmt.step_done();
                }
            }
            db.exec("COMMIT TRANSACTION");
            Console.WriteLine();
        }
Beispiel #22
0
        public void test_blob_read()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                const int len = 100;

                db.exec("CREATE TABLE foo (b blob);");
                db.exec("INSERT INTO foo (b) VALUES (randomblob(?))", len);
                long rowid = db.last_insert_rowid();

                byte[] blob = db.query_scalar <byte[]>("SELECT b FROM foo;");
                Assert.AreEqual(blob.Length, len);

                using (sqlite3_blob bh = db.blob_open("main", "foo", "b", rowid, 0))
                {
                    int len2 = bh.bytes();
                    Assert.AreEqual(len, len2);

                    int passes = 10;

                    Assert.AreEqual(len % passes, 0);

                    int    sublen = len / passes;
                    byte[] buf    = new byte[sublen];

                    for (int q = 0; q < passes; q++)
                    {
                        bh.read(buf, q * sublen);

                        for (int i = 0; i < sublen; i++)
                        {
                            Assert.AreEqual(blob[q * sublen + i], buf[i]);
                        }
                    }
                }
            }
        }
        public void test_result_zeroblob()
        {
            delegate_function_scalar zeroblob_func =
                (ctx, user_data, args) =>
            {
                int size = raw.sqlite3_value_int(args[0]);
                raw.sqlite3_result_zeroblob(ctx, size);
            };

            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x blob);");
                db.create_function("createblob", 1, null, zeroblob_func);
                db.exec("INSERT INTO foo (x) VALUES(createblob(10));");

                var    rowid = db.last_insert_rowid();
                byte[] blob  = db.query_scalar <byte[]>("SELECT x FROM foo WHERE rowid=" + rowid);
                Assert.AreEqual(blob.Length, 10);
                foreach (var b in blob)
                {
                    Assert.AreEqual(b, 0);
                }
            }
        }
Beispiel #24
0
        public void test_create_table_explicit_close_v2()
        {
#if not
            // maybe we should just let this fail so we can
            // see the differences between running against the built-in
            // sqlite vs a recent version?
            if (raw.sqlite3_libversion_number() < 3007014)
            {
                return;
            }
#endif
            sqlite3 db = ugly.open(":memory:");
            db.exec("CREATE TABLE foo (x int);");
            db.close_v2();
        }
Beispiel #25
0
        public void test_stmt_complete()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x int);");

                Assert.IsTrue(raw.sqlite3_complete("SELECT x FROM") == 0);
                Assert.IsTrue(raw.sqlite3_complete("SELECT") == 0);
                Assert.IsTrue(raw.sqlite3_complete("INSERT INTO") == 0);
                Assert.IsTrue(raw.sqlite3_complete("SELECT x FROM foo") == 0);

                Assert.IsTrue(raw.sqlite3_complete("SELECT x FROM foo;") != 0);
                Assert.IsTrue(raw.sqlite3_complete("SELECT COUNT(*) FROM foo;") != 0);
                Assert.IsTrue(raw.sqlite3_complete("SELECT 5;") != 0);
            }
        }
Beispiel #26
0
 public void test_exec_with_callback()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x text);");
         db.exec("INSERT INTO foo (x) VALUES ('b')");
         db.exec("INSERT INTO foo (x) VALUES ('c')");
         db.exec("INSERT INTO foo (x) VALUES ('d')");
         db.exec("INSERT INTO foo (x) VALUES ('e')");
         db.exec("INSERT INTO foo (x) VALUES ('f')");
         string errmsg;
         work   w = new work();
         db.exec("SELECT x FROM foo", my_cb, w, out errmsg);
         Assert.AreEqual(w.count, 5);
     }
 }
Beispiel #27
0
        public void test_create_table_file()
        {
            string name;

            using (sqlite3 db = ugly.open(":memory:"))
            {
                name = "tmp" + db.query_scalar <string>("SELECT lower(hex(randomblob(16)));");
            }
            string filename;

            using (sqlite3 db = ugly.open(name))
            {
                db.exec("CREATE TABLE foo (x int);");
                filename = db.db_filename("main");
            }

            // TODO verify the filename is what we expect

            ugly.vfs__delete(null, filename, 1);
        }
Beispiel #28
0
 public void test_explicit_prepare()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x int);");
         const int num = 7;
         using (sqlite3_stmt stmt = db.prepare("INSERT INTO foo (x) VALUES (?)"))
         {
             for (int i = 0; i < num; i++)
             {
                 stmt.reset();
                 stmt.clear_bindings();
                 stmt.bind(1, i);
                 stmt.step();
             }
         }
         int c = db.query_scalar <int>("SELECT COUNT(*) FROM foo");
         Assert.AreEqual(c, num);
     }
 }
Beispiel #29
0
 public void test_collation()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.create_collation("e2a", null, my_collation);
         db.exec("CREATE TABLE foo (x text COLLATE e2a);");
         db.exec("INSERT INTO foo (x) VALUES ('b')");
         db.exec("INSERT INTO foo (x) VALUES ('c')");
         db.exec("INSERT INTO foo (x) VALUES ('d')");
         db.exec("INSERT INTO foo (x) VALUES ('e')");
         db.exec("INSERT INTO foo (x) VALUES ('f')");
         string top = db.query_scalar <string>("SELECT x FROM foo ORDER BY x ASC LIMIT 1;");
         Assert.AreEqual(top, "e");
     }
 }
        public void test_wal()
        {
            string tmpFile;

            using (sqlite3 db = ugly.open(":memory:"))
            {
                tmpFile = "tmp" + db.query_scalar <string>("SELECT lower(hex(randomblob(16)));");
            }
            using (sqlite3 db = ugly.open(tmpFile))
            {
                db.exec("PRAGMA journal_mode=WAL;");

                // CREATE TABLE results in 2 frames check pointed and increaseses the log size by 2
                // so manually do a checkpoint to reset the counters thus testing both
                // sqlite3_wal_checkpoint and sqlite3_wal_checkpoint_v2.
                db.exec("CREATE TABLE foo (x int);");
                db.wal_checkpoint("main");

                db.exec("INSERT INTO foo (x) VALUES (1);");
                db.exec("INSERT INTO foo (x) VALUES (2);");

                int logSize;
                int framesCheckPointed;
                db.wal_checkpoint("main", raw.SQLITE_CHECKPOINT_FULL, out logSize, out framesCheckPointed);

                Assert.AreEqual(2, logSize);
                Assert.AreEqual(2, framesCheckPointed);

                // Set autocheckpoint to 1 so that regardless of the number of
                // commits, explicit checkpoints only checkpoint the last update.
                db.wal_autocheckpoint(1);

                db.exec("INSERT INTO foo (x) VALUES (3);");
                db.exec("INSERT INTO foo (x) VALUES (4);");
                db.exec("INSERT INTO foo (x) VALUES (5);");
                db.wal_checkpoint("main", raw.SQLITE_CHECKPOINT_PASSIVE, out logSize, out framesCheckPointed);

                Assert.AreEqual(1, logSize);
                Assert.AreEqual(1, framesCheckPointed);
            }

            ugly.vfs__delete(null, tmpFile, 1);
        }