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
652 # 2018-01-09: If a column is the last token if a string, the column name
653 # was not being set correctly, due to changes in check-in
654 # https://sqlite.org/src/info/0fdf97efe5df7455
656 # This problem was detected by the community during beta-testing.
659 set STMT [sqlite3_prepare $DB {SELECT :a, :b} -1 TAIL]
660 sqlite3_column_count $STMT
662 check_header $STMT capi-5.35 {:a :b} {{} {}}
663 sqlite3_finalize $STMT
665 set ::ENC [execsql {pragma encoding}]
670 set DB [sqlite3_connection_pointer db]
671 if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy }
672 set sql {SELECT a FROM t1 order by rowid}
673 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
681 # 6.2 and 6.3 used to return SQLITE_ERROR and SQLITE_SCHEMA, respectively.
682 # But since attempting to close a connection no longer resets the internal
683 # schema and expires all statements, this is no longer the case.
687 #check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
689 sqlite3_finalize $STMT
692 if {[clang_sanitize_address]==0} {
693 do_test capi3-6.4-misuse {
700 # This procedure sets the value of the file-format in file 'test.db'
701 # to $newval. Also, the schema cookie is incremented.
703 proc set_file_format {newval} {
704 hexio_write test.db 44 [hexio_render_int32 $newval]
705 set schemacookie [hexio_get_int [hexio_read test.db 40 4]]
707 hexio_write test.db 40 [hexio_render_int32 $schemacookie]
711 # This procedure returns the value of the file-format in file 'test.db'.
713 proc get_file_format {{fname test.db}} {
714 return [hexio_get_int [hexio_read $fname 44 4]]
717 if {![sqlite3 -has-codec]} {
718 # Test what happens when the library encounters a newer file format.
723 catch { sqlite3 db test.db }
725 SELECT * FROM sqlite_master;
727 } {1 {unsupported file format}}
731 if {![sqlite3 -has-codec]} {
732 # Now test that the library correctly handles bogus entries in the
733 # sqlite_master table (schema corruption).
735 forcedelete test.db test.db-journal
745 PRAGMA writable_schema=ON;
746 INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL);
751 catch { sqlite3 db test.db }
753 SELECT * FROM sqlite_master;
755 } {1 {malformed database schema (?)}}
757 # Build a 5-field row record. The first field is a string 'table', and
758 # subsequent fields are all NULL.
760 forcedelete test.db test.db-journal
764 PRAGMA writable_schema=ON;
765 INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL);
770 catch { sqlite3 db test.db }
772 SELECT * FROM sqlite_master;
774 } {1 {malformed database schema (?)}}
778 forcedelete test.db-journal
781 # Test the english language string equivalents for sqlite error codes
782 set code2english [list \
783 SQLITE_OK {not an error} \
784 SQLITE_ERROR {SQL logic error} \
785 SQLITE_PERM {access permission denied} \
786 SQLITE_ABORT {query aborted} \
787 SQLITE_BUSY {database is locked} \
788 SQLITE_LOCKED {database table is locked} \
789 SQLITE_NOMEM {out of memory} \
790 SQLITE_READONLY {attempt to write a readonly database} \
791 SQLITE_INTERRUPT {interrupted} \
792 SQLITE_IOERR {disk I/O error} \
793 SQLITE_CORRUPT {database disk image is malformed} \
794 SQLITE_FULL {database or disk is full} \
795 SQLITE_CANTOPEN {unable to open database file} \
796 SQLITE_SCHEMA {database schema has changed} \
797 SQLITE_CONSTRAINT {constraint failed} \
798 SQLITE_MISMATCH {datatype mismatch} \
799 SQLITE_MISUSE {bad parameter or other API misuse} \
800 SQLITE_AUTH {authorization denied} \
801 SQLITE_RANGE {column index out of range} \
802 SQLITE_NOTADB {file is not a database} \
803 unknownerror {unknown error} \
807 foreach {code english} $code2english {
808 do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english
812 # Test the error message when a "real" out of memory occurs.
813 if { [permutation] != "nofaultsim" } {
817 set DB [sqlite3_connection_pointer db]
818 sqlite3_memdebug_fail 1
820 select * from sqlite_master;
822 } {1 {out of memory}}
828 utf8 [sqlite3_errmsg16 $::DB]
832 sqlite3_memdebug_fail -1
835 set DB [sqlite3_connection_pointer db]
836 sqlite3_memdebug_fail 1
838 select * from sqlite_master where rowid>5;
840 } {1 {out of memory}}
846 utf8 [sqlite3_errmsg16 $::DB]
850 sqlite3_memdebug_fail -1
854 # The following tests - capi3-11.* - test that a COMMIT or ROLLBACK
855 # statement issued while there are still outstanding VMs that are part of
856 # the transaction fails.
858 set DB [sqlite3_connection_pointer db]
859 sqlite_register_test_function $DB func
863 CREATE TABLE t1(a, b);
864 INSERT INTO t1 VALUES(1, 'int');
865 INSERT INTO t1 VALUES(2, 'notatype');
868 do_test capi3-11.1.1 {
869 sqlite3_get_autocommit $DB
872 set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL]
876 # As of 3.6.5 a COMMIT is OK during while a query is still running -
877 # as long as it is a read-only query and not an incremental BLOB write.
879 do_test capi3-11.3.1 {
884 do_test capi3-11.3.2 {
885 sqlite3_extended_errcode $DB
887 do_test capi3-11.3.3 {
888 sqlite3_get_autocommit $DB
890 do_test capi3-11.3.4 {
891 db eval {PRAGMA lock_status}
892 } {main shared temp closed}
898 sqlite3_finalize $STMT
904 } {0 {1 int 2 notatype}}
906 sqlite3_get_autocommit $DB
911 INSERT INTO t2 VALUES(1);
912 INSERT INTO t2 VALUES(2);
914 INSERT INTO t2 VALUES(3);
917 do_test capi3-11.8.1 {
918 sqlite3_get_autocommit $DB
921 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
924 do_test capi3-11.9.1 {
925 sqlite3_get_autocommit $DB
927 do_test capi3-11.9.2 {
932 do_test capi3-11.9.3 {
933 sqlite3_get_autocommit $DB
935 do_test capi3-11.10 {
938 do_test capi3-11.11 {
941 ifcapable !autoreset {
942 do_test capi3-11.12armor {
947 do_test capi3-11.12 {
952 do_test capi3-11.13 {
953 sqlite3_finalize $STMT
955 do_test capi3-11.14 {
960 do_test capi3-11.14.1 {
961 sqlite3_get_autocommit $DB
963 do_test capi3-11.15 {
967 } {1 {cannot rollback - no transaction is active}}
968 do_test capi3-11.15.1 {
969 sqlite3_get_autocommit $DB
971 do_test capi3-11.16 {
977 # Sanity check on the definition of 'outstanding VM'. This means any VM
978 # that has had sqlite3_step() called more recently than sqlite3_finalize() or
979 # sqlite3_reset(). So a VM that has just been prepared or reset does not
980 # count as an active VM.
981 do_test capi3-11.17 {
986 do_test capi3-11.18 {
987 set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL]
992 do_test capi3-11.19 {
995 do_test capi3-11.20 {
1001 do_test capi3-11.20 {
1006 } {1 {cannot commit - no transaction is active}}
1007 do_test capi3-11.21 {
1008 sqlite3_finalize $STMT
1011 # The following tests - capi3-12.* - check that its Ok to start a
1012 # transaction while other VMs are active, and that its Ok to execute
1013 # atomic updates in the same situation
1015 do_test capi3-12.1 {
1016 set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL]
1019 do_test capi3-12.2 {
1021 INSERT INTO t1 VALUES(3, NULL);
1024 do_test capi3-12.3 {
1026 INSERT INTO t2 VALUES(4);
1029 do_test capi3-12.4 {
1032 INSERT INTO t1 VALUES(4, NULL);
1035 do_test capi3-12.5 {
1038 do_test capi3-12.5.1 {
1041 do_test capi3-12.6 {
1044 do_test capi3-12.7 {
1045 sqlite3_finalize $STMT
1047 do_test capi3-12.8 {
1054 # Test cases capi3-13.* test the sqlite3_clear_bindings() and
1055 # sqlite3_sleep APIs.
1057 if {[llength [info commands sqlite3_clear_bindings]]>0} {
1058 do_test capi3-13.1 {
1062 set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL]
1065 do_test capi3-13.2 {
1067 sqlite3_bind_text $STMT 1 hello 5
1068 sqlite3_bind_text $STMT 2 world 5
1071 do_test capi3-13.3 {
1073 sqlite3_clear_bindings $STMT
1076 do_test capi3-13-4 {
1077 sqlite3_finalize $STMT
1081 } {{} {} hello world {} {}}
1083 if {[llength [info commands sqlite3_sleep]]>0} {
1084 do_test capi3-13-5 {
1085 set ms [sqlite3_sleep 80]
1086 expr {$ms==80 || $ms==1000}
1090 # Ticket #1219: Make sure binding APIs can handle a NULL pointer.
1092 if {[clang_sanitize_address]==0} {
1093 do_test capi3-14.1-misuse {
1094 set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
1099 # Ticket #1650: Honor the nBytes parameter to sqlite3_prepare.
1101 do_test capi3-15.1 {
1102 set sql {SELECT * FROM t2}
1103 set nbytes [string length $sql]
1104 append sql { WHERE a==1}
1105 set STMT [sqlite3_prepare $DB $sql $nbytes TAIL]
1107 sqlite3_column_int $STMT 0
1109 do_test capi3-15.2 {
1111 sqlite3_column_int $STMT 0
1113 do_test capi3-15.3 {
1114 sqlite3_finalize $STMT
1116 do_test capi3-15.4 {
1118 set sql {SELECT 1234567890}
1119 set STMT [sqlite3_prepare $DB $sql 8 TAIL]
1121 set v1 [sqlite3_column_int $STMT 0]
1122 sqlite3_finalize $STMT
1125 do_test capi3-15.5 {
1127 set sql {SELECT 1234567890}
1128 set STMT [sqlite3_prepare $DB $sql 9 TAIL]
1130 set v1 [sqlite3_column_int $STMT 0]
1131 sqlite3_finalize $STMT
1134 do_test capi3-15.6 {
1136 set sql {SELECT 1234567890}
1137 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1139 set v1 [sqlite3_column_int $STMT 0]
1140 sqlite3_finalize $STMT
1143 do_test capi3-15.7 {
1145 set sql {SELECT 12.34567890}
1146 set STMT [sqlite3_prepare $DB $sql 12 TAIL]
1148 set v1 [sqlite3_column_double $STMT 0]
1149 sqlite3_finalize $STMT
1152 do_test capi3-15.8 {
1154 set sql {SELECT 12.34567890}
1155 set STMT [sqlite3_prepare $DB $sql 14 TAIL]
1157 set v1 [sqlite3_column_double $STMT 0]
1158 sqlite3_finalize $STMT
1162 # Make sure code is always generated even if an IF EXISTS or
1163 # IF NOT EXISTS clause is present that the table does not or
1164 # does exists. That way we will always have a prepared statement
1165 # to expire when the schema changes.
1167 do_test capi3-16.1 {
1168 set sql {DROP TABLE IF EXISTS t3}
1169 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1170 sqlite3_finalize $STMT
1173 do_test capi3-16.2 {
1174 set sql {CREATE TABLE IF NOT EXISTS t1(x,y)}
1175 set STMT [sqlite3_prepare $DB $sql -1 TAIL]
1176 sqlite3_finalize $STMT
1180 # But still we do not generate code if there is no SQL
1182 do_test capi3-16.3 {
1183 set STMT [sqlite3_prepare $DB {} -1 TAIL]
1184 sqlite3_finalize $STMT
1187 do_test capi3-16.4 {
1188 set STMT [sqlite3_prepare $DB {;} -1 TAIL]
1189 sqlite3_finalize $STMT
1193 # Ticket #2426: Misuse of sqlite3_column_* by calling it after
1194 # a sqlite3_reset should be harmless.
1196 do_test capi3-17.1 {
1197 set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL]
1199 sqlite3_column_int $STMT 0
1201 do_test capi3-17.2 {
1203 sqlite3_column_int $STMT 0
1205 do_test capi3-17.3 {
1206 sqlite3_finalize $STMT
1209 # Verify that sqlite3_step() fails with an SQLITE_SCHEMA error
1210 # when the statement is prepared with sqlite3_prepare() (not
1211 # sqlite3_prepare_v2()) and the schema has changed.
1213 do_test capi3-18.1 {
1214 set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL]
1216 db2 eval {CREATE TABLE t3(x)}
1220 do_test capi3-18.2 {
1224 do_test capi3-18.3 {
1226 } {database schema has changed}
1227 # The error persist on retry when sqlite3_prepare() has been used.
1228 do_test capi3-18.4 {
1231 do_test capi3-18.5 {
1235 do_test capi3-18.6 {
1237 } {database schema has changed}
1238 sqlite3_finalize $STMT
1240 # Ticket #3134. Prepare a statement with an nBytes parameter of 0.
1241 # Make sure this works correctly and does not reference memory out of
1244 do_test capi3-19.1 {
1245 sqlite3_prepare_tkt3134 db
1248 # Test that calling sqlite3_column_blob() on a TEXT value does not change
1249 # the return type of subsequent calls to sqlite3_column_type().
1251 do_execsql_test 20.1 {
1253 INSERT INTO t4 VALUES('abcdefghij');
1256 set stmt [sqlite3_prepare db "SELECT * FROM t4" -1 dummy]
1259 do_test 20.3 { sqlite3_column_type $stmt 0 } {TEXT}
1260 do_test 20.4 { sqlite3_column_blob $stmt 0 } {abcdefghij}
1261 do_test 20.5 { sqlite3_column_type $stmt 0 } {TEXT}
1262 do_test 20.6 { sqlite3_finalize $stmt } SQLITE_OK
1265 # Tests of the interface when no VFS is registered.
1267 if {![info exists tester_do_binarylog]} {
1270 do_test capi3-20.1 {