3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script testing the callback-free C/C++ API.
14 # $Id: capi3.test,v 1.70 2009/01/09 02:49:32 drh Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 set ::testprefix capi3
21 # Do not use a codec for tests in this file, as the database file is
22 # manipulated directly using tcl scripts (using the [hexio_write] command).
26 # Return the UTF-16 representation of the supplied UTF-8 string $str.
27 # If $nt is true, append two 0x00 bytes as a nul terminator.
28 proc utf16 {str {nt 1}} {
29 set r [encoding convertto unicode $str]
36 # Return the UTF-8 representation of the supplied UTF-16 string $str.
38 # If $str ends in two 0x00 0x00 bytes, knock these off before
39 # converting to UTF-8 using TCL.
40 binary scan $str \c* vals
41 if {[lindex $vals end]==0 && [lindex $vals end-1]==0} {
42 set str [binary format \c* [lrange $vals 0 end-2]]
45 set r [encoding convertfrom unicode $str]
49 # These tests complement those in capi2.test. They are organized
52 # capi3-1.*: Test sqlite3_prepare
53 # capi3-2.*: Test sqlite3_prepare16
54 # capi3-3.*: Test sqlite3_open
55 # capi3-4.*: Test sqlite3_open16
56 # capi3-5.*: Test the various sqlite3_result_* APIs
57 # capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs.
60 set DB [sqlite3_connection_pointer db]
63 sqlite3_get_autocommit $DB
66 set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
67 sqlite3_finalize $STMT
74 sqlite3_extended_errcode $DB
80 set sql {SELECT name FROM sqlite_master;SELECT 10}
81 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
82 sqlite3_finalize $STMT
86 set sql {SELECT name FROM sqlite_master;SELECT 10}
87 set STMT [sqlite3_prepare $DB $sql [string length $sql] TAIL]
88 sqlite3_finalize $STMT
92 set sql {SELECT name FROM sqlite_master;SELECT 10}
93 set STMT [sqlite3_prepare $DB $sql [expr [string length $sql]+1] TAIL]
94 sqlite3_finalize $STMT
99 set sql {SELECT namex FROM sqlite_master}
101 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
104 do_test capi3-1.8.1 {
107 do_test capi3-1.8.2 {
108 sqlite3_extended_errcode $DB
112 } {no such column: namex}
116 set sql16 [utf16 {SELECT name FROM sqlite_master}]
117 set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL]
118 sqlite3_finalize $STMT
122 set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}]
123 set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
124 sqlite3_finalize $STMT
128 set sql [utf16 {SELECT namex FROM sqlite_master}]
130 set STMT [sqlite3_prepare16 $DB $sql -1]
133 do_test capi3-2.4.1 {
136 do_test capi3-2.4.2 {
137 sqlite3_extended_errcode $DB
141 } {no such column: namex}
143 ifcapable schema_pragmas {
145 execsql {CREATE TABLE tablename(x)}
146 set sql16 [utf16 {PRAGMA table_info("TableName"); --excess text}]
147 set STMT [sqlite3_prepare16 $DB $sql16 -1]
154 sqlite3_finalize $STMT
160 # rename sqlite3_open sqlite3_open_old
161 # proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}
164 set db2 [sqlite3_open test.db {}]
167 # FIX ME: Should test the db handle works.
173 set db2 [sqlite3_open /bogus/path/test.db {}]
175 sqlite3_extended_errcode $db2
179 } {unable to open database file}
183 if {[clang_sanitize_address]==0} {
184 do_test capi3-3.6.1-misuse {
187 do_test capi3-3.6.2-misuse {
189 } {library routine called out of sequence}
191 do_test capi3-3.6.3-misuse {
192 utf8 [sqlite3_errmsg16 $db2]
193 } {library routine called out of sequence}
198 set db2 [sqlite3_open]
205 # rename sqlite3_open ""
206 # rename sqlite3_open_old sqlite3_open
210 set db2 [sqlite3_open16 [utf16 test.db] {}]
213 # FIX ME: Should test the db handle works.
219 set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}]
224 utf8 [sqlite3_errmsg16 $db2]
225 } {unable to open database file}
231 # This proc is used to test the following API calls:
233 # sqlite3_column_count
234 # sqlite3_column_name
235 # sqlite3_column_name16
236 # sqlite3_column_decltype
237 # sqlite3_column_decltype16
239 # $STMT is a compiled SQL statement. $test is a prefix
240 # to use for test names within this proc. $names is a list
241 # of the column names that should be returned by $STMT.
242 # $decltypes is a list of column declaration types for $STMT.
246 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
247 # check_header test1.1 {1 2 3} {"" "" ""}
249 proc check_header {STMT test names decltypes} {
251 # Use the return value of sqlite3_column_count() to build
252 # a list of column indexes. i.e. If sqlite3_column_count
253 # is 3, build the list {0 1 2}.
255 set ::numcols [sqlite3_column_count $STMT]
256 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
258 # Column names in UTF-8
261 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
265 # Column names in UTF-16
270 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
276 # Column names in UTF-8
279 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
283 # Column names in UTF-16
288 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
294 # Column names in UTF-8
297 foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]}
301 # Column declaration types in UTF-16
306 lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
313 # Test some out of range conditions:
317 [sqlite3_column_name $STMT -1] \
318 [sqlite3_column_name16 $STMT -1] \
319 [sqlite3_column_decltype $STMT -1] \
320 [sqlite3_column_decltype16 $STMT -1] \
321 [sqlite3_column_name $STMT $numcols] \
322 [sqlite3_column_name16 $STMT $numcols] \
323 [sqlite3_column_decltype $STMT $numcols] \
324 [sqlite3_column_decltype16 $STMT $numcols]
325 } {{} {} {} {} {} {} {} {}}
329 # This proc is used to test the following API calls:
331 # sqlite3_column_origin_name
332 # sqlite3_column_origin_name16
333 # sqlite3_column_table_name
334 # sqlite3_column_table_name16
335 # sqlite3_column_database_name
336 # sqlite3_column_database_name16
338 # $STMT is a compiled SQL statement. $test is a prefix
339 # to use for test names within this proc. $names is a list
340 # of the column names that should be returned by $STMT.
341 # $decltypes is a list of column declaration types for $STMT.
345 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
346 # check_header test1.1 {1 2 3} {"" "" ""}
348 proc check_origin_header {STMT test dbs tables cols} {
349 # If sqlite3_column_origin_name() and friends are not compiled into
350 # this build, this proc is a no-op.
351 ifcapable columnmetadata {
352 # Use the return value of sqlite3_column_count() to build
353 # a list of column indexes. i.e. If sqlite3_column_count
354 # is 3, build the list {0 1 2}.
356 set ::numcols [sqlite3_column_count $STMT]
357 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
359 # Database names in UTF-8
363 lappend cnamelist [sqlite3_column_database_name $STMT $i]
368 # Database names in UTF-16
373 lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]]
379 # Table names in UTF-8
383 lappend cnamelist [sqlite3_column_table_name $STMT $i]
388 # Table names in UTF-16
393 lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]]
399 # Origin names in UTF-8
403 lappend cnamelist [sqlite3_column_origin_name $STMT $i]
408 # Origin declaration types in UTF-16
413 lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]]
421 # This proc is used to test the following APIs:
424 # sqlite3_column_type
426 # sqlite3_column_text
427 # sqlite3_column_text16
428 # sqlite3_column_double
430 # $STMT is a compiled SQL statement for which the previous call
431 # to sqlite3_step returned SQLITE_ROW. $test is a prefix to use
432 # for test names within this proc. $types is a list of the
433 # manifest types for the current row. $ints, $doubles and $strings
434 # are lists of the integer, real and string representations of
435 # the values in the current row.
439 # set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY]
441 # check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}}
443 proc check_data {STMT test types ints doubles strings} {
445 # Use the return value of sqlite3_column_count() to build
446 # a list of column indexes. i.e. If sqlite3_column_count
447 # is 3, build the list {0 1 2}.
449 set numcols [sqlite3_data_count $STMT]
450 for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i}
455 foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
462 foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]}
468 foreach i $::idxlist {
469 lappend lens [string length [lindex $strings $i]]
475 lappend bytes [sqlite3_column_bytes $STMT $i]
483 foreach i $::idxlist {
484 lappend lens [expr 2 * [string length [lindex $strings $i]]]
490 lappend bytes [sqlite3_column_bytes16 $STMT $i]
499 foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]}
506 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
513 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
521 foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
529 foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
536 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
543 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
550 foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
554 # Test that an out of range request returns the equivalent of NULL
556 sqlite3_column_int $STMT -1
559 sqlite3_column_text $STMT -1
564 ifcapable !floatingpoint {
571 CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
572 INSERT INTO t1 VALUES(1, 2, 3);
573 INSERT INTO t1 VALUES('one', 'two', NULL);
574 INSERT INTO t1 VALUES(1.2, 1.3, 1.4);
576 set sql "SELECT * FROM t1"
577 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
578 sqlite3_column_count $STMT
581 check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
582 check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c}
587 check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
588 check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c}
589 check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
595 check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
596 check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c}
597 check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
603 check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
604 check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c}
605 check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
612 sqlite3_finalize $STMT
616 set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a"
617 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
618 sqlite3_column_count $STMT
621 check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}}
622 check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}}
624 sqlite3_finalize $STMT
628 set sql "SELECT a AS x, sum(b) AS y, max(c) AS z FROM t1 AS m GROUP BY x"
629 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
630 sqlite3_column_count $STMT
633 check_header $STMT capi3-5.31 {x y z} {VARINT {} {}}
634 check_origin_header $STMT capi3-5.32 {main {} {}} {t1 {} {}} {a {} {}}
636 sqlite3_finalize $STMT
640 set ::ENC [execsql {pragma encoding}]
645 set DB [sqlite3_connection_pointer db]
646 if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy }
647 set sql {SELECT a FROM t1 order by rowid}
648 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
656 # 6.2 and 6.3 used to return SQLITE_ERROR and SQLITE_SCHEMA, respectively.
657 # But since attempting to close a connection no longer resets the internal
658 # schema and expires all statements, this is no longer the case.
662 #check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
664 sqlite3_finalize $STMT
667 if {[clang_sanitize_address]==0} {
668 do_test capi3-6.4-misuse {
675 # This procedure sets the value of the file-format in file 'test.db'
676 # to $newval. Also, the schema cookie is incremented.
678 proc set_file_format {newval} {
679 hexio_write test.db 44 [hexio_render_int32 $newval]
680 set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
682 hexio_write test.db 40 [hexio_render_int32 $schemacookie]
686 # This procedure returns the value of the file-format in file 'test.db'.
688 proc get_file_format {{fname test.db}} {
689 return [hexio_get_int [hexio_read $fname 44 4]]
692 if {![sqlite3 -has-codec]} {
693 # Test what happens when the library encounters a newer file format.
698 catch { sqlite3 db test.db }
700 SELECT * FROM sqlite_master;
702 } {1 {unsupported file format}}
706 if {![sqlite3 -has-codec]} {
707 # Now test that the library correctly handles bogus entries in the
708 # sqlite_master table (schema corruption).
710 forcedelete test.db test.db-journal
720 PRAGMA writable_schema=ON;
721 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
726 catch { sqlite3 db test.db }
728 SELECT * FROM sqlite_master;
730 } {1 {malformed database schema (?)}}
732 # Build a 5-field row record. The first field is a string 'table', and
733 # subsequent fields are all NULL.
735 forcedelete test.db test.db-journal
739 PRAGMA writable_schema=ON;
740 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
745 catch { sqlite3 db test.db }
747 SELECT * FROM sqlite_master;
749 } {1 {malformed database schema (?)}}
753 forcedelete test.db-journal
756 # Test the english language string equivalents for sqlite error codes
757 set code2english [list \
758 SQLITE_OK {not an error} \
759 SQLITE_ERROR {SQL logic error or missing database} \
760 SQLITE_PERM {access permission denied} \
761 SQLITE_ABORT {callback requested query abort} \
762 SQLITE_BUSY {database is locked} \
763 SQLITE_LOCKED {database table is locked} \
764 SQLITE_NOMEM {out of memory} \
765 SQLITE_READONLY {attempt to write a readonly database} \
766 SQLITE_INTERRUPT {interrupted} \
767 SQLITE_IOERR {disk I/O error} \
768 SQLITE_CORRUPT {database disk image is malformed} \
769 SQLITE_FULL {database or disk is full} \
770 SQLITE_CANTOPEN {unable to open database file} \
771 SQLITE_EMPTY {table contains no data} \
772 SQLITE_SCHEMA {database schema has changed} \
773 SQLITE_CONSTRAINT {constraint failed} \
774 SQLITE_MISMATCH {datatype mismatch} \
775 SQLITE_MISUSE {library routine called out of sequence} \
776 SQLITE_NOLFS {large file support is disabled} \
777 SQLITE_AUTH {authorization denied} \
778 SQLITE_FORMAT {auxiliary database format error} \
779 SQLITE_RANGE {bind or column index out of range} \
780 SQLITE_NOTADB {file is encrypted or is not a database} \
781 unknownerror {unknown error} \
785 foreach {code english} $code2english {
786 do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english
790 # Test the error message when a "real" out of memory occurs.
791 if { [permutation] != "nofaultsim" } {
795 set DB [sqlite3_connection_pointer db]
796 sqlite3_memdebug_fail 1
798 select * from sqlite_master;
800 } {1 {out of memory}}
806 utf8 [sqlite3_errmsg16 $::DB]
810 sqlite3_memdebug_fail -1
813 set DB [sqlite3_connection_pointer db]
814 sqlite3_memdebug_fail 1
816 select * from sqlite_master where rowid>5;
818 } {1 {out of memory}}
824 utf8 [sqlite3_errmsg16 $::DB]
828 sqlite3_memdebug_fail -1
832 # The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
833 # statement issued while there are still outstanding VMs that are part of
834 # the transaction fails.
836 set DB [sqlite3_connection_pointer db]
837 sqlite_register_test_function $DB func
841 CREATE TABLE t1(a, b);
842 INSERT INTO t1 VALUES(1, 'int');
843 INSERT INTO t1 VALUES(2, 'notatype');
846 do_test capi3-11.1.1 {
847 sqlite3_get_autocommit $DB
850 set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
854 # As of 3.6.5 a COMMIT is OK during while a query is still running -
855 # as long as it is a read-only query and not an incremental BLOB write.
857 do_test capi3-11.3.1 {
862 do_test capi3-11.3.2 {
863 sqlite3_extended_errcode $DB
865 do_test capi3-11.3.3 {
866 sqlite3_get_autocommit $DB
868 do_test capi3-11.3.4 {
869 db eval {PRAGMA lock_status}
870 } {main shared temp closed}
876 sqlite3_finalize $STMT
882 } {0 {1 int 2 notatype}}
884 sqlite3_get_autocommit $DB
889 INSERT INTO t2 VALUES(1);
890 INSERT INTO t2 VALUES(2);
892 INSERT INTO t2 VALUES(3);
895 do_test capi3-11.8.1 {
896 sqlite3_get_autocommit $DB
899 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
902 do_test capi3-11.9.1 {
903 sqlite3_get_autocommit $DB
905 do_test capi3-11.9.2 {
910 do_test capi3-11.9.3 {
911 sqlite3_get_autocommit $DB
913 do_test capi3-11.10 {
916 ifcapable !autoreset {
917 # If SQLITE_OMIT_AUTORESET is defined, then the statement must be
918 # reset() before it can be passed to step() again.
919 do_test capi3-11.11a { sqlite3_step $STMT } {SQLITE_MISUSE}
920 do_test capi3-11.11b { sqlite3_reset $STMT } {SQLITE_ABORT}
922 do_test capi3-11.11 {
925 do_test capi3-11.12 {
929 do_test capi3-11.13 {
930 sqlite3_finalize $STMT
932 do_test capi3-11.14 {
937 do_test capi3-11.14.1 {
938 sqlite3_get_autocommit $DB
940 do_test capi3-11.15 {
944 } {1 {cannot rollback - no transaction is active}}
945 do_test capi3-11.15.1 {
946 sqlite3_get_autocommit $DB
948 do_test capi3-11.16 {
954 # Sanity check on the definition of 'outstanding VM'. This means any VM
955 # that has had sqlite3_step() called more recently than sqlite3_finalize() or
956 # sqlite3_reset(). So a VM that has just been prepared or reset does not
957 # count as an active VM.
958 do_test capi3-11.17 {
963 do_test capi3-11.18 {
964 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
969 do_test capi3-11.19 {
972 do_test capi3-11.20 {
978 do_test capi3-11.20 {
983 } {1 {cannot commit - no transaction is active}}
984 do_test capi3-11.21 {
985 sqlite3_finalize $STMT
988 # The following tests - capi3-12.* - check that its Ok to start a
989 # transaction while other VMs are active, and that its Ok to execute
990 # atomic updates in the same situation
993 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
998 INSERT INTO t1 VALUES(3, NULL);
1001 do_test capi3-12.3 {
1003 INSERT INTO t2 VALUES(4);
1006 do_test capi3-12.4 {
1009 INSERT INTO t1 VALUES(4, NULL);
1012 do_test capi3-12.5 {
1015 do_test capi3-12.5.1 {
1018 do_test capi3-12.6 {
1021 do_test capi3-12.7 {
1022 sqlite3_finalize $STMT
1024 do_test capi3-12.8 {
1031 # Test cases capi3-13.* test the sqlite3_clear_bindings() and
1032 # sqlite3_sleep APIs.
1034 if {[llength [info commands sqlite3_clear_bindings]]>0} {
1035 do_test capi3-13.1 {
1039 set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL]
1042 do_test capi3-13.2 {
1044 sqlite3_bind_text $STMT 1 hello 5
1045 sqlite3_bind_text $STMT 2 world 5
1048 do_test capi3-13.3 {
1050 sqlite3_clear_bindings $STMT
1053 do_test capi3-13-4 {
1054 sqlite3_finalize $STMT
1058 } {{} {} hello world {} {}}
1060 if {[llength [info commands sqlite3_sleep]]>0} {
1061 do_test capi3-13-5 {
1062 set ms [sqlite3_sleep 80]
1063 expr {$ms==80 || $ms==1000}
1067 # Ticket #1219: Make sure binding APIs can handle a NULL pointer.
1069 if {[clang_sanitize_address]==0} {
1070 do_test capi3-14.1-misuse {
1071 set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
1076 # Ticket #1650: Honor the nBytes parameter to sqlite3_prepare.
1078 do_test capi3-15.1 {
1079 set sql {SELECT * FROM t2}
1080 set nbytes [string length $sql]
1081 append sql { WHERE a==1}
1082 set STMT [sqlite3_prepare $DB $sql $nbytes TAIL]
1084 sqlite3_column_int $STMT 0
1086 do_test capi3-15.2 {
1088 sqlite3_column_int $STMT 0
1090 do_test capi3-15.3 {
1091 sqlite3_finalize $STMT
1093 do_test capi3-15.4 {
1095 set sql {SELECT 1234567890}
1096 set STMT [sqlite3_prepare $DB $sql 8 TAIL]
1098 set v1 [sqlite3_column_int $STMT 0]
1099 sqlite3_finalize $STMT
1102 do_test capi3-15.5 {
1104 set sql {SELECT 1234567890}
1105 set STMT [sqlite3_prepare $DB $sql 9 TAIL]
1107 set v1 [sqlite3_column_int $STMT 0]
1108 sqlite3_finalize $STMT
1111 do_test capi3-15.6 {
1113 set sql {SELECT 1234567890}
1114 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1116 set v1 [sqlite3_column_int $STMT 0]
1117 sqlite3_finalize $STMT
1120 do_test capi3-15.7 {
1122 set sql {SELECT 12.34567890}
1123 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1125 set v1 [sqlite3_column_double $STMT 0]
1126 sqlite3_finalize $STMT
1129 do_test capi3-15.8 {
1131 set sql {SELECT 12.34567890}
1132 set STMT [sqlite3_prepare $DB $sql 14 TAIL]
1134 set v1 [sqlite3_column_double $STMT 0]
1135 sqlite3_finalize $STMT
1139 # Make sure code is always generated even if an IF EXISTS or
1140 # IF NOT EXISTS clause is present that the table does not or
1141 # does exists. That way we will always have a prepared statement
1142 # to expire when the schema changes.
1144 do_test capi3-16.1 {
1145 set sql {DROP TABLE IF EXISTS t3}
1146 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1147 sqlite3_finalize $STMT
1150 do_test capi3-16.2 {
1151 set sql {CREATE TABLE IF NOT EXISTS t1(x,y)}
1152 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1153 sqlite3_finalize $STMT
1157 # But still we do not generate code if there is no SQL
1159 do_test capi3-16.3 {
1160 set STMT [sqlite3_prepare $DB {} -1 TAIL]
1161 sqlite3_finalize $STMT
1164 do_test capi3-16.4 {
1165 set STMT [sqlite3_prepare $DB {;} -1 TAIL]
1166 sqlite3_finalize $STMT
1170 # Ticket #2426: Misuse of sqlite3_column_* by calling it after
1171 # a sqlite3_reset should be harmless.
1173 do_test capi3-17.1 {
1174 set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
1176 sqlite3_column_int $STMT 0
1178 do_test capi3-17.2 {
1180 sqlite3_column_int $STMT 0
1182 do_test capi3-17.3 {
1183 sqlite3_finalize $STMT
1186 # Verify that sqlite3_step() fails with an SQLITE_SCHEMA error
1187 # when the statement is prepared with sqlite3_prepare() (not
1188 # sqlite3_prepare_v2()) and the schema has changed.
1190 do_test capi3-18.1 {
1191 set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL]
1193 db2 eval {CREATE TABLE t3(x)}
1197 do_test capi3-18.2 {
1201 do_test capi3-18.3 {
1203 } {database schema has changed}
1204 # The error persist on retry when sqlite3_prepare() has been used.
1205 do_test capi3-18.4 {
1208 do_test capi3-18.5 {
1212 do_test capi3-18.6 {
1214 } {database schema has changed}
1215 sqlite3_finalize $STMT
1217 # Ticket #3134. Prepare a statement with an nBytes parameter of 0.
1218 # Make sure this works correctly and does not reference memory out of
1221 do_test capi3-19.1 {
1222 sqlite3_prepare_tkt3134 db
1225 # Test that calling sqlite3_column_blob() on a TEXT value does not change
1226 # the return type of subsequent calls to sqlite3_column_type().
1228 do_execsql_test 20.1 {
1230 INSERT INTO t4 VALUES('abcdefghij');
1233 set stmt [sqlite3_prepare db "SELECT * FROM t4" -1 dummy]
1236 do_test 20.3 { sqlite3_column_type $stmt 0 } {TEXT}
1237 do_test 20.4 { sqlite3_column_blob $stmt 0 } {abcdefghij}
1238 do_test 20.5 { sqlite3_column_type $stmt 0 } {TEXT}
1239 do_test 20.6 { sqlite3_finalize $stmt } SQLITE_OK
1242 # Tests of the interface when no VFS is registered.
1244 if {![info exists tester_do_binarylog]} {
1247 do_test capi3-20.1 {