?? capi2.test
字號(hào):
sqlite3_finalize $VM2} {SQLITE_OK}# Check for proper SQLITE_BUSY returns.#do_test capi2-6.1 { execsql { BEGIN; CREATE TABLE t3(x counter); INSERT INTO t3 VALUES(1); INSERT INTO t3 VALUES(2); INSERT INTO t3 SELECT x+2 FROM t3; INSERT INTO t3 SELECT x+4 FROM t3; INSERT INTO t3 SELECT x+8 FROM t3; COMMIT; } set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL] sqlite3 db2 test.db execsql {BEGIN} db2} {}# Update for v3: BEGIN doesn't write-lock the database. It is quite# difficult to get v3 to write-lock the database, which causes a few# problems for test scripts.## do_test capi2-6.2 {# list [sqlite3_step $VM1] \# [sqlite3_column_count $VM1] \# [get_row_values $VM1] \# [get_column_names $VM1]# } {SQLITE_BUSY 0 {} {}}do_test capi2-6.3 { execsql {COMMIT} db2} {}do_test capi2-6.4 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 1 {x counter}}do_test capi2-6.5 { catchsql {INSERT INTO t3 VALUES(10);} db2} {1 {database is locked}}do_test capi2-6.6 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 2 {x counter}}do_test capi2-6.7 { execsql {SELECT * FROM t2} db2} {2 3 3 4 1 2}do_test capi2-6.8 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 3 {x counter}}do_test capi2-6.9 { execsql {SELECT * FROM t2} } {2 3 3 4 1 2}do_test capi2-6.10 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 4 {x counter}}do_test capi2-6.11 { execsql {BEGIN}} {}do_test capi2-6.12 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 5 {x counter}}do_test capi2-6.13 { catchsql {UPDATE t3 SET x=x+1}} {1 {database table is locked}}do_test capi2-6.14 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 6 {x counter}}do_test capi2-6.15 { execsql {SELECT * FROM t1}} {1 2 3}do_test capi2-6.16 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 7 {x counter}}do_test capi2-6.17 { catchsql {UPDATE t1 SET b=b+1}} {0 {}}do_test capi2-6.18 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 8 {x counter}}do_test capi2-6.19 { execsql {SELECT * FROM t1}} {1 3 3}do_test capi2-6.20 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 9 {x counter}}#do_test capi2-6.21 {# execsql {ROLLBACK; SELECT * FROM t1}#} {1 2 3}do_test capi2-6.22 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 10 {x counter}}#do_test capi2-6.23 {# execsql {BEGIN TRANSACTION;}#} {}do_test capi2-6.24 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 11 {x counter}}do_test capi2-6.25 { execsql { INSERT INTO t1 VALUES(2,3,4); SELECT * FROM t1; }} {1 3 3 2 3 4}do_test capi2-6.26 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 12 {x counter}}do_test capi2-6.27 { catchsql { INSERT INTO t1 VALUES(2,4,5); SELECT * FROM t1; }} {1 {column a is not unique}}do_test capi2-6.28 { list [sqlite3_step $VM1] \ [sqlite3_column_count $VM1] \ [get_row_values $VM1] \ [get_column_names $VM1]} {SQLITE_ROW 1 13 {x counter}}do_test capi2-6.99 { sqlite3_finalize $VM1} {SQLITE_OK}catchsql {ROLLBACK}do_test capi2-7.1 { stepsql $DB { SELECT * FROM t1 }} {0 1 2 3}do_test capi2-7.2 { stepsql $DB { PRAGMA count_changes=on }} {0}do_test capi2-7.3 { stepsql $DB { UPDATE t1 SET a=a+10; }} {0 1}do_test capi2-7.4 { stepsql $DB { INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1; }} {0 1}do_test capi2-7.4b {sqlite3_changes $DB} {1}do_test capi2-7.5 { stepsql $DB { UPDATE t1 SET a=a+10; }} {0 2}do_test capi2-7.5b {sqlite3_changes $DB} {2}do_test capi2-7.6 { stepsql $DB { SELECT * FROM t1; }} {0 21 2 3 22 3 4}do_test capi2-7.7 { stepsql $DB { INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1; }} {0 2}do_test capi2-7.8 { sqlite3_changes $DB} {2}do_test capi2-7.9 { stepsql $DB { SELECT * FROM t1; }} {0 21 2 3 22 3 4 23 4 5 24 5 6}do_test capi2-7.10 { stepsql $DB { UPDATE t1 SET a=a-20; SELECT * FROM t1; }} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}# Update for version 3: A SELECT statement no longer resets the change# counter (Test result changes from 0 to 4).do_test capi2-7.11 { sqlite3_changes $DB} {4}do_test capi2-7.11a { execsql {SELECT count(*) FROM t1}} {4}ifcapable {explain} { do_test capi2-7.12 {btree_breakpoint set x [stepsql $DB {EXPLAIN SELECT * FROM t1}] lindex $x 0 } {0}}# Ticket #261 - make sure we can finalize before the end of a query.#do_test capi2-8.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] sqlite3_finalize $VM1} {SQLITE_OK} # Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare# and all of the return pointers in sqlite_step can be null.#do_test capi2-9.1 { set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY] sqlite3_step $VM1 sqlite3_finalize $VM1} {SQLITE_OK}# Test that passing a NULL pointer to sqlite3_finalize() or sqlite3_reset# does not cause an error.do_test capi2-10.1 { sqlite3_finalize 0} {SQLITE_OK}do_test capi2-10.2 { sqlite3_reset 0} {SQLITE_OK}#---------------------------------------------------------------------------# The following tests - capi2-11.* - test the "column origin" APIs.## sqlite3_column_origin_name()# sqlite3_column_database_name()# sqlite3_column_table_name()#ifcapable columnmetadata {# This proc uses the database handle $::DB to compile the SQL statement passed# as a parameter. The return value of this procedure is a list with one# element for each column returned by the compiled statement. Each element of# this list is itself a list of length three, consisting of the origin# database, table and column for the corresponding returned column.proc check_origins {sql} { set ret [list] set ::STMT [sqlite3_prepare $::DB $sql -1 dummy] for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} { lappend ret [list \ [sqlite3_column_database_name $::STMT $i] \ [sqlite3_column_table_name $::STMT $i] \ [sqlite3_column_origin_name $::STMT $i] \ ] } sqlite3_finalize $::STMT return $ret}do_test capi2-11.1 { execsql { CREATE TABLE tab1(col1, col2); }} {}do_test capi2-11.2 { check_origins {SELECT col2, col1 FROM tab1}} [list {main tab1 col2} {main tab1 col1}]do_test capi2-11.3 { check_origins {SELECT col2 AS hello, col1 AS world FROM tab1}} [list {main tab1 col2} {main tab1 col1}]ifcapable subquery { do_test capi2-11.4 { check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM tab1)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-11.5 { check_origins {SELECT (SELECT col2 FROM tab1), (SELECT col1 FROM tab1)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-11.6 { check_origins {SELECT (SELECT col2), (SELECT col1) FROM tab1} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-11.7 { check_origins {SELECT * FROM tab1} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-11.8 { check_origins {SELECT * FROM (SELECT * FROM tab1)} } [list {main tab1 col1} {main tab1 col2}]}ifcapable view&&subquery { do_test capi2-12.1 { execsql { CREATE VIEW view1 AS SELECT * FROM tab1; } } {} do_test capi2-12.2 { check_origins {SELECT col2, col1 FROM view1} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-12.3 { check_origins {SELECT col2 AS hello, col1 AS world FROM view1} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-12.4 { check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view1)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-12.5 { check_origins {SELECT (SELECT col2 FROM view1), (SELECT col1 FROM view1)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-12.6 { check_origins {SELECT (SELECT col2), (SELECT col1) FROM view1} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-12.7 { check_origins {SELECT * FROM view1} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-12.8 { check_origins {select * from (select * from view1)} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-12.9 { check_origins {select * from (select * from (select * from view1))} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-12.10 { db close sqlite3 db test.db set ::DB [sqlite3_connection_pointer db] check_origins {select * from (select * from (select * from view1))} } [list {main tab1 col1} {main tab1 col2}] # This view will thwart the flattening optimization. do_test capi2-13.1 { execsql { CREATE VIEW view2 AS SELECT * FROM tab1 limit 10 offset 10; } } {} breakpoint do_test capi2-13.2 { check_origins {SELECT col2, col1 FROM view2} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-13.3 { check_origins {SELECT col2 AS hello, col1 AS world FROM view2} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-13.4 { check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view2)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-13.5 { check_origins {SELECT (SELECT col2 FROM view2), (SELECT col1 FROM view2)} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-13.6 { check_origins {SELECT (SELECT col2), (SELECT col1) FROM view2} } [list {main tab1 col2} {main tab1 col1}] do_test capi2-13.7 { check_origins {SELECT * FROM view2} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-13.8 { check_origins {select * from (select * from view2)} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-13.9 { check_origins {select * from (select * from (select * from view2))} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-13.10 { db close sqlite3 db test.db set ::DB [sqlite3_connection_pointer db] check_origins {select * from (select * from (select * from view2))} } [list {main tab1 col1} {main tab1 col2}] do_test capi2-13.11 { check_origins {select * from (select * from tab1 limit 10 offset 10)} } [list {main tab1 col1} {main tab1 col2}]}} ;# ifcapable columnmetadatadb2 closefinish_test
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -