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 file is creating and dropping virtual tables.
14 # $Id: vtab1.test,v 1.57 2008/08/01 17:51:47 danielk1977 Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable !vtab||!schema_pragmas {
24 #----------------------------------------------------------------------
25 # Organization of tests in this file:
27 # vtab1-1.*: Error conditions and other issues surrounding creation/connection
28 # of a virtual module.
29 # vtab1-2.*: Test sqlite3_declare_vtab() and the xConnect/xDisconnect methods.
30 # vtab1-3.*: Table scans and WHERE clauses.
31 # vtab1-4.*: Table scans and ORDER BY clauses.
32 # vtab1-5.*: Test queries that include joins. This brings the
33 # sqlite3_index_info.estimatedCost variable into play.
34 # vtab1-6.*: Test UPDATE/INSERT/DELETE on vtables.
35 # vtab1-7.*: Test sqlite3_last_insert_rowid().
37 # This file uses the "echo" module (see src/test8.c). Refer to comments
38 # in that file for the special behaviour of the Tcl $echo_module variable.
41 # * How to test the sqlite3_index_constraint_usage.omit field?
44 # vtab1-14.*: Test 'IN' constraints - i.e. "SELECT * FROM t1 WHERE id IN(...)"
48 #----------------------------------------------------------------------
49 # Test cases vtab1.1.*
52 # We cannot create a virtual table if the module has not been registered.
56 CREATE VIRTUAL TABLE t1 USING echo;
59 CREATE VIRTUAL TABLE t1 USING echo;
61 } {1 {no such module: echo}}
64 SELECT name FROM sqlite_master ORDER BY 1
69 register_echo_module [sqlite3_connection_pointer db]
71 # Once a module has been registered, virtual tables using that module
72 # may be created. However if a module xCreate() fails to call
73 # sqlite3_declare_vtab() an error will be raised and the table not created.
75 # The "echo" module does not invoke sqlite3_declare_vtab() if it is
76 # passed zero arguments.
80 CREATE VIRTUAL TABLE t1 USING echo;
82 } {1 {vtable constructor did not declare schema: t1}}
85 SELECT name FROM sqlite_master ORDER BY 1
89 # The "echo" module xCreate method returns an error and does not create
90 # the virtual table if it is passed an argument that does not correspond
91 # to an existing real table in the same database.
95 CREATE VIRTUAL TABLE t1 USING echo(no_such_table);
97 } {1 {vtable constructor failed: t1}}
100 SELECT name FROM sqlite_master ORDER BY 1
104 # Ticket #2156. Using the sqlite3_prepare_v2() API, make sure that
105 # a CREATE VIRTUAL TABLE statement can be used multiple times.
107 do_test vtab1-1.2152.1 {
108 set DB [sqlite3_connection_pointer db]
109 set sql {CREATE VIRTUAL TABLE t2152a USING echo(t2152b)}
110 set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
113 do_test vtab-1.2152.2 {
117 do_test vtab-1.2152.3 {
119 db eval {CREATE TABLE t2152b(x,y)}
122 do_test vtab-1.2152.4 {
123 sqlite3_finalize $STMT
124 db eval {DROP TABLE t2152a; DROP TABLE t2152b}
127 # Test to make sure nothing goes wrong and no memory is leaked if we
128 # select an illegal table-name (i.e a reserved name or the name of a
129 # table that already exists).
133 CREATE VIRTUAL TABLE sqlite_master USING echo;
135 } {1 {object name reserved for internal use: sqlite_master}}
138 CREATE TABLE treal(a, b, c);
139 CREATE VIRTUAL TABLE treal USING echo(treal);
141 } {1 {table treal already exists}}
145 SELECT name FROM sqlite_master ORDER BY 1
151 CREATE TABLE treal(a, b, c);
152 CREATE VIRTUAL TABLE techo USING echo(treal);
159 } {1 {no such module: echo}}
162 INSERT INTO techo VALUES(1, 2, 3);
164 } {1 {no such module: echo}}
167 UPDATE techo SET a = 10;
169 } {1 {no such module: echo}}
174 } {1 {no such module: echo}}
177 PRAGMA table_info(techo)
179 } {1 {no such module: echo}}
184 } {1 {no such module: echo}}
186 register_echo_module [sqlite3_connection_pointer db]
187 register_echo_module [sqlite3_connection_pointer db]
189 # Test an error message returned from a v-table constructor.
194 CREATE TABLE logmsg(log);
197 CREATE VIRTUAL TABLE techo USING echo(treal, logmsg);
199 } {1 {table 'logmsg' already exists}}
205 SELECT sql FROM sqlite_master;
209 #----------------------------------------------------------------------
210 # Test cases vtab1.2.*
212 # At this point, the database is completely empty. The echo module
213 # has already been registered.
215 # If a single argument is passed to the echo module during table
216 # creation, it is assumed to be the name of a table in the same
217 # database. The echo module attempts to set the schema of the
218 # new virtual table to be the same as the existing database table.
222 CREATE TABLE template(a, b, c);
224 execsql { PRAGMA table_info(template); }
232 CREATE VIRTUAL TABLE t1 USING echo(template);
234 execsql { PRAGMA table_info(t1); }
241 # Test that the database can be unloaded. This should invoke the xDisconnect()
242 # callback for the successfully create virtual table (t1).
245 set echo_module [list]
250 # Re-open the database. This should not cause any virtual methods to
251 # be called. The invocation of xConnect() is delayed until the virtual
252 # table schema is first required by the compiler.
255 set echo_module [list]
261 # Try to query the virtual table schema. This should fail, as the
262 # echo module has not been registered with this database connection.
265 catchsql { PRAGMA table_info(t1); }
266 } {1 {no such module: echo}}
268 # Register the module
269 register_echo_module [sqlite3_connection_pointer db]
271 # Try to query the virtual table schema again. This time it should
272 # invoke the xConnect method and succeed.
275 execsql { PRAGMA table_info(t1); }
283 } {xConnect echo main t1 template}
285 # Drop table t1. This should cause the xDestroy (but not xDisconnect) method
297 PRAGMA table_info(t1);
302 SELECT sql FROM sqlite_master;
304 } [list {CREATE TABLE template(a, b, c)}]
305 # Clean up other test artifacts:
309 SELECT sql FROM sqlite_master;
313 #----------------------------------------------------------------------
314 # Test case vtab1-3 test table scans and the echo module's
315 # xBestIndex/xFilter handling of WHERE conditions.
320 CREATE TABLE treal(a INTEGER, b INTEGER, c);
321 CREATE INDEX treal_idx ON treal(b);
322 CREATE VIRTUAL TABLE t1 USING echo(treal);
325 } [list xCreate echo main t1 treal \
327 xCommit echo(treal) \
330 # Test that a SELECT on t1 doesn't crash. No rows are returned
331 # because the underlying real table is currently empty.
335 SELECT a, b, c FROM t1;
339 # Put some data into the table treal. Then try a few simple SELECT
344 INSERT INTO treal VALUES(1, 2, 3);
345 INSERT INTO treal VALUES(4, 5, 6);
356 SELECT rowid FROM t1;
367 SELECT rowid, * FROM t1;
372 SELECT a AS d, b AS e, c AS f FROM t1;
376 # Execute some SELECT statements with WHERE clauses on the t1 table.
377 # Then check the echo_module variable (written to by the module methods
378 # in test8.c) to make sure the xBestIndex() and xFilter() methods were
387 } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
388 xFilter {SELECT rowid, * FROM 'treal'} ]
392 SELECT * FROM t1 WHERE b = 5;
397 } [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b = ?} \
398 xFilter {SELECT rowid, * FROM 'treal' WHERE b = ?} 5 ]
402 SELECT * FROM t1 WHERE b >= 5 AND b <= 10;
407 } [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} \
408 xFilter {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 5 10 ]
412 SELECT * FROM t1 WHERE b BETWEEN 2 AND 10;
417 } [list xBestIndex {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} \
418 xFilter {SELECT rowid, * FROM 'treal' WHERE b >= ? AND b <= ?} 2 10 ]
420 # Add a function for the MATCH operator. Everything always matches!
421 #proc test_match {lhs rhs} {
422 # lappend ::echo_module MATCH $lhs $rhs
425 #db function match test_match
431 SELECT * FROM t1 WHERE a MATCH 'string';
433 } {1 {unable to use function MATCH in the requested context}}
436 } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
437 xFilter {SELECT rowid, * FROM 'treal'}]
439 # The echo module uses a subquery internally to implement the MATCH operator.
443 SELECT * FROM t1 WHERE b MATCH 'string';
449 {SELECT rowid, * FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \
451 {SELECT rowid, * FROM 'treal' WHERE b LIKE (SELECT '%'||?||'%')} \
453 }; #ifcapable subquery
455 #----------------------------------------------------------------------
456 # Test case vtab1-3 test table scans and the echo module's
457 # xBestIndex/xFilter handling of ORDER BY clauses.
459 # This procedure executes the SQL. Then it checks to see if the OP_Sort
460 # opcode was executed. If an OP_Sort did occur, then "sort" is appended
461 # to the result. If no OP_Sort happened, then "nosort" is appended.
463 # This procedure is used to check to make sure sorting is or is not
464 # occurring as expected.
467 set ::sqlite_sort_count 0
468 set data [execsql $sql]
469 if {$::sqlite_sort_count} {set x sort} {set x nosort}
477 SELECT b FROM t1 ORDER BY b;
482 } [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b ASC} \
483 xFilter {SELECT rowid, * FROM 'treal' ORDER BY b ASC} ]
487 SELECT b FROM t1 ORDER BY b DESC;
492 } [list xBestIndex {SELECT rowid, * FROM 'treal' ORDER BY b DESC} \
493 xFilter {SELECT rowid, * FROM 'treal' ORDER BY b DESC} ]
497 SELECT b FROM t1 ORDER BY b||'';
502 } [list xBestIndex {SELECT rowid, * FROM 'treal'} \
503 xFilter {SELECT rowid, * FROM 'treal'} ]
510 #----------------------------------------------------------------------
511 # Test cases vtab1-5 test SELECT queries that include joins on virtual
516 for {set ii 0} {$ii < [llength $log]} {incr ii} {
517 if {[lindex $log $ii] eq "xFilter"} {
519 lappend out [lindex $log [expr $ii+1]]
527 CREATE TABLE t1(a, b, c);
528 CREATE TABLE t2(d, e, f);
529 INSERT INTO t1 VALUES(1, 'red', 'green');
530 INSERT INTO t1 VALUES(2, 'blue', 'black');
531 INSERT INTO t2 VALUES(1, 'spades', 'clubs');
532 INSERT INTO t2 VALUES(2, 'hearts', 'diamonds');
533 CREATE VIRTUAL TABLE et1 USING echo(t1);
534 CREATE VIRTUAL TABLE et2 USING echo(t2);
541 SELECT * FROM et1, et2;
544 1 red green 1 spades clubs \
545 1 red green 2 hearts diamonds \
546 2 blue black 1 spades clubs \
547 2 blue black 2 hearts diamonds \
552 xFilter {SELECT rowid, * FROM 't1'} \
553 xFilter {SELECT rowid, * FROM 't2'} \
554 xFilter {SELECT rowid, * FROM 't2'} \
559 SELECT * FROM et1, et2 WHERE et2.d = 2;
562 1 red green 2 hearts diamonds \
563 2 blue black 2 hearts diamonds \
568 xFilter {SELECT rowid, * FROM 't1'} \
569 xFilter {SELECT rowid, * FROM 't2'} \
570 xFilter {SELECT rowid, * FROM 't2'} \
574 CREATE INDEX i1 ON t2(d);
579 register_echo_module [sqlite3_connection_pointer db]
583 SELECT * FROM et1, et2 WHERE et2.d = 2;
586 1 red green 2 hearts diamonds \
587 2 blue black 2 hearts diamonds \
590 filter $::echo_module
592 xFilter {SELECT rowid, * FROM 't2' WHERE d = ?} \
593 xFilter {SELECT rowid, * FROM 't1'} \
603 #----------------------------------------------------------------------
604 # Test cases vtab1-6 test INSERT, UPDATE and DELETE operations
607 execsql { SELECT sql FROM sqlite_master }
611 CREATE TABLE treal(a PRIMARY KEY, b, c);
612 CREATE VIRTUAL TABLE techo USING echo(treal);
613 SELECT name FROM sqlite_master WHERE type = 'table';
616 do_test vtab1-6-3.1.1 {
618 PRAGMA count_changes=ON;
619 INSERT INTO techo VALUES(1, 2, 3);
622 do_test vtab1-6-3.1.2 {
625 do_test vtab1-6-3.2 {
630 do_test vtab1-6-4.1 {
632 UPDATE techo SET a = 5;
636 do_test vtab1-6-4.2 {
641 do_test vtab1-6-4.3 {
643 UPDATE techo SET a=6 WHERE a<0;
647 do_test vtab1-6-4.4 {
653 do_test vtab1-6-5.1 {
655 UPDATE techo set a = a||b||c;
659 do_test vtab1-6-5.2 {
665 do_test vtab1-6-6.1 {
667 UPDATE techo set rowid = 10;
671 do_test vtab1-6-6.2 {
673 SELECT rowid FROM techo;
677 do_test vtab1-6-7.1.1 {
679 INSERT INTO techo VALUES(11,12,13);
682 do_test vtab1-6-7.1.2 {
685 do_test vtab1-6-7.2 {
687 SELECT * FROM techo ORDER BY a;
690 do_test vtab1-6-7.3 {
692 UPDATE techo SET b=b+1000
696 do_test vtab1-6-7.4 {
698 SELECT * FROM techo ORDER BY a;
700 } {11 1012 13 523 1002 3}
703 do_test vtab1-6-8.1 {
705 DELETE FROM techo WHERE a=5;
709 do_test vtab1-6-8.2 {
711 SELECT * FROM techo ORDER BY a;
713 } {11 1012 13 523 1002 3}
714 do_test vtab1-6-8.3 {
720 do_test vtab1-6-8.4 {
722 SELECT * FROM techo ORDER BY a;
725 execsql {PRAGMA count_changes=OFF}
727 file delete -force test2.db
728 file delete -force test2.db-journal
731 CREATE TABLE techo(a PRIMARY KEY, b, c);
733 proc check_echo_table {tn} {
734 set ::data1 [execsql {SELECT rowid, * FROM techo}]
735 set ::data2 [execsql {SELECT rowid, * FROM techo} db2]
737 string equal $::data1 $::data2
742 {INSERT INTO techo VALUES('abc', 'def', 'ghi')} \
743 {INSERT INTO techo SELECT a||'.'||rowid, b, c FROM techo} \
744 {INSERT INTO techo SELECT a||'x'||rowid, b, c FROM techo} \
745 {INSERT INTO techo SELECT a||'y'||rowid, b, c FROM techo} \
746 {DELETE FROM techo WHERE (oid % 3) = 0} \
747 {UPDATE techo set rowid = 100 WHERE rowid = 1} \
748 {INSERT INTO techo(a, b) VALUES('hello', 'world')} \
749 {DELETE FROM techo} \
753 check_echo_table vtab1-6.8.[incr tn]
760 #----------------------------------------------------------------------
761 # Test cases vtab1-7 tests that the value returned by
762 # sqlite3_last_insert_rowid() is set correctly when rows are inserted
763 # into virtual tables.
766 CREATE TABLE real_abc(a PRIMARY KEY, b, c);
767 CREATE VIRTUAL TABLE echo_abc USING echo(real_abc);
772 INSERT INTO echo_abc VALUES(1, 2, 3);
773 SELECT last_insert_rowid();
778 INSERT INTO echo_abc(rowid) VALUES(31427);
779 SELECT last_insert_rowid();
784 INSERT INTO echo_abc SELECT a||'.v2', b, c FROM echo_abc;
785 SELECT last_insert_rowid();
790 SELECT rowid, a, b, c FROM echo_abc
798 # Now test that DELETE and UPDATE operations do not modify the value.
801 UPDATE echo_abc SET c = 5 WHERE b = 2;
802 SELECT last_insert_rowid();
807 UPDATE echo_abc SET rowid = 5 WHERE rowid = 1;
808 SELECT last_insert_rowid();
813 DELETE FROM echo_abc WHERE b = 2;
814 SELECT last_insert_rowid();
819 SELECT rowid, a, b, c FROM echo_abc
821 } [list 31427 {} {} {} \
826 DELETE FROM echo_abc WHERE b = 2;
827 SELECT last_insert_rowid();
832 SELECT rowid, a, b, c FROM real_abc
834 } [list 31427 {} {} {} \
839 DELETE FROM echo_abc;
840 SELECT last_insert_rowid();
845 SELECT rowid, a, b, c FROM real_abc
853 ATTACH 'test2.db' AS aux;
854 CREATE VIRTUAL TABLE aux.e2 USING echo(real_abc);
857 } [list xCreate echo aux e2 real_abc \
858 xSync echo(real_abc) \
859 xCommit echo(real_abc) \
877 CREATE TABLE r(a, b, c);
878 CREATE VIRTUAL TABLE e USING echo(r, e_log);
879 SELECT name FROM sqlite_master;
885 SELECT name FROM sqlite_master;
892 CREATE VIRTUAL TABLE e USING echo(r, e_log, virtual 1 2 3 varchar(32));
896 xCreate echo main e r e_log {virtual 1 2 3 varchar(32)} \
904 CREATE VIRTUAL TABLE e2 USING echo(del);
908 register_echo_module [sqlite3_connection_pointer db]
915 } {1 {vtable constructor failed: e2}}
918 set ptr [sqlite3_connection_pointer db]
919 sqlite3_declare_vtab $ptr {CREATE TABLE abc(a, b, c)}
922 } {1 {library routine called out of sequence}}
924 set ::echo_module_begin_fail r
926 INSERT INTO e VALUES(1, 2, 3);
928 } {1 {SQL logic error or missing database}}
931 EXPLAIN SELECT * FROM e WHERE rowid = 2;
932 EXPLAIN QUERY PLAN SELECT * FROM e WHERE rowid = 2 ORDER BY rowid;
939 SELECT * FROM e WHERE rowid||'' MATCH 'pattern';
943 xBestIndex {SELECT rowid, * FROM 'r'} \
944 xFilter {SELECT rowid, * FROM 'r'} \
946 proc match_func {args} {return ""}
949 db function match match_func
951 SELECT * FROM e WHERE match('pattern', rowid, 'pattern2');
955 xBestIndex {SELECT rowid, * FROM 'r'} \
956 xFilter {SELECT rowid, * FROM 'r'} \
960 # Testing the xFindFunction interface
962 catch {rename ::echo_glob_overload {}}
965 INSERT INTO r(a,b,c) VALUES(1,'?',99);
966 INSERT INTO r(a,b,c) VALUES(2,3,99);
967 SELECT a GLOB b FROM e
970 proc ::echo_glob_overload {a b} {
975 SELECT a like 'b' FROM e
980 SELECT a glob '2' FROM e
985 SELECT glob('2',a) FROM e
990 SELECT glob(a,'2') FROM e
994 #----------------------------------------------------------------------
995 # Test the outcome if a constraint is encountered half-way through
996 # a multi-row INSERT that is inside a transaction
1000 CREATE TABLE b(a, b, c);
1001 CREATE TABLE c(a UNIQUE, b, c);
1002 INSERT INTO b VALUES(1, 'A', 'B');
1003 INSERT INTO b VALUES(2, 'C', 'D');
1004 INSERT INTO b VALUES(3, 'E', 'F');
1005 INSERT INTO c VALUES(3, 'G', 'H');
1006 CREATE VIRTUAL TABLE echo_c USING echo(c);
1010 # First test outside of a transaction.
1011 do_test vtab1.12-2 {
1012 catchsql { INSERT INTO echo_c SELECT * FROM b; }
1013 } {1 {echo-vtab-error: column a is not unique}}
1014 do_test vtab1.12-2.1 {
1016 } {echo-vtab-error: column a is not unique}
1017 do_test vtab1.12-3 {
1018 execsql { SELECT * FROM c }
1021 # Now the real test - wrapped in a transaction.
1022 do_test vtab1.12-4 {
1024 catchsql { INSERT INTO echo_c SELECT * FROM b; }
1025 } {1 {echo-vtab-error: column a is not unique}}
1026 do_test vtab1.12-5 {
1027 execsql { SELECT * FROM c }
1029 do_test vtab1.12-6 {
1031 execsql { SELECT * FROM c }
1034 # At one point (ticket #2759), a WHERE clause of the form "<column> IS NULL"
1035 # on a virtual table was causing an assert() to fail in the compiler.
1037 # "IS NULL" clauses should not be passed through to the virtual table
1038 # implementation. They are handled by SQLite after the vtab returns its
1041 do_test vtab1.13-1 {
1043 SELECT * FROM echo_c WHERE a IS NULL
1046 do_test vtab1.13-2 {
1048 INSERT INTO c VALUES(NULL, 15, 16);
1049 SELECT * FROM echo_c WHERE a IS NULL
1052 do_test vtab1.13-3 {
1054 INSERT INTO c VALUES(15, NULL, 16);
1055 SELECT * FROM echo_c WHERE b IS NULL
1058 do_test vtab1.13-3 {
1060 SELECT * FROM echo_c WHERE b IS NULL AND a = 15;
1065 do_test vtab1-14.1 {
1066 execsql { DELETE FROM c }
1068 execsql { SELECT * FROM echo_c WHERE rowid IN (1, 2, 3) }
1070 } [list xBestIndex {SELECT rowid, * FROM 'c'} xFilter {SELECT rowid, * FROM 'c'}]
1072 do_test vtab1-14.2 {
1074 execsql { SELECT * FROM echo_c WHERE rowid = 1 }
1076 } [list xBestIndex {SELECT rowid, * FROM 'c' WHERE rowid = ?} xFilter {SELECT rowid, * FROM 'c' WHERE rowid = ?} 1]
1078 do_test vtab1-14.3 {
1080 execsql { SELECT * FROM echo_c WHERE a = 1 }
1082 } [list xBestIndex {SELECT rowid, * FROM 'c' WHERE a = ?} xFilter {SELECT rowid, * FROM 'c' WHERE a = ?} 1]
1084 do_test vtab1-14.4 {
1086 execsql { SELECT * FROM echo_c WHERE a IN (1, 2) }
1088 } [list xBestIndex {SELECT rowid, * FROM 'c'} xFilter {SELECT rowid, * FROM 'c'}]
1090 do_test vtab1-15.1 {
1092 CREATE TABLE t1(a, b, c);
1093 CREATE VIRTUAL TABLE echo_t1 USING echo(t1);
1096 do_test vtab1-15.2 {
1098 INSERT INTO echo_t1(rowid) VALUES(45);
1099 SELECT rowid, * FROM echo_t1;
1102 do_test vtab1-15.3 {
1104 INSERT INTO echo_t1(rowid) VALUES(NULL);
1105 SELECT rowid, * FROM echo_t1;
1107 } {45 {} {} {} 46 {} {} {}}
1108 do_test vtab1-15.4 {
1110 INSERT INTO echo_t1(rowid) VALUES('new rowid');
1112 } {1 {datatype mismatch}}
1114 # The following tests - vtab1-16.* - are designed to test that setting
1115 # sqlite3_vtab.zErrMsg variable can be used by the vtab interface to
1116 # return an error message to the user.
1118 do_test vtab1-16.1 {
1120 CREATE TABLE t2(a PRIMARY KEY, b, c);
1121 INSERT INTO t2 VALUES(1, 2, 3);
1122 INSERT INTO t2 VALUES(4, 5, 6);
1123 CREATE VIRTUAL TABLE echo_t2 USING echo(t2);
1128 foreach method [list \
1136 do_test vtab1-16.$tn {
1137 set echo_module_fail($method,t2) "the $method method has failed"
1138 catchsql { SELECT rowid, * FROM echo_t2 WHERE a >= 1 }
1139 } "1 {echo-vtab-error: the $method method has failed}"
1140 unset echo_module_fail($method,t2)
1144 foreach method [list \
1149 do_test vtab1-16.$tn {
1150 set echo_module_fail($method,t2) "the $method method has failed"
1151 catchsql { INSERT INTO echo_t2 VALUES(7, 8, 9) }
1152 } "1 {echo-vtab-error: the $method method has failed}"
1153 unset echo_module_fail($method,t2)
1157 ifcapable altertable {
1158 do_test vtab1-16.$tn {
1159 set echo_module_fail(xRename,t2) "the xRename method has failed"
1160 catchsql { ALTER TABLE echo_t2 RENAME TO another_name }
1161 } "1 {echo-vtab-error: the xRename method has failed}"
1162 unset echo_module_fail(xRename,t2)
1166 # The following test case exposes an instance in sqlite3_declare_vtab()
1167 # an error message was set using a call similar to sqlite3_mprintf(zErr),
1168 # where zErr is an arbitrary string. This is no good if the string contains
1169 # characters that can be mistaken for printf() formatting directives.
1171 do_test vtab1-17.1 {
1173 PRAGMA writable_schema = 1;
1174 INSERT INTO sqlite_master VALUES(
1175 'table', 't3', 't3', 0, 'INSERT INTO "%s%s" VALUES(1)'
1178 catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); }
1179 } {1 {vtable constructor failed: t4}}
1181 unset -nocomplain echo_module_begin_fail