2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A# May you do good and not evil.
2N/A# May you find forgiveness for yourself and forgive others.
2N/A# May you share freely, never taking more than you give.
2N/A#***********************************************************************
2N/A# This file implements regression tests for SQLite library. The
2N/A# focus of this script testing the callback-free C/C++ API.
2N/Aset testdir [file dirname $argv0]
2N/A# Check basic functionality
2N/A execsql {CREATE TABLE t1(a,b,c)}
2N/A set VM [sqlite_compile $DB {SELECT name, rowid FROM sqlite_master} TAIL]
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A} {name rowid text INTEGER}
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A list $N $VALUES $COLNAMES
2N/A} {2 {} {name rowid text INTEGER}}
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A list $N $VALUES $COLNAMES
2N/A# Check to make sure that the "tail" of a multi-statement SQL script
2N/A# is returned by sqlite_compile.
2N/A SELECT name, rowid FROM sqlite_master;
2N/A SELECT name, rowid FROM sqlite_temp_master;
2N/A -- A comment at the end
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A SELECT name, rowid FROM sqlite_temp_master;
2N/A -- A comment at the end
2N/A set r [sqlite_step $VM n val colname]
2N/A lappend r $n $val $colname
2N/A} {SQLITE_ROW 2 {t1 1} {name rowid text INTEGER}}
2N/A set r [sqlite_step $VM n val colname]
2N/A lappend r $n $val $colname
2N/A} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A -- A comment at the end
2N/A set r [sqlite_step $VM n val colname]
2N/A lappend r $n $val $colname
2N/A} {SQLITE_DONE 2 {} {name rowid text INTEGER}}
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A# Check the error handling.
2N/A sqlite_compile $DB {select bogus from sqlite_master} TAIL
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {}}
2N/A sqlite_compile $DB {select bogus from } TAIL
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) near " ": syntax error} {}}
2N/A sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {}}
2N/A sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {x;}}
2N/A sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {;;x;}}
2N/A sqlite_compile $DB {select 5/0} TAIL
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
2N/A execsql {CREATE UNIQUE INDEX i1 ON t1(a)}
2N/A set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,2,3)} TAIL]
2N/Ado_test capi2-3.9b {db changes} {0}
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/Ado_test capi2-3.10b {db changes} {1}
2N/Ado_test capi2-3.11b {db changes} {1}
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {1 {(21) library routine called out of sequence}}
2N/A set VM [sqlite_compile $DB {INSERT INTO t1 VALUES(1,3,4)} TAIL]
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ERROR 0 {} {}}
2N/Ado_test capi2-3.13b {db changes} {0}
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {1 {(19) column a is not unique}}
2N/A set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A set VM [sqlite_compile $DB {INSERT INTO t2 VALUES(NULL,2)} TAIL]
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ERROR 0 {} {}}
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A# Two or more virtual machines exists at the same time.
2N/A set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
2N/A set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
2N/A set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
2N/A list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A list [catch {sqlite_finalize $VM2} msg] [set msg]
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A list [catch {sqlite_finalize $VM3} msg] [set msg]
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A# Interleaved SELECTs
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
2N/A set VM2 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
2N/A set VM3 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {2 3} {a b {} {}}}
2N/A list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {2 3} {a b {} {}}}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {3 4} {a b {} {}}}
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {2 3} {a b {} {}}}
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {3 4} {a b {} {}}}
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {1 2} {a b {} {}}}
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 2 {} {a b {} {}}}
2N/A list [catch {sqlite_finalize $VM3} msg] [set msg]
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {1 2} {a b {} {}}}
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {3 4} {a b {} {}}}
2N/A list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 2 {1 2} {a b {} {}}}
2N/A list [catch {sqlite_finalize $VM2} msg] [set msg]
2N/A# Check for proper SQLITE_BUSY returns.
2N/A CREATE TABLE t3(x counter);
2N/A INSERT INTO t3 VALUES(1);
2N/A INSERT INTO t3 VALUES(2);
2N/A INSERT INTO t3 SELECT x+2 FROM t3;
2N/A INSERT INTO t3 SELECT x+4 FROM t3;
2N/A INSERT INTO t3 SELECT x+8 FROM t3;
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_BUSY 0 {} {}}
2N/A execsql {COMMIT} db2
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 1 {x counter}}
2N/A catchsql {BEGIN} db2
2N/A} {1 {database is locked}}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 2 {x counter}}
2N/A execsql {SELECT * FROM t2} db2
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 3 {x counter}}
2N/A execsql {SELECT * FROM t2}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 4 {x counter}}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 5 {x counter}}
2N/A# execsql {pragma vdbe_trace=on}
2N/A catchsql {UPDATE t3 SET x=x+1}
2N/A} {1 {database table is locked}}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 6 {x counter}}
2N/A# puts [list [catch {sqlite_finalize $VM1} msg] [set msg]]; exit
2N/A execsql {SELECT * FROM t1}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 7 {x counter}}
2N/A catchsql {UPDATE t1 SET b=b+1}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 8 {x counter}}
2N/A execsql {SELECT * FROM t1}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 9 {x counter}}
2N/A execsql {ROLLBACK; SELECT * FROM t1}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 10 {x counter}}
2N/A execsql {BEGIN TRANSACTION ON CONFLICT ROLLBACK;}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 11 {x counter}}
2N/A INSERT INTO t1 VALUES(2,3,4);
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 12 {x counter}}
2N/A INSERT INTO t1 VALUES(2,4,5);
2N/A} {1 {column a is not unique}}
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 13 {x counter}}
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A PRAGMA count_changes=on
2N/A UPDATE t1 SET a=a+10;
2N/A INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
2N/Ado_test capi2-7.4b {db changes} {1}
2N/A UPDATE t1 SET a=a+10;
2N/Ado_test capi2-7.5b {db changes} {2}
2N/A INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
2N/A} {0 21 2 3 22 3 4 23 4 5 24 5 6}
2N/A UPDATE t1 SET a=a-20;
2N/A} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
2N/A set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
2N/A# Ticket #261 - make sure we can finalize before the end of a query.
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
2N/A sqlite_finalize $VM1
2N/A# Tickets #384 and #385 - make sure the TAIL argument to sqlite_compile
2N/A# and all of the return pointers in sqlite_step can be null.
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
2N/A sqlite_finalize $VM1