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
20 # Do not use a codec for tests in this file, as the database file is
21 # manipulated directly using tcl scripts (using the [hexio_write] command).
25 # Return the UTF-16 representation of the supplied UTF-8 string $str.
26 # If $nt is true, append two 0x00 bytes as a nul terminator.
27 proc utf16 {str {nt 1}} {
28 set r [encoding convertto unicode $str]
35 # Return the UTF-8 representation of the supplied UTF-16 string $str.
37 # If $str ends in two 0x00 0x00 bytes, knock these off before
38 # converting to UTF-8 using TCL.
39 binary scan $str \c* vals
40 if {[lindex $vals end]==0 && [lindex $vals end-1]==0} {
41 set str [binary format \c* [lrange $vals 0 end-2]]
44 set r [encoding convertfrom unicode $str]
48 # These tests complement those in capi2.test. They are organized
51 # capi3-1.*: Test sqlite3_prepare
52 # capi3-2.*: Test sqlite3_prepare16
53 # capi3-3.*: Test sqlite3_open
54 # capi3-4.*: Test sqlite3_open16
55 # capi3-5.*: Test the various sqlite3_result_* APIs
56 # capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs.
59 set DB [sqlite3_connection_pointer db]
62 sqlite3_get_autocommit $DB
65 set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL]
66 sqlite3_finalize $STMT
73 sqlite3_extended_errcode $DB
79 set sql {SELECT name FROM sqlite_master;SELECT 10}
80 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
81 sqlite3_finalize $STMT
85 set sql {SELECT name FROM sqlite_master;SELECT 10}
86 set STMT [sqlite3_prepare $DB $sql [string length $sql] TAIL]
87 sqlite3_finalize $STMT
91 set sql {SELECT name FROM sqlite_master;SELECT 10}
92 set STMT [sqlite3_prepare $DB $sql [expr [string length $sql]+1] TAIL]
93 sqlite3_finalize $STMT
98 set sql {SELECT namex FROM sqlite_master}
100 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
103 do_test capi3-1.8.1 {
106 do_test capi3-1.8.2 {
107 sqlite3_extended_errcode $DB
111 } {no such column: namex}
115 set sql16 [utf16 {SELECT name FROM sqlite_master}]
116 set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL]
117 sqlite3_finalize $STMT
121 set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}]
122 set STMT [sqlite3_prepare16 $DB $sql -1 TAIL]
123 sqlite3_finalize $STMT
127 set sql [utf16 {SELECT namex FROM sqlite_master}]
129 set STMT [sqlite3_prepare16 $DB $sql -1]
132 do_test capi3-2.4.1 {
135 do_test capi3-2.4.2 {
136 sqlite3_extended_errcode $DB
140 } {no such column: namex}
142 ifcapable schema_pragmas {
144 execsql {CREATE TABLE tablename(x)}
145 set sql16 [utf16 {PRAGMA table_info("TableName"); --excess text}]
146 set STMT [sqlite3_prepare16 $DB $sql16 -1]
153 sqlite3_finalize $STMT
159 # rename sqlite3_open sqlite3_open_old
160 # proc sqlite3_open {fname options} {sqlite3_open_new $fname $options}
163 set db2 [sqlite3_open test.db {}]
166 # FIX ME: Should test the db handle works.
172 set db2 [sqlite3_open /bogus/path/test.db {}]
174 sqlite3_extended_errcode $db2
178 } {unable to open database file}
182 do_test capi3-3.6.1-misuse {
185 do_test capi3-3.6.2-misuse {
187 } {library routine called out of sequence}
189 do_test capi3-3.6.3-misuse {
190 utf8 [sqlite3_errmsg16 $db2]
191 } {library routine called out of sequence}
195 set db2 [sqlite3_open]
202 # rename sqlite3_open ""
203 # rename sqlite3_open_old sqlite3_open
207 set db2 [sqlite3_open16 [utf16 test.db] {}]
210 # FIX ME: Should test the db handle works.
216 set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}]
221 utf8 [sqlite3_errmsg16 $db2]
222 } {unable to open database file}
228 # This proc is used to test the following API calls:
230 # sqlite3_column_count
231 # sqlite3_column_name
232 # sqlite3_column_name16
233 # sqlite3_column_decltype
234 # sqlite3_column_decltype16
236 # $STMT is a compiled SQL statement. $test is a prefix
237 # to use for test names within this proc. $names is a list
238 # of the column names that should be returned by $STMT.
239 # $decltypes is a list of column declaration types for $STMT.
243 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
244 # check_header test1.1 {1 2 3} {"" "" ""}
246 proc check_header {STMT test names decltypes} {
248 # Use the return value of sqlite3_column_count() to build
249 # a list of column indexes. i.e. If sqlite3_column_count
250 # is 3, build the list {0 1 2}.
252 set ::numcols [sqlite3_column_count $STMT]
253 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
255 # Column names in UTF-8
258 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
262 # Column names in UTF-16
267 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
273 # Column names in UTF-8
276 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
280 # Column names in UTF-16
285 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
291 # Column names in UTF-8
294 foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]}
298 # Column declaration types in UTF-16
303 lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
310 # Test some out of range conditions:
314 [sqlite3_column_name $STMT -1] \
315 [sqlite3_column_name16 $STMT -1] \
316 [sqlite3_column_decltype $STMT -1] \
317 [sqlite3_column_decltype16 $STMT -1] \
318 [sqlite3_column_name $STMT $numcols] \
319 [sqlite3_column_name16 $STMT $numcols] \
320 [sqlite3_column_decltype $STMT $numcols] \
321 [sqlite3_column_decltype16 $STMT $numcols]
322 } {{} {} {} {} {} {} {} {}}
326 # This proc is used to test the following API calls:
328 # sqlite3_column_origin_name
329 # sqlite3_column_origin_name16
330 # sqlite3_column_table_name
331 # sqlite3_column_table_name16
332 # sqlite3_column_database_name
333 # sqlite3_column_database_name16
335 # $STMT is a compiled SQL statement. $test is a prefix
336 # to use for test names within this proc. $names is a list
337 # of the column names that should be returned by $STMT.
338 # $decltypes is a list of column declaration types for $STMT.
342 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
343 # check_header test1.1 {1 2 3} {"" "" ""}
345 proc check_origin_header {STMT test dbs tables cols} {
346 # If sqlite3_column_origin_name() and friends are not compiled into
347 # this build, this proc is a no-op.
348 ifcapable columnmetadata {
349 # Use the return value of sqlite3_column_count() to build
350 # a list of column indexes. i.e. If sqlite3_column_count
351 # is 3, build the list {0 1 2}.
353 set ::numcols [sqlite3_column_count $STMT]
354 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
356 # Database names in UTF-8
360 lappend cnamelist [sqlite3_column_database_name $STMT $i]
365 # Database names in UTF-16
370 lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]]
376 # Table names in UTF-8
380 lappend cnamelist [sqlite3_column_table_name $STMT $i]
385 # Table names in UTF-16
390 lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]]
396 # Origin names in UTF-8
400 lappend cnamelist [sqlite3_column_origin_name $STMT $i]
405 # Origin declaration types in UTF-16
410 lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]]
418 # This proc is used to test the following APIs:
421 # sqlite3_column_type
423 # sqlite3_column_text
424 # sqlite3_column_text16
425 # sqlite3_column_double
427 # $STMT is a compiled SQL statement for which the previous call
428 # to sqlite3_step returned SQLITE_ROW. $test is a prefix to use
429 # for test names within this proc. $types is a list of the
430 # manifest types for the current row. $ints, $doubles and $strings
431 # are lists of the integer, real and string representations of
432 # the values in the current row.
436 # set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY]
438 # check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}}
440 proc check_data {STMT test types ints doubles strings} {
442 # Use the return value of sqlite3_column_count() to build
443 # a list of column indexes. i.e. If sqlite3_column_count
444 # is 3, build the list {0 1 2}.
446 set numcols [sqlite3_data_count $STMT]
447 for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i}
452 foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
459 foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]}
465 foreach i $::idxlist {
466 lappend lens [string length [lindex $strings $i]]
472 lappend bytes [sqlite3_column_bytes $STMT $i]
480 foreach i $::idxlist {
481 lappend lens [expr 2 * [string length [lindex $strings $i]]]
487 lappend bytes [sqlite3_column_bytes16 $STMT $i]
496 foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]}
503 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
510 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
518 foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
526 foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
533 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
540 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
547 foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
551 # Test that an out of range request returns the equivalent of NULL
553 sqlite3_column_int $STMT -1
556 sqlite3_column_text $STMT -1
561 ifcapable !floatingpoint {
568 CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
569 INSERT INTO t1 VALUES(1, 2, 3);
570 INSERT INTO t1 VALUES('one', 'two', NULL);
571 INSERT INTO t1 VALUES(1.2, 1.3, 1.4);
573 set sql "SELECT * FROM t1"
574 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
575 sqlite3_column_count $STMT
578 check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
579 check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c}
584 check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
585 check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c}
586 check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
592 check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
593 check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c}
594 check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
600 check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
601 check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c}
602 check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
609 sqlite3_finalize $STMT
613 set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a"
614 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
615 sqlite3_column_count $STMT
618 check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}}
619 check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}}
621 sqlite3_finalize $STMT
625 set sql "SELECT a AS x, sum(b) AS y, max(c) AS z FROM t1 AS m GROUP BY x"
626 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
627 sqlite3_column_count $STMT
630 check_header $STMT capi3-5.31 {x y z} {VARINT {} {}}
631 check_origin_header $STMT capi3-5.32 {main {} {}} {t1 {} {}} {a {} {}}
633 sqlite3_finalize $STMT
637 set ::ENC [execsql {pragma encoding}]
642 set DB [sqlite3_connection_pointer db]
643 if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy }
644 set sql {SELECT a FROM t1 order by rowid}
645 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
655 #check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
657 sqlite3_finalize $STMT
659 do_test capi3-6.4-misuse {
665 # This procedure sets the value of the file-format in file 'test.db'
666 # to $newval. Also, the schema cookie is incremented.
668 proc set_file_format {newval} {
669 hexio_write test.db 44 [hexio_render_int32 $newval]
670 set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
672 hexio_write test.db 40 [hexio_render_int32 $schemacookie]
676 # This procedure returns the value of the file-format in file 'test.db'.
678 proc get_file_format {{fname test.db}} {
679 return [hexio_get_int [hexio_read $fname 44 4]]
682 if {![sqlite3 -has-codec]} {
683 # Test what happens when the library encounters a newer file format.
688 catch { sqlite3 db test.db }
690 SELECT * FROM sqlite_master;
692 } {1 {unsupported file format}}
696 if {![sqlite3 -has-codec]} {
697 # Now test that the library correctly handles bogus entries in the
698 # sqlite_master table (schema corruption).
700 file delete -force test.db test.db-journal
710 PRAGMA writable_schema=ON;
711 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
716 catch { sqlite3 db test.db }
718 SELECT * FROM sqlite_master;
720 } {1 {malformed database schema (?)}}
722 # Build a 5-field row record. The first field is a string 'table', and
723 # subsequent fields are all NULL.
725 file delete -force test.db test.db-journal
729 PRAGMA writable_schema=ON;
730 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
735 catch { sqlite3 db test.db }
737 SELECT * FROM sqlite_master;
739 } {1 {malformed database schema (?)}}
742 file delete -force test.db
743 file delete -force test.db-journal
746 # Test the english language string equivalents for sqlite error codes
747 set code2english [list \
748 SQLITE_OK {not an error} \
749 SQLITE_ERROR {SQL logic error or missing database} \
750 SQLITE_PERM {access permission denied} \
751 SQLITE_ABORT {callback requested query abort} \
752 SQLITE_BUSY {database is locked} \
753 SQLITE_LOCKED {database table is locked} \
754 SQLITE_NOMEM {out of memory} \
755 SQLITE_READONLY {attempt to write a readonly database} \
756 SQLITE_INTERRUPT {interrupted} \
757 SQLITE_IOERR {disk I/O error} \
758 SQLITE_CORRUPT {database disk image is malformed} \
759 SQLITE_FULL {database or disk is full} \
760 SQLITE_CANTOPEN {unable to open database file} \
761 SQLITE_EMPTY {table contains no data} \
762 SQLITE_SCHEMA {database schema has changed} \
763 SQLITE_CONSTRAINT {constraint failed} \
764 SQLITE_MISMATCH {datatype mismatch} \
765 SQLITE_MISUSE {library routine called out of sequence} \
766 SQLITE_NOLFS {large file support is disabled} \
767 SQLITE_AUTH {authorization denied} \
768 SQLITE_FORMAT {auxiliary database format error} \
769 SQLITE_RANGE {bind or column index out of range} \
770 SQLITE_NOTADB {file is encrypted or is not a database} \
771 unknownerror {unknown error} \
775 foreach {code english} $code2english {
776 do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english
780 # Test the error message when a "real" out of memory occurs.
784 set DB [sqlite3_connection_pointer db]
785 sqlite3_memdebug_fail 1
787 select * from sqlite_master;
789 } {1 {out of memory}}
795 utf8 [sqlite3_errmsg16 $::DB]
799 sqlite3_memdebug_fail -1
802 set DB [sqlite3_connection_pointer db]
803 sqlite3_memdebug_fail 1
805 select * from sqlite_master where rowid>5;
807 } {1 {out of memory}}
813 utf8 [sqlite3_errmsg16 $::DB]
817 sqlite3_memdebug_fail -1
820 # The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
821 # statement issued while there are still outstanding VMs that are part of
822 # the transaction fails.
824 set DB [sqlite3_connection_pointer db]
825 sqlite_register_test_function $DB func
829 CREATE TABLE t1(a, b);
830 INSERT INTO t1 VALUES(1, 'int');
831 INSERT INTO t1 VALUES(2, 'notatype');
834 do_test capi3-11.1.1 {
835 sqlite3_get_autocommit $DB
838 set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
842 # As of 3.6.5 a COMMIT is OK during while a query is still running -
843 # as long as it is a read-only query and not an incremental BLOB write.
845 do_test capi3-11.3.1 {
850 do_test capi3-11.3.2 {
851 sqlite3_extended_errcode $DB
853 do_test capi3-11.3.3 {
854 sqlite3_get_autocommit $DB
856 do_test capi3-11.3.4 {
857 db eval {PRAGMA lock_status}
858 } {main shared temp closed}
864 sqlite3_finalize $STMT
870 } {0 {1 int 2 notatype}}
872 sqlite3_get_autocommit $DB
877 INSERT INTO t2 VALUES(1);
878 INSERT INTO t2 VALUES(2);
880 INSERT INTO t2 VALUES(3);
883 do_test capi3-11.8.1 {
884 sqlite3_get_autocommit $DB
887 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
890 do_test capi3-11.9.1 {
891 sqlite3_get_autocommit $DB
893 do_test capi3-11.9.2 {
897 } {1 {cannot rollback transaction - SQL statements in progress}}
898 do_test capi3-11.9.3 {
899 sqlite3_get_autocommit $DB
901 do_test capi3-11.10 {
904 do_test capi3-11.11 {
907 do_test capi3-11.12 {
910 do_test capi3-11.13 {
911 sqlite3_finalize $STMT
913 do_test capi3-11.14 {
918 do_test capi3-11.14.1 {
919 sqlite3_get_autocommit $DB
921 do_test capi3-11.15 {
926 do_test capi3-11.15.1 {
927 sqlite3_get_autocommit $DB
929 do_test capi3-11.16 {
935 # Sanity check on the definition of 'outstanding VM'. This means any VM
936 # that has had sqlite3_step() called more recently than sqlite3_finalize() or
937 # sqlite3_reset(). So a VM that has just been prepared or reset does not
938 # count as an active VM.
939 do_test capi3-11.17 {
944 do_test capi3-11.18 {
945 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
950 do_test capi3-11.19 {
953 do_test capi3-11.20 {
959 do_test capi3-11.20 {
964 } {1 {cannot commit - no transaction is active}}
965 do_test capi3-11.21 {
966 sqlite3_finalize $STMT
969 # The following tests - capi3-12.* - check that its Ok to start a
970 # transaction while other VMs are active, and that its Ok to execute
971 # atomic updates in the same situation
974 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
979 INSERT INTO t1 VALUES(3, NULL);
984 INSERT INTO t2 VALUES(4);
990 INSERT INTO t1 VALUES(4, NULL);
996 do_test capi3-12.5.1 {
1002 do_test capi3-12.7 {
1003 sqlite3_finalize $STMT
1005 do_test capi3-12.8 {
1012 # Test cases capi3-13.* test the sqlite3_clear_bindings() and
1013 # sqlite3_sleep APIs.
1015 if {[llength [info commands sqlite3_clear_bindings]]>0} {
1016 do_test capi3-13.1 {
1020 set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL]
1023 do_test capi3-13.2 {
1025 sqlite3_bind_text $STMT 1 hello 5
1026 sqlite3_bind_text $STMT 2 world 5
1029 do_test capi3-13.3 {
1031 sqlite3_clear_bindings $STMT
1034 do_test capi3-13-4 {
1035 sqlite3_finalize $STMT
1039 } {{} {} hello world {} {}}
1041 if {[llength [info commands sqlite3_sleep]]>0} {
1042 do_test capi3-13-5 {
1043 set ms [sqlite3_sleep 80]
1044 expr {$ms==80 || $ms==1000}
1048 # Ticket #1219: Make sure binding APIs can handle a NULL pointer.
1050 do_test capi3-14.1-misuse {
1051 set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
1055 # Ticket #1650: Honor the nBytes parameter to sqlite3_prepare.
1057 do_test capi3-15.1 {
1058 set sql {SELECT * FROM t2}
1059 set nbytes [string length $sql]
1060 append sql { WHERE a==1}
1061 set STMT [sqlite3_prepare $DB $sql $nbytes TAIL]
1063 sqlite3_column_int $STMT 0
1065 do_test capi3-15.2 {
1067 sqlite3_column_int $STMT 0
1069 do_test capi3-15.3 {
1070 sqlite3_finalize $STMT
1072 do_test capi3-15.4 {
1074 set sql {SELECT 1234567890}
1075 set STMT [sqlite3_prepare $DB $sql 8 TAIL]
1077 set v1 [sqlite3_column_int $STMT 0]
1078 sqlite3_finalize $STMT
1081 do_test capi3-15.5 {
1083 set sql {SELECT 1234567890}
1084 set STMT [sqlite3_prepare $DB $sql 9 TAIL]
1086 set v1 [sqlite3_column_int $STMT 0]
1087 sqlite3_finalize $STMT
1090 do_test capi3-15.6 {
1092 set sql {SELECT 1234567890}
1093 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1095 set v1 [sqlite3_column_int $STMT 0]
1096 sqlite3_finalize $STMT
1099 do_test capi3-15.7 {
1101 set sql {SELECT 12.34567890}
1102 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1104 set v1 [sqlite3_column_double $STMT 0]
1105 sqlite3_finalize $STMT
1108 do_test capi3-15.8 {
1110 set sql {SELECT 12.34567890}
1111 set STMT [sqlite3_prepare $DB $sql 14 TAIL]
1113 set v1 [sqlite3_column_double $STMT 0]
1114 sqlite3_finalize $STMT
1118 # Make sure code is always generated even if an IF EXISTS or
1119 # IF NOT EXISTS clause is present that the table does not or
1120 # does exists. That way we will always have a prepared statement
1121 # to expire when the schema changes.
1123 do_test capi3-16.1 {
1124 set sql {DROP TABLE IF EXISTS t3}
1125 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1126 sqlite3_finalize $STMT
1129 do_test capi3-16.2 {
1130 set sql {CREATE TABLE IF NOT EXISTS t1(x,y)}
1131 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1132 sqlite3_finalize $STMT
1136 # But still we do not generate code if there is no SQL
1138 do_test capi3-16.3 {
1139 set STMT [sqlite3_prepare $DB {} -1 TAIL]
1140 sqlite3_finalize $STMT
1143 do_test capi3-16.4 {
1144 set STMT [sqlite3_prepare $DB {;} -1 TAIL]
1145 sqlite3_finalize $STMT
1149 # Ticket #2426: Misuse of sqlite3_column_* by calling it after
1150 # a sqlite3_reset should be harmless.
1152 do_test capi3-17.1 {
1153 set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
1155 sqlite3_column_int $STMT 0
1157 do_test capi3-17.2 {
1159 sqlite3_column_int $STMT 0
1161 do_test capi3-17.3 {
1162 sqlite3_finalize $STMT
1165 # Verify that sqlite3_step() fails with an SQLITE_SCHEMA error
1166 # when the statement is prepared with sqlite3_prepare() (not
1167 # sqlite3_prepare_v2()) and the schema has changed.
1169 do_test capi3-18.1 {
1170 set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL]
1172 db2 eval {CREATE TABLE t3(x)}
1176 do_test capi3-18.2 {
1180 do_test capi3-18.3 {
1182 } {database schema has changed}
1183 # The error persist on retry when sqlite3_prepare() has been used.
1184 do_test capi3-18.4 {
1187 do_test capi3-18.5 {
1191 do_test capi3-18.6 {
1193 } {database schema has changed}
1194 sqlite3_finalize $STMT
1196 # Ticket #3134. Prepare a statement with an nBytes parameter of 0.
1197 # Make sure this works correctly and does not reference memory out of
1200 do_test capi3-19.1 {
1201 sqlite3_prepare_tkt3134 db
1204 # Tests of the interface when no VFS is registered.
1206 if {![info exists tester_do_binarylog]} {
1209 do_test capi3-20.1 {