⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capi3.test

📁 sqlite嵌入式数据库源码
💻 TEST
📖 第 1 页 / 共 2 页
字号:
ifcapable !floatingpoint {  finish_test  return}do_test capi3-5.0 {  execsql {    CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));    INSERT INTO t1 VALUES(1, 2, 3);    INSERT INTO t1 VALUES('one', 'two', NULL);    INSERT INTO t1 VALUES(1.2, 1.3, 1.4);  }  set sql "SELECT * FROM t1"  set STMT [sqlite3_prepare $DB $sql -1 TAIL]  sqlite3_column_count $STMT} 3check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c}do_test capi3-5.2 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}do_test capi3-5.5 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}do_test capi3-5.8 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}do_test capi3-5.11 {  sqlite3_step $STMT} SQLITE_DONEdo_test capi3-5.12 {  sqlite3_finalize $STMT} SQLITE_OKdo_test capi3-5.20 {  set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a"  set STMT [sqlite3_prepare $DB $sql -1 TAIL]  sqlite3_column_count $STMT} 3check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}}check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}}do_test capi3-5.23 {  sqlite3_finalize $STMT} SQLITE_OKset ::ENC [execsql {pragma encoding}]db closedo_test capi3-6.0 {btree_breakpoint  sqlite3 db test.db  set DB [sqlite3_connection_pointer db]btree_breakpoint  sqlite3_key $DB xyzzy  set sql {SELECT a FROM t1 order by rowid}  set STMT [sqlite3_prepare $DB $sql -1 TAIL]  expr 0} {0}do_test capi3-6.1 {  db cache flush  sqlite3_close $DB} {SQLITE_BUSY}do_test capi3-6.2 {  sqlite3_step $STMT} {SQLITE_ROW}check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}do_test capi3-6.3 {  sqlite3_finalize $STMT} {SQLITE_OK}do_test capi3-6.4 {  db cache flush  sqlite3_close $DB} {SQLITE_OK}db closeif {![sqlite3 -has-codec]} {  # Test what happens when the library encounters a newer file format.  # Do this by updating the file format via the btree layer.  do_test capi3-7.1 {    set ::bt [btree_open test.db 10 0]    btree_begin_transaction $::bt    set meta [btree_get_meta $::bt]    lset meta 2 5    eval [concat btree_update_meta $::bt [lrange $meta 0 end]]    btree_commit $::bt    btree_close $::bt  } {}  do_test capi3-7.2 {    sqlite3 db test.db    catchsql {      SELECT * FROM sqlite_master;    }  } {1 {unsupported file format}}  db close}if {![sqlite3 -has-codec]} {  # Now test that the library correctly handles bogus entries in the  # sqlite_master table (schema corruption).  do_test capi3-8.1 {    file delete -force test.db    file delete -force test.db-journal    sqlite3 db test.db    execsql {      CREATE TABLE t1(a);    }    db close  } {}  do_test capi3-8.2 {    set ::bt [btree_open test.db 10 0]    btree_begin_transaction $::bt    set ::bc [btree_cursor $::bt 1 1]    # Build a 5-field row record consisting of 5 null records. This is    # officially black magic.    catch {unset data}    set data [binary format c6 {6 0 0 0 0 0}]    btree_insert $::bc 5 $data    btree_close_cursor $::bc    btree_commit $::bt    btree_close $::bt  } {}  do_test capi3-8.3 {    sqlite3 db test.db    catchsql {      SELECT * FROM sqlite_master;    }  } {1 {malformed database schema}}  do_test capi3-8.4 {    set ::bt [btree_open test.db 10 0]    btree_begin_transaction $::bt    set ::bc [btree_cursor $::bt 1 1]      # Build a 5-field row record. The first field is a string 'table', and    # subsequent fields are all NULL. Replace the other broken record with    # this one and try to read the schema again. The broken record uses    # either UTF-8 or native UTF-16 (if this file is being run by    # utf16.test).    if { [string match UTF-16* $::ENC] } {      set data [binary format c6a10 {6 33 0 0 0 0} [utf16 table]]    } else {      set data [binary format c6a5 {6 23 0 0 0 0} table]    }    btree_insert $::bc 5 $data      btree_close_cursor $::bc    btree_commit $::bt    btree_close $::bt  } {};  do_test capi3-8.5 {    db close     sqlite3 db test.db    catchsql {      SELECT * FROM sqlite_master;    }  } {1 {malformed database schema}}  db close}file delete -force test.dbfile delete -force test.db-journal# Test the english language string equivalents for sqlite error codesset code2english [list \SQLITE_OK         {not an error} \SQLITE_ERROR      {SQL logic error or missing database} \SQLITE_PERM       {access permission denied} \SQLITE_ABORT      {callback requested query abort} \SQLITE_BUSY       {database is locked} \SQLITE_LOCKED     {database table is locked} \SQLITE_NOMEM      {out of memory} \SQLITE_READONLY   {attempt to write a readonly database} \SQLITE_INTERRUPT  {interrupted} \SQLITE_IOERR      {disk I/O error} \SQLITE_CORRUPT    {database disk image is malformed} \SQLITE_FULL       {database or disk is full} \SQLITE_CANTOPEN   {unable to open database file} \SQLITE_PROTOCOL   {database locking protocol failure} \SQLITE_EMPTY      {table contains no data} \SQLITE_SCHEMA     {database schema has changed} \SQLITE_CONSTRAINT {constraint failed} \SQLITE_MISMATCH   {datatype mismatch} \SQLITE_MISUSE     {library routine called out of sequence} \SQLITE_NOLFS      {kernel lacks large file support} \SQLITE_AUTH       {authorization denied} \SQLITE_FORMAT     {auxiliary database format error} \SQLITE_RANGE      {bind or column index out of range} \SQLITE_NOTADB     {file is encrypted or is not a database} \unknownerror      {unknown error} \]set test_number 1foreach {code english} $code2english {  do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english  incr test_number}# Test the error message when a "real" out of memory occurs.if {[info command sqlite_malloc_stat]!=""} {set sqlite_malloc_fail 1do_test capi3-10-1 {  sqlite3 db test.db  set DB [sqlite3_connection_pointer db]  sqlite_malloc_fail 1  catchsql {    select * from sqlite_master;  }} {1 {out of memory}}do_test capi3-10-2 {  sqlite3_errmsg $::DB} {out of memory}ifcapable {utf16} {  do_test capi3-10-3 {    utf8 [sqlite3_errmsg16 $::DB]  } {out of memory}}db closesqlite_malloc_fail 0}# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK# statement issued while there are still outstanding VMs that are part of# the transaction fails.sqlite3 db test.dbset DB [sqlite3_connection_pointer db]sqlite_register_test_function $DB funcdo_test capi3-11.1 {  execsql {    BEGIN;    CREATE TABLE t1(a, b);    INSERT INTO t1 VALUES(1, 'int');    INSERT INTO t1 VALUES(2, 'notatype');  }} {}do_test capi3-11.1.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.2 {  set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-11.3 {  catchsql {    COMMIT;  }} {1 {cannot commit transaction - SQL statements in progress}}do_test capi3-11.3.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.4 {  sqlite3_step $STMT} {SQLITE_ERROR}do_test capi3-11.5 {  sqlite3_finalize $STMT} {SQLITE_ERROR}do_test capi3-11.6 {  catchsql {    SELECT * FROM t1;  }} {0 {1 int 2 notatype}}do_test capi3-11.6.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.7 {  catchsql {    COMMIT;  }} {0 {}}do_test capi3-11.7.1 {  sqlite3_get_autocommit $DB} 1do_test capi3-11.8 {  execsql {    CREATE TABLE t2(a);    INSERT INTO t2 VALUES(1);    INSERT INTO t2 VALUES(2);    BEGIN;    INSERT INTO t2 VALUES(3);  }} {}do_test capi3-11.8.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.9 {  set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-11.9.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.9.2 {  catchsql {    ROLLBACK;  }} {1 {cannot rollback transaction - SQL statements in progress}}do_test capi3-11.9.3 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.10 {  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-11.11 {  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-11.12 {  sqlite3_step $STMT} {SQLITE_DONE}do_test capi3-11.13 {  sqlite3_finalize $STMT} {SQLITE_OK}do_test capi3-11.14 {  execsql {    SELECT a FROM t2;  }} {1 2 3}do_test capi3-11.14.1 {  sqlite3_get_autocommit $DB} 0do_test capi3-11.15 {  catchsql {    ROLLBACK;  }} {0 {}}do_test capi3-11.15.1 {  sqlite3_get_autocommit $DB} 1do_test capi3-11.16 {  execsql {    SELECT a FROM t2;  }} {1 2}# Sanity check on the definition of 'outstanding VM'. This means any VM# that has had sqlite3_step() called more recently than sqlite3_finalize() or# sqlite3_reset(). So a VM that has just been prepared or reset does not# count as an active VM.do_test capi3-11.17 {  execsql {    BEGIN;  }} {}do_test capi3-11.18 {  set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]  catchsql {    COMMIT;  }} {0 {}}do_test capi3-11.19 {  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-11.20 {  catchsql {    BEGIN;    COMMIT;  }} {1 {cannot commit transaction - SQL statements in progress}}do_test capi3-11.20 {  sqlite3_reset $STMT  catchsql {    COMMIT;  }} {0 {}}do_test capi3-11.21 {  sqlite3_finalize $STMT} {SQLITE_OK}# The following tests - capi3-12.* - check that it's Ok to start a# transaction while other VMs are active, and that it's Ok to execute# atomic updates in the same situation (so long as they are on a different# table).do_test capi3-12.1 {  set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-12.2 {  catchsql {    INSERT INTO t1 VALUES(3, NULL);  }} {0 {}}do_test capi3-12.3 {  catchsql {    INSERT INTO t2 VALUES(4);  }} {1 {database table is locked}}do_test capi3-12.4 {  catchsql {    BEGIN;    INSERT INTO t1 VALUES(4, NULL);  }} {0 {}}do_test capi3-12.5 {  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3-12.6 {  sqlite3_step $STMT} {SQLITE_DONE}do_test capi3-12.7 {  sqlite3_finalize $STMT} {SQLITE_OK}do_test capi3-12.8 {  execsql {    COMMIT;    SELECT a FROM t1;  }} {1 2 3 4}# Test cases capi3-13.* test the sqlite3_clear_bindings() and # sqlite3_sleep APIs.#if {[llength [info commands sqlite3_clear_bindings]]>0} {  do_test capi3-13.1 {    execsql {      DELETE FROM t1;    }    set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL]    sqlite3_step $STMT  } {SQLITE_DONE}  do_test capi3-13.2 {    sqlite3_reset $STMT    sqlite3_bind_text $STMT 1 hello 5    sqlite3_bind_text $STMT 2 world 5    sqlite3_step $STMT  } {SQLITE_DONE}  do_test capi3-13.3 {    sqlite3_reset $STMT    sqlite3_clear_bindings $STMT    sqlite3_step $STMT  } {SQLITE_DONE}  do_test capi3-13-4 {    sqlite3_finalize $STMT    execsql {      SELECT * FROM t1;    }  } {{} {} hello world {} {}}}if {[llength [info commands sqlite3_sleep]]>0} {  do_test capi3-13-5 {    set ms [sqlite3_sleep 80]    expr {$ms==80 || $ms==1000}  } {1}}# Ticket #1219:  Make sure binding APIs can handle a NULL pointer.#do_test capi3-14.1 {  set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]  lappend rc $msg} {1 SQLITE_MISUSE}# Ticket #1650:  Honor the nBytes parameter to sqlite3_prepare.#do_test capi3-15.1 {  set sql {SELECT * FROM t2}  set nbytes [string length $sql]  append sql { WHERE a==1}  set STMT [sqlite3_prepare $DB $sql $nbytes TAIL]  sqlite3_step $STMT  sqlite3_column_int $STMT 0} {1}do_test capi3-15.2 {  sqlite3_step $STMT  sqlite3_column_int $STMT 0} {2}do_test capi3-15.3 {  sqlite3_finalize $STMT} {SQLITE_OK}# Make sure code is always generated even if an IF EXISTS or # IF NOT EXISTS clause is present that the table does not or# does exists.  That way we will always have a prepared statement# to expire when the schema changes.#do_test capi3-16.1 {  set sql {DROP TABLE IF EXISTS t3}  set STMT [sqlite3_prepare $DB $sql -1 TAIL]  sqlite3_finalize $STMT  expr {$STMT!=""}} {1}do_test capi3-16.2 {  set sql {CREATE TABLE IF NOT EXISTS t1(x,y)}  set STMT [sqlite3_prepare $DB $sql -1 TAIL]  sqlite3_finalize $STMT  expr {$STMT!=""}} {1}# But still we do not generate code if there is no SQL#do_test capi3-16.3 {  set STMT [sqlite3_prepare $DB {} -1 TAIL]  sqlite3_finalize $STMT  expr {$STMT==""}} {1}do_test capi3-16.4 {  set STMT [sqlite3_prepare $DB {;} -1 TAIL]  sqlite3_finalize $STMT  expr {$STMT==""}} {1}finish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -