CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
bestindexB.test88 linesDownload Raw Back to test
1# 2023-10-262#3# The author disclaims copyright to this source code.  In place of4# a legal notice, here is a blessing:5#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.9#10#***********************************************************************11# 12#13 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16set testprefix bestindexB17 18ifcapable !vtab {19  finish_test20  return21}22 23register_tcl_module db24 25proc vtab_command {method args} {26  switch -- $method {27    xConnect {28      return "CREATE TABLE t1(a, b, c)"29    }30 31    xBestIndex {32      set hdl [lindex $args 0]33      set clist [$hdl constraints]34      set orderby [$hdl orderby]35 36      if {[info exists ::xbestindex_sql]} { 37        explain_i $::xbestindex_sql 38        set ::xbestindex_res [ execsql $::xbestindex_sql ]39      }40 41      return "cost 1000000 rows 1000000 idxnum 0 idxstr hello"42    }43 44    xFilter {45      return "sql {SELECT 0, 1, 2, 3}"46    }47  }48 49  return {}50}51 52do_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} {}57 58do_execsql_test 1.1 {59  SELECT * FROM x160} {1 2 3}61 62do_execsql_test 1.2 {63  INSERT INTO y1 VALUES(1, 2) RETURNING rowid;64} {1}65 66do_execsql_test 1.3 {67  CREATE TRIGGER y1tr BEFORE INSERT ON y1 BEGIN68    SELECT * FROM x1;69  END;70  INSERT INTO y1 VALUES(3, 4) RETURNING rowid;71} {2}72 73 74# This time, rig the xBestIndex() method of the vtab to invoke an SQL75# statement that uses RETURNING.76set ::xbestindex_sql {77  INSERT INTO y2 VALUES(NULL, NULL) RETURNING rowid;78}79do_execsql_test 1.4 {80  INSERT INTO y1 VALUES(5, 6) RETURNING rowid;81} {3}82 83do_test 1.5 {84  set ::xbestindex_res85} {1}86 87finish_test88