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

📄 capi3c.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
📖 第 1 页 / 共 3 页
字号:
# typesdo_test $test.1 {  set types [list]  foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}  set types} $types# Integersdo_test $test.2 {  set ints [list]  foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]}  set ints} $ints# bytesset lens [list]foreach i $::idxlist {  lappend lens [string length [lindex $strings $i]]}do_test $test.3 {  set bytes [list]  set lens [list]  foreach i $idxlist {    lappend bytes [sqlite3_column_bytes $STMT $i]  }  set bytes} $lens# bytes16ifcapable {utf16} {  set lens [list]  foreach i $::idxlist {    lappend lens [expr 2 * [string length [lindex $strings $i]]]  }  do_test $test.4 {    set bytes [list]    set lens [list]    foreach i $idxlist {      lappend bytes [sqlite3_column_bytes16 $STMT $i]    }    set bytes  } $lens}# Blobdo_test $test.5 {  set utf8 [list]  foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]}  set utf8} $strings# UTF-8do_test $test.6 {  set utf8 [list]  foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}  set utf8} $strings# Floatsdo_test $test.7 {  set utf8 [list]  foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}  set utf8} $doubles# UTF-16ifcapable {utf16} {  do_test $test.8 {    set utf8 [list]    foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}    set utf8  } $strings}# Integersdo_test $test.9 {  set ints [list]  foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}  set ints} $ints# Floatsdo_test $test.10 {  set utf8 [list]  foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}  set utf8} $doubles# UTF-8do_test $test.11 {  set utf8 [list]  foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}  set utf8} $strings# Typesdo_test $test.12 {  set types [list]  foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}  set types} $types# Test that an out of range request returns the equivalent of NULLdo_test $test.13 {  sqlite3_column_int $STMT -1} {0}do_test $test.13 {  sqlite3_column_text $STMT -1} {}}ifcapable !floatingpoint {  finish_test  return}do_test capi3c-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_v2 $DB $sql -1 TAIL]  sqlite3_column_count $STMT} 3check_header $STMT capi3c-5.1 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3c-5.1 {main main main} {t1 t1 t1} {a b c}do_test capi3c-5.2 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3c-5.3 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3c-5.3 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3c-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}do_test capi3c-5.5 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3c-5.6 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3c-5.6 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3c-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}do_test capi3c-5.8 {  sqlite3_step $STMT} SQLITE_ROWcheck_header $STMT capi3c-5.9 {a b c} {VARINT BLOB VARCHAR(16)}check_origin_header $STMT capi3c-5.9 {main main main} {t1 t1 t1} {a b c}check_data $STMT capi3c-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}do_test capi3c-5.11 {  sqlite3_step $STMT} SQLITE_DONEdo_test capi3c-5.12 {  sqlite3_finalize $STMT} SQLITE_OKdo_test capi3c-5.20 {  set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a"  set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]  sqlite3_column_count $STMT} 3check_header $STMT capi3c-5.21 {a sum(b) max(c)} {VARINT {} {}}check_origin_header $STMT capi3c-5.22 {main {} {}} {t1 {} {}} {a {} {}}do_test capi3c-5.23 {  sqlite3_finalize $STMT} SQLITE_OKset ::ENC [execsql {pragma encoding}]db closedo_test capi3c-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_v2 $DB $sql -1 TAIL]  expr 0} {0}do_test capi3c-6.1 {  db cache flush  sqlite3_close $DB} {SQLITE_BUSY}do_test capi3c-6.2 {  sqlite3_step $STMT} {SQLITE_ROW}check_data $STMT capi3c-6.3 {INTEGER} {1} {1.0} {1}do_test capi3c-6.3 {  sqlite3_finalize $STMT} {SQLITE_OK}do_test capi3c-6.4 {  db cache flush  sqlite3_close $DB} {SQLITE_OK}do_test capi3c-6.99-misuse {  db close} {}if {![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 capi3c-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 capi3c-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 capi3c-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 capi3c-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 capi3c-8.3 {    sqlite3 db test.db    catchsql {      SELECT * FROM sqlite_master;    }  } {1 {malformed database schema}}  do_test capi3c-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 capi3c-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_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 capi3c-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 capi3c-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 capi3c-10-2 {  sqlite3_errmsg $::DB} {out of memory}ifcapable {utf16} {  do_test capi3c-10-3 {    utf8 [sqlite3_errmsg16 $::DB]  } {out of memory}}db closesqlite_malloc_fail 0}# The following tests - capi3c-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 capi3c-11.1 {  execsql {    BEGIN;    CREATE TABLE t1(a, b);    INSERT INTO t1 VALUES(1, 'int');    INSERT INTO t1 VALUES(2, 'notatype');  }} {}do_test capi3c-11.1.1 {  sqlite3_get_autocommit $DB} 0do_test capi3c-11.2 {  set STMT [sqlite3_prepare_v2 $DB "SELECT func(b, a) FROM t1" -1 TAIL]  sqlite3_step $STMT} {SQLITE_ROW}do_test capi3c-11.3 {  catchsql {    COMMIT;  }} {1 {cannot commit transaction - SQL statements in progress}}do_test capi3c-11.3.1 {  sqlite3_get_autocommit $DB} 0do_test capi3c-11.4 {  sqlite3_step $STMT} {SQLITE_ERROR}do_test capi3c-11.5 {  sqlite3_finalize $STMT} {SQLITE_ERROR}do_test capi3c-11.6 {  catchsql {    SELECT * FROM t1;  }} {0 {1 int 2 notatype}}do_test capi3c-11.6.1 {  sqlite3_get_autocommit $DB} 0do_test capi3c-11.7 {  catchsql {    COMMIT;  }} {0 {}}do_test capi3c-11.7.1 {  sqlite3_get_autocommit $DB} 1do_test capi3c-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 capi3c-11.8.1 {  sqlite3_get_autocommit $DB} 0

⌨️ 快捷键说明

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