capi2.test revision 2
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A# 2003 January 29
2N/A#
2N/A# The author disclaims copyright to this source code. In place of
2N/A# a legal notice, here is a blessing:
2N/A#
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#***********************************************************************
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/A#
2N/A# $Id: capi2.test,v 1.10 2003/08/05 13:13:38 drh Exp $
2N/A#
2N/A
2N/Aset testdir [file dirname $argv0]
2N/Asource $testdir/tester.tcl
2N/A
2N/A# Check basic functionality
2N/A#
2N/Ado_test capi2-1.1 {
2N/A db close
2N/A set DB [sqlite db test.db]
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 set TAIL
2N/A} {}
2N/Ado_test capi2-1.2 {
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A} {SQLITE_ROW}
2N/Ado_test capi2-1.3 {
2N/A set N
2N/A} {2}
2N/Ado_test capi2-1.4 {
2N/A set VALUES
2N/A} {t1 1}
2N/Ado_test capi2-1.5 {
2N/A set COLNAMES
2N/A} {name rowid text INTEGER}
2N/Ado_test capi2-1.6 {
2N/A set N x
2N/A set VALUES y
2N/A set COLNAMES z
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A} {SQLITE_DONE}
2N/Ado_test capi2-1.7 {
2N/A list $N $VALUES $COLNAMES
2N/A} {2 {} {name rowid text INTEGER}}
2N/Ado_test capi2-1.8 {
2N/A set N x
2N/A set VALUES y
2N/A set COLNAMES z
2N/A sqlite_step $VM N VALUES COLNAMES
2N/A} {SQLITE_MISUSE}
2N/Ado_test capi2-1.9 {
2N/A list $N $VALUES $COLNAMES
2N/A} {0 {} {}}
2N/Ado_test capi2-1.10 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/A
2N/A# Check to make sure that the "tail" of a multi-statement SQL script
2N/A# is returned by sqlite_compile.
2N/A#
2N/Ado_test capi2-2.1 {
2N/A set SQL {
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 }
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A set SQL
2N/A} {
2N/A SELECT name, rowid FROM sqlite_temp_master;
2N/A -- A comment at the end
2N/A }
2N/Ado_test capi2-2.2 {
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/Ado_test capi2-2.3 {
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/Ado_test capi2-2.4 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/Ado_test capi2-2.5 {
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A set SQL
2N/A} {
2N/A -- A comment at the end
2N/A }
2N/Ado_test capi2-2.6 {
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/Ado_test capi2-2.7 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/Ado_test capi2-2.8 {
2N/A set VM [sqlite_compile $DB $SQL SQL]
2N/A list $SQL $VM
2N/A} {{} {}}
2N/A
2N/A# Check the error handling.
2N/A#
2N/Ado_test capi2-3.1 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {select bogus from sqlite_master} TAIL
2N/A } msg]
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {}}
2N/Ado_test capi2-3.2 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {select bogus from } TAIL
2N/A } msg]
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) near " ": syntax error} {}}
2N/Ado_test capi2-3.3 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {;;;;select bogus from sqlite_master} TAIL
2N/A } msg]
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {}}
2N/Ado_test capi2-3.4 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {select bogus from sqlite_master;x;} TAIL
2N/A } msg]
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {x;}}
2N/Ado_test capi2-3.5 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {select bogus from sqlite_master;;;x;} TAIL
2N/A } msg]
2N/A lappend rc $msg $TAIL
2N/A} {1 {(1) no such column: bogus} {;;x;}}
2N/Ado_test capi2-3.6 {
2N/A set rc [catch {
2N/A sqlite_compile $DB {select 5/0} TAIL
2N/A } VM]
2N/A lappend rc $TAIL
2N/A} {0 {}}
2N/Ado_test capi2-3.7 {
2N/A set N {}
2N/A set VALUE {}
2N/A set COLNAME {}
2N/A list [sqlite_step $VM N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 {{}} {5/0 NUMERIC}}
2N/Ado_test capi2-3.8 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/Ado_test capi2-3.9 {
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/A set TAIL
2N/A} {}
2N/Ado_test capi2-3.9b {db changes} {0}
2N/Ado_test capi2-3.10 {
2N/A set N {}
2N/A set VALUE {}
2N/A set COLNAME {}
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.11 {
2N/A sqlite_finalize $VM
2N/A} {}
2N/Ado_test capi2-3.11b {db changes} {1}
2N/Ado_test capi2-3.12 {
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {1 {(21) library routine called out of sequence}}
2N/Ado_test capi2-3.13 {
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/Ado_test capi2-3.14 {
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {1 {(19) column a is not unique}}
2N/Ado_test capi2-3.15 {
2N/A set VM [sqlite_compile $DB {CREATE TABLE t2(a NOT NULL, b)} TAIL]
2N/A set TAIL
2N/A} {}
2N/Ado_test capi2-3.16 {
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.17 {
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {0 {}}
2N/Ado_test capi2-3.18 {
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/Ado_test capi2-3.19 {
2N/A list [catch {sqlite_finalize $VM} msg] [set msg]
2N/A} {1 {(19) t2.a may not be NULL}}
2N/A
2N/A# Two or more virtual machines exists at the same time.
2N/A#
2N/Ado_test capi2-4.1 {
2N/A set VM1 [sqlite_compile $DB {INSERT INTO t2 VALUES(1,2)} TAIL]
2N/A set TAIL
2N/A} {}
2N/Ado_test capi2-4.2 {
2N/A set VM2 [sqlite_compile $DB {INSERT INTO t2 VALUES(2,3)} TAIL]
2N/A set TAIL
2N/A} {}
2N/Ado_test capi2-4.3 {
2N/A set VM3 [sqlite_compile $DB {INSERT INTO t2 VALUES(3,4)} TAIL]
2N/A set TAIL
2N/A} {}
2N/Ado_test capi2-4.4 {
2N/A list [sqlite_step $VM2 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/Ado_test capi2-4.5 {
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A} {2 3}
2N/Ado_test capi2-4.6 {
2N/A list [catch {sqlite_finalize $VM2} msg] [set msg]
2N/A} {0 {}}
2N/Ado_test capi2-4.7 {
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/Ado_test capi2-4.8 {
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A} {2 3 3 4}
2N/Ado_test capi2-4.9 {
2N/A list [catch {sqlite_finalize $VM3} msg] [set msg]
2N/A} {0 {}}
2N/Ado_test capi2-4.10 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 0 {} {}}
2N/Ado_test capi2-4.11 {
2N/A execsql {SELECT * FROM t2 ORDER BY a}
2N/A} {1 2 2 3 3 4}
2N/Ado_test capi2-4.12 {
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A} {0 {}}
2N/A
2N/A# Interleaved SELECTs
2N/A#
2N/Ado_test capi2-5.1 {
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/Ado_test capi2-5.2 {
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/Ado_test capi2-5.3 {
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/Ado_test capi2-5.4 {
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/Ado_test capi2-5.5 {
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/Ado_test capi2-5.6 {
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/Ado_test capi2-5.7 {
2N/A list [sqlite_step $VM3 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_DONE 2 {} {a b {} {}}}
2N/Ado_test capi2-5.8 {
2N/A list [catch {sqlite_finalize $VM3} msg] [set msg]
2N/A} {0 {}}
2N/Ado_test capi2-5.9 {
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/Ado_test capi2-5.10 {
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A} {0 {}}
2N/Ado_test capi2-5.11 {
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/Ado_test capi2-5.12 {
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/Ado_test capi2-5.11 {
2N/A list [catch {sqlite_finalize $VM2} msg] [set msg]
2N/A} {0 {}}
2N/A
2N/A# Check for proper SQLITE_BUSY returns.
2N/A#
2N/Ado_test capi2-6.1 {
2N/A execsql {
2N/A BEGIN;
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 COMMIT;
2N/A }
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t3} TAIL]
2N/A sqlite db2 test.db
2N/A execsql {BEGIN} db2
2N/A} {}
2N/Ado_test capi2-6.2 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_BUSY 0 {} {}}
2N/Ado_test capi2-6.3 {
2N/A execsql {COMMIT} db2
2N/A} {}
2N/Ado_test capi2-6.4 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 1 {x counter}}
2N/Ado_test capi2-6.5 {
2N/A catchsql {BEGIN} db2
2N/A} {1 {database is locked}}
2N/Ado_test capi2-6.6 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 2 {x counter}}
2N/Ado_test capi2-6.7 {
2N/A execsql {SELECT * FROM t2} db2
2N/A} {2 3 3 4 1 2}
2N/Ado_test capi2-6.8 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 3 {x counter}}
2N/Ado_test capi2-6.9 {
2N/A execsql {SELECT * FROM t2}
2N/A} {2 3 3 4 1 2}
2N/Ado_test capi2-6.10 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 4 {x counter}}
2N/Ado_test capi2-6.11 {
2N/A execsql {BEGIN}
2N/A} {}
2N/Ado_test capi2-6.12 {
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/Ado_test capi2-6.13 {
2N/A catchsql {UPDATE t3 SET x=x+1}
2N/A} {1 {database table is locked}}
2N/Ado_test capi2-6.14 {
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/Ado_test capi2-6.15 {
2N/A execsql {SELECT * FROM t1}
2N/A} {1 2 3}
2N/Ado_test capi2-6.16 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 7 {x counter}}
2N/Ado_test capi2-6.17 {
2N/A catchsql {UPDATE t1 SET b=b+1}
2N/A} {0 {}}
2N/Ado_test capi2-6.18 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 8 {x counter}}
2N/Ado_test capi2-6.19 {
2N/A execsql {SELECT * FROM t1}
2N/A} {1 3 3}
2N/Ado_test capi2-6.20 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 9 {x counter}}
2N/Ado_test capi2-6.21 {
2N/A execsql {ROLLBACK; SELECT * FROM t1}
2N/A} {1 2 3}
2N/Ado_test capi2-6.22 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 10 {x counter}}
2N/Ado_test capi2-6.23 {
2N/A execsql {BEGIN TRANSACTION ON CONFLICT ROLLBACK;}
2N/A} {}
2N/Ado_test capi2-6.24 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 11 {x counter}}
2N/Ado_test capi2-6.25 {
2N/A execsql {
2N/A INSERT INTO t1 VALUES(2,3,4);
2N/A SELECT * FROM t1;
2N/A }
2N/A} {1 2 3 2 3 4}
2N/Ado_test capi2-6.26 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 12 {x counter}}
2N/Ado_test capi2-6.27 {
2N/A catchsql {
2N/A INSERT INTO t1 VALUES(2,4,5);
2N/A SELECT * FROM t1;
2N/A }
2N/A} {1 {column a is not unique}}
2N/Ado_test capi2-6.28 {
2N/A list [sqlite_step $VM1 N VALUE COLNAME] [set N] [set VALUE] [set COLNAME]
2N/A} {SQLITE_ROW 1 13 {x counter}}
2N/Ado_test capi2-6.99 {
2N/A list [catch {sqlite_finalize $VM1} msg] [set msg]
2N/A} {0 {}}
2N/Acatchsql {ROLLBACK}
2N/A
2N/Ado_test capi2-7.1 {
2N/A stepsql $DB {
2N/A SELECT * FROM t1
2N/A }
2N/A} {0 1 2 3}
2N/Ado_test capi2-7.2 {
2N/A stepsql $DB {
2N/A PRAGMA count_changes=on
2N/A }
2N/A} {0}
2N/Ado_test capi2-7.3 {
2N/A stepsql $DB {
2N/A UPDATE t1 SET a=a+10;
2N/A }
2N/A} {0 1}
2N/Ado_test capi2-7.4 {
2N/A stepsql $DB {
2N/A INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1;
2N/A }
2N/A} {0 1}
2N/Ado_test capi2-7.4b {db changes} {1}
2N/Ado_test capi2-7.5 {
2N/A stepsql $DB {
2N/A UPDATE t1 SET a=a+10;
2N/A }
2N/A} {0 2}
2N/Ado_test capi2-7.5b {db changes} {2}
2N/Ado_test capi2-7.6 {
2N/A stepsql $DB {
2N/A SELECT * FROM t1;
2N/A }
2N/A} {0 21 2 3 22 3 4}
2N/Ado_test capi2-7.7 {
2N/A stepsql $DB {
2N/A INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1;
2N/A }
2N/A} {0 2}
2N/Ado_test capi2-7.8 {
2N/A db changes
2N/A} {2}
2N/Ado_test capi2-7.9 {
2N/A stepsql $DB {
2N/A SELECT * FROM t1;
2N/A }
2N/A} {0 21 2 3 22 3 4 23 4 5 24 5 6}
2N/Ado_test capi2-7.10 {
2N/A stepsql $DB {
2N/A UPDATE t1 SET a=a-20;
2N/A SELECT * FROM t1;
2N/A }
2N/A} {0 4 1 2 3 2 3 4 3 4 5 4 5 6}
2N/Ado_test capi2-7.11 {
2N/A db changes
2N/A} {0}
2N/Ado_test capi2-7.12 {
2N/A set x [stepsql $DB {EXPLAIN SELECT * FROM t1}]
2N/A lindex $x 0
2N/A} {0}
2N/A
2N/A# Ticket #261 - make sure we can finalize before the end of a query.
2N/A#
2N/Ado_test capi2-8.1 {
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t2} TAIL]
2N/A sqlite_finalize $VM1
2N/A} {}
2N/A
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#
2N/Ado_test capi2-9.1 {
2N/A set VM1 [sqlite_compile $DB {SELECT * FROM t2}]
2N/A sqlite_step $VM1
2N/A sqlite_finalize $VM1
2N/A} {}
2N/A
2N/Adb2 close
2N/A
2N/Afinish_test