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 set ::capi3_errno [sqlite3_system_errno $db2]
176 list [sqlite3_extended_errcode $db2] [expr {$::capi3_errno!=0}]
177 } {SQLITE_CANTOPEN 1}
180 } {unable to open database file}
182 list [sqlite3_system_errno $db2] [sqlite3_close $db2]
183 } [list $::capi3_errno SQLITE_OK]
184 if {[clang_sanitize_address]==0} {
185 do_test capi3-3.6.1-misuse {
188 do_test capi3-3.6.2-misuse {
190 } {bad parameter or other API misuse}
192 do_test capi3-3.6.3-misuse {
193 utf8 [sqlite3_errmsg16 $db2]
194 } {bad parameter or other API misuse}
199 set db2 [sqlite3_open]
206 # rename sqlite3_open ""
207 # rename sqlite3_open_old sqlite3_open
211 set db2 [sqlite3_open16 [utf16 test.db] {}]
214 # FIX ME: Should test the db handle works.
220 set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}]
225 utf8 [sqlite3_errmsg16 $db2]
226 } {unable to open database file}
232 # This proc is used to test the following API calls:
234 # sqlite3_column_count
235 # sqlite3_column_name
236 # sqlite3_column_name16
237 # sqlite3_column_decltype
238 # sqlite3_column_decltype16
240 # $STMT is a compiled SQL statement. $test is a prefix
241 # to use for test names within this proc. $names is a list
242 # of the column names that should be returned by $STMT.
243 # $decltypes is a list of column declaration types for $STMT.
247 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
248 # check_header test1.1 {1 2 3} {"" "" ""}
250 proc check_header {STMT test names decltypes} {
252 # Use the return value of sqlite3_column_count() to build
253 # a list of column indexes. i.e. If sqlite3_column_count
254 # is 3, build the list {0 1 2}.
256 set ::numcols [sqlite3_column_count $STMT]
257 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
259 # Column names in UTF-8
262 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
266 # Column names in UTF-16
271 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
277 # Column names in UTF-8
280 foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]}
284 # Column names in UTF-16
289 lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
295 # Column names in UTF-8
298 foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]}
302 # Column declaration types in UTF-16
307 lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
314 # Test some out of range conditions:
318 [sqlite3_column_name $STMT -1] \
319 [sqlite3_column_name16 $STMT -1] \
320 [sqlite3_column_decltype $STMT -1] \
321 [sqlite3_column_decltype16 $STMT -1] \
322 [sqlite3_column_name $STMT $numcols] \
323 [sqlite3_column_name16 $STMT $numcols] \
324 [sqlite3_column_decltype $STMT $numcols] \
325 [sqlite3_column_decltype16 $STMT $numcols]
326 } {{} {} {} {} {} {} {} {}}
330 # This proc is used to test the following API calls:
332 # sqlite3_column_origin_name
333 # sqlite3_column_origin_name16
334 # sqlite3_column_table_name
335 # sqlite3_column_table_name16
336 # sqlite3_column_database_name
337 # sqlite3_column_database_name16
339 # $STMT is a compiled SQL statement. $test is a prefix
340 # to use for test names within this proc. $names is a list
341 # of the column names that should be returned by $STMT.
342 # $decltypes is a list of column declaration types for $STMT.
346 # set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY]
347 # check_header test1.1 {1 2 3} {"" "" ""}
349 proc check_origin_header {STMT test dbs tables cols} {
350 # If sqlite3_column_origin_name() and friends are not compiled into
351 # this build, this proc is a no-op.
352 ifcapable columnmetadata {
353 # Use the return value of sqlite3_column_count() to build
354 # a list of column indexes. i.e. If sqlite3_column_count
355 # is 3, build the list {0 1 2}.
357 set ::numcols [sqlite3_column_count $STMT]
358 for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i}
360 # Database names in UTF-8
364 lappend cnamelist [sqlite3_column_database_name $STMT $i]
369 # Database names in UTF-16
374 lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]]
380 # Table names in UTF-8
384 lappend cnamelist [sqlite3_column_table_name $STMT $i]
389 # Table names in UTF-16
394 lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]]
400 # Origin names in UTF-8
404 lappend cnamelist [sqlite3_column_origin_name $STMT $i]
409 # Origin declaration types in UTF-16
414 lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]]
422 # This proc is used to test the following APIs:
425 # sqlite3_column_type
427 # sqlite3_column_text
428 # sqlite3_column_text16
429 # sqlite3_column_double
431 # $STMT is a compiled SQL statement for which the previous call
432 # to sqlite3_step returned SQLITE_ROW. $test is a prefix to use
433 # for test names within this proc. $types is a list of the
434 # manifest types for the current row. $ints, $doubles and $strings
435 # are lists of the integer, real and string representations of
436 # the values in the current row.
440 # set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY]
442 # check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}}
444 proc check_data {STMT test types ints doubles strings} {
446 # Use the return value of sqlite3_column_count() to build
447 # a list of column indexes. i.e. If sqlite3_column_count
448 # is 3, build the list {0 1 2}.
450 set numcols [sqlite3_data_count $STMT]
451 for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i}
457 set x [sqlite3_column_type $STMT $i]
458 # EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five
459 # fundamental datatypes: 64-bit signed integer 64-bit IEEE floating
460 # point number string BLOB NULL
461 if {[lsearch {INTEGER FLOAT TEXT BLOB NULL} $x]<0} {
475 foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]}
481 foreach i $::idxlist {
482 lappend lens [string length [lindex $strings $i]]
488 lappend bytes [sqlite3_column_bytes $STMT $i]
496 foreach i $::idxlist {
497 lappend lens [expr 2 * [string length [lindex $strings $i]]]
503 lappend bytes [sqlite3_column_bytes16 $STMT $i]
512 foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]}
519 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
526 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
534 foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]}
542 foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]}
549 foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]}
556 foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]}
563 foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]}
567 # Test that an out of range request returns the equivalent of NULL
569 sqlite3_column_int $STMT -1
572 sqlite3_column_text $STMT -1
577 ifcapable !floatingpoint {
584 CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16));
585 INSERT INTO t1 VALUES(1, 2, 3);
586 INSERT INTO t1 VALUES('one', 'two', NULL);
587 INSERT INTO t1 VALUES(1.2, 1.3, 1.4);
589 set sql "SELECT * FROM t1"
590 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
591 sqlite3_column_count $STMT
594 check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
595 check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c}
600 check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
601 check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c}
602 check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
608 check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
609 check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c}
610 check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
616 check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
617 check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c}
618 check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
625 sqlite3_finalize $STMT
629 set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a"
630 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
631 sqlite3_column_count $STMT
634 check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}}
635 check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}}
637 sqlite3_finalize $STMT
641 set sql "SELECT a AS x, sum(b) AS y, max(c) AS z FROM t1 AS m GROUP BY x"
642 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
643 sqlite3_column_count $STMT
646 check_header $STMT capi3-5.31 {x y z} {VARINT {} {}}
647 check_origin_header $STMT capi3-5.32 {main {} {}} {t1 {} {}} {a {} {}}
649 sqlite3_finalize $STMT
653 set ::ENC [execsql {pragma encoding}]
658 set DB [sqlite3_connection_pointer db]
659 if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy }
660 set sql {SELECT a FROM t1 order by rowid}
661 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
669 # 6.2 and 6.3 used to return SQLITE_ERROR and SQLITE_SCHEMA, respectively.
670 # But since attempting to close a connection no longer resets the internal
671 # schema and expires all statements, this is no longer the case.
675 #check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
677 sqlite3_finalize $STMT
680 if {[clang_sanitize_address]==0} {
681 do_test capi3-6.4-misuse {
688 # This procedure sets the value of the file-format in file 'test.db'
689 # to $newval. Also, the schema cookie is incremented.
691 proc set_file_format {newval} {
692 hexio_write test.db 44 [hexio_render_int32 $newval]
693 set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
695 hexio_write test.db 40 [hexio_render_int32 $schemacookie]
699 # This procedure returns the value of the file-format in file 'test.db'.
701 proc get_file_format {{fname test.db}} {
702 return [hexio_get_int [hexio_read $fname 44 4]]
705 if {![sqlite3 -has-codec]} {
706 # Test what happens when the library encounters a newer file format.
711 catch { sqlite3 db test.db }
713 SELECT * FROM sqlite_master;
715 } {1 {unsupported file format}}
719 if {![sqlite3 -has-codec]} {
720 # Now test that the library correctly handles bogus entries in the
721 # sqlite_master table (schema corruption).
723 forcedelete test.db test.db-journal
733 PRAGMA writable_schema=ON;
734 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
739 catch { sqlite3 db test.db }
741 SELECT * FROM sqlite_master;
743 } {1 {malformed database schema (?)}}
745 # Build a 5-field row record. The first field is a string 'table', and
746 # subsequent fields are all NULL.
748 forcedelete test.db test.db-journal
752 PRAGMA writable_schema=ON;
753 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
758 catch { sqlite3 db test.db }
760 SELECT * FROM sqlite_master;
762 } {1 {malformed database schema (?)}}
766 forcedelete test.db-journal
769 # Test the english language string equivalents for sqlite error codes
770 set code2english [list \
771 SQLITE_OK {not an error} \
772 SQLITE_ERROR {SQL logic error} \
773 SQLITE_PERM {access permission denied} \
774 SQLITE_ABORT {query aborted} \
775 SQLITE_BUSY {database is locked} \
776 SQLITE_LOCKED {database table is locked} \
777 SQLITE_NOMEM {out of memory} \
778 SQLITE_READONLY {attempt to write a readonly database} \
779 SQLITE_INTERRUPT {interrupted} \
780 SQLITE_IOERR {disk I/O error} \
781 SQLITE_CORRUPT {database disk image is malformed} \
782 SQLITE_FULL {database or disk is full} \
783 SQLITE_CANTOPEN {unable to open database file} \
784 SQLITE_SCHEMA {database schema has changed} \
785 SQLITE_CONSTRAINT {constraint failed} \
786 SQLITE_MISMATCH {datatype mismatch} \
787 SQLITE_MISUSE {bad parameter or other API misuse} \
788 SQLITE_AUTH {authorization denied} \
789 SQLITE_RANGE {column index out of range} \
790 SQLITE_NOTADB {file is not a database} \
791 unknownerror {unknown error} \
795 foreach {code english} $code2english {
796 do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english
800 # Test the error message when a "real" out of memory occurs.
801 if { [permutation] != "nofaultsim" } {
805 set DB [sqlite3_connection_pointer db]
806 sqlite3_memdebug_fail 1
808 select * from sqlite_master;
810 } {1 {out of memory}}
816 utf8 [sqlite3_errmsg16 $::DB]
820 sqlite3_memdebug_fail -1
823 set DB [sqlite3_connection_pointer db]
824 sqlite3_memdebug_fail 1
826 select * from sqlite_master where rowid>5;
828 } {1 {out of memory}}
834 utf8 [sqlite3_errmsg16 $::DB]
838 sqlite3_memdebug_fail -1
842 # The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
843 # statement issued while there are still outstanding VMs that are part of
844 # the transaction fails.
846 set DB [sqlite3_connection_pointer db]
847 sqlite_register_test_function $DB func
851 CREATE TABLE t1(a, b);
852 INSERT INTO t1 VALUES(1, 'int');
853 INSERT INTO t1 VALUES(2, 'notatype');
856 do_test capi3-11.1.1 {
857 sqlite3_get_autocommit $DB
860 set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
864 # As of 3.6.5 a COMMIT is OK during while a query is still running -
865 # as long as it is a read-only query and not an incremental BLOB write.
867 do_test capi3-11.3.1 {
872 do_test capi3-11.3.2 {
873 sqlite3_extended_errcode $DB
875 do_test capi3-11.3.3 {
876 sqlite3_get_autocommit $DB
878 do_test capi3-11.3.4 {
879 db eval {PRAGMA lock_status}
880 } {main shared temp closed}
886 sqlite3_finalize $STMT
892 } {0 {1 int 2 notatype}}
894 sqlite3_get_autocommit $DB
899 INSERT INTO t2 VALUES(1);
900 INSERT INTO t2 VALUES(2);
902 INSERT INTO t2 VALUES(3);
905 do_test capi3-11.8.1 {
906 sqlite3_get_autocommit $DB
909 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
912 do_test capi3-11.9.1 {
913 sqlite3_get_autocommit $DB
915 do_test capi3-11.9.2 {
920 do_test capi3-11.9.3 {
921 sqlite3_get_autocommit $DB
923 do_test capi3-11.10 {
926 do_test capi3-11.11 {
929 ifcapable !autoreset {
930 do_test capi3-11.12armor {
935 do_test capi3-11.12 {
940 do_test capi3-11.13 {
941 sqlite3_finalize $STMT
943 do_test capi3-11.14 {
948 do_test capi3-11.14.1 {
949 sqlite3_get_autocommit $DB
951 do_test capi3-11.15 {
955 } {1 {cannot rollback - no transaction is active}}
956 do_test capi3-11.15.1 {
957 sqlite3_get_autocommit $DB
959 do_test capi3-11.16 {
965 # Sanity check on the definition of 'outstanding VM'. This means any VM
966 # that has had sqlite3_step() called more recently than sqlite3_finalize() or
967 # sqlite3_reset(). So a VM that has just been prepared or reset does not
968 # count as an active VM.
969 do_test capi3-11.17 {
974 do_test capi3-11.18 {
975 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
980 do_test capi3-11.19 {
983 do_test capi3-11.20 {
989 do_test capi3-11.20 {
994 } {1 {cannot commit - no transaction is active}}
995 do_test capi3-11.21 {
996 sqlite3_finalize $STMT
999 # The following tests - capi3-12.* - check that its Ok to start a
1000 # transaction while other VMs are active, and that its Ok to execute
1001 # atomic updates in the same situation
1003 do_test capi3-12.1 {
1004 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
1007 do_test capi3-12.2 {
1009 INSERT INTO t1 VALUES(3, NULL);
1012 do_test capi3-12.3 {
1014 INSERT INTO t2 VALUES(4);
1017 do_test capi3-12.4 {
1020 INSERT INTO t1 VALUES(4, NULL);
1023 do_test capi3-12.5 {
1026 do_test capi3-12.5.1 {
1029 do_test capi3-12.6 {
1032 do_test capi3-12.7 {
1033 sqlite3_finalize $STMT
1035 do_test capi3-12.8 {
1042 # Test cases capi3-13.* test the sqlite3_clear_bindings() and
1043 # sqlite3_sleep APIs.
1045 if {[llength [info commands sqlite3_clear_bindings]]>0} {
1046 do_test capi3-13.1 {
1050 set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL]
1053 do_test capi3-13.2 {
1055 sqlite3_bind_text $STMT 1 hello 5
1056 sqlite3_bind_text $STMT 2 world 5
1059 do_test capi3-13.3 {
1061 sqlite3_clear_bindings $STMT
1064 do_test capi3-13-4 {
1065 sqlite3_finalize $STMT
1069 } {{} {} hello world {} {}}
1071 if {[llength [info commands sqlite3_sleep]]>0} {
1072 do_test capi3-13-5 {
1073 set ms [sqlite3_sleep 80]
1074 expr {$ms==80 || $ms==1000}
1078 # Ticket #1219: Make sure binding APIs can handle a NULL pointer.
1080 if {[clang_sanitize_address]==0} {
1081 do_test capi3-14.1-misuse {
1082 set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
1087 # Ticket #1650: Honor the nBytes parameter to sqlite3_prepare.
1089 do_test capi3-15.1 {
1090 set sql {SELECT * FROM t2}
1091 set nbytes [string length $sql]
1092 append sql { WHERE a==1}
1093 set STMT [sqlite3_prepare $DB $sql $nbytes TAIL]
1095 sqlite3_column_int $STMT 0
1097 do_test capi3-15.2 {
1099 sqlite3_column_int $STMT 0
1101 do_test capi3-15.3 {
1102 sqlite3_finalize $STMT
1104 do_test capi3-15.4 {
1106 set sql {SELECT 1234567890}
1107 set STMT [sqlite3_prepare $DB $sql 8 TAIL]
1109 set v1 [sqlite3_column_int $STMT 0]
1110 sqlite3_finalize $STMT
1113 do_test capi3-15.5 {
1115 set sql {SELECT 1234567890}
1116 set STMT [sqlite3_prepare $DB $sql 9 TAIL]
1118 set v1 [sqlite3_column_int $STMT 0]
1119 sqlite3_finalize $STMT
1122 do_test capi3-15.6 {
1124 set sql {SELECT 1234567890}
1125 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1127 set v1 [sqlite3_column_int $STMT 0]
1128 sqlite3_finalize $STMT
1131 do_test capi3-15.7 {
1133 set sql {SELECT 12.34567890}
1134 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1136 set v1 [sqlite3_column_double $STMT 0]
1137 sqlite3_finalize $STMT
1140 do_test capi3-15.8 {
1142 set sql {SELECT 12.34567890}
1143 set STMT [sqlite3_prepare $DB $sql 14 TAIL]
1145 set v1 [sqlite3_column_double $STMT 0]
1146 sqlite3_finalize $STMT
1150 # Make sure code is always generated even if an IF EXISTS or
1151 # IF NOT EXISTS clause is present that the table does not or
1152 # does exists. That way we will always have a prepared statement
1153 # to expire when the schema changes.
1155 do_test capi3-16.1 {
1156 set sql {DROP TABLE IF EXISTS t3}
1157 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1158 sqlite3_finalize $STMT
1161 do_test capi3-16.2 {
1162 set sql {CREATE TABLE IF NOT EXISTS t1(x,y)}
1163 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1164 sqlite3_finalize $STMT
1168 # But still we do not generate code if there is no SQL
1170 do_test capi3-16.3 {
1171 set STMT [sqlite3_prepare $DB {} -1 TAIL]
1172 sqlite3_finalize $STMT
1175 do_test capi3-16.4 {
1176 set STMT [sqlite3_prepare $DB {;} -1 TAIL]
1177 sqlite3_finalize $STMT
1181 # Ticket #2426: Misuse of sqlite3_column_* by calling it after
1182 # a sqlite3_reset should be harmless.
1184 do_test capi3-17.1 {
1185 set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
1187 sqlite3_column_int $STMT 0
1189 do_test capi3-17.2 {
1191 sqlite3_column_int $STMT 0
1193 do_test capi3-17.3 {
1194 sqlite3_finalize $STMT
1197 # Verify that sqlite3_step() fails with an SQLITE_SCHEMA error
1198 # when the statement is prepared with sqlite3_prepare() (not
1199 # sqlite3_prepare_v2()) and the schema has changed.
1201 do_test capi3-18.1 {
1202 set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL]
1204 db2 eval {CREATE TABLE t3(x)}
1208 do_test capi3-18.2 {
1212 do_test capi3-18.3 {
1214 } {database schema has changed}
1215 # The error persist on retry when sqlite3_prepare() has been used.
1216 do_test capi3-18.4 {
1219 do_test capi3-18.5 {
1223 do_test capi3-18.6 {
1225 } {database schema has changed}
1226 sqlite3_finalize $STMT
1228 # Ticket #3134. Prepare a statement with an nBytes parameter of 0.
1229 # Make sure this works correctly and does not reference memory out of
1232 do_test capi3-19.1 {
1233 sqlite3_prepare_tkt3134 db
1236 # Test that calling sqlite3_column_blob() on a TEXT value does not change
1237 # the return type of subsequent calls to sqlite3_column_type().
1239 do_execsql_test 20.1 {
1241 INSERT INTO t4 VALUES('abcdefghij');
1244 set stmt [sqlite3_prepare db "SELECT * FROM t4" -1 dummy]
1247 do_test 20.3 { sqlite3_column_type $stmt 0 } {TEXT}
1248 do_test 20.4 { sqlite3_column_blob $stmt 0 } {abcdefghij}
1249 do_test 20.5 { sqlite3_column_type $stmt 0 } {TEXT}
1250 do_test 20.6 { sqlite3_finalize $stmt } SQLITE_OK
1253 # Tests of the interface when no VFS is registered.
1255 if {![info exists tester_do_binarylog]} {
1258 do_test capi3-20.1 {