Update tests in returning1.test to account for [c7896e88].
[sqlite.git] / test / bestindexB.test
blobb50e74fee3e29309fa389f97281ad6f4dc0d2fa2
1 # 2023-10-26
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
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix bestindexB
18 ifcapable !vtab {
19   finish_test
20   return
23 register_tcl_module db
25 proc vtab_command {method args} {
26   switch -- $method {
27     xConnect {
28       return "CREATE TABLE t1(a, b, c)"
29     }
31     xBestIndex {
32       set hdl [lindex $args 0]
33       set clist [$hdl constraints]
34       set orderby [$hdl orderby]
36       if {[info exists ::xbestindex_sql]} { 
37         explain_i $::xbestindex_sql 
38         set ::xbestindex_res [ execsql $::xbestindex_sql ]
39       }
41       return "cost 1000000 rows 1000000 idxnum 0 idxstr hello"
42     }
44     xFilter {
45       return "sql {SELECT 0, 1, 2, 3}"
46     }
47   }
49   return {}
52 do_execsql_test 1.0 {
53   CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
54   CREATE TABLE y1(a, b);
55   CREATE TABLE y2(a, b);
56 } {}
58 do_execsql_test 1.1 {
59   SELECT * FROM x1
60 } {1 2 3}
62 do_execsql_test 1.2 {
63   INSERT INTO y1 VALUES(1, 2) RETURNING rowid;
64 } {1}
66 do_execsql_test 1.3 {
67   CREATE TRIGGER y1tr BEFORE INSERT ON y1 BEGIN
68     SELECT * FROM x1;
69   END;
70   INSERT INTO y1 VALUES(3, 4) RETURNING rowid;
71 } {2}
74 # This time, rig the xBestIndex() method of the vtab to invoke an SQL
75 # statement that uses RETURNING.
76 set ::xbestindex_sql {
77   INSERT INTO y2 VALUES(NULL, NULL) RETURNING rowid;
79 do_execsql_test 1.4 {
80   INSERT INTO y1 VALUES(5, 6) RETURNING rowid;
81 } {3}
83 do_test 1.5 {
84   set ::xbestindex_res
85 } {1}
87 finish_test