summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:16:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-03 05:16:48 +0000
commit3640b21e686fef7e3f25dc775112c7d4be43f197 (patch)
treee7fec2ad45891adeada1227d655062cbd201dd5a /test
parentReleasing progress-linux version 3.45.3-1~progress7.99u1. (diff)
downloadsqlite3-3640b21e686fef7e3f25dc775112c7d4be43f197.tar.xz
sqlite3-3640b21e686fef7e3f25dc775112c7d4be43f197.zip
Merging upstream version 3.46.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--test/alter2.test8
-rw-r--r--test/altertab2.test22
-rw-r--r--test/altertab3.test50
-rw-r--r--test/avfs.test1
-rw-r--r--test/bestindex8.test2
-rw-r--r--test/bestindexC.test213
-rw-r--r--test/busy.test2
-rw-r--r--test/capi3.test2
-rw-r--r--test/cksumvfs.test33
-rw-r--r--test/corruptC.test2
-rw-r--r--test/corruptD.test2
-rw-r--r--test/corruptL.test85
-rw-r--r--test/cost.test2
-rw-r--r--test/date.test85
-rw-r--r--test/date4.test6
-rw-r--r--test/default.test4
-rw-r--r--test/distinctagg.test9
-rw-r--r--test/e_reindex.test6
-rw-r--r--test/eqp.test6
-rw-r--r--test/eqp2.test49
-rw-r--r--test/exprfault2.test35
-rw-r--r--test/fts3fault3.test28
-rw-r--r--test/fts3snippet2.test11
-rw-r--r--test/func2.test23
-rw-r--r--test/func4.test35
-rw-r--r--test/fuzzcheck.c16
-rw-r--r--test/fuzzinvariants.c39
-rw-r--r--test/icu.test18
-rw-r--r--test/in4.test4
-rw-r--r--test/in5.test22
-rw-r--r--test/in7.test141
-rw-r--r--test/indexexpr1.test52
-rw-r--r--test/json102.test31
-rw-r--r--test/json106.test6
-rw-r--r--test/json108.test45
-rw-r--r--test/json501.test27
-rw-r--r--test/lemon-test01.y7
-rw-r--r--test/literal.test103
-rw-r--r--test/literal2.tcl40
-rw-r--r--test/literal2.test84
-rw-r--r--test/misc1.test2
-rw-r--r--test/misc5.test24
-rw-r--r--test/mmapcorrupt.test4
-rw-r--r--test/orderby1.test2
-rw-r--r--test/permutations.test1
-rw-r--r--test/pragma.test35
-rw-r--r--test/pragma4.test32
-rw-r--r--test/pragma6.test74
-rw-r--r--test/pushdown.test113
-rw-r--r--test/quote.test10
-rw-r--r--test/readonly.test55
-rw-r--r--test/recover.test1
-rw-r--r--test/returning1.test81
-rw-r--r--test/scanstatus2.test13
-rw-r--r--test/selectA.test4
-rw-r--r--test/sessionfuzz.c1
-rw-r--r--test/shell1.test1
-rw-r--r--test/shell2.test1
-rw-r--r--test/shell3.test1
-rw-r--r--test/shell4.test1
-rw-r--r--test/shell5.test1
-rw-r--r--test/shell6.test1
-rw-r--r--test/shell7.test1
-rw-r--r--test/shell8.test28
-rw-r--r--test/shell9.test1
-rw-r--r--test/speedtest1.c46
-rw-r--r--test/sqllimits1.test4
-rw-r--r--test/subquery.test59
-rw-r--r--test/tabfunc01.test26
-rw-r--r--test/testrunner.tcl239
-rw-r--r--test/testrunner_data.tcl45
-rw-r--r--test/tkt-8454a207b9.test2
-rw-r--r--test/tkt-bd484a090c.test2
-rw-r--r--test/upsert1.test24
-rw-r--r--test/values.test715
-rw-r--r--test/valuesfault.test37
-rw-r--r--test/view.test23
-rw-r--r--test/vtabL.test75
-rw-r--r--test/whereL.test45
-rw-r--r--test/whereN.test103
80 files changed, 3156 insertions, 133 deletions
diff --git a/test/alter2.test b/test/alter2.test
index aae0061..20b75b5 100644
--- a/test/alter2.test
+++ b/test/alter2.test
@@ -371,7 +371,7 @@ do_test alter2-7.5 {
execsql {
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
-} {1 integer -123 integer 5 text}
+} {1 integer -123.0 real 5 text}
#-----------------------------------------------------------------------
# Test that UPDATE trigger tables work with default values, and that when
@@ -397,11 +397,11 @@ do_test alter2-8.2 {
UPDATE t1 SET c = 10 WHERE a = 1;
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
}
-} {1 integer -123 integer 10 text}
+} {1 integer -123.0 real 10 text}
ifcapable trigger {
do_test alter2-8.3 {
set ::val
- } {-123 integer 5 text -123 integer 10 text}
+ } {-123.0 real 5 text -123.0 real 10 text}
}
#-----------------------------------------------------------------------
@@ -425,7 +425,7 @@ ifcapable trigger {
DELETE FROM t1 WHERE a = 2;
}
set ::val
- } {-123 integer 5 text}
+ } {-123.0 real 5 text}
}
#-----------------------------------------------------------------------
diff --git a/test/altertab2.test b/test/altertab2.test
index def9e56..576dc49 100644
--- a/test/altertab2.test
+++ b/test/altertab2.test
@@ -360,4 +360,26 @@ do_catchsql_test 8.6 {
SELECT sql FROM sqlite_master WHERE name='i0';
} {1 {error in index i0: second argument to likelihood() must be a constant between 0.0 and 1.0}}
+
+reset_db
+
+do_execsql_test 9.0 {
+ CREATE TABLE t1(a,b,c,d);
+ CREATE TABLE t2(a,b,c,d,x);
+
+ CREATE TRIGGER AFTER INSERT ON t2 BEGIN
+
+ SELECT group_conct(
+ 123 ORDER BY (
+ SELECT 1 FROM ( VALUES(a, 'b'), ('c') )
+ ))
+ FROM t1;
+
+ END;
+}
+
+do_catchsql_test 9.1 {
+ ALTER TABLE t2 RENAME TO newname;
+} {1 {error in trigger AFTER: all VALUES must have the same number of terms}}
+
finish_test
diff --git a/test/altertab3.test b/test/altertab3.test
index 5fd17f3..5f5c11b 100644
--- a/test/altertab3.test
+++ b/test/altertab3.test
@@ -736,4 +736,54 @@ do_execsql_test 29.7 {
END}
}
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 30.0 {
+ CREATE TABLE t1(a, b);
+ CREATE VIEW v1 AS
+ SELECT ( VALUES(a), (b) ) FROM (
+ SELECT a, b FROM t1
+ )
+ ;
+}
+
+do_execsql_test 30.1 {
+ SELECT * FROM v1
+}
+
+do_execsql_test 30.1 {
+ ALTER TABLE t1 RENAME TO t2;
+}
+do_execsql_test 30.2 {
+ SELECT sql FROM sqlite_schema WHERE type='view'
+} {
+ {CREATE VIEW v1 AS
+ SELECT ( VALUES(a), (b) ) FROM (
+ SELECT a, b FROM "t2"
+ )}
+}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 31.0 {
+ CREATE TABLE t1(ii INTEGER PRIMARY KEY, tt INTEGER, rr REAL);
+ WITH s(i) AS (
+ SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000
+ )
+ INSERT INTO t1 SELECT NULL, i, 5.0 FROM s;
+}
+
+do_test 31.1 {
+ set pg [db one {PRAGMA page_count}]
+ execsql {
+ ALTER TABLE t1 DROP COLUMN tt;
+ }
+ set pg2 [db one {PRAGMA page_count}]
+ expr $pg==$pg2
+} {1}
+
+do_execsql_test 31.2 {
+ SELECT rr FROM t1 LIMIT 1
+} {5.0}
+
finish_test
diff --git a/test/avfs.test b/test/avfs.test
index 2ebd608..ffd6b30 100644
--- a/test/avfs.test
+++ b/test/avfs.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# This file implements tests for the appendvfs extension.
#
diff --git a/test/bestindex8.test b/test/bestindex8.test
index e95c3c6..3ed7f67 100644
--- a/test/bestindex8.test
+++ b/test/bestindex8.test
@@ -158,7 +158,7 @@ do_test 2.2 {
set ::lFilterArgs [list]
execsql { SELECT * FROM vt1 LIMIT 5 OFFSET 50 }
set ::lFilterArgs
-} {{5 50}}
+} {{50 5}}
do_test 2.3 {
set ::lFilterArgs [list]
diff --git a/test/bestindexC.test b/test/bestindexC.test
new file mode 100644
index 0000000..c6ddf30
--- /dev/null
+++ b/test/bestindexC.test
@@ -0,0 +1,213 @@
+# 2024-04-26
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix bestindexC
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+register_tcl_module db
+
+proc vtab_command {lVal method args} {
+ switch -- $method {
+ xConnect {
+ return "CREATE TABLE t1(a)"
+ }
+
+ xBestIndex {
+ set hdl [lindex $args 0]
+ set clist [$hdl constraints]
+ set orderby [$hdl orderby]
+
+ set idxstr [list]
+ set res [list]
+
+ set idx 0
+ foreach c $clist {
+ array set a $c
+ if {$a(usable)==0} continue
+ if {$a(op)=="limit" && ![info exists ::do_not_use_limit]} {
+ lappend idxstr limit
+ lappend res omit $idx
+ }
+ if {$a(op)=="offset" && ![info exists ::do_not_use_offset]} {
+ lappend idxstr offset
+ lappend res omit $idx
+ }
+ incr idx
+ }
+
+ return "cost 1000000 rows 1000000 idxnum 0 idxstr {$idxstr} $res"
+ }
+
+ xFilter {
+ set idxstr [lindex $args 1]
+ set LIMIT ""
+ foreach a $idxstr b [lindex $args 2] {
+ set x($a) $b
+ }
+
+ if {![info exists x(limit)]} { set x(limit) -1 }
+ if {![info exists x(offset)]} { set x(offset) -1 }
+ set LIMIT " LIMIT $x(limit) OFFSET $x(offset)"
+
+ set idx 1
+ foreach v $lVal {
+ lappend lRow "($idx, '$v')"
+ incr idx
+ }
+
+ return [list sql "
+ SELECT * FROM ( VALUES [join $lRow ,]) $LIMIT
+ "]
+ }
+ }
+
+ return {}
+}
+
+do_execsql_test 1.0 {
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f");
+ CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "A B C D E F a b");
+} {}
+
+do_execsql_test 1.1 {
+ CREATE TEMP TABLE t_unionall AS
+ SELECT * FROM x1 UNION ALL SELECT * FROM x2;
+
+ CREATE TEMP TABLE t_intersect AS
+ SELECT * FROM x1 INTERSECT SELECT * FROM x2;
+
+ CREATE TEMP TABLE t_union AS
+ SELECT * FROM x1 UNION SELECT * FROM x2;
+
+ CREATE TEMP TABLE t_except AS
+ SELECT * FROM x1 EXCEPT SELECT * FROM x2;
+}
+
+foreach {tn limit} {
+ 1 "LIMIT 8"
+ 2 "LIMIT 4"
+ 3 "LIMIT 4 OFFSET 2"
+ 4 "LIMIT 8 OFFSET 4"
+} {
+
+ foreach {op tbl} {
+ "UNION ALL" t_unionall
+ "UNION" t_union
+ "INTERSECT" t_intersect
+ "EXCEPT" t_except
+ } {
+
+ set expect [execsql "SELECT * FROM $tbl $limit"]
+ do_execsql_test 1.2.$tbl.$tn "SELECT * FROM (
+ SELECT * FROM x1 $op SELECT * FROM x2
+ ) $limit" $expect
+
+ }
+
+}
+
+#-------------------------------------------------------------------------
+reset_db
+register_tcl_module db
+
+do_execsql_test 2.0 {
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command "a b c d e f");
+ CREATE VIRTUAL TABLE x2 USING tcl(vtab_command "a b e f");
+} {}
+
+do_execsql_test 2.1 {
+ SELECT * FROM x1
+ EXCEPT
+ SELECT * FROM x2
+ LIMIT 3
+} {c d}
+
+#-------------------------------------------------------------------------
+reset_db
+register_tcl_module db
+do_execsql_test 3.0 {
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "1 2 3 4 5 6 7 8 9 10");
+} {}
+
+do_execsql_test 3.1 {
+ SELECT * FROM y1 WHERE a = COALESCE('8', a) LIMIT 3
+} {8}
+
+do_execsql_test 3.2 {
+ SELECT * FROM y1 WHERE a = '2' LIMIT 3
+} {2}
+
+load_static_extension db series
+do_execsql_test 3.3 {
+ SELECT * FROM generate_series(1, 5) WHERE value = (value & 14) LIMIT 3
+} {2 4}
+
+do_execsql_test 3.4 {
+ SELECT value FROM generate_series(1,10) WHERE value>2 LIMIT 4 OFFSET 1;
+} {4 5 6 7}
+
+set ::do_not_use_limit 1
+do_execsql_test 3.5 {
+ SELECT * FROM y1 LIMIT 5 OFFSET 3
+} {4 5 6 7 8}
+unset ::do_not_use_limit
+set ::do_not_use_offset 1
+do_execsql_test 3.6 {
+ SELECT * FROM y1 LIMIT 5 OFFSET 3
+} {4 5 6 7 8}
+unset ::do_not_use_offset
+
+#-------------------------------------------------------------------------
+reset_db
+proc vtab_command {lVal method args} {
+ switch -- $method {
+ xConnect { error "not happy!" }
+ }
+
+ return {}
+}
+
+register_tcl_module db
+do_catchsql_test 4.0 {
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command 1);
+} {1 {not happy!}}
+do_test 4.1 {
+ sqlite3_errcode db
+} SQLITE_ERROR
+
+proc vtab_command {lVal method args} {
+ switch -- $method {
+ xConnect {
+ return $lVal
+ }
+ }
+ return {}
+}
+
+do_catchsql_test 4.2 {
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "PRAGMA page_size=1024");
+} {1 {declare_vtab: syntax error}}
+do_catchsql_test 4.3 {
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1(");
+} {1 {declare_vtab: incomplete input}}
+do_catchsql_test 4.4 {
+ CREATE VIRTUAL TABLE y1 USING tcl(vtab_command "CREATE TABLE x1(insert)");
+} {1 {declare_vtab: near "insert": syntax error}}
+
+finish_test
diff --git a/test/busy.test b/test/busy.test
index be0515b..896c7fa 100644
--- a/test/busy.test
+++ b/test/busy.test
@@ -106,7 +106,7 @@ do_test 3.4 {
proc busy_handler {n} { return 1 }
do_test 3.5 {
catchsql { PRAGMA optimize }
-} {0 {}}
+} {1 {database is locked}}
do_test 3.6 {
execsql { COMMIT } db2
diff --git a/test/capi3.test b/test/capi3.test
index 40d87ac..e65f90e 100644
--- a/test/capi3.test
+++ b/test/capi3.test
@@ -181,7 +181,7 @@ do_test capi3-3.4 {
do_test capi3-3.5 {
list [sqlite3_system_errno $db2] [sqlite3_close $db2]
} [list $::capi3_errno SQLITE_OK]
-if {[clang_sanitize_address]==0} {
+if {[clang_sanitize_address]==0 && 0} {
do_test capi3-3.6.1-misuse {
sqlite3_close $db2
} {SQLITE_MISUSE}
diff --git a/test/cksumvfs.test b/test/cksumvfs.test
new file mode 100644
index 0000000..8c7bcf5
--- /dev/null
+++ b/test/cksumvfs.test
@@ -0,0 +1,33 @@
+# 2024 March 19
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix cksumvfs
+
+sqlite3_register_cksumvfs
+db close
+sqlite3 db test.db
+file_control_reservebytes db 8
+
+set text [db one "SELECT hex(randomblob(5000))"]
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
+ INSERT INTO t1 VALUES(1, $text);
+}
+
+do_execsql_test 1.1 {
+ SELECT * FROM t1;
+} [list 1 $text]
+
+finish_test
diff --git a/test/corruptC.test b/test/corruptC.test
index f5733a8..bf324c1 100644
--- a/test/corruptC.test
+++ b/test/corruptC.test
@@ -98,7 +98,7 @@ do_test corruptC-2.1 {
sqlite3 db test.db
catchsql {PRAGMA integrity_check}
} {0 {{*** in database main ***
-Tree 3 page 3: free space corruption}}}
+Tree 3 page 3: free space corruption} {wrong # of entries in index t1i1}}}
# test that a corrupt content offset size is handled (seed 5649)
#
diff --git a/test/corruptD.test b/test/corruptD.test
index c35388a..381e52c 100644
--- a/test/corruptD.test
+++ b/test/corruptD.test
@@ -113,7 +113,7 @@ do_test corruptD-1.1.1 {
hexio_write test.db [expr 1024+1] FFFF
catchsql { PRAGMA quick_check }
} {0 {{*** in database main ***
-Tree 2 page 2: free space corruption}}}
+Tree 2 page 2: free space corruption} {wrong # of entries in index i1}}}
do_test corruptD-1.1.2 {
incr_change_counter
hexio_write test.db [expr 1024+1] [hexio_render_int32 1021]
diff --git a/test/corruptL.test b/test/corruptL.test
index cf38764..52adf6f 100644
--- a/test/corruptL.test
+++ b/test/corruptL.test
@@ -1505,4 +1505,89 @@ do_catchsql_test 19.4 {
PRAGMA integrity_check;
} {1 {database disk image is malformed}}
+#-------------------------------------------------------------------------
+reset_db
+do_test 18.0 {
+ sqlite3 db {}
+ db deserialize [decode_hexdb {
+.open --hexdb
+| size 20480 pagesize 4096 filename crash-a4150b729051e4.db
+| page 1 offset 0
+| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
+| 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05 .....@ ........
+| 32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 ................
+| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
+| 64: 00 00 00 00 00 00 00 00 00 00 ff f0 00 00 00 00 ................
+| 96: 00 00 00 00 0d 00 00 00 04 0e e5 00 0f c2 0f 75 ...............u
+| 112: 0f 19 0e e5 00 00 00 00 00 00 00 01 00 00 00 00 ................
+| 3808: 00 00 00 00 00 32 04 06 17 17 11 01 4b 69 6e 64 .....2......Kind
+| 3824: 65 78 74 31 61 62 63 74 31 05 43 52 45 41 54 45 ext1abct1.CREATE
+| 3840: 20 49 4e 44 45 58 20 74 31 61 62 63 20 4f 4e 20 INDEX t1abc ON
+| 3856: 74 31 28 61 2c 62 2c 63 29 5a 03 06 17 25 25 01 t1(a,b,c)Z...%%.
+| 3872: 79 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 ytablesqlite_sta
+| 3888: 74 34 73 71 6c 69 74 65 5f 73 74 61 74 34 04 43 t4sqlite_stat4.C
+| 3904: 52 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 REATE TABLE sqli
+| 3920: 74 65 5f 73 74 61 74 34 28 74 62 6c 2c 69 64 78 te_stat4(tbl,idx
+| 3936: 2c 6e 65 71 2c 6e 6c 74 2c 6e 64 6c 74 2c 73 61 ,neq,nlt,ndlt,sa
+| 3952: 6d 70 6c 65 29 4b 02 06 17 25 25 01 5b 74 61 62 mple)K...%%.[tab
+| 3968: 6c 65 73 71 6c 69 74 65 5f 73 74 61 74 31 73 71 lesqlite_stat1sq
+| 3984: 6c 69 74 65 5f 73 74 61 74 31 03 43 52 45 41 54 lite_stat1.CREAT
+| 4000: 45 20 54 41 42 4c 45 20 73 71 6c 69 74 65 5f 73 E TABLE sqlite_s
+| 4016: 74 61 74 31 28 74 62 6c 2c 69 64 78 2c 73 74 61 tat1(tbl,idx,sta
+| 4032: 74 29 3c 01 06 17 11 11 01 65 74 61 62 6c 65 74 t)<......etablet
+| 4048: 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c 45 1t1.CREATE TABLE
+| 4064: 20 74 31 28 61 20 54 45 58 54 2c 20 62 20 49 4e t1(a TEXT, b IN
+| 4080: 54 2c 20 63 20 49 4e 54 2c 20 64 20 49 4e 54 29 T, c INT, d INT)
+| page 2 offset 4096
+| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
+| 4000: 0b 07 05 13 01 01 01 62 63 64 64 06 0b 0c 06 05 .......bcdd.....
+| 4016: 13 02 01 01 64 65 66 01 59 09 0a 0c 05 05 13 03 ....def.Y.......
+| 4032: 01 01 64 65 66 02 6f 08 09 0c 04 05 13 02 01 01 ..def.o.........
+| 4048: 61 62 63 01 59 07 08 0c 03 05 13 02 01 01 87 62 abc.Y..........b
+| 4064: 63 00 ea 06 07 0c 02 05 13 02 01 01 61 62 63 00 c...........abc.
+| 4080: ea 06 06 0b 01 05 13 01 01 01 61 62 63 7b 04 04 ..........abc...
+| page 3 offset 8192
+| 0: 0d 00 00 00 01 0f e0 00 0f e1 00 00 00 00 00 00 ................
+| 4064: 00 1d 01 04 11 17 31 74 31 74 31 61 62 63 31 30 ......1t1t1abc10
+| 4080: 30 30 30 20 35 30 30 30 20 32 30 30 30 20 31 30 000 5000 2000 10
+| page 4 offset 12288
+| 0: 0d 00 00 00 07 0e ac 00 0f d1 0f a0 0f 6f 0f 3e .............o.>
+| 16: 0f 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
+| 3744: 00 00 00 00 00 00 00 00 00 00 00 00 2f 07 07 11 ............/...
+| 3760: 17 1b 1b 1b 24 74 31 74 31 61 62 63 32 20 31 20 ....$t1t1abc2 1
+| 3776: 31 20 31 35 20 36 20 36 20 36 32 20 35 20 36 20 1 15 6 6 62 5 6
+| 3792: 36 05 13 02 01 01 64 65 66 02 37 08 05 2f 06 07 6.....def.7../..
+| 3808: 11 17 1b 1b 1b 24 74 41 74 31 61 62 63 32 20 31 .....$tAt1abc2 1
+| 3824: 20 31 20 31 35 20 35 20 55 20 35 32 20 34 20 35 1 15 5 U 52 4 5
+| 3840: 20 35 05 13 02 01 01 64 65 66 01 59 09 06 2e 05 5.....def.Y....
+| 3856: 07 11 17 1b 1b 1b 22 74 31 74 31 61 62 63 31 20 .......t1t1abc1
+| 3872: 31 20 31 20 31 34 20 34 20 34 20 34 31 20 33 20 1 1 14 4 4 41 3
+| 3888: 34 20 34 08 b3 cd f0 f1 62 63 64 64 06 07 2f 05 4 4.....bcdd../.
+| 3904: 07 11 17 1b 1b 1b 24 74 37 74 31 61 62 63 34 20 ......$t7t1abc4
+| 3920: 31 20 31 20 31 30 20 33 20 33 20 33 30 20 32 20 1 1 10 3 3 30 2
+| 3936: 33 20 33 05 13 02 01 01 61 62 63 01 59 07 04 2f 3 3.....abc.Y../
+| 3952: 03 07 11 17 1b 1b 1b 24 74 31 74 31 61 62 63 34 .......$t1t1abc4
+| 3968: 20 32 20 31 20 31 30 20 31 20 32 20 32 30 20 31 2 1 10 1 2 20 1
+| 3984: 20 32 20 32 05 13 02 01 01 61 62 63 00 ea 06 03 2 2.....abc....
+| 4000: 2f 02 07 11 17 1b 1b 1b 24 74 31 74 31 61 62 63 /.......$t1t1abc
+| 4016: 34 20 32 20 31 20 31 30 20 31 20 31 20 31 30 20 4 2 1 10 1 1 10
+| 4032: 31 20 31 20 31 05 13 02 01 01 61 62 63 00 ea 05 1 1 1.....abc...
+| 4048: 02 2d 01 07 11 17 1b 1b 1b 20 74 31 74 31 61 62 .-....... t1t1ab
+| 4064: 63 34 20 31 20 31 20 31 30 20 30 20 30 1f 30 30 c4 1 1 10 0 0.00
+| 4080: 20 30 20 30 20 30 05 13 01 01 09 61 62 63 7b 04 0 0 0.....abc..
+| page 5 offset 16384
+| 0: 0a 00 00 00 07 0f a8 00 0f f5 00 00 00 00 00 00 ................
+| 4000: 00 00 00 00 00 00 00 00 0c 05 13 02 01 01 64 65 ..............de
+| 4016: 66 02 37 08 05 0c 05 13 02 01 01 64 65 66 01 59 f.7........def.Y
+| 4032: 09 06 0b 05 12 01 01 01 62 63 64 64 06 07 0c 05 ........bcdd....
+| 4048: 13 02 01 01 61 62 63 01 59 07 01 2c 05 13 02 01 ....abc.Y..,....
+| 4064: 01 61 62 63 00 ea 06 03 0c 05 13 02 01 01 61 62 .abc..........ab
+| 4080: 63 00 ea 05 00 00 00 00 00 00 00 00 00 00 00 00 c...............
+| end crash-a4150b729051e4.db
+}]} {}
+
+do_catchsql_test 18.1 {
+ SELECT a FROM t1 WHERE b GLOB b AND b GLOB '0^x]␅6␚xz]';
+} {1 {database disk image is malformed}}
+
finish_test
diff --git a/test/cost.test b/test/cost.test
index 5684177..6106cab 100644
--- a/test/cost.test
+++ b/test/cost.test
@@ -103,7 +103,7 @@ do_eqp_test 5.2 {
} {
QUERY PLAN
|--SCAN t2 USING INDEX t2i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
}
do_eqp_test 5.3 {
diff --git a/test/date.test b/test/date.test
index 19cecc2..d22b652 100644
--- a/test/date.test
+++ b/test/date.test
@@ -209,8 +209,8 @@ datetest 3.16 "strftime('[repeat 200 %Y]','2003-10-31')" [repeat 200 2003]
datetest 3.17 "strftime('[repeat 200 abc%m123]','2003-10-31')" \
[repeat 200 abc10123]
-foreach c {a b c g h i n o q r t v x y z
- A B C D E G K L N O Q V Z
+foreach c {a b c h i n o q r t v x y z
+ A B C D E K L N O Q Z
0 1 2 3 4 5 6 6 7 9 _} {
datetest 3.18.$c "strftime('%$c','2003-10-31')" NULL
}
@@ -262,7 +262,7 @@ datetest 5.15 {datetime('1994-04-16 14:00:00 +05:00 Z')} NULL
# localtime->utc and utc->localtime conversions.
#
# Use SQLITE_TESTCTRL_LOCALTIME_FAULT=2 to set an alternative localtime_r()
-# implementation that is not locale-dependent. This testing localtime_r()
+# implementation that is not locale-dependent. The testing localtime_r()
# operates as follows:
#
# (1) Localtime is 30 minutes earlier than (west of) UTC on
@@ -321,6 +321,38 @@ utc_to_local 6.22 {1800-10-29 12:30:00} {1800-10-29 12:00:00}
local_to_utc 6.23 {3000-10-30 12:00:00} {3000-10-30 11:30:00}
utc_to_local 6.24 {3000-10-30 11:30:00} {3000-10-30 12:00:00}
+# If the time is specified to be ZULU, or if it has an explicit
+# timezone extension, then the time will already be UTC and subsequent
+# 'utc' modifiers are no-ops.
+#
+do_execsql_test date-6.25 {
+ SELECT datetime('2000-10-29 12:00Z','utc','utc');
+} {{2000-10-29 12:00:00}}
+do_execsql_test date-6.26 {
+ SELECT datetime('2000-10-29 12:00:00+05:00');
+} {{2000-10-29 07:00:00}}
+do_execsql_test date-6.27 {
+ SELECT datetime('2000-10-29 12:00:00+05:00', 'utc');
+} {{2000-10-29 07:00:00}}
+
+# Multiple back-and-forth UTC to LOCAL to UTC...
+do_execsql_test date-6.28 {
+ SELECT datetime('2000-10-29 12:00:00Z', 'localtime');
+} {{2000-10-29 12:30:00}}
+do_execsql_test date-6.29 {
+ SELECT datetime('2000-10-29 12:00:00Z', 'utc', 'localtime');
+} {{2000-10-29 12:30:00}}
+do_execsql_test date-6.30 {
+ SELECT datetime('2000-10-29 12:00:00Z', 'utc', 'localtime', 'utc');
+} {{2000-10-29 12:00:00}}
+do_execsql_test date-6.31 {
+ SELECT datetime('2000-10-29 12:00:00Z', 'utc','localtime','utc','localtime');
+} {{2000-10-29 12:30:00}}
+do_execsql_test date-6.32 {
+ SELECT datetime('2000-10-29 12:00:00Z', 'localtime','localtime');
+} {{2000-10-29 12:30:00}}
+
+
# Restore the use of the OS localtime_r() before going on...
sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0
@@ -573,4 +605,51 @@ datetest 18.2 {unixepoch('1970-01-01T00:00:00.1', 'subsec')} {0.1}
datetest 18.3 {unixepoch('1970-01-01T00:00:00.2', 'subsecond')} {0.2}
datetest 18.4 {julianday('-4713-11-24 13:40:48.864', 'subsec')} {0.07001}
datetest 18.5 {typeof(unixepoch('now', 'subsecond'))} {real}
+
+# 2024-03-03 the 'ceiling' and 'floor' operators.
+#
+datetest 19.1 {date('2000-01-31','floor')} {2000-01-31}
+datetest 19.2a {date('2000-02-31','floor')} {2000-02-29}
+datetest 19.2b {date('1999-02-31','floor')} {1999-02-28}
+datetest 19.2c {date('1900-02-31','floor')} {1900-02-28}
+datetest 19.3 {date('2000-03-31','floor')} {2000-03-31}
+datetest 19.4 {date('2000-04-31','floor')} {2000-04-30}
+datetest 19.5 {date('2000-05-31','floor')} {2000-05-31}
+datetest 19.6 {date('2000-06-31','floor')} {2000-06-30}
+datetest 19.7 {date('2000-07-31','floor')} {2000-07-31}
+datetest 19.8 {date('2000-08-31','floor')} {2000-08-31}
+datetest 19.9 {date('2000-09-31','floor')} {2000-09-30}
+datetest 19.10 {date('2000-10-31','floor')} {2000-10-31}
+datetest 19.11 {date('2000-11-31','floor')} {2000-11-30}
+datetest 19.12 {date('2000-12-31','floor')} {2000-12-31}
+datetest 19.21 {date('2000-01-31','ceiling')} {2000-01-31}
+datetest 19.22a {date('2000-02-31','ceiling')} {2000-03-02}
+datetest 19.22b {date('1999-02-31','ceiling')} {1999-03-03}
+datetest 19.22c {date('1900-02-31','ceiling')} {1900-03-03}
+datetest 19.23 {date('2000-03-31','ceiling')} {2000-03-31}
+datetest 19.24 {date('2000-04-31','ceiling')} {2000-05-01}
+datetest 19.25 {date('2000-05-31','ceiling')} {2000-05-31}
+datetest 19.26 {date('2000-06-31','ceiling')} {2000-07-01}
+datetest 19.27 {date('2000-07-31','ceiling')} {2000-07-31}
+datetest 19.28 {date('2000-08-31','ceiling')} {2000-08-31}
+datetest 19.29 {date('2000-09-31','ceiling')} {2000-10-01}
+datetest 19.30 {date('2000-10-31','ceiling')} {2000-10-31}
+datetest 19.31 {date('2000-11-31','ceiling')} {2000-12-01}
+datetest 19.32 {date('2000-12-31','ceiling')} {2000-12-31}
+datetest 19.40 {date('2024-01-31','+1 month','ceiling')} {2024-03-02}
+datetest 19.41 {date('2024-01-31','+1 month','floor')} {2024-02-29}
+datetest 19.42 {date('2023-01-31','+1 month','ceiling')} {2023-03-03}
+datetest 19.43 {date('2023-01-31','+1 month','floor')} {2023-02-28}
+datetest 19.44 {date('2024-02-29','+1 year','ceiling')} {2025-03-01}
+datetest 19.45 {date('2024-02-29','+1 year','floor')} {2025-02-28}
+datetest 19.46 {date('2024-02-29','-110 years','ceiling')} {1914-03-01}
+datetest 19.47 {date('2024-02-29','-110 years','floor')} {1914-02-28}
+datetest 19.48 {date('2024-02-29','-0110-00-00','floor')} {1914-02-28}
+datetest 19.49 {date('2024-02-29','-0110-00-00','ceiling')} {1914-03-01}
+datetest 19.50 {date('2000-08-31','+0023-06-00','floor')} {2024-02-29}
+datetest 19.51 {date('2000-08-31','+0022-06-00','floor')} {2023-02-28}
+datetest 19.52 {date('2000-08-31','+0023-06-00','ceiling')} {2024-03-02}
+datetest 19.53 {date('2000-08-31','+0022-06-00','ceiling')} {2023-03-03}
+
+
finish_test
diff --git a/test/date4.test b/test/date4.test
index 0d820a0..56a9090 100644
--- a/test/date4.test
+++ b/test/date4.test
@@ -24,12 +24,12 @@ ifcapable {!datetime} {
}
if {$tcl_platform(os)=="Linux"} {
- set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p}
+ set FMT {%d,%e,%F,%H,%k,%I,%l,%j,%m,%M,%u,%w,%W,%Y,%%,%P,%p,%U,%V,%G,%g}
} else {
set FMT {%d,%e,%F,%H,%I,%j,%p,%R,%u,%w,%W,%%}
}
-for {set i 0} {$i<=24854} {incr i} {
- set TS [expr {$i*86401}]
+for {set i 0} {$i<=24858} {incr i} {
+ set TS [expr {$i*86390}]
do_execsql_test date4-$i {
SELECT strftime($::FMT,$::TS,'unixepoch');
} [list [strftime $FMT $TS]]
diff --git a/test/default.test b/test/default.test
index de67f64..192b3d2 100644
--- a/test/default.test
+++ b/test/default.test
@@ -135,10 +135,10 @@ reset_db
do_catchsql_test default-5.1 {
CREATE TABLE t1 (a,b DEFAULT(random() NOTNULL IN (RAISE(IGNORE),2,3)));
INSERT INTO t1(a) VALUES(1);
-} {1 {RAISE() may only be used within a trigger-program}}
+} {1 {default value of column [b] is not constant}}
do_catchsql_test default-5.2 {
CREATE TABLE Table0 (Col0 DEFAULT (RAISE(IGNORE) ) ) ;
INSERT INTO Table0 DEFAULT VALUES ;
-} {1 {RAISE() may only be used within a trigger-program}}
+} {1 {default value of column [Col0] is not constant}}
finish_test
diff --git a/test/distinctagg.test b/test/distinctagg.test
index 199ca06..9eedd35 100644
--- a/test/distinctagg.test
+++ b/test/distinctagg.test
@@ -95,7 +95,7 @@ foreach {tn use_eph sql res} {
7 0 "SELECT count(DISTINCT a) FROM t2, t1" 5
8 1 "SELECT count(DISTINCT a+b) FROM t1, t2, t2, t2" 6
9 0 "SELECT count(DISTINCT c) FROM t1 WHERE c=2" 1
- 10 1 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10
+ 10 0 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10
} {
do_test 3.$tn.1 {
set prg [db eval "EXPLAIN $sql"]
@@ -148,6 +148,10 @@ do_execsql_test 3.0 {
CREATE TABLE t3(x, y, z);
INSERT INTO t3 VALUES(1,1,1);
INSERT INTO t3 VALUES(2,2,2);
+
+ CREATE TABLE t4(a);
+ CREATE INDEX t4a ON t4(a);
+ INSERT INTO t4 VALUES(1), (2), (2), (3), (1);
}
foreach {tn use_eph sql res} {
@@ -158,6 +162,9 @@ foreach {tn use_eph sql res} {
4 0 "SELECT count(DISTINCT f) FROM t2 GROUP BY d, e" {1 2 2 3}
5 1 "SELECT count(DISTINCT f) FROM t2 GROUP BY d" {2 3}
6 0 "SELECT count(DISTINCT f) FROM t2 WHERE d IS 1 GROUP BY e" {1 2 2}
+
+ 7 0 "SELECT count(DISTINCT a) FROM t1" {4}
+ 8 0 "SELECT count(DISTINCT a) FROM t4" {3}
} {
do_test 4.$tn.1 {
set prg [db eval "EXPLAIN $sql"]
diff --git a/test/e_reindex.test b/test/e_reindex.test
index 00291b7..50d2e7d 100644
--- a/test/e_reindex.test
+++ b/test/e_reindex.test
@@ -73,12 +73,12 @@ sqlite3 db test.db
do_execsql_test e_reindex-1.3 {
PRAGMA integrity_check;
} [list \
+ {wrong # of entries in index i2} \
+ {wrong # of entries in index i1} \
{row 3 missing from index i2} \
{row 3 missing from index i1} \
{row 4 missing from index i2} \
- {row 4 missing from index i1} \
- {wrong # of entries in index i2} \
- {wrong # of entries in index i1}
+ {row 4 missing from index i1}
]
do_execsql_test e_reindex-1.4 {
diff --git a/test/eqp.test b/test/eqp.test
index 61fd617..cd441c2 100644
--- a/test/eqp.test
+++ b/test/eqp.test
@@ -413,7 +413,7 @@ do_eqp_test 4.2.3 {
| `--USE TEMP B-TREE FOR ORDER BY
`--RIGHT
|--SCAN t2 USING INDEX t2i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
}
do_eqp_test 4.2.4 {
SELECT * FROM t1 INTERSECT SELECT * FROM t2 ORDER BY 1
@@ -425,7 +425,7 @@ do_eqp_test 4.2.4 {
| `--USE TEMP B-TREE FOR ORDER BY
`--RIGHT
|--SCAN t2 USING INDEX t2i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
}
do_eqp_test 4.2.5 {
SELECT * FROM t1 EXCEPT SELECT * FROM t2 ORDER BY 1
@@ -437,7 +437,7 @@ do_eqp_test 4.2.5 {
| `--USE TEMP B-TREE FOR ORDER BY
`--RIGHT
|--SCAN t2 USING INDEX t2i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
}
do_eqp_test 4.3.1 {
diff --git a/test/eqp2.test b/test/eqp2.test
new file mode 100644
index 0000000..3c634fc
--- /dev/null
+++ b/test/eqp2.test
@@ -0,0 +1,49 @@
+# 2024 March 20
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+set testprefix eqp2
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a, b, c, d);
+ CREATE INDEX i1 ON t1(a, b, c);
+}
+
+do_eqp_test 1.1 {
+ SELECT * FROM t1 ORDER BY a, b, c
+} {
+ QUERY PLAN
+ `--SCAN t1 USING INDEX i1
+}
+
+
+do_eqp_test 1.2 {
+ SELECT * FROM t1 ORDER BY a, b, +c
+} {
+ QUERY PLAN
+ |--SCAN t1 USING INDEX i1
+ `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
+}
+
+do_eqp_test 1.3 {
+ SELECT * FROM t1 ORDER BY a, +b, +c
+} {
+ QUERY PLAN
+ |--SCAN t1 USING INDEX i1
+ `--USE TEMP B-TREE FOR LAST 2 TERMS OF ORDER BY
+}
+
+finish_test
+
+
diff --git a/test/exprfault2.test b/test/exprfault2.test
new file mode 100644
index 0000000..acbead5
--- /dev/null
+++ b/test/exprfault2.test
@@ -0,0 +1,35 @@
+# 2024-05-11
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix exprfault2
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a,b,c,d,f,PRIMARY KEY(b,b));
+ CREATE TABLE t2(x INT PRIMARY KEY, y, z);
+ CREATE TABLE t3(a,b,c,d,e,PRIMARY KEY(a,b))WITHOUT ROWID;
+}
+faultsim_save_and_close
+
+
+do_faultsim_test 1 -faults oom-t* -prep {
+ faultsim_restore_and_reopen
+} -body {
+ execsql {
+ UPDATE t3 SET (d,d,d,d, a )=(SELECT EXISTS(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( 1 IN(SELECT x NOT IN(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( (SELECT x NOT IN(SELECT 1 NOT IN(SELECT EXISTS(SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT (SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) a)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(ORDER BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)|9 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z) ORDER BY 1) IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) a)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)|9 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))EXCEPT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z) ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 5 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) ORDERa)| (SELECT 1 IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(ORDER BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) z)| 1 AS blob) IN(SELECT max( 1 IN(SELECT x ORDER BY 1)) OVER(PARTITION BY sum((SELECT DISTINCT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 UNION SELECT d ORDER BY 1) ORDER BY 1) z)| (SELECT 1 IN(SELECT max( 1 IN(SELECT c ORDER BY 1)) OVER(PARTITION BY sum((SELECT y FROM t2 UNION SELECT x ORDER BY 1)))INTERSECT SELECT (SELECT 1 FROM t2 UNION SELECT x ORDER BY 1) ORDER BY 1) e)|9 AS blob) FROM t2 WHERE a<x), e= BY 1) FROM t2 UNION SELECT 1 ORDER BY 1) ORDER BY 1)) a) FILTER (GROUP BY 1 HAVING b<= OVER(ORDER BY (SELECT max(x INPARTITION BY sum((SELECT y FROM t2 UNION SELECT x IN(SELECT 1 ORDER BY 1) ORDER 1)))INTERSECT SELECT EXISTS(SELECT 1 FROM t2 WHERE xBY 1) ORDER BY 1)) FROM77;
+ }
+} -test {
+ faultsim_test_result {1 {near ")": syntax error}}
+}
+
+finish_test
diff --git a/test/fts3fault3.test b/test/fts3fault3.test
index 6e1c0cd..ae20471 100644
--- a/test/fts3fault3.test
+++ b/test/fts3fault3.test
@@ -50,5 +50,33 @@ do_faultsim_test 1 -faults oom* -prep {
faultsim_test_result {0 {}}
}
+#-------------------------------------------------------------------
+reset_db
+
+do_execsql_test 2.0 {
+ BEGIN;
+ CREATE VIRTUAL TABLE t1 USING fts3(a);
+ WITH s(i) AS (
+ SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50
+ )
+ INSERT INTO t1 SELECT 'abc def ghi jkl mno pqr' FROM s;
+ COMMIT;
+}
+
+faultsim_save_and_close
+do_faultsim_test 2 -faults oom-t* -prep {
+ faultsim_restore_and_reopen
+ execsql {
+ BEGIN;
+ CREATE TABLE x1(a PRIMARY KEY);
+ }
+} -body {
+ execsql {
+ PRAGMA integrity_check;
+ }
+} -test {
+ faultsim_test_result {0 ok} $::TMPDBERROR
+}
+
finish_test
diff --git a/test/fts3snippet2.test b/test/fts3snippet2.test
index 607b01e..f55a5f2 100644
--- a/test/fts3snippet2.test
+++ b/test/fts3snippet2.test
@@ -55,5 +55,16 @@ do_execsql_test 2.2 {
'(def AND (one NEAR abc)) OR one'
} {<b>one</b>}
+#-------------------------------------------------------------------------
+
+do_execsql_test 3.0 {
+CREATE VIRTUAL TABLE f USING fts3(a,b);
+INSERT INTO f VALUES (101,x'056522650565056505650d051e056505650565286505650565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056f05650565056505650565056505650565050565056505640565056505650565056505651e05650565056505650565056505650505656565056505650565056505651e0565056505650565056505650565052265056505650569056505650565056505650565056505650565056505650500406505650565056505650565056505000101e5c501014b010101c501c5c501010101f5010201010101014101017373737373737373737373737373737373737373737373737373737330737373737373737373737373737365056505650d051e05650565056528056505650d05650505656505650565650565056505650565056505e505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565286505c705650565050565059494949494949494949494949494949494949494949494949494949494949494949494650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650505650565056505650565056505650565056500000000000000000000000000000000000000000000000000000000000000000565056505656505650565056505650d056500000000000000000000000000000000000000000000000000000000000000000100000000000000ed0000000000ffffffffffffffffffffff0007ffffff0001c5c50001c5c50001c5c50001c5c50001c5c50001c5c50001e5c50001c5c50001c5c50001c5c50001c5c50001c5c5000100000014720000000000000016dac5c50001c5c50001c5c50001c5c50001c5c50001c5c50d0505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800465056505650565056505651e650565056505650565056505650d05650505656505650565050565650584058005650565056505650565056505650565056522650565056505650d051e056505650561286505c70565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef650565058405056505650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650565226505737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373737373733a73737373737373737373737373737373737373737373737373737373737373737373737373737373737c7373737365056505650d051e05650565056528650565056505650505650565056505650565056505650565056505e505650565056505656505650565056505650d05650505656505650565ef65056505');
+}
+
+do_execsql_test 3.1 {
+ SELECT length(snippet(f)) FROM f WHERE b MATCH x'0565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056505650565056505650565056505650565050565056505640565056505650565056505651e05650565056522650565056505650d051e056505650565286505650565056505056505650565056505650565056505650565056505650565056505656505650565056505650d05650505656505650565ef65056505844c746e65650565056505650565056505650565056505650565058405800565056505650565056505651e650565056505650565056505650d056505056565056505650565056505840580056505650565056f05650565056505650565056505650565050565056505640565056505650565056505651e05650565056505650565056505650505656565056505650565056505651e0565056505650565056505650565052265056505650569056505650565056505650565056505650565056505650500406505650565056505650565056505000101e5c501014b010101c501c5c501010101f50102010101010141010141010001017bf15905000000000017';
+} {192}
+
set sqlite_fts3_enable_parentheses 0
finish_test
diff --git a/test/func2.test b/test/func2.test
index 08ad857..a7c7ec3 100644
--- a/test/func2.test
+++ b/test/func2.test
@@ -508,4 +508,27 @@ do_test func2-3.9.2 {
bin_to_hex [lindex $blob 0]
} "12"
+#-------------------------------------------------------------------------
+# At one point this was extremely slow to compile.
+#
+do_test func2-3.10 {
+ set tm [time {
+ execsql {
+ SELECT '' IN (zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(
+ zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(zerobloB(1)
+ )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
+ }
+ }]
+
+ set tm [lindex $tm 0]
+ expr $tm<2000000
+} {1}
+
finish_test
diff --git a/test/func4.test b/test/func4.test
index 64c7a11..56cc906 100644
--- a/test/func4.test
+++ b/test/func4.test
@@ -1,4 +1,4 @@
-# 2013 March 10
+# 2023-03-10
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
@@ -9,7 +9,10 @@
#
#***********************************************************************
# This file implements regression tests for SQLite library. The focus of
-# this file is testing the tointeger() and toreal() functions.
+# this file is testing the tointeger() and toreal() functions that are
+# part of the "totype.c" extension. This file does not test the core
+# SQLite library. Failures of tests in this file are related to the
+# ext/misc/totype.c extension.
#
# Several of the toreal() tests are disabled on platforms where floating
# point precision is not high enough to represent their constant integer
@@ -23,6 +26,20 @@ load_static_extension db totype
set highPrecision(1) [expr \
{[db eval {SELECT tointeger(9223372036854775807 + 1);}] eq {{}}}]
+set highPrecision(2) [expr \
+ {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
+
+# highPrecision(3) is only known to be false on i586 with gcc-13 and -O2.
+# It is true on the exact same platform with -O0. Both results seem
+# reasonable, so we'll just very the expectation accordingly.
+#
+set highPrecision(3) [expr \
+ {[db eval {SELECT toreal(9007199254740992 + 1);}] eq {{}}}]
+
+if {!$highPrecision(1) || !$highPrecision(2) || !$highPrecision(3)} {
+ puts "NOTICE: use_long_double: [use_long_double] \
+ highPrecision: $highPrecision(1) $highPrecision(2) $highPrecision(3)"
+}
do_execsql_test func4-1.1 {
SELECT tointeger(NULL);
@@ -195,8 +212,6 @@ do_execsql_test func4-1.55 {
} {{}}
ifcapable floatingpoint {
- set highPrecision(2) [expr \
- {[db eval {SELECT toreal(-9223372036854775808 + 1);}] eq {{}}}]
do_execsql_test func4-2.1 {
SELECT toreal(NULL);
@@ -341,10 +356,14 @@ ifcapable floatingpoint {
do_execsql_test func4-2.45 {
SELECT toreal(9007199254740992);
} {9007199254740992.0}
- if {$highPrecision(2)} {
+ if {$highPrecision(3)} {
do_execsql_test func4-2.46 {
SELECT toreal(9007199254740992 + 1);
} {{}}
+ } else {
+ do_execsql_test func4-2.46 {
+ SELECT toreal(9007199254740992 + 1);
+ } {9007199254740992.0}
}
do_execsql_test func4-2.47 {
SELECT toreal(9007199254740992 + 2);
@@ -626,10 +645,14 @@ ifcapable floatingpoint {
do_execsql_test func4-5.22 {
SELECT tointeger(toreal(9007199254740992));
} {9007199254740992}
- if {$highPrecision(2)} {
+ if {$highPrecision(3)} {
do_execsql_test func4-5.23 {
SELECT tointeger(toreal(9007199254740992 + 1));
} {{}}
+ } else {
+ do_execsql_test func4-5.23 {
+ SELECT tointeger(toreal(9007199254740992 + 1));
+ } {9007199254740992}
}
do_execsql_test func4-5.24 {
SELECT tointeger(toreal(9007199254740992 + 2));
diff --git a/test/fuzzcheck.c b/test/fuzzcheck.c
index e4ad1c1..6cae348 100644
--- a/test/fuzzcheck.c
+++ b/test/fuzzcheck.c
@@ -979,7 +979,8 @@ extern int fuzz_invariant(
int iRow, /* The row number for pStmt */
int nRow, /* Total number of output rows */
int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */
- int eVerbosity /* How much debugging output */
+ int eVerbosity, /* How much debugging output */
+ unsigned int dbOpt /* Default optimization flags */
);
/* Implementation of sqlite_dbdata and sqlite_dbptr */
@@ -1031,7 +1032,12 @@ static int recoverDatabase(sqlite3 *db){
/*
** Run the SQL text
*/
-static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){
+static int runDbSql(
+ sqlite3 *db, /* Run SQL on this database connection */
+ const char *zSql, /* The SQL to be run */
+ unsigned int *pBtsFlags,
+ unsigned int dbOpt /* Default optimization flags */
+){
int rc;
sqlite3_stmt *pStmt;
int bCorrupt = 0;
@@ -1107,7 +1113,7 @@ static int runDbSql(sqlite3 *db, const char *zSql, unsigned int *pBtsFlags){
iRow++;
for(iCnt=0; iCnt<99999; iCnt++){
rc = fuzz_invariant(db, pStmt, iCnt, iRow, nRow,
- &bCorrupt, eVerbosity);
+ &bCorrupt, eVerbosity, dbOpt);
if( rc==SQLITE_DONE ) break;
if( rc!=SQLITE_ERROR ) g.nInvariant++;
if( eVerbosity>0 ){
@@ -1330,7 +1336,7 @@ int runCombinedDbSqlInput(
char cSaved = zSql[i+1];
zSql[i+1] = 0;
if( sqlite3_complete(zSql+j) ){
- rc = runDbSql(cx.db, zSql+j, &btsFlags);
+ rc = runDbSql(cx.db, zSql+j, &btsFlags, dbOpt);
j = i+1;
}
zSql[i+1] = cSaved;
@@ -1340,7 +1346,7 @@ int runCombinedDbSqlInput(
}
}
if( j<i ){
- runDbSql(cx.db, zSql+j, &btsFlags);
+ runDbSql(cx.db, zSql+j, &btsFlags, dbOpt);
}
}
testrun_finished:
diff --git a/test/fuzzinvariants.c b/test/fuzzinvariants.c
index 00b2c11..80eb4ae 100644
--- a/test/fuzzinvariants.c
+++ b/test/fuzzinvariants.c
@@ -30,7 +30,13 @@
/* Forward references */
static char *fuzz_invariant_sql(sqlite3_stmt*, int);
static int sameValue(sqlite3_stmt*,int,sqlite3_stmt*,int,sqlite3_stmt*);
-static void reportInvariantFailed(sqlite3_stmt*,sqlite3_stmt*,int);
+static void reportInvariantFailed(
+ sqlite3_stmt *pOrig, /* The original query */
+ sqlite3_stmt *pTest, /* The alternative test query with a missing row */
+ int iRow, /* Row number in pOrig */
+ unsigned int dbOpt, /* Optimization flags on pOrig */
+ int noOpt /* True if opt flags inverted for pTest */
+);
/*
** Do an invariant check on pStmt. iCnt determines which invariant check to
@@ -68,7 +74,8 @@ int fuzz_invariant(
int iRow, /* Current row number */
int nRow, /* Number of output rows from pStmt */
int *pbCorrupt, /* IN/OUT: Flag indicating a corrupt database file */
- int eVerbosity /* How much debugging output */
+ int eVerbosity, /* How much debugging output */
+ unsigned int dbOpt /* Default optimization flags */
){
char *zTest;
sqlite3_stmt *pTestStmt = 0;
@@ -76,13 +83,20 @@ int fuzz_invariant(
int i;
int nCol;
int nParam;
+ int noOpt = (iCnt%3)==0;
if( *pbCorrupt ) return SQLITE_DONE;
nParam = sqlite3_bind_parameter_count(pStmt);
if( nParam>100 ) return SQLITE_DONE;
zTest = fuzz_invariant_sql(pStmt, iCnt);
if( zTest==0 ) return SQLITE_DONE;
+ if( noOpt ){
+ sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, ~dbOpt);
+ }
rc = sqlite3_prepare_v2(db, zTest, -1, &pTestStmt, 0);
+ if( noOpt ){
+ sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS, db, dbOpt);
+ }
if( rc ){
if( eVerbosity ){
printf("invariant compile failed: %s\n%s\n",
@@ -212,7 +226,7 @@ int fuzz_invariant(
}
sqlite3_finalize(pCk);
if( rc==SQLITE_DONE ){
- reportInvariantFailed(pStmt, pTestStmt, iRow);
+ reportInvariantFailed(pStmt, pTestStmt, iRow, dbOpt, noOpt);
return SQLITE_INTERNAL;
}else if( eVerbosity>0 ){
printf("invariant-error ignored due to the use of virtual tables\n");
@@ -223,7 +237,6 @@ not_a_fault:
return SQLITE_OK;
}
-
/*
** Generate SQL used to test a statement invariant.
**
@@ -296,14 +309,6 @@ static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){
** WHERE clause. */
continue;
}
-#ifdef SQLITE_ALLOW_ROWID_IN_VIEW
- if( sqlite3_strlike("%rowid%",zColName,0)==0
- || sqlite3_strlike("%oid%",zColName,0)==0
- ){
- /* ROWID values are unreliable if SQLITE_ALLOW_ROWID_IN_VIEW is used */
- continue;
- }
-#endif
for(j=0; j<i; j++){
const char *zPrior = sqlite3_column_name(pBase, j);
if( sqlite3_stricmp(zPrior, zColName)==0 ) break;
@@ -497,13 +502,17 @@ static void printRow(sqlite3_stmt *pStmt, int iRow){
static void reportInvariantFailed(
sqlite3_stmt *pOrig, /* The original query */
sqlite3_stmt *pTest, /* The alternative test query with a missing row */
- int iRow /* Row number in pOrig */
+ int iRow, /* Row number in pOrig */
+ unsigned int dbOpt, /* Optimization flags on pOrig */
+ int noOpt /* True if opt flags inverted for pTest */
){
int iTestRow = 0;
printf("Invariant check failed on row %d.\n", iRow);
- printf("Original query --------------------------------------------------\n");
+ printf("Original query (opt-flags: 0x%08x) --------------------------\n",
+ dbOpt);
printf("%s\n", sqlite3_expanded_sql(pOrig));
- printf("Alternative query -----------------------------------------------\n");
+ printf("Alternative query (opt-flags: 0x%08x) -----------------------\n",
+ noOpt ? ~dbOpt : dbOpt);
printf("%s\n", sqlite3_expanded_sql(pTest));
printf("Result row that is missing from the alternative -----------------\n");
printRow(pOrig, iRow);
diff --git a/test/icu.test b/test/icu.test
index 644cbb1..c1b5653 100644
--- a/test/icu.test
+++ b/test/icu.test
@@ -149,7 +149,7 @@ ifcapable icu {
# 2020-03-19
# The ESCAPE clause on LIKE takes precedence over wildcards
#
-do_execsql_test idu-6.0 {
+do_execsql_test icu-6.0 {
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(id INTEGER PRIMARY KEY, x TEXT);
INSERT INTO t1 VALUES
@@ -164,4 +164,20 @@ do_execsql_test icu-6.1 {
SELECT id FROM t1 WHERE x LIKE 'abc__' ESCAPE '_';
} {2}
+# 2024-04-02
+# Optional 3rd argument to icu_load_collation() that specifies
+# the "strength" of comparison.
+#
+reset_db
+do_catchsql_test icu-7.1 {
+ SELECT icu_load_collation('en_US','error','xyzzy');
+} {1 {unknown collation strength "xyzzy" - should be one of: PRIMARY SECONDARY TERTIARY DEFAULT QUARTERNARY IDENTICAL}}
+do_execsql_test icu-7.2 {
+ SELECT icu_load_collation('en_US','prim','PRIMARY'),
+ icu_load_collation('en_US','dflt','DEFAULT');
+} {{} {}}
+do_execsql_test icu-7.3 {
+ SELECT char(0x100)=='a', char(0x100)=='a' COLLATE dflt, char(0x100)=='a' COLLATE prim;
+} {0 0 1}
+
finish_test
diff --git a/test/in4.test b/test/in4.test
index a3fe22e..71993e7 100644
--- a/test/in4.test
+++ b/test/in4.test
@@ -458,14 +458,14 @@ do_execsql_test 11.0 {
do_execsql_test 11.1 {
SELECT * FROM t1
WHERE b IN (345, (SELECT 1 FROM t1
- WHERE b IN (345 NOT GLOB 510)
+ WHERE b IN (coalesce(1,random()))
AND c GLOB 'abc*xyz'))
AND c BETWEEN 'abc' AND 'xyz';
} {xyz 1 abcdefxyz 99}
do_execsql_test 11.2 {
EXPLAIN SELECT * FROM t1
WHERE b IN (345, (SELECT 1 FROM t1
- WHERE b IN (345 NOT GLOB 510)
+ WHERE b IN (coalesce(1,random()))
AND c GLOB 'abc*xyz'))
AND c BETWEEN 'abc' AND 'xyz';
} {/ SeekScan /}
diff --git a/test/in5.test b/test/in5.test
index 6680641..933eb90 100644
--- a/test/in5.test
+++ b/test/in5.test
@@ -266,4 +266,26 @@ do_execsql_test 9.2 {
SELECT lower('1e500') FROM t0 WHERE rowid != lower('1e500');
} {1e500}
+#-------------------------------------------------------------------------
+#
+reset_db
+
+do_execsql_test 10.0 {
+ CREATE TABLE t1(a, b TEXT COLLATE NOCASE);
+ INSERT INTO t1 VALUES('abc', 'def');
+ INSERT INTO t1 VALUES('ghi', 'jkl');
+}
+
+do_execsql_test 10.1 {
+ SELECT rowid FROM t1 WHERE (a, b) IN ( VALUES('abc', 'def'), ('ghi', 'JKL') );
+} {1 2}
+
+do_execsql_test 10.2 {
+ CREATE INDEX i1 ON t1(a, b COLLATE BINARY);
+}
+
+do_execsql_test 10.3 {
+ SELECT rowid FROM t1 WHERE (a, b) IN ( VALUES('abc', 'def'), ('ghi', 'JKL') );
+} {1 2}
+
finish_test
diff --git a/test/in7.test b/test/in7.test
new file mode 100644
index 0000000..099f75c
--- /dev/null
+++ b/test/in7.test
@@ -0,0 +1,141 @@
+# 2024-05-01
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix in7
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a, b, c PRIMARY KEY);
+ CREATE TABLE t2(x, y, z);
+}
+
+foreach {tn nNext idx sql} {
+ 1 1 {
+ CREATE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE (a, b) IN (SELECT x, y FROM t2)
+ }
+
+ 2 0 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE (a, b) IN (SELECT x, y FROM t2)
+ }
+
+ 3 0 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a = ? AND b = ?
+ }
+
+ 3 1 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a = ? AND b IS ?
+ }
+
+ 4 0 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a = ? AND b IN (?, ?, ?);
+ }
+
+ 5 1 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b, c);
+ } {
+ SELECT * FROM t1 WHERE a = ? AND b = ?
+ }
+
+ 6 0 {
+ } {
+ SELECT * FROM t1 WHERE c IN (SELECT z FROM t2)
+ }
+
+ 7 0 {
+ } {
+ SELECT * FROM t1 WHERE (a, c) IN (SELECT z, x FROM t2)
+ }
+
+ 8 1 {
+ } {
+ SELECT * FROM t1 WHERE a IN (SELECT z FROM t2)
+ }
+
+ 9 1 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) AND b IS ?
+ }
+ 10 0 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a IN (SELECT z FROM t2) AND b = ?
+ }
+ 11 1 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a IS NULL AND b IN (SELECT z FROM t2)
+ }
+ 12 0 {
+ CREATE UNIQUE INDEX i1 ON t1(a, b);
+ } {
+ SELECT * FROM t1 WHERE a = ? AND b IN (SELECT z FROM t2)
+ }
+} {
+ do_test 1.1.$tn {
+ execsql BEGIN
+ execsql $idx
+
+ catch { array unset root_to_tbl }
+ catch { array unset csr_to_root }
+
+ db eval {SELECT rootpage, tbl_name FROM sqlite_schema} {
+ set root_to_tbl($rootpage) $tbl_name
+ }
+
+ set nSeen 0
+ db eval "explain $sql" {
+ if {$opcode=="OpenRead"} {
+ set csr_to_root($p1) $p2
+ }
+ if {$opcode=="Next"} {
+ catch {
+ set root $csr_to_root($p1)
+ set tbl $root_to_tbl($root)
+ if {$tbl=="t1"} {incr nSeen}
+ }
+ }
+ }
+
+ execsql ROLLBACK
+
+ set nSeen
+ } $nNext
+}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 2.0 {
+ CREATE TABLE t1(a TEXT PRIMARY KEY, b TEXT) WITHOUT ROWID;
+ INSERT INTO t1 VALUES('1', 'one');
+ INSERT INTO t1 VALUES('2', NULL);
+ INSERT INTO t1 VALUES('3', 'three');
+}
+
+do_execsql_test 2.1 {
+ SELECT b FROM t1 WHERE a IN (1,2,3) ORDER BY b ASC NULLS LAST;
+} {one three {}}
+
+
+finish_test
diff --git a/test/indexexpr1.test b/test/indexexpr1.test
index 0316ee9..3ba5944 100644
--- a/test/indexexpr1.test
+++ b/test/indexexpr1.test
@@ -615,6 +615,58 @@ do_execsql_test indexexpr1-2200 {
GROUP BY t2.type, t1.tag
) v ON v.type = 0 AND v.tag = u.tag;
} {7 100 8 101}
+do_execsql_test indexexpr1-2210 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INT, y TEXT);
+ INSERT INTO t1(x,y) VALUES(1,'{b:5}');
+ SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1;
+} {5}
+db null NULL
+do_execsql_test indexexpr1-2211 {
+ CREATE INDEX t1j ON t1(coalesce(null,json(y)));
+ SELECT json_insert('{}', '$.a', coalesce(null,json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2220 {
+ DROP INDEX t1j;
+ SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2221 {
+ CREATE INDEX t1j ON t1(iif(1,json(y),123));
+ SELECT json_insert('{}', '$.a', iif(1,json(y),123))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2230 {
+ DROP INDEX t1j;
+ SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2231 {
+ CREATE INDEX t1j ON t1(ifnull(NULL,json(y)));
+ SELECT json_insert('{}', '$.a', ifnull(NULL,json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2240 {
+ DROP INDEX t1j;
+ SELECT json_insert('{}', '$.a', nullif(json(y),8))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2241 {
+ CREATE INDEX t1j ON t1(nullif(json(y),8));
+ SELECT json_insert('{}', '$.a', nullif(json(y),8))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2250 {
+ DROP INDEX t1j;
+ SELECT json_insert('{}', '$.a', min('~',json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2251 {
+ CREATE INDEX t1j ON t1(min('~',json(y)));
+ SELECT json_insert('{}', '$.a', min('~',json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2260 {
+ DROP INDEX t1j;
+ SELECT json_insert('{}', '$.a', max('...',json(y)))->>'$.a.b' FROM t1;
+} {5}
+do_execsql_test indexexpr1-2261 {
+ CREATE INDEX t1j ON t1(max('...',json(y)));
+ SELECT json_insert('{}', '$.a', max('...',json(y)))->>'$.a.b' FROM t1;
+} {5}
+
# 2023-11-08 Forum post https://sqlite.org/forum/forumpost/68d284c86b082c3e
#
diff --git a/test/json102.test b/test/json102.test
index 15a54b4..1a00cb6 100644
--- a/test/json102.test
+++ b/test/json102.test
@@ -764,4 +764,35 @@ do_execsql_test json102-1720 {
SELECT * FROM t1;
} {ok 2023-08-03 876 5 {{"x":77,"y":6}}}
+# 2024-05-21 https://sqlite.org/forum/forumpost/9e52cdfe15c3926e
+# What if the RHS of the -> or ->> operator is a string that looks
+# like a number? PostgreSQL treats it as a string.
+#
+do_execsql_test json102-1800 {
+ SELECT '{"1":"one","2":"two","3":"three"}'->>'2';
+} two
+db null NULL
+do_execsql_test json102-1801 {
+ SELECT '{"1":"one","2":"two","3":"three"}'->>2;
+} NULL
+do_execsql_test json102-1810 {
+ SELECT '["zero","one","two"]'->>'1';
+} NULL
+do_execsql_test json102-1811 {
+ SELECT '["zero","one","two"]'->>1;
+} one
+do_execsql_test json102-1820 {
+ SELECT '{"1":"one","2":"two","3":"three"}'->'2';
+} {{"two"}}
+do_execsql_test json102-1821 {
+ SELECT '{"1":"one","2":"two","3":"three"}'->2;
+} {NULL}
+do_execsql_test json102-1830 {
+ SELECT '["zero","one","two"]'->'1';
+} {NULL}
+do_execsql_test json102-1831 {
+ SELECT '["zero","one","two"]'->1;
+} {{"one"}}
+
+
finish_test
diff --git a/test/json106.test b/test/json106.test
index 23fa028..06859a1 100644
--- a/test/json106.test
+++ b/test/json106.test
@@ -67,6 +67,12 @@ for {set ii 1} {$ii<=5000} {incr ii} {
FROM t1, kv
WHERE p->>key IS NOT val
} 0
+ do_execsql_test $ii.8 {
+ SELECT j0 FROM t1 WHERE json(j0)!=json(json_pretty(j0));
+ } {}
+ do_execsql_test $ii.9 {
+ SELECT j5 FROM t1 WHERE json(j5)!=json(json_pretty(j5));
+ } {}
}
diff --git a/test/json108.test b/test/json108.test
new file mode 100644
index 0000000..71f3814
--- /dev/null
+++ b/test/json108.test
@@ -0,0 +1,45 @@
+# 2024-03-06
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# Invariant tests for JSON built around the randomjson extension
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix json108
+
+# These tests require virtual table "json_tree" to run.
+ifcapable !vtab { finish_test ; return }
+
+load_static_extension db randomjson
+db eval {
+ CREATE TEMP TABLE t1(j0,j5);
+ WITH RECURSIVE c(n) AS (VALUES(0) UNION ALL SELECT n+1 FROM c WHERE n<9)
+ INSERT INTO t1 SELECT random_json(n), random_json5(n) FROM c;
+}
+
+do_execsql_test 1.1 {
+ SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
+} 10
+do_execsql_test 1.2 {
+ SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
+} 10
+do_execsql_test 1.3 {
+ SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,''));
+} 10
+do_execsql_test 1.4 {
+ SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,char(9)));
+} 10
+do_execsql_test 1.5 {
+ SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,'/*hello*/'));
+} 10
+
+
+finish_test
diff --git a/test/json501.test b/test/json501.test
index 40b3b56..bfd2105 100644
--- a/test/json501.test
+++ b/test/json501.test
@@ -306,4 +306,31 @@ do_execsql_test 13.1 {
SELECT json('{x:''a "b" c''}');
} {{{"x":"a \"b\" c"}}}
+# 2024-01-31
+# Allow control characters within JSON5 string literals.
+#
+for {set c 1} {$c<=0x1f} {incr c} {
+ do_execsql_test 14.$c.1 {
+ SELECT json_valid('"abc' || char($c) || 'xyz"');
+ } {0}
+ do_execsql_test 14.$c.2 {
+ SELECT json_valid('"abc' || char($c) || 'xyz"', 2);
+ } {1}
+ switch $c {
+ 8 {set e "\\b"}
+ 9 {set e "\\t"}
+ 10 {set e "\\n"}
+ 12 {set e "\\f"}
+ 13 {set e "\\r"}
+ default {set e [format "\\u00%02x" $c]}
+ }
+ do_execsql_test 14.$c.3 {
+ SELECT json('{label:"abc' || char($c) || 'xyz"}');
+ } "{{\"label\":\"abc${e}xyz\"}}"
+ do_execsql_test 14.$c.4 {
+ SELECT jsonb('{label:"abc' || char($c) || 'xyz"}') -> '$';
+ } "{{\"label\":\"abc${e}xyz\"}}"
+}
+
+
finish_test
diff --git a/test/lemon-test01.y b/test/lemon-test01.y
index 0fd514f..67890c6 100644
--- a/test/lemon-test01.y
+++ b/test/lemon-test01.y
@@ -2,6 +2,11 @@
//
// lemon lemon-test01.y && gcc -g lemon-test01.c && ./a.out
//
+// This testcase was made obsolete by check-in 7cca80808cef192f on
+// 2021-08-17 (associated with Forum Thread
+// https://sqlite.org/forum/forumpost/bd91fd965c9803c4) and no longer
+// works. It is retained for historical reference only.
+//
%token_prefix TK_
%token_type int
%default_type int
@@ -28,7 +33,7 @@ all ::= error B.
#include "lemon-test01.h"
static int nTest = 0;
static int nErr = 0;
- static int testCase(int testId, int shouldBe, int actual){
+ static void testCase(int testId, int shouldBe, int actual){
nTest++;
if( shouldBe==actual ){
printf("test %d: ok\n", testId);
diff --git a/test/literal.test b/test/literal.test
new file mode 100644
index 0000000..5aa331e
--- /dev/null
+++ b/test/literal.test
@@ -0,0 +1,103 @@
+# 2024-01-19
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file implements tests for SQL literals
+
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set ::testprefix literal
+
+proc test_literal {tn lit type val} {
+ do_execsql_test $tn.1 "SELECT typeof( $lit ), $lit" [list $type $val]
+
+ ifcapable altertable {
+ do_execsql_test $tn.2 "
+ DROP TABLE IF EXISTS x1;
+ CREATE TABLE x1(a);
+ INSERT INTO x1 VALUES(123);
+ ALTER TABLE x1 ADD COLUMN b DEFAULT $lit ;
+ SELECT typeof(b), b FROM x1;
+ " [list $type $val]
+ }
+
+ do_execsql_test $tn.3 "
+ DROP TABLE IF EXISTS x1;
+ CREATE TABLE x1(a DEFAULT $lit);
+ INSERT INTO x1 DEFAULT VALUES;
+ SELECT typeof(a), a FROM x1;
+ " [list $type $val]
+}
+
+proc test_literal_error {tn lit unrec} {
+ do_catchsql_test $tn "SELECT $lit" "1 {unrecognized token: \"$unrec\"}"
+}
+
+
+test_literal 1.0 45 integer 45
+test_literal 1.1 0xFF integer 255
+test_literal 1.2 0xFFFFFFFF integer [expr 0xFFFFFFFF]
+test_literal 1.3 0x123FFFFFFFF integer [expr 0x123FFFFFFFF]
+test_literal 1.4 -0x123FFFFFFFF integer [expr -1 * 0x123FFFFFFFF]
+test_literal 1.5 0xFFFFFFFFFFFFFFFF integer -1
+test_literal 1.7 0x7FFFFFFFFFFFFFFF integer [expr 0x7FFFFFFFFFFFFFFF]
+test_literal 1.8 -0x7FFFFFFFFFFFFFFF integer [expr -0x7FFFFFFFFFFFFFFF]
+test_literal 1.9 +0x7FFFFFFFFFFFFFFF integer [expr +0x7FFFFFFFFFFFFFFF]
+test_literal 1.10 -45 integer -45
+test_literal 1.11 '0xFF' text 0xFF
+test_literal 1.12 '-0xFF' text -0xFF
+test_literal 1.13 -'0xFF' integer 0
+test_literal 1.14 -9223372036854775808 integer -9223372036854775808
+
+test_literal 2.1 1e12 real 1000000000000.0
+test_literal 2.2 1.0 real 1.0
+test_literal 2.3 1e1000 real Inf
+test_literal 2.4 -1e1000 real -Inf
+
+test_literal 3.1 1_000 integer 1000
+test_literal 3.2 1.1_1 real 1.11
+test_literal 3.3 1_0.1_1 real 10.11
+test_literal 3.4 1e1_000 real Inf
+test_literal 3.5 12_3_456.7_8_9 real 123456.789
+test_literal 3.6 9_223_372_036_854_775_807 integer 9223372036854775807
+test_literal 3.7 9_223_372_036_854_775_808 real 9.22337203685478e+18
+test_literal 3.8 -9_223_372_036_854_775_808 integer -9223372036854775808
+
+foreach {tn lit unrec} {
+ 0 123a456 123a456
+ 1 1_ 1_
+ 2 1_.4 1_.4
+ 3 1e_4 1e_4
+ 4 1_e4 1_e4
+ 5 1.4_e4 1.4_e4
+ 6 1.4e+_4 1.4e
+ 7 1.4e-_4 1.4e
+ 8 1.4e4_ 1.4e4_
+ 9 1.4_e4 1.4_e4
+ 10 1.4e_4 1.4e_4
+ 11 12__34 12__34
+ 12 1234_ 1234_
+ 13 12._34 12._34
+ 14 12_.34 12_.34
+ 15 12.34_ 12.34_
+ 16 1.0e1_______2 1.0e1_______2
+} {
+ test_literal_error 4.$tn $lit $unrec
+}
+
+# dbsqlfuzz e3186a9e7826e9cd7f4085aa4452f8696485f9e1
+# See tag-20240224-a and -b
+#
+do_catchsql_test 5.1 {
+ SELECT 1 ORDER BY 2_3;
+} {1 {1st ORDER BY term out of range - should be between 1 and 1}}
+
+finish_test
diff --git a/test/literal2.tcl b/test/literal2.tcl
new file mode 100644
index 0000000..e14a035
--- /dev/null
+++ b/test/literal2.tcl
@@ -0,0 +1,40 @@
+# 2018 May 19
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+source [file join [file dirname $argv0] pg_common.tcl]
+
+#=========================================================================
+
+
+start_test literal2 "2024 Jan 23"
+
+execsql_test 1.0 { SELECT 123_456 }
+errorsql_test 1.1 { SELECT 123__456 }
+
+execsql_float_test 2.1 { SELECT 1.0e1_2 }
+
+
+execsql_test 3.0.0 { SELECT 0xFF_FF }
+execsql_test 3.0.1 { SELECT 0xFF_EF }
+errorsql_test 3.0.2 { SELECT 0xFF__EF }
+# errorsql_test 3.0.3 { SELECT 0x_FFEF }
+errorsql_test 3.0.4 { SELECT 0xFFEF_ }
+
+execsql_test 3.1.0 { SELECT 0XFF_FF }
+execsql_test 3.1.1 { SELECT 0XFF_EF }
+errorsql_test 3.1.2 { SELECT 0XFF__EF }
+# errorsql_test 3.1.3 { SELECT 0X_FFEF }
+errorsql_test 3.1.4 { SELECT 0XFFEF_ }
+
+finish_test
+
+
diff --git a/test/literal2.test b/test/literal2.test
new file mode 100644
index 0000000..ed177ca
--- /dev/null
+++ b/test/literal2.test
@@ -0,0 +1,84 @@
+# 2024 Jan 23
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+
+####################################################
+# DO NOT EDIT! THIS FILE IS AUTOMATICALLY GENERATED!
+####################################################
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix literal2
+
+do_execsql_test 1.0 {
+ SELECT 123_456
+} {123456}
+
+# PG says ERROR: trailing junk after numeric literal at or near "123_"
+do_test 1.1 { catch { execsql {
+ SELECT 123__456
+} } } 1
+
+
+do_test 2.1 {
+ set myres {}
+ foreach r [db eval {SELECT 1.0e1_2}] {
+ lappend myres [format %.4f [set r]]
+ }
+ set res2 {1000000000000.0000}
+ set i 0
+ foreach r [set myres] r2 [set res2] {
+ if {[set r]<([set r2]-0.0001) || [set r]>([set r2]+0.0001)} {
+ error "list element [set i] does not match: got=[set r] expected=[set r2]"
+ }
+ incr i
+ }
+ set {} {}
+} {}
+
+do_execsql_test 3.0.0 {
+ SELECT 0xFF_FF
+} {65535}
+
+do_execsql_test 3.0.1 {
+ SELECT 0xFF_EF
+} {65519}
+
+# PG says ERROR: trailing junk after numeric literal at or near "0xFF_"
+do_test 3.0.2 { catch { execsql {
+ SELECT 0xFF__EF
+} } } 1
+
+# PG says ERROR: trailing junk after numeric literal at or near "0xFFEF_"
+do_test 3.0.4 { catch { execsql {
+ SELECT 0xFFEF_
+} } } 1
+
+do_execsql_test 3.1.0 {
+ SELECT 0XFF_FF
+} {65535}
+
+do_execsql_test 3.1.1 {
+ SELECT 0XFF_EF
+} {65519}
+
+# PG says ERROR: trailing junk after numeric literal at or near "0XFF_"
+do_test 3.1.2 { catch { execsql {
+ SELECT 0XFF__EF
+} } } 1
+
+# PG says ERROR: trailing junk after numeric literal at or near "0XFFEF_"
+do_test 3.1.4 { catch { execsql {
+ SELECT 0XFFEF_
+} } } 1
+
+finish_test
diff --git a/test/misc1.test b/test/misc1.test
index 83acc75..8110d38 100644
--- a/test/misc1.test
+++ b/test/misc1.test
@@ -654,7 +654,7 @@ do_catchsql_test misc1-21.1 {
} {1 {near "#0": syntax error}}
do_catchsql_test misc1-21.2 {
VALUES(0,0x0MATCH#0;
-} {1 {near ";": syntax error}}
+} {1 {unrecognized token: "0x0MATCH"}}
# 2015-04-15
do_execsql_test misc1-22.1 {
diff --git a/test/misc5.test b/test/misc5.test
index f7c6048..84aa958 100644
--- a/test/misc5.test
+++ b/test/misc5.test
@@ -569,11 +569,11 @@ ifcapable subquery&&compound {
}
# Overflow the lemon parser stack by providing an overly complex
-# expression. Make sure that the overflow is detected and reported.
+# expression. Make sure that the overflow is detected and the
+# stack is grown automatically such that the application calling
+# SQLite never notices.
#
-# This test fails when building with -DYYSTACKDEPTH=0
-#
-do_test misc5-7.1 {
+do_test misc5-7.1.1 {
execsql {CREATE TABLE t1(x)}
set sql "INSERT INTO t1 VALUES("
set tail ""
@@ -581,9 +581,21 @@ do_test misc5-7.1 {
append sql "(1+"
append tail ")"
}
- append sql 2$tail
+ append sql "0$tail); SELECT * FROM t1;"
+ catchsql $sql
+} {0 200}
+do_test misc5-7.1.2 {
+ execsql {DELETE FROM t1}
+ set sql "INSERT INTO t1 VALUES("
+ set tail ""
+ for {set i 0} {$i<900} {incr i} {
+ append sql "(1+"
+ append tail ")"
+ }
+ append sql "0$tail); SELECT * FROM t1;"
catchsql $sql
-} {1 {parser stack overflow}}
+} {0 900}
+
# Parser stack overflow is silently ignored when it occurs while parsing the
# schema and PRAGMA writable_schema is turned on.
diff --git a/test/mmapcorrupt.test b/test/mmapcorrupt.test
index 70dbe84..d434ec1 100644
--- a/test/mmapcorrupt.test
+++ b/test/mmapcorrupt.test
@@ -16,6 +16,10 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix mmapcorrupt
+ifcapable !mmap {
+ finish_test
+ return
+}
database_may_be_corrupt
db close
diff --git a/test/orderby1.test b/test/orderby1.test
index 7432b54..41444a4 100644
--- a/test/orderby1.test
+++ b/test/orderby1.test
@@ -520,7 +520,7 @@ do_eqp_test 8.1 {
} {
QUERY PLAN
|--SCAN t1 USING INDEX i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
}
do_execsql_test 8.2 {
diff --git a/test/permutations.test b/test/permutations.test
index 25aa7de..c26d6ea 100644
--- a/test/permutations.test
+++ b/test/permutations.test
@@ -95,6 +95,7 @@ foreach f [glob -nocomplain \
$testdir/../ext/lsm1/test/*.test \
$testdir/../ext/recover/*.test \
$testdir/../ext/rbu/*.test \
+ $testdir/../ext/intck/*.test \
] {
lappend alltests $f
}
diff --git a/test/pragma.test b/test/pragma.test
index 8f78a7e..e823a67 100644
--- a/test/pragma.test
+++ b/test/pragma.test
@@ -372,27 +372,30 @@ ifcapable attach {
db close
sqlite3 db test.db
execsql {PRAGMA integrity_check}
- } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
do_test pragma-3.3 {
execsql {PRAGMA integrity_check=1}
- } {{row 1 missing from index i2}}
+ } {{wrong # of entries in index i2}}
do_test pragma-3.4 {
execsql {
ATTACH DATABASE 'test.db' AS t2;
PRAGMA integrity_check
}
- } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
do_test pragma-3.5 {
execsql {
PRAGMA integrity_check=4
}
- } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2}}
+ } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+ do_catchsql_test pragma-3.5.2 {
+ PRAGMA integrity_check='4'
+ } {1 {no such table: 4}}
do_catchsql_test pragma-3.6 {
PRAGMA integrity_check=xyz
} {1 {no such table: xyz}}
do_catchsql_test pragma-3.6b {
PRAGMA integrity_check=t2
- } {0 {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}}
+ } {0 {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}}
do_catchsql_test pragma-3.6c {
PRAGMA integrity_check=sqlite_schema
} {0 ok}
@@ -400,7 +403,7 @@ ifcapable attach {
execsql {
PRAGMA integrity_check=0
}
- } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
# Add additional corruption by appending unused pages to the end of
# the database file testerr.db
@@ -435,10 +438,10 @@ ifcapable attach {
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
do_execsql_test pragma-3.9b {
PRAGMA t2.integrity_check=t2;
- } {{row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+ } {{wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
do_execsql_test pragma-3.9c {
PRAGMA t2.integrity_check=sqlite_schema;
} {ok}
@@ -455,7 +458,7 @@ Page 4: never used}}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2}}
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2}}
do_test pragma-3.12 {
execsql {
PRAGMA integrity_check=4
@@ -463,7 +466,7 @@ Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2}}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2}}
+Page 6: never used} {wrong # of entries in index i2}}
do_test pragma-3.13 {
execsql {
PRAGMA integrity_check=3
@@ -487,10 +490,10 @@ Page 5: never used}}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2}}
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2}}
do_test pragma-3.16 {
execsql {
PRAGMA integrity_check(10)
@@ -498,10 +501,10 @@ Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2}}
+Page 6: never used} {wrong # of entries in index i2}}
do_test pragma-3.17 {
execsql {
PRAGMA integrity_check=8
@@ -509,7 +512,7 @@ Page 6: never used} {row 1 missing from index i2}}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2} {row 2 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
+Page 6: never used} {wrong # of entries in index i2} {row 1 missing from index i2} {row 2 missing from index i2} {*** in database t3 ***
Page 4: never used
Page 5: never used}}
do_test pragma-3.18 {
@@ -519,7 +522,7 @@ Page 5: never used}}
} {{*** in database t2 ***
Page 4: never used
Page 5: never used
-Page 6: never used} {row 1 missing from index i2}}
+Page 6: never used} {wrong # of entries in index i2}}
}
do_test pragma-3.19 {
catch {db close}
diff --git a/test/pragma4.test b/test/pragma4.test
index 97c6226..5360fba 100644
--- a/test/pragma4.test
+++ b/test/pragma4.test
@@ -97,7 +97,7 @@ do_test pragma4-2.100 {
}
string map {\[ x \] x \173 {} \175 {}} \
[db eval {EXPLAIN PRAGMA integrity_check}]
-} {/ IntegrityCk 2 2 1 x[0-9]+,1x /}
+} {/ IntegrityCk 1 2 8 x[0-9]+,1x /}
#--------------------------------------------------------------------------
@@ -271,6 +271,8 @@ catch {db3 close}
ifcapable vtab {
reset_db
do_execsql_test 6.0 {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
CREATE TABLE t1(a INT PRIMARY KEY, b INT);
CREATE TABLE t2(c INT PRIMARY KEY, d INT REFERENCES t1);
SELECT t.name, f."table", f."from", i.name, i.pk
@@ -281,4 +283,32 @@ ifcapable vtab {
} {t2 t1 d a 1}
}
+# 2024-05-08 https://sqlite.org/forum/forumpost/cf29a33e94
+#
+ifcapable vtab {
+ do_execsql_test 7.0 {
+ CREATE TABLE t3 ("a" TEXT, "b" TEXT);
+ CREATE TABLE t4 ("a" TEXT, "b" TEXT, "c" TEXT);
+ }
+
+ do_execsql_test 7.1 {
+ CREATE TABLE pragma_t3 AS SELECT * FROM pragma_table_info('t3');
+ CREATE TABLE pragma_t4 AS SELECT * FROM pragma_table_info('t4');
+ }
+
+ do_execsql_test 7.2 {
+ SELECT pragma_t4.name, pragma_t3.name
+ FROM pragma_t4 RIGHT JOIN pragma_t3 ON (pragma_t4.name=pragma_t3.name);
+ } {a a b b}
+
+ do_execsql_test 7.3 {
+ SELECT t4.name, t3.name
+ FROM pragma_table_info('t4') t4
+ RIGHT JOIN pragma_table_info('t3') t3 ON (t4.name=t3.name);
+ } {a a b b}
+}
+
+
+
+
finish_test
diff --git a/test/pragma6.test b/test/pragma6.test
new file mode 100644
index 0000000..fc5566a
--- /dev/null
+++ b/test/pragma6.test
@@ -0,0 +1,74 @@
+# 2024 February 27
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements tests for PRAGMAs quick_check and integrity_check.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix pragma6
+
+database_may_be_corrupt
+
+#-------------------------------------------------------------------------
+#
+do_test 1.0 {
+ sqlite3 db {}
+ db deserialize [decode_hexdb {
+ .open --hexdb
+ | size 12288 pagesize 4096 filename crash-540f4c1eb1e7ac.db
+ | page 1 offset 0
+ | 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
+ | 16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 03 .....@ ........
+ | 32: 00 bb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
+ | 96: 00 00 00 00 0d 00 00 00 02 0f 7f 00 0f c3 0f 7f ................
+ | 3952: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42 ...............B
+ | 3968: 02 06 17 11 11 01 71 74 61 62 6c 65 74 32 74 32 ......qtablet2t2
+ | 3984: 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 .CREATE TABLE t2
+ | 4000: 28 61 20 49 4e 54 2c 20 62 20 41 53 20 28 61 2a (a INT, b AS (a*
+ | 4016: 32 29 20 53 54 4f 52 45 44 20 4e 4f 54 20 4e 55 2) STORED NOT NU
+ | 4032: 4c 4c 29 3b 01 06 17 11 11 01 63 74 61 62 6c 65 LL);......ctable
+ | 4048: 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c t1t1.CREATE TABL
+ | 4064: 45 20 74 31 28 61 20 49 4e 54 2c 20 62 20 41 53 E t1(a INT, b AS
+ | 4080: 20 28 61 2a 32 29 20 4e 4f 54 20 4e 55 4c 4c 29 (a*2) NOT NULL)
+ | page 2 offset 4096
+ | 0: 0d 00 00 00 05 0f e7 00 00 00 00 00 00 00 00 00 ................
+ | 4064: 00 00 00 00 00 00 00 00 03 05 02 01 05 03 04 02 ................
+ | 4080: 01 04 03 03 02 01 03 03 02 02 01 02 02 01 02 09 ................
+ | page 3 offset 8192
+ | 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
+ | 4048: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 05 ................
+ | 4064: 03 01 01 05 0a 05 04 03 01 01 04 08 05 03 03 01 ................
+ | 4080: 01 03 06 05 02 03 00 00 00 00 00 00 00 00 00 00 ................
+ | end crash-540f4c1eb1e7ac.db
+ }]
+} {}
+
+do_test 1.1 {
+ execsql {
+ CREATE TEMP TABLE t2(
+ a t1 PRIMARY KEY default 27,
+ b default(current_timestamp),
+ d TEXT UNIQUE DEFAULT 'ch`arlie',
+ c TEXT UNIQUE DEFAULT 084,
+ UNIQUE(c,b,b,a,b)
+ ) WITHOUT ROWID;
+ }
+ catchsql { INSERT INTO t1(a) VALUES(zeroblob(40000)) }
+ set {} {}
+} {}
+
+do_test 1.2 {
+ execsql { PRAGMA integrity_check; }
+ execsql { PRAGMA quick_check; }
+ set {} {}
+} {}
+
+finish_test
diff --git a/test/pushdown.test b/test/pushdown.test
index 1fbe6f3..5c3e818 100644
--- a/test/pushdown.test
+++ b/test/pushdown.test
@@ -1,4 +1,4 @@
-# 2017 April 29
+# 2017-04-29
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
@@ -8,6 +8,26 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+#
+# Test cases for the push-down optimizations.
+#
+#
+# There are two different meanings for "push-down optimization".
+#
+# (1) "MySQL push-down" means that WHERE clause terms that can be
+# evaluated using only the index and without reference to the
+# table are run first, so that if they are false, unnecessary table
+# seeks are avoided. See https://sqlite.org/src/info/d7bb79ed3a40419d
+# from 2017-04-29.
+#
+# (2) "WHERE-clause pushdown" means to push WHERE clause terms in
+# outer queries down into subqueries. See
+# https://sqlite.org/src/info/6df18e949d367629 from 2015-06-02.
+#
+# This module started out as tests for MySQL push-down only. But because
+# of naming ambiguity, it has picked up test cases for WHERE-clause push-down
+# over the years.
+#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -87,8 +107,8 @@ do_test 2.2 {
} {three}
# 2022-11-25 dbsqlfuzz crash-3a548de406a50e896c1bf7142692d35d339d697f
-# Disable the push-down optimization for compound subqueries if any
-# arm of the compound has an incompatible affinity.
+# Disable the WHERE-clause push-down optimization for compound subqueries
+# if any arm of the compound has an incompatible affinity.
#
reset_db
do_execsql_test 3.1 {
@@ -185,7 +205,7 @@ do_eqp_test 3.8 {
# SELECT (SELECT count(*) FROM t1)+(SELECT count(*) FROM t2)
# 2023-05-09 https://sqlite.org/forum/forumpost/a7d4be7fb6
-# Restriction (9) on the push-down optimization.
+# Restriction (9) on the WHERE-clause push-down optimization.
#
reset_db
db null -
@@ -227,4 +247,89 @@ do_execsql_test 5.0 {
WHERE e>0;
} {- - 3 4 5}
+
+# 2024-04-05
+# Allow push-down of operators of the form "expr IN table".
+#
+reset_db
+do_execsql_test 6.0 {
+ CREATE TABLE t01(w,x,y,z);
+ CREATE TABLE t02(w,x,y,z);
+ CREATE VIEW t0(w,x,y,z) AS
+ SELECT w,x,y,z FROM t01 UNION ALL SELECT w,x,y,z FROM t02;
+ CREATE INDEX t01x ON t01(w,x,y);
+ CREATE INDEX t02x ON t02(w,x,y);
+ CREATE VIEW v1(k) AS VALUES(77),(88),(99);
+ CREATE TABLE k1(k);
+ INSERT INTO k1 SELECT * FROM v1;
+}
+do_eqp_test 6.1 {
+ WITH k(n) AS (VALUES(77),(88),(99))
+ SELECT max(z) FROM t0 WHERE w=123 AND x IN k AND y BETWEEN 44 AND 55;
+} {
+ QUERY PLAN
+ |--CO-ROUTINE t0
+ | `--COMPOUND QUERY
+ | |--LEFT-MOST SUBQUERY
+ | | |--SEARCH t01 USING INDEX t01x (w=? AND x=? AND y>? AND y<?)
+ | | `--LIST SUBQUERY xxxxxx
+ | | |--MATERIALIZE k
+ | | | `--SCAN 3 CONSTANT ROWS
+ | | `--SCAN k
+ | `--UNION ALL
+ | |--SEARCH t02 USING INDEX t02x (w=? AND x=? AND y>? AND y<?)
+ | `--LIST SUBQUERY xxxxxx
+ | `--SCAN k
+ |--SEARCH t0
+ `--LIST SUBQUERY xxxxxx
+ `--SCAN k
+}
+# ^^^^--- The key feature above is that the SEARCH for each subquery
+# uses all three fields of the index w, x, and y. Prior to the push-down
+# of "expr IN table", only the w term of the index would be used. Similar
+# for the following tests:
+#
+do_eqp_test 6.2 {
+ SELECT max(z) FROM t0 WHERE w=123 AND x IN v1 AND y BETWEEN 44 AND 55;
+} {
+ QUERY PLAN
+ |--CO-ROUTINE t0
+ | `--COMPOUND QUERY
+ | |--LEFT-MOST SUBQUERY
+ | | |--SEARCH t01 USING INDEX t01x (w=? AND x=? AND y>? AND y<?)
+ | | `--LIST SUBQUERY xxxxxx
+ | | |--CO-ROUTINE v1
+ | | | `--SCAN 3 CONSTANT ROWS
+ | | `--SCAN v1
+ | `--UNION ALL
+ | |--SEARCH t02 USING INDEX t02x (w=? AND x=? AND y>? AND y<?)
+ | `--LIST SUBQUERY xxxxxx
+ | |--CO-ROUTINE v1
+ | | `--SCAN 3 CONSTANT ROWS
+ | `--SCAN v1
+ |--SEARCH t0
+ `--LIST SUBQUERY xxxxxx
+ |--CO-ROUTINE v1
+ | `--SCAN 3 CONSTANT ROWS
+ `--SCAN v1
+}
+do_eqp_test 6.3 {
+ SELECT max(z) FROM t0 WHERE w=123 AND x IN k1 AND y BETWEEN 44 AND 55;
+} {
+ QUERY PLAN
+ |--CO-ROUTINE t0
+ | `--COMPOUND QUERY
+ | |--LEFT-MOST SUBQUERY
+ | | |--SEARCH t01 USING INDEX t01x (w=? AND x=? AND y>? AND y<?)
+ | | `--LIST SUBQUERY xxxxxx
+ | | `--SCAN k1
+ | `--UNION ALL
+ | |--SEARCH t02 USING INDEX t02x (w=? AND x=? AND y>? AND y<?)
+ | `--LIST SUBQUERY xxxxxx
+ | `--SCAN k1
+ |--SEARCH t0
+ `--LIST SUBQUERY xxxxxx
+ `--SCAN k1
+}
+
finish_test
diff --git a/test/quote.test b/test/quote.test
index 6d7b317..4e40a9e 100644
--- a/test/quote.test
+++ b/test/quote.test
@@ -103,7 +103,7 @@ foreach {tn sql errname} {
3 { CREATE INDEX i3 ON t1("w") } w
4 { CREATE INDEX i4 ON t1(x) WHERE z="w" } w
} {
- do_catchsql_test 2.1.$tn $sql [list 1 "no such column: $errname"]
+ do_catchsql_test 2.1.$tn $sql [list 1 "no such column: \"$errname\" - should this be a string literal in single-quotes?"]
}
do_execsql_test 2.2 {
@@ -147,19 +147,19 @@ ifcapable altertable {
CREATE TABLE t1(a,b);
CREATE INDEX x1 on t1("b");
ALTER TABLE t1 DROP COLUMN b;
- } {1 {error in index x1 after drop column: no such column: b}}
+ } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}}
do_catchsql_test 3.1 {
DROP TABLE t1;
CREATE TABLE t1(a,"b");
CREATE INDEX x1 on t1("b");
ALTER TABLE t1 DROP COLUMN b;
- } {1 {error in index x1 after drop column: no such column: b}}
+ } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}}
do_catchsql_test 3.2 {
DROP TABLE t1;
CREATE TABLE t1(a,'b');
CREATE INDEX x1 on t1("b");
ALTER TABLE t1 DROP COLUMN b;
- } {1 {error in index x1 after drop column: no such column: b}}
+ } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}}
do_catchsql_test 3.3 {
DROP TABLE t1;
CREATE TABLE t1(a,"b");
@@ -172,7 +172,7 @@ ifcapable altertable {
CREATE INDEX x1 ON t1("a"||"b");
INSERT INTO t1 VALUES(1,2,3),(1,4,5);
ALTER TABLE t1 DROP COLUMN b;
- } {1 {error in index x1 after drop column: no such column: b}}
+ } {1 {error in index x1 after drop column: no such column: "b" - should this be a string literal in single-quotes?}}
sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1
do_catchsql_test 3.5 {
DROP TABLE t1;
diff --git a/test/readonly.test b/test/readonly.test
new file mode 100644
index 0000000..1ccbcee
--- /dev/null
+++ b/test/readonly.test
@@ -0,0 +1,55 @@
+# 2024 March 21
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# This file contains tests for using databases in read-only mode on
+# unix.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+if {$tcl_platform(platform)=="windows"} finish_test
+source $testdir/lock_common.tcl
+source $testdir/wal_common.tcl
+set ::testprefix readonly
+
+do_execsql_test 1.0 {
+ CREATE TABLE t1(a, b);
+ INSERT INTO t1 VALUES(1, 2), (3, 4), (5, 6);
+}
+
+db close
+file attributes test.db -permissions r--r--r--
+
+sqlite3 db test.db
+
+do_catchsql_test 1.1 {
+ INSERT INTO t1 VALUES(7, 8);
+} {1 {attempt to write a readonly database}}
+
+do_execsql_test 1.2 {
+ BEGIN;
+ SELECT * FROM t1;
+} {1 2 3 4 5 6}
+
+# The following attempts to open a read/write fd on the database 20,000
+# times. And each time instead opens a read-only fd. At one point this
+# was failing to reuse cached fds, causing a "too many open file-descriptors"
+# error.
+do_test 1.3 {
+ for {set ii 0} {$ii < 20000} {incr ii} {
+ sqlite3 db2 test.db
+ db2 close
+ }
+ set {} {}
+} {}
+
+
+finish_test
diff --git a/test/recover.test b/test/recover.test
index 8d9ad01..5495b7a 100644
--- a/test/recover.test
+++ b/test/recover.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# Test the shell tool ".ar" command.
#
diff --git a/test/returning1.test b/test/returning1.test
index 2403249..05bd445 100644
--- a/test/returning1.test
+++ b/test/returning1.test
@@ -227,21 +227,21 @@ ifcapable !allow_rowid_in_view {
} else {
# Note: The values returned by the RETURNING clauses of the following
# two statements are the rowid columns of views. These values are not
- # well defined, so the INSERT returns -1, and the UPDATE returns 1, 2
- # and 3. These match the values used for new.rowid expressions, but
- # not much else.
+ # well defined, so the INSERT returns -1, and the UPDATE returns NULL.
+ # These match the values used for new.rowid expressions, but not much
+ # else.
do_catchsql_test 10.3a {
INSERT INTO t1(a, b) VALUES(1234, 5678) RETURNING rowid;
} {0 -1}
do_catchsql_test 10.3b {
UPDATE t1 SET a='z' WHERE b='y' RETURNING rowid;
- } {0 {1 2 3}}
+ } {0 {{} {} {}}}
do_execsql_test 10.4 {
SELECT * FROM log;
} {
- insert -1 1234 5678 update 1 z y update 2 z y update 3 z y
+ insert -1 1234 5678 update {} z y update {} z y update {} z y
}
}
@@ -460,4 +460,75 @@ do_catchsql_test 19.1 {
END;
} {0 {}}
+# 2024-04-24
+# https://sqlite.org/forum/forumpost/2c83569ce8945d39
+#
+# If the RETURNING clause includes subqueries that reference the
+# table being modified, make sure that the subqueries are identified
+# as correlated so that the results are recomputed after each step
+# instead of being computed once and reused.
+#
+reset_db
+db null N
+do_execsql_test 20.1 {
+ CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT);
+ INSERT INTO t1 VALUES(1,10),(2,20),(3,30),(4,40),(6,60),(8,80);
+ BEGIN;
+ DELETE FROM t1 WHERE a<>3
+ RETURNING a,
+ (SELECT min(a) FROM t1),
+ (SELECT max(a) FROM t1),
+ (SELECT round(avg(a),2) FROM t1);
+ ROLLBACK;
+} {
+ 1 2 8 4.6
+ 2 3 8 5.25
+ 4 3 8 5.67
+ 6 3 8 5.5
+ 8 3 3 3.0
+}
+do_execsql_test 20.2 {
+ BEGIN;
+ DELETE FROM t1
+ RETURNING a,
+ (SELECT min(a) FROM t1),
+ (SELECT max(a) FROM t1),
+ (SELECT round(avg(a),2) FROM t1);
+ ROLLBACK;
+} {
+ 1 2 8 4.6
+ 2 3 8 5.25
+ 3 4 8 6.0
+ 4 6 8 7.0
+ 6 8 8 8.0
+ 8 N N N
+}
+do_execsql_test 20.3 {
+ BEGIN;
+ DELETE FROM t1
+ RETURNING a,
+ (SELECT min(t2.a)+t1.a*100 FROM t1 AS t2),
+ (SELECT max(t2.a)+t1.a*100 FROM t1 AS t2),
+ (SELECT round(avg(t2.a),2)+t1.a*100 FROM t1 AS t2);
+ ROLLBACK;
+} {
+ 1 102 108 104.6
+ 2 203 208 205.25
+ 3 304 308 306.0
+ 4 406 408 407.0
+ 6 608 608 608.0
+ 8 N N N
+}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 21.0 {
+ PRAGMA writable_schema=ON;
+ INSERT INTO sqlite_schema DEFAULT VALUES RETURNING sqlite_schema.name;
+} {{}}
+
+do_execsql_test 21.1 {
+ INSERT INTO sqlite_temp_schema DEFAULT VALUES RETURNING sqlite_temp_schema.name;
+} {{}}
+
finish_test
diff --git a/test/scanstatus2.test b/test/scanstatus2.test
index ca3a42f..7f107cd 100644
--- a/test/scanstatus2.test
+++ b/test/scanstatus2.test
@@ -247,7 +247,7 @@ QUERY (nCycle=nnn)
----SCAN rt2 (nCycle=nnn)
----USE TEMP B-TREE FOR GROUP BY (nCycle=nnn)
--SCAN rt1 (nCycle=nnn)
---CREATE AUTOMATIC INDEX ON v1(x1, cnt, x1) (nCycle=nnn)
+--CREATE AUTOMATIC INDEX ON v1(x1, cnt) (nCycle=nnn)
--BLOOM FILTER ON v1 (x1=?)
--SEARCH v1 USING AUTOMATIC COVERING INDEX (x1=?) (nCycle=nnn)
}
@@ -328,6 +328,17 @@ QUERY (nCycle=nnn)
--SCAN xy2 (nCycle=nnn)
}
+#-------------------------------------------------------------------------
+reset_db
+
+# Check that an OOB parameter (45) does not cause asan or valgrind errors.
+#
+do_test 7.0 {
+ db eval {SELECT * FROM sqlite_schema}
+ set stmt [db version -last-stmt-ptr]
+ sqlite3_stmt_scanstatus -flags complex $stmt 1000000
+} {}
+
#explain_i { SELECT (a % 2), group_concat(b) FROM t1 GROUP BY 1 }
#puts_debug_info { SELECT (a % 2), group_concat(b) FROM t1 GROUP BY 1 }
diff --git a/test/selectA.test b/test/selectA.test
index 7d72bb3..91b1548 100644
--- a/test/selectA.test
+++ b/test/selectA.test
@@ -1340,10 +1340,10 @@ do_eqp_test 4.1.2 {
`--MERGE (UNION ALL)
|--LEFT
| |--SCAN t5 USING INDEX i2
- | `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ | `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
`--RIGHT
|--SCAN t4 USING INDEX i1
- `--USE TEMP B-TREE FOR RIGHT PART OF ORDER BY
+ `--USE TEMP B-TREE FOR LAST TERM OF ORDER BY
}
do_execsql_test 4.1.3 {
diff --git a/test/sessionfuzz.c b/test/sessionfuzz.c
index 093c2b0..c389a5e 100644
--- a/test/sessionfuzz.c
+++ b/test/sessionfuzz.c
@@ -60,6 +60,7 @@
#define SQLITE_DEBUG 1
#define SQLITE_THREADSAFE 0
+#undef SQLITE_OMIT_LOAD_EXTENSION
#define SQLITE_OMIT_LOAD_EXTENSION 0
#define SQLITE_ENABLE_SESSION 1
#define SQLITE_ENABLE_PREUPDATE_HOOK 1
diff --git a/test/shell1.test b/test/shell1.test
index 5d4243f..206fb0a 100644
--- a/test/shell1.test
+++ b/test/shell1.test
@@ -11,6 +11,7 @@
#
# The focus of this file is testing the CLI shell tool.
#
+# TESTRUNNER: shell
#
# Test plan:
diff --git a/test/shell2.test b/test/shell2.test
index 16ed33c..c6c27d2 100644
--- a/test/shell2.test
+++ b/test/shell2.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# The focus of this file is testing the CLI shell tool.
#
diff --git a/test/shell3.test b/test/shell3.test
index f8d6994..c1ea9f6 100644
--- a/test/shell3.test
+++ b/test/shell3.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# The focus of this file is testing the CLI shell tool.
#
diff --git a/test/shell4.test b/test/shell4.test
index eee59b0..4b7e9b8 100644
--- a/test/shell4.test
+++ b/test/shell4.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# The focus of this file is testing the CLI shell tool.
# These tests are specific to the .stats command.
diff --git a/test/shell5.test b/test/shell5.test
index 20f2ba2..877676d 100644
--- a/test/shell5.test
+++ b/test/shell5.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# The focus of this file is testing the CLI shell tool.
# These tests are specific to the .import command.
diff --git a/test/shell6.test b/test/shell6.test
index 49b4cc3..4841d6c 100644
--- a/test/shell6.test
+++ b/test/shell6.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# Test the shell tool ".lint fkey-indexes" command.
#
diff --git a/test/shell7.test b/test/shell7.test
index 898018d..dfd9e47 100644
--- a/test/shell7.test
+++ b/test/shell7.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# Test the readfile() function built into the shell tool. Specifically,
# that it does not truncate the blob read at the first embedded 0x00
diff --git a/test/shell8.test b/test/shell8.test
index bee6039..ca37598 100644
--- a/test/shell8.test
+++ b/test/shell8.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# Test the shell tool ".ar" command.
#
@@ -164,7 +165,7 @@ foreach {tn tcl} {
#
# Because it is slow, only do this for $tn==1.
if {$tn==1} {
- do_test 1.$tn.1 {
+ do_test 1.$tn.4 {
catchcmd test_ar.db $c1
file delete -force ar1
after 2000
@@ -193,4 +194,29 @@ do_test 2.1.1 {
regsub -all {ar4} [dir_content ar4] ar2
} {ar2/file1 ar2/file2 ar2/junk1}
+# Test symbolic links.
+#
+if {$tcl_platform(platform)=="unix"} {
+ populate_dir ar2 {
+ file1 "1234"
+ file2 "3456"
+ }
+ file link ar2/link1 file1
+
+ forcedelete shell8.db
+ forcedelete link1
+
+ do_test 3.1 {
+ catchcmd shell8.db {.ar -C ar2 -c file2 link1 }
+ } {0 {}}
+
+ do_test 3.2 {
+ catchcmd shell8.db {.ar -x}
+ } {0 {}}
+
+ do_test 3.3 {
+ catchcmd shell8.db {.ar -x}
+ } {0 {}}
+}
+
finish_test
diff --git a/test/shell9.test b/test/shell9.test
index 34c9d8c..869cb07 100644
--- a/test/shell9.test
+++ b/test/shell9.test
@@ -8,6 +8,7 @@
# May you share freely, never taking more than you give.
#
#***********************************************************************
+# TESTRUNNER: shell
#
# The focus of this file is testing the CLI shell tool. Specifically,
# testing that it is possible to run a ".dump" script that creates
diff --git a/test/speedtest1.c b/test/speedtest1.c
index 4f32580..5709423 100644
--- a/test/speedtest1.c
+++ b/test/speedtest1.c
@@ -2150,6 +2150,50 @@ void testset_debug1(void){
}
}
+/*
+** This testset focuses on the speed of parsing numeric literals (integers
+** and real numbers). This was added to test the impact of allowing "_"
+** characters to appear in numeric SQL literals to make them easier to read.
+** For example, "SELECT 1_000_000;" instead of "SELECT 1000000;".
+*/
+void testset_parsenumber(void){
+ const char *zSql1 = "SELECT 1, 12, 123, 1234, 12345, 123456";
+ const char *zSql2 = "SELECT 8227256643844975616, 7932208612563860480, "
+ "2010730661871032832, 9138463067404021760, "
+ "2557616153664746496, 2557616153664746496";
+ const char *zSql3 = "SELECT 1.0, 1.2, 1.23, 123.4, 1.2345, 1.23456";
+ const char *zSql4 = "SELECT 8.227256643844975616, 7.932208612563860480, "
+ "2.010730661871032832, 9.138463067404021760, "
+ "2.557616153664746496, 2.557616153664746496";
+
+ const int NROW = 100*g.szTest;
+ int ii;
+
+ speedtest1_begin_test(100, "parsing small integers");
+ for(ii=0; ii<NROW; ii++){
+ sqlite3_exec(g.db, zSql1, 0, 0, 0);
+ }
+ speedtest1_end_test();
+
+ speedtest1_begin_test(110, "parsing large integers");
+ for(ii=0; ii<NROW; ii++){
+ sqlite3_exec(g.db, zSql2, 0, 0, 0);
+ }
+ speedtest1_end_test();
+
+ speedtest1_begin_test(200, "parsing small reals");
+ for(ii=0; ii<NROW; ii++){
+ sqlite3_exec(g.db, zSql3, 0, 0, 0);
+ }
+ speedtest1_end_test();
+
+ speedtest1_begin_test(210, "parsing large reals");
+ for(ii=0; ii<NROW; ii++){
+ sqlite3_exec(g.db, zSql4, 0, 0, 0);
+ }
+ speedtest1_end_test();
+}
+
#ifdef __linux__
#include <sys/types.h>
#include <unistd.h>
@@ -2557,6 +2601,8 @@ int main(int argc, char **argv){
testset_fp();
}else if( strcmp(zThisTest,"trigger")==0 ){
testset_trigger();
+ }else if( strcmp(zThisTest,"parsenumber")==0 ){
+ testset_parsenumber();
}else if( strcmp(zThisTest,"rtree")==0 ){
#ifdef SQLITE_ENABLE_RTREE
testset_rtree(6, 147);
diff --git a/test/sqllimits1.test b/test/sqllimits1.test
index f16208f..14d39e6 100644
--- a/test/sqllimits1.test
+++ b/test/sqllimits1.test
@@ -707,6 +707,7 @@ if {$SQLITE_MAX_EXPR_DEPTH==0} {
}]
} "1 {Expression tree is too large (maximum depth $::SQLITE_MAX_EXPR_DEPTH)}"
+if 0 {
# Attempting to beat the expression depth limit using nested SELECT
# queries causes a parser stack overflow.
do_test sqllimits1-9.2 {
@@ -718,7 +719,6 @@ if {$SQLITE_MAX_EXPR_DEPTH==0} {
catchsql [subst { $expr }]
} "1 {parser stack overflow}"
-if 0 {
do_test sqllimits1-9.3 {
execsql {
PRAGMA max_page_count = 1000000; -- 1 GB
@@ -922,7 +922,7 @@ do_catchsql_test sqllimits1-18.1 {
do_catchsql_test sqllimits1-18.2 {
INSERT INTO b1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9), (10)
UNION VALUES(11);
-} {1 {too many terms in compound SELECT}}
+} {0 {}}
#-------------------------------------------------------------------------
#
diff --git a/test/subquery.test b/test/subquery.test
index c51edba..17061d4 100644
--- a/test/subquery.test
+++ b/test/subquery.test
@@ -651,5 +651,64 @@ do_eqp_test subquery-10.2 {
# `--SEARCH t1 USING INDEX x12 (aa=?)
#
+#-----------------------------------------------------------------------------
+# 2024-04-25 Column affinities for columns of compound subqueries
+#
+reset_db
+sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db
+do_execsql_test subquery-11.1 {
+ CREATE TABLE t1(ix INT, rx REAL, bx BLOB, tx TEXT, ax);
+ INSERT INTO t1 VALUES(1,1.0,x'31','x',NULL);
+ WITH c(a) AS (SELECT 'y' UNION SELECT tx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 'y') SELECT affinity(a) FROM c;
+} {text text text text}
+do_execsql_test subquery-11.2 {
+ WITH c(a) AS (SELECT 2 UNION SELECT tx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 2) SELECT affinity(a) FROM c;
+} {blob blob blob blob}
+do_execsql_test subquery-11.3 {
+ WITH c(a) AS (SELECT 2.0 UNION SELECT tx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT tx FROM t1 UNION SELECT 2.0) SELECT affinity(a) FROM c;
+} {blob blob blob blob}
+do_execsql_test subquery-11.4 {
+ WITH c(a) AS (SELECT null UNION SELECT tx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT tx FROM t1 UNION SELECT null) SELECT affinity(a) FROM c;
+} {text text text text}
+do_execsql_test subquery-11.5 {
+ WITH c(a) AS (SELECT x'32' UNION SELECT tx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT tx FROM t1 UNION SELECT x'32') SELECT affinity(a) FROM c;
+} {text text text text}
+do_execsql_test subquery-11.6 {
+ WITH c(a) AS (SELECT 3 UNION SELECT ix FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT ix FROM t1 UNION SELECT 3) SELECT affinity(a) FROM c;
+} {integer integer integer integer}
+do_execsql_test subquery-11.7 {
+ WITH c(a) AS (SELECT 3.0 UNION SELECT ix FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT ix FROM t1 UNION SELECT 3.0) SELECT affinity(a) FROM c;
+} {integer integer integer integer}
+do_execsql_test subquery-11.8 {
+ WITH c(a) AS (SELECT '3' UNION SELECT ix FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT ix FROM t1 UNION SELECT '3') SELECT affinity(a) FROM c;
+} {blob blob blob blob}
+do_execsql_test subquery-11.10 {
+ WITH c(a) AS (SELECT x'32' UNION SELECT ix FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT ix FROM t1 UNION SELECT x'32') SELECT affinity(a) FROM c;
+} {integer integer integer integer}
+do_execsql_test subquery-11.11 {
+ WITH c(a) AS (SELECT 4 UNION SELECT rx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT rx FROM t1 UNION SELECT 4) SELECT affinity(a) FROM c;
+} {real real real real}
+do_execsql_test subquery-11.12 {
+ WITH c(a) AS (SELECT '4' UNION SELECT rx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT rx FROM t1 UNION SELECT '4') SELECT affinity(a) FROM c;
+} {blob blob blob blob}
+do_execsql_test subquery-11.13 {
+ WITH c(a) AS (SELECT null UNION SELECT rx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT rx FROM t1 UNION SELECT null) SELECT affinity(a) FROM c;
+} {real real real real}
+do_execsql_test subquery-11.14 {
+ WITH c(a) AS (SELECT x'b4' UNION SELECT rx FROM t1) SELECT affinity(a) FROM c;
+ WITH c(a) AS (SELECT rx FROM t1 UNION SELECT x'b4') SELECT affinity(a) FROM c;
+} {real real real real}
finish_test
diff --git a/test/tabfunc01.test b/test/tabfunc01.test
index 8e90c54..3a62b81 100644
--- a/test/tabfunc01.test
+++ b/test/tabfunc01.test
@@ -322,6 +322,32 @@ ifcapable altertable {
} {1 {table pragma_compile_options may not be altered}}
}
+#-----------------------------------------------------------------------------
+# 2024-04-26 LIMIT and OFFSET passed into virtual tables
+# https://sqlite.org/forum/forumpost/c243b8f856
+#
+do_execsql_test tabfunc01-900 {
+ SELECT * FROM (
+ SELECT * FROM generate_series(1,10)
+ UNION ALL
+ SELECT * FROM generate_series(101,104)
+ ) LIMIT 10 OFFSET 5;
+} {6 7 8 9 10 101 102 103 104}
+do_execsql_test tabfunc01-910 {
+ SELECT * FROM (
+ SELECT * FROM generate_series(1,10)
+ UNION ALL
+ SELECT * FROM generate_series(101,104)
+ ) LIMIT -1 OFFSET 5;
+} {6 7 8 9 10 101 102 103 104}
+do_execsql_test tabfunc01-920 {
+ SELECT * FROM (
+ SELECT * FROM generate_series(1,10)
+ UNION ALL
+ SELECT * FROM generate_series(101,104)
+ ) LIMIT -1 OFFSET 0;
+} {1 2 3 4 5 6 7 8 9 10 101 102 103 104}
+
# Free up memory allocations
intarray_addr
diff --git a/test/testrunner.tcl b/test/testrunner.tcl
index 0c704da..fd82716 100644
--- a/test/testrunner.tcl
+++ b/test/testrunner.tcl
@@ -54,22 +54,35 @@ proc usage {} {
Usage:
$a0 ?SWITCHES? ?PERMUTATION? ?PATTERNS?
$a0 PERMUTATION FILE
+ $a0 help
$a0 njob ?NJOB?
+ $a0 script ?-msvc? CONFIG
$a0 status
where SWITCHES are:
- --buildonly
- --dryrun
- --jobs NUMBER-OF-JOBS
- --zipvfs ZIPVFS-SOURCE-DIR
+ --buildonly Build test exes but do not run tests
+ --config CONFIGS Only use configs on comma-separate list CONFIGS
+ --dryrun Write what would have happened to testrunner.log
+ --explain Write summary to stdout
+ --jobs NUM Run tests using NUM separate processes
+ --omit CONFIGS Omit configs on comma-separated list CONFIGS
+ --stop-on-coredump Stop running if any test segfaults
+ --stop-on-error Stop running after any reported error
+ --zipvfs ZIPVFSDIR ZIPVFS source directory
+
+Special values for PERMUTATION that work with plain tclsh:
+
+ list - show all allowed PERMUTATION arguments.
+ mdevtest - tests recommended prior to normal development check-ins.
+ release - full release test with various builds.
+ sdevtest - like mdevtest but using ASAN and UBSAN.
-Interesting values for PERMUTATION are:
+Other PERMUTATION arguments must be run using testfixture, not tclsh:
- veryquick - a fast subset of the tcl test scripts. This is the default.
- full - all tcl test scripts.
all - all tcl test scripts, plus a subset of test scripts rerun
with various permutations.
- release - full release test with various builds.
+ full - all tcl test scripts.
+ veryquick - a fast subset of the tcl test scripts. This is the default.
If no PATTERN arguments are present, all tests specified by the PERMUTATION
are run. Otherwise, each pattern is interpreted as a glob pattern. Only
@@ -89,6 +102,12 @@ directory as a running testrunner.tcl script that is running tests. The
"status" command prints a report describing the current state and progress
of the tests. The "njob" command may be used to query or modify the number
of sub-processes the test script uses to run tests.
+
+The "script" command outputs the script used to build a configuration.
+Add the "-msvc" option for a Windows-compatible script. For a list of
+available configurations enter "$a0 script help".
+
+Full documentation here: https://sqlite.org/src/doc/trunk/doc/testrunner.md
}]]
exit 1
@@ -126,6 +145,10 @@ proc guess_number_of_cores {} {
}
proc default_njob {} {
+ global env
+ if {[info exists env(NJOB)] && $env(NJOB)>=1} {
+ return $env(NJOB)
+ }
set nCore [guess_number_of_cores]
if {$nCore<=2} {
set nHelper 1
@@ -151,7 +174,12 @@ set TRG(reporttime) 2000
set TRG(fuzztest) 0 ;# is the fuzztest option present.
set TRG(zipvfs) "" ;# -zipvfs option, if any
set TRG(buildonly) 0 ;# True if --buildonly option
+set TRG(config) {} ;# Only build the named configurations
+set TRG(omitconfig) {} ;# Do not build these configurations
set TRG(dryrun) 0 ;# True if --dryrun option
+set TRG(explain) 0 ;# True for the --explain option
+set TRG(stopOnError) 0 ;# Stop running at first failure
+set TRG(stopOnCore) 0 ;# Stop on a core-dump
switch -nocase -glob -- $tcl_platform(os) {
*darwin* {
@@ -159,6 +187,7 @@ switch -nocase -glob -- $tcl_platform(os) {
set TRG(make) make.sh
set TRG(makecmd) "bash make.sh"
set TRG(testfixture) testfixture
+ set TRG(shell) sqlite3
set TRG(run) run.sh
set TRG(runcmd) "bash run.sh"
}
@@ -167,14 +196,16 @@ switch -nocase -glob -- $tcl_platform(os) {
set TRG(make) make.sh
set TRG(makecmd) "bash make.sh"
set TRG(testfixture) testfixture
+ set TRG(shell) sqlite3
set TRG(run) run.sh
set TRG(runcmd) "bash run.sh"
}
*win* {
set TRG(platform) win
set TRG(make) make.bat
- set TRG(makecmd) make.bat
+ set TRG(makecmd) "call make.bat"
set TRG(testfixture) testfixture.exe
+ set TRG(shell) sqlite3.exe
set TRG(run) run.bat
set TRG(runcmd) "run.bat"
}
@@ -239,7 +270,7 @@ set TRG(schema) {
/* Fields updated as jobs run */
starttime INTEGER,
endtime INTEGER,
- state TEXT CHECK( state IN ('', 'ready', 'running', 'done', 'failed') ),
+ state TEXT CHECK( state IN ('','ready','running','done','failed','omit') ),
output TEXT
);
@@ -327,6 +358,14 @@ if {([llength $argv]==2 || [llength $argv]==1)
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
+# Check if this is the "help" command:
+#
+if {[string compare -nocase help [lindex $argv 0]]==0} {
+ usage
+}
+#--------------------------------------------------------------------------
+
+#--------------------------------------------------------------------------
# Check if this is the "script" command:
#
if {[string compare -nocase script [lindex $argv 0]]==0} {
@@ -408,6 +447,10 @@ if {[llength $argv]==1
} job {
display_job [array get job]
}
+ set nOmit [db one {SELECT count(*) FROM jobs WHERE state='omit'}]
+ if {$nOmit} {
+ puts "$nOmit jobs omitted due to failures"
+ }
}
mydb close
@@ -433,8 +476,20 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} {
if {$isLast} { usage }
} elseif {($n>2 && [string match "$a*" --buildonly]) || $a=="-b"} {
set TRG(buildonly) 1
+ } elseif {($n>2 && [string match "$a*" --config]) || $a=="-c"} {
+ incr ii
+ set TRG(config) [lindex $argv $ii]
} elseif {($n>2 && [string match "$a*" --dryrun]) || $a=="-d"} {
set TRG(dryrun) 1
+ } elseif {($n>2 && [string match "$a*" --explain]) || $a=="-e"} {
+ set TRG(explain) 1
+ } elseif {($n>2 && [string match "$a*" --omit]) || $a=="-c"} {
+ incr ii
+ set TRG(omitconfig) [lindex $argv $ii]
+ } elseif {[string match "$a*" --stop-on-error]} {
+ set TRG(stopOnError) 1
+ } elseif {[string match "$a*" --stop-on-coredump]} {
+ set TRG(stopOnCore) 1
} else {
usage
}
@@ -444,8 +499,6 @@ for {set ii 0} {$ii < [llength $argv]} {incr ii} {
}
set argv [list]
-
-
# This script runs individual tests - tcl scripts or [make xyz] commands -
# in directories named "testdir$N", where $N is an integer. This variable
# contains a list of integers indicating the directories in use.
@@ -617,7 +670,16 @@ proc add_job {args} {
trdb last_insert_rowid
}
-proc add_tcl_jobs {build config patternlist} {
+# Argument $build is either an empty string, or else a list of length 3
+# describing the job to build testfixture. In the usual form:
+#
+# {ID DIRNAME DISPLAYNAME}
+#
+# e.g
+#
+# {1 /home/user/sqlite/test/testrunner_bld_xyz All-Debug}
+#
+proc add_tcl_jobs {build config patternlist {shelldepid ""}} {
global TRG
set topdir [file dirname $::testdir]
@@ -666,34 +728,59 @@ proc add_tcl_jobs {build config patternlist} {
if {[lsearch $lProp slow]>=0} { set priority 2 }
if {[lsearch $lProp superslow]>=0} { set priority 4 }
+ set depid [lindex $build 0]
+ if {$shelldepid!="" && [lsearch $lProp shell]>=0} { set depid $shelldepid }
+
add_job \
-displaytype tcl \
-displayname $displayname \
-cmd $cmd \
- -depid [lindex $build 0] \
+ -depid $depid \
-priority $priority
-
}
}
-proc add_build_job {buildname target} {
+proc add_build_job {buildname target {postcmd ""} {depid ""}} {
global TRG
set dirname "[string tolower [string map {- _} $buildname]]_$target"
set dirname "testrunner_bld_$dirname"
+ set cmd "$TRG(makecmd) $target"
+ if {$postcmd!=""} {
+ append cmd "\n"
+ append cmd $postcmd
+ }
+
set id [add_job \
-displaytype bld \
-displayname "Build $buildname ($target)" \
-dirname $dirname \
-build $buildname \
- -cmd "$TRG(makecmd) $target" \
+ -cmd $cmd \
+ -depid $depid \
-priority 3
]
list $id [file normalize $dirname] $buildname
}
+proc add_shell_build_job {buildname dirname depid} {
+ global TRG
+
+ if {$TRG(platform)=="win"} {
+ set path [string map {/ \\} "$dirname/"]
+ set copycmd "xcopy $TRG(shell) $path"
+ } else {
+ set copycmd "cp $TRG(shell) $dirname/"
+ }
+
+ return [
+ add_build_job $buildname $TRG(shell) $copycmd $depid
+ ]
+}
+
+
proc add_make_job {bld target} {
global TRG
@@ -767,10 +854,30 @@ proc add_devtest_jobs {lBld patternlist} {
foreach b $lBld {
set bld [add_build_job $b $TRG(testfixture)]
- add_tcl_jobs $bld veryquick $patternlist
+ add_tcl_jobs $bld veryquick $patternlist SHELL
if {$patternlist==""} {
add_fuzztest_jobs $b
}
+
+ if {[trdb one "SELECT EXISTS (SELECT 1 FROM jobs WHERE depid='SHELL')"]} {
+ set sbld [add_shell_build_job $b [lindex $bld 1] [lindex $bld 0]]
+ set sbldid [lindex $sbld 0]
+ trdb eval {
+ UPDATE jobs SET depid=$sbldid WHERE depid='SHELL'
+ }
+ }
+
+ }
+}
+
+# Check to ensure that the interpreter is a full-blown "testfixture"
+# build and not just a "tclsh". If this is not the case, issue an
+# error message and exit.
+#
+proc must_be_testfixture {} {
+ if {[lsearch [info commands] sqlite3_soft_heap_limit]<0} {
+ puts "Use testfixture, not tclsh, for these arguments."
+ exit 1
}
}
@@ -789,6 +896,7 @@ proc add_jobs_from_cmdline {patternlist} {
set first [lindex $patternlist 0]
switch -- $first {
all {
+ must_be_testfixture
set patternlist [lrange $patternlist 1 end]
set clist [trd_all_configs]
foreach c $clist {
@@ -797,16 +905,26 @@ proc add_jobs_from_cmdline {patternlist} {
}
mdevtest {
- add_devtest_jobs {All-O0 All-Debug} [lrange $patternlist 1 end]
+ set config_set {
+ All-O0
+ All-Debug
+ }
+ add_devtest_jobs $config_set [lrange $patternlist 1 end]
}
sdevtest {
- add_devtest_jobs {All-Sanitize All-Debug} [lrange $patternlist 1 end]
+ set config_set {
+ All-Sanitize
+ All-Debug
+ }
+ add_devtest_jobs $config_set [lrange $patternlist 1 end]
}
release {
set patternlist [lrange $patternlist 1 end]
foreach b [trd_builds $TRG(platform)] {
+ if {$TRG(config)!="" && ![regexp "\\y$b\\y" $TRG(config)]} continue
+ if {[regexp "\\y$b\\y" $TRG(omitconfig)]} continue
set bld [add_build_job $b $TRG(testfixture)]
foreach c [trd_configs $TRG(platform) $b] {
add_tcl_jobs $bld $c $patternlist
@@ -824,7 +942,15 @@ proc add_jobs_from_cmdline {patternlist} {
}
}
+ list {
+ set allperm [array names ::testspec]
+ lappend allperm all mdevtest sdevtest release list
+ puts "Allowed values for the PERMUTATION argument: [lsort $allperm]"
+ exit 0
+ }
+
default {
+ must_be_testfixture
if {[info exists ::testspec($first)]} {
add_tcl_jobs "" $first [lrange $patternlist 1 end]
} else {
@@ -853,11 +979,16 @@ proc make_new_testset {} {
proc mark_job_as_finished {jobid output state endtm} {
r_write_db {
+ if {$state=="failed"} {
+ set childstate omit
+ } else {
+ set childstate ready
+ }
trdb eval {
UPDATE jobs
SET output=$output, state=$state, endtime=$endtm
WHERE jobid=$jobid;
- UPDATE jobs SET state='ready' WHERE depid=$jobid;
+ UPDATE jobs SET state=$childstate WHERE depid=$jobid;
}
}
}
@@ -888,6 +1019,14 @@ proc script_input_ready {fd iJob jobid} {
}
puts "FAILED: $job(displayname) ($iJob)"
set state "failed"
+ if {$TRG(stopOnError)} {
+ puts "OUTPUT: $O($iJob)"
+ exit 1
+ }
+ if {$TRG(stopOnCore) && [string first {core dumped} $O($iJob)]>0} {
+ puts "OUTPUT: $O($iJob)"
+ exit 1
+ }
}
set tm [clock_milliseconds]
@@ -948,6 +1087,16 @@ proc launch_another_job {iJob} {
close $fd
}
+ # Add a batch/shell file command to set the directory used for temp
+ # files to the test's working directory. Otherwise, tests that use
+ # large numbers of temp files (e.g. zipvfs), might generate temp
+ # filename collisions.
+ if {$TRG(platform)=="win"} {
+ set set_tmp_dir "SET SQLITE_TMPDIR=[file normalize $dir]"
+ } else {
+ set set_tmp_dir "export SQLITE_TMPDIR=\"[file normalize $dir]\""
+ }
+
if { $TRG(dryrun) } {
mark_job_as_finished $job(jobid) "" done 0
@@ -962,7 +1111,8 @@ proc launch_another_job {iJob} {
set pwd [pwd]
cd $dir
set fd [open $TRG(run) w]
- puts $fd $job(cmd)
+ puts $fd $set_tmp_dir
+ puts $fd $job(cmd)
close $fd
set fd [open "|$TRG(runcmd) 2>@1" r]
cd $pwd
@@ -1061,6 +1211,10 @@ proc run_testset {} {
puts "FAILED: $displayname"
}
}
+ set nOmit [trdb one {SELECT count(*) FROM jobs WHERE state='omit'}]
+ if {$nOmit>0} {
+ puts "$nOmit jobs skipped due to prior failures"
+ }
}
puts "\nTest database is $TRG(dbname)"
@@ -1078,15 +1232,42 @@ proc handle_buildonly {} {
}
}
+# Handle the --explain option. Provide a human-readable
+# explanation of all the tests that are in the trdb database jobs
+# table.
+#
+proc explain_layer {indent depid} {
+ global TRG
+ if {$TRG(buildonly)} {
+ set showtests 0
+ } else {
+ set showtests 1
+ }
+ trdb eval {SELECT jobid, displayname, displaytype, dirname
+ FROM jobs WHERE depid=$depid ORDER BY displayname} {
+ if {$displaytype=="bld"} {
+ puts "${indent}$displayname in $dirname"
+ explain_layer "${indent} " $jobid
+ } elseif {$showtests} {
+ puts "${indent}[lindex $displayname end]"
+ }
+ }
+}
+proc explain_tests {} {
+ explain_layer "" ""
+}
+
sqlite3 trdb $TRG(dbname)
trdb timeout $TRG(timeout)
set tm [lindex [time { make_new_testset }] 0]
-if {$TRG(nJob)>1} {
- puts "splitting work across $TRG(nJob) jobs"
+if {$TRG(explain)} {
+ explain_tests
+} else {
+ if {$TRG(nJob)>1} {
+ puts "splitting work across $TRG(nJob) jobs"
+ }
+ puts "built testset in [expr $tm/1000]ms.."
+ handle_buildonly
+ run_testset
}
-puts "built testset in [expr $tm/1000]ms.."
-
-handle_buildonly
-run_testset
trdb close
-#puts [pwd]
diff --git a/test/testrunner_data.tcl b/test/testrunner_data.tcl
index 984c6d8..f8f12d9 100644
--- a/test/testrunner_data.tcl
+++ b/test/testrunner_data.tcl
@@ -23,6 +23,7 @@ namespace eval trd {
set tcltest(linux.No-lookaside) veryquick
set tcltest(linux.Devkit) veryquick
set tcltest(linux.Apple) veryquick
+ set tcltest(linux.Android) veryquick
set tcltest(linux.Sanitize) veryquick
set tcltest(linux.Device-One) all
set tcltest(linux.Default) all_plus_autovacuum_crash
@@ -53,6 +54,7 @@ namespace eval trd {
set extra(linux.Device-Two) {fuzztest sourcetest threadtest}
set extra(linux.No-lookaside) {fuzztest sourcetest}
set extra(linux.Devkit) {fuzztest sourcetest}
+ set extra(linux.Android) {fuzztest sourcetest}
set extra(linux.Apple) {fuzztest sourcetest}
set extra(linux.Sanitize) {fuzztest sourcetest}
set extra(linux.Default) {fuzztest sourcetest threadtest}
@@ -108,6 +110,7 @@ namespace eval trd {
-DSQLITE_ENABLE_STAT4
-DSQLITE_OMIT_LOOKASIDE=1
-DCONFIG_SLOWDOWN_FACTOR=5.0
+ -DSQLITE_ENABLE_RBU
--enable-debug
--enable-all
}
@@ -245,6 +248,40 @@ namespace eval trd {
-O2
-DSQLITE_ENABLE_LOCKING_STYLE=1
}
+ set build(Android) {
+ -Os
+ -DHAVE_USLEEP=1
+ -DSQLITE_HAVE_ISNAN
+ -DSQLITE_POWERSAFE_OVERWRITE=1
+ -DSQLITE_DEFAULT_FILE_FORMAT=4
+ -DSQLITE_DEFAULT_AUTOVACUUM=1
+ -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1
+ -DSQLITE_ENABLE_FTS3
+ -DSQLITE_ENABLE_FTS3_BACKWARDS
+ -DSQLITE_ENABLE_FTS4
+ -DSQLITE_SECURE_DELETE
+ -DSQLITE_ENABLE_BATCH_ATOMIC_WRITE
+ -DBIONIC_IOCTL_NO_SIGNEDNESS_OVERLOAD
+ -DSQLITE_ALLOW_ROWID_IN_VIEW
+ -DSQLITE_ENABLE_BYTECODE_VTAB
+ -Wno-unused-parameter
+ -Werror
+ -DUSE_PREAD64
+ -Dfdatasync=fdatasync
+ -DHAVE_MALLOC_H=1
+ -DHAVE_MALLOC_USABLE_SIZE
+ -DSQLITE_ENABLE_DBSTAT_VTAB
+ }
+ # Compile-options used by Android but omitted from these
+ # tests:
+ # -DNDEBUG=1
+ # -DSQLITE_DEFAULT_LEGACY_ALTER_TABLE
+ # -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576
+ # -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600
+ # -DSQLITE_OMIT_BUILTIN_TEST
+ # -DSQLITE_OMIT_LOAD_EXTENSION
+ # -DSQLITE_OMIT_COMPILEOPTION_DIAGS
+ #
set build(Apple) {
-Os
-DHAVE_GMTIME_R=1
@@ -598,7 +635,12 @@ proc trd_buildscript {config srcdir bMsvc} {
# Ensure that the named configuration exists.
if {![info exists build($config)]} {
- error "No such build config: $config"
+ if {$config!="help"} {
+ puts "No such build config: $config"
+ }
+ puts "Available configurations: [lsort [array names build]]"
+ flush stdout
+ exit 1
}
# Generate and return the script.
@@ -637,4 +679,3 @@ proc trd_test_script_properties {path} {
set trd_test_script_properties_cache($path)
}
-
diff --git a/test/tkt-8454a207b9.test b/test/tkt-8454a207b9.test
index 20e1420..42b95c8 100644
--- a/test/tkt-8454a207b9.test
+++ b/test/tkt-8454a207b9.test
@@ -49,7 +49,7 @@ do_test tkt-8454a207b9.4 {
ALTER TABLE t1 ADD COLUMN e DEFAULT -123.0;
SELECT e, typeof(e) FROM t1;
}
-} {-123 integer}
+} {-123.0 real}
do_test tkt-8454a207b9.5 {
db eval {
ALTER TABLE t1 ADD COLUMN f DEFAULT -123.5;
diff --git a/test/tkt-bd484a090c.test b/test/tkt-bd484a090c.test
index 3d2b599..7867c8d 100644
--- a/test/tkt-bd484a090c.test
+++ b/test/tkt-bd484a090c.test
@@ -30,7 +30,7 @@ do_test 2.1 {
catchsql { SELECT datetime('now', 'localtime') }
} {1 {local time unavailable}}
do_test 2.2 {
- catchsql { SELECT datetime('now', 'utc') }
+ catchsql { SELECT datetime('2000-01-01', 'utc') }
} {1 {local time unavailable}}
sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0
diff --git a/test/upsert1.test b/test/upsert1.test
index 7818311..8af273a 100644
--- a/test/upsert1.test
+++ b/test/upsert1.test
@@ -268,4 +268,28 @@ do_catchsql_test upsert1-1210 {
INSERT INTO t1(a,b) VALUES(1,2) ON CONFLICT(b+?1) DO NOTHING;
} {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}}
+# 2024-04-11 https://sqlite.org/forum/forumpost/284955a3cd454a15
+# Incorrect value passed into a trigger that fires as the result of
+# an upsert.
+#
+reset_db
+do_execsql_test upsert1-1300 {
+ CREATE TABLE t1(x INT, y TEXT);
+ INSERT INTO t1 VALUES
+ (11, printf('%.9000c','a')),
+ (11, printf('%.9000c','a')),
+ (33, printf('%.9000c','b')),
+ (33, printf('%.9000c','b'));
+ CREATE TABLE t2(x INT UNIQUE, y TEXT);
+ CREATE TRIGGER r1 BEFORE UPDATE ON t2 BEGIN
+ SELECT raise(ABORT,'Incorrect old.y value passed to trigger!')
+ WHERE old.y != new.y;
+ /* ^^^ This trigger will fire and cause the ABORT if the problem has
+ ** not been fixed, or if there is a regression. */
+ END;
+ INSERT INTO t2(x, y) SELECT x, y FROM t1
+ WHERE true
+ ON CONFLICT (x) DO UPDATE SET y = excluded.y;
+} {}
+
finish_test
diff --git a/test/values.test b/test/values.test
new file mode 100644
index 0000000..fed2c5c
--- /dev/null
+++ b/test/values.test
@@ -0,0 +1,715 @@
+# 2024 March 3
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix values
+
+
+do_execsql_test 1.0 {
+ CREATE TABLE x1(a, b, c);
+}
+
+
+explain_i {
+ INSERT INTO x1(a, b, c) VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
+}
+do_execsql_test 1.1.1 {
+ INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
+}
+do_execsql_test 1.1.2 {
+ SELECT * FROM x1;
+} {
+ 1 1 1
+ 2 2 2
+ 3 3 3
+ 4 4 4
+}
+
+do_execsql_test 1.2.0 {
+ DELETE FROM x1
+}
+do_execsql_test 1.2.1 {
+ INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 4, 4, 4;
+ SELECT * FROM x1;
+} {1 1 1 2 2 2 3 3 3 4 4 4}
+
+sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 4
+
+do_execsql_test 1.2.2 {
+ DELETE FROM x1;
+ INSERT INTO x1
+ VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5)
+ UNION ALL SELECT 6, 6, 6;
+ SELECT * FROM x1;
+} {1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6}
+
+do_execsql_test 1.2.3 {
+ DELETE FROM x1;
+ INSERT INTO x1
+ VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4)
+ UNION ALL SELECT 6, 6, 6;
+ SELECT * FROM x1;
+} {1 1 1 2 2 2 3 3 3 4 4 4 6 6 6}
+
+do_execsql_test 1.2.4 {
+ DELETE FROM x1;
+ INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3) UNION ALL SELECT 6, 6, 6;
+ SELECT * FROM x1;
+} {
+ 1 1 1
+ 2 2 2
+ 3 3 3
+ 6 6 6
+}
+
+set a 4
+set b 5
+set c 6
+do_execsql_test 1.2.5 {
+ DELETE FROM x1;
+ INSERT INTO x1
+ VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3),
+ (4, 4, $a), (5, 5, $b), (6, 6, $c)
+}
+
+do_execsql_test 1.2.6 {
+ SELECT * FROM x1;
+} {
+ 1 1 1
+ 2 2 2
+ 3 3 3
+ 4 4 4
+ 5 5 5
+ 6 6 6
+}
+
+#-------------------------------------------------------------------------
+# SQLITE_LIMIT_COMPOUND_SELECT set to 0.
+#
+reset_db
+
+do_execsql_test 2.0 {
+ CREATE TABLE x1(a, b, c);
+}
+
+sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 3
+
+do_catchsql_test 2.1.1 {
+ INSERT INTO x1 VALUES
+ (1, 1, 1),
+ (2, 2, 2),
+ (3, 3, 3),
+ (4, 4, 4),
+ (5, 5, 5),
+ (6, 6, 6),
+ (7, 7, 7),
+ (8, 8, 8),
+ (9, 9, 9),
+ (10, 10, 10, 10)
+} {1 {all VALUES must have the same number of terms}}
+
+do_catchsql_test 2.1.2 {
+ INSERT INTO x1 VALUES
+ (1, 1, 1),
+ (2, 2, 2, 2),
+ (3, 3, 3),
+ (4, 4, 4),
+ (5, 5, 5),
+ (6, 6, 6),
+ (7, 7, 7),
+ (8, 8, 8),
+ (9, 9, 9),
+ (10, 10, 10)
+} {1 {all VALUES must have the same number of terms}}
+
+sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 0
+
+do_execsql_test 2.2 {
+ INSERT INTO x1 VALUES
+ (1, 1, 1),
+ (2, 2, 2),
+ (3, 3, 3),
+ (4, 4, 4),
+ (5, 5, 5),
+ (6, 6, 6),
+ (7, 7, 7),
+ (8, 8, 8),
+ (9, 9, 9),
+ (10, 10, 10)
+} {}
+do_execsql_test 2.3 {
+ INSERT INTO x1 VALUES
+ (1, 1, 1),
+ (2, 2, 2),
+ (3, 3, 3),
+ (4, 4, 4),
+ (5, 5, 5),
+ (6, 6, 6),
+ (7, 7, 7),
+ (8, 8, 8),
+ (9, 9, 9),
+ (10, 10, 10)
+ UNION ALL
+ SELECT 5, 12, 12
+ ORDER BY 1
+} {}
+
+#-------------------------------------------------------------------------
+reset_db
+
+do_execsql_test 3.0 {
+ CREATE TABLE y1(x, y);
+}
+
+do_execsql_test 3.1.1 {
+ DELETE FROM y1;
+ INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 5);
+}
+do_execsql_test 3.1.2 {
+ SELECT * FROM y1;
+} {1 2 3 4 1 5}
+do_execsql_test 3.2.1 {
+ DELETE FROM y1;
+ INSERT INTO y1 VALUES(1, 2), (3, 4), (row_number() OVER (), 6)
+ , (row_number() OVER (), 7)
+}
+do_execsql_test 3.1.2 {
+ SELECT * FROM y1;
+} {1 2 3 4 1 6 1 7}
+
+#-------------------------------------------------------------------------
+reset_db
+
+do_execsql_test 4.0 {
+ CREATE TABLE x1(a PRIMARY KEY, b) WITHOUT ROWID;
+}
+
+foreach {tn iLimit} {1 0 2 3} {
+ sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT $iLimit
+
+ do_execsql_test 4.1.1 {
+ DELETE FROM x1;
+ INSERT INTO x1 VALUES
+ (1, 1),
+ (2, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) ))
+ }
+ do_execsql_test 4.1.2 {
+ SELECT * FROM x1
+ } {1 1 2 a}
+
+ do_execsql_test 4.2.1 {
+ DELETE FROM x1;
+ INSERT INTO x1 VALUES
+ (1, 1),
+ (2, 2),
+ (3, 3),
+ (4, 4),
+ (5, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d')) ))
+ }
+ do_execsql_test 4.2.2 {
+ SELECT * FROM x1
+ } {1 1 2 2 3 3 4 4 5 a}
+
+ do_execsql_test 4.3.1 {
+ DELETE FROM x1;
+ INSERT INTO x1 VALUES
+ (1, (SELECT * FROM (VALUES('a'), ('b'), ('c'), ('d'), ('e')) ))
+ }
+ do_execsql_test 4.3.2 {
+ SELECT * FROM x1
+ } {1 a}
+}
+
+#------------------------------------------------------------------------
+reset_db
+
+do_execsql_test 5.0 {
+ CREATE VIEW v1 AS VALUES(1, 2, 3), (4, 5, 6), (7, 8, 9);
+}
+do_execsql_test 5.1 {
+ SELECT * FROM v1
+} {1 2 3 4 5 6 7 8 9}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 6.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES(1), (2);
+}
+
+do_execsql_test 6.1 {
+ SELECT ( VALUES( x ), ( x ) ) FROM t1;
+} {1 2}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 6.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('x'), ('y');
+}
+
+do_execsql_test 6.1 {
+ SELECT * FROM t1, (VALUES(1), (2))
+} {x 1 x 2 y 1 y 2}
+
+do_execsql_test 6.2 {
+ VALUES(CAST(44 AS REAL)),(55);
+} {44.0 55}
+
+#------------------------------------------------------------------------
+do_execsql_test 7.1 {
+ WITH x1(a, b) AS (
+ VALUES(1, 2), ('a', 'b')
+ )
+ SELECT * FROM x1 one, x1 two
+} {
+ 1 2 1 2
+ 1 2 a b
+ a b 1 2
+ a b a b
+}
+
+#-------------------------------------------------------------------------
+reset_db
+
+set VVV {
+ ( VALUES('a', 'b'), ('c', 'd'), (123, NULL) )
+}
+set VVV2 {
+ (
+ SELECT 'a' AS column1, 'b' AS column2
+ UNION ALL SELECT 'c', 'd' UNION ALL SELECT 123, NULL
+ )
+}
+
+do_execsql_test 8.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('d'), (NULL), (123)
+}
+foreach {tn q res} {
+ 1 "SELECT * FROM t1 LEFT JOIN VVV" {
+ d a b d c d d 123 {}
+ {} a b {} c d {} 123 {}
+ 123 a b 123 c d 123 123 {}
+ }
+
+ 2 "SELECT * FROM t1 LEFT JOIN VVV ON (column1=x)" {
+ d {} {}
+ {} {} {}
+ 123 123 {}
+ }
+
+ 3 "SELECT * FROM t1 RIGHT JOIN VVV" {
+ d a b d c d d 123 {}
+ {} a b {} c d {} 123 {}
+ 123 a b 123 c d 123 123 {}
+ }
+
+ 4 "SELECT * FROM t1 RIGHT JOIN VVV ON (column1=x)" {
+ 123 123 {}
+ {} a b
+ {} c d
+ }
+
+ 5 "SELECT * FROM t1 FULL OUTER JOIN VVV ON (column1=x)" {
+ d {} {}
+ {} {} {}
+ 123 123 {}
+ {} a b
+ {} c d
+ }
+
+ 6 "SELECT count(*) FROM VVV" { 3 }
+
+ 7 "SELECT (SELECT column1 FROM VVV)" { a }
+
+ 8 "SELECT * FROM VVV UNION ALL SELECT * FROM VVV" {
+ a b c d 123 {}
+ a b c d 123 {}
+ }
+
+ 9 "SELECT * FROM VVV INTERSECT SELECT * FROM VVV" {
+ 123 {} a b c d
+ }
+
+ 10 "SELECT * FROM VVV eXCEPT SELECT * FROM VVV" { }
+
+ 11 "SELECT * FROM VVV eXCEPT SELECT 'a', 'b'" { 123 {} c d }
+
+} {
+ set q1 [string map [list VVV $VVV] $q]
+ set q2 [string map [list VVV $VVV2] $q]
+ set q3 "WITH VVV AS $VVV $q"
+
+ do_execsql_test 8.1.$tn.1 $q1 $res
+ do_execsql_test 8.1.$tn.2 $q2 $res
+ do_execsql_test 8.1.$tn.3 $q3 $res
+}
+
+#-------------------------------------------------------------------------
+reset_db
+
+do_execsql_test 9.1 {
+ VALUES(456), (123), (NULL) UNION ALL SELECT 122 ORDER BY 1
+} { {} 122 123 456 }
+
+do_execsql_test 9.2 {
+ VALUES (1, 2), (3, 4), (
+ ( SELECT column1 FROM ( VALUES (5, 6), (7, 8) ) ),
+ ( SELECT max(column2) FROM ( VALUES (5, 1), (7, 6) ) )
+ )
+} { 1 2 3 4 5 6 }
+
+do_execsql_test 10.1 {
+ CREATE TABLE a2(a, b, c DEFAULT 'xyz');
+}
+do_execsql_test 10.2 {
+ INSERT INTO a2(a) VALUES(3),(4);
+}
+
+#-------------------------------------------------------------------------
+reset_db
+ifcapable fts5 {
+ do_execsql_test 11.0 {
+ CREATE VIRTUAL TABLE ft USING fts3(x);
+ }
+ do_execsql_test 11.1 {
+ INSERT INTO ft VALUES('one'), ('two');
+ }
+}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 12.0 {
+ CREATE TABLE t1(a, b);
+}
+do_execsql_test 12.1 {
+ INSERT INTO t1 SELECT 1, 2 UNION ALL VALUES(3, 4), (5, 6);
+}
+do_execsql_test 12.2 {
+ SELECT * FROM t1
+} {1 2 3 4 5 6}
+
+#-------------------------------------------------------------------------
+reset_db
+do_execsql_test 13.0 {
+ CREATE TABLE t1(x);
+ INSERT INTO t1 VALUES('xyz');
+
+ SELECT (
+ VALUES( (max(substr('abc', 1, 1), x)) ),
+ (123),
+ (456)
+ )
+ FROM t1;
+} {xyz}
+
+do_catchsql_test 13.1 {
+ VALUES(300), (zeroblob(300) OVER win);
+} {1 {zeroblob() may not be used as a window function}}
+
+#--------------------------------------------------------------------------
+reset_db
+do_execsql_test 14.1 {
+ PRAGMA encoding = utf16;
+ CREATE TABLE t1(a, b);
+} {}
+
+db close
+sqlite3 db test.db
+
+do_execsql_test 14.2 {
+ INSERT INTO t1 VALUES
+ (17, 'craft'),
+ (16, 'urtlek' IN(1,2,3));
+}
+
+#--------------------------------------------------------------------------
+#
+reset_db
+do_eqp_test 15.1 {
+ VALUES(1),(2),(3),(4),(5);
+} {
+ QUERY PLAN
+ `--SCAN 5-ROW VALUES CLAUSE
+}
+do_execsql_test 15.2 {
+ CREATE TABLE t1(a,b);
+}
+do_eqp_test 15.3 {
+ INSERT INTO t1 VALUES
+ (1,2),(3,4),(7,8);
+} {
+ QUERY PLAN
+ `--SCAN 3-ROW VALUES CLAUSE
+}
+do_eqp_test 15.4 {
+ INSERT INTO t1 VALUES
+ (1,2),(3,4),(7,8),
+ (5,row_number()OVER());
+} {
+ QUERY PLAN
+ `--COMPOUND QUERY
+ |--LEFT-MOST SUBQUERY
+ | `--SCAN 3-ROW VALUES CLAUSE
+ `--UNION ALL
+ |--CO-ROUTINE (subquery-xxxxxx)
+ | `--SCAN CONSTANT ROW
+ `--SCAN (subquery-xxxxxx)
+}
+do_eqp_test 15.5 {
+ SELECT * FROM (VALUES(1),(2),(3),(4),(5),(6)), (VALUES('a'),('b'),('c'));
+} {
+ QUERY PLAN
+ |--SCAN 6-ROW VALUES CLAUSE
+ `--SCAN 3-ROW VALUES CLAUSE
+}
+do_execsql_test 15.6 {
+ CREATE TABLE t2(x,y);
+}
+do_eqp_test 15.7 {
+ SELECT * FROM t2 UNION ALL VALUES(1,2),(3,4),(5,6),(7,8);
+} {
+ QUERY PLAN
+ `--COMPOUND QUERY
+ |--LEFT-MOST SUBQUERY
+ | `--SCAN t2
+ `--UNION ALL
+ `--SCAN 4-ROW VALUES CLAUSE
+}
+
+#--------------------------------------------------------------------------
+# The VALUES-as-coroutine optimization can be applied to later rows of
+# a VALUES clause even if earlier rows do not qualify.
+#
+reset_db
+do_execsql_test 16.1 {
+ CREATE TABLE t1(a,b);
+}
+do_execsql_test 16.2 {
+ BEGIN;
+ INSERT INTO t1 VALUES(1,2),(3,4),(5,6),
+ (7,row_number()OVER()),
+ (9,10), (11,12), (13,14), (15,16);
+ SELECT * FROM t1 ORDER BY a, b;
+ ROLLBACK;
+} {1 2 3 4 5 6 7 1 9 10 11 12 13 14 15 16}
+do_eqp_test 16.3 {
+ INSERT INTO t1 VALUES(1,2),(3,4),(5,6),
+ (7,row_number()OVER()),
+ (9,10), (11,12), (13,14), (15,16);
+} {
+ QUERY PLAN
+ `--COMPOUND QUERY
+ |--LEFT-MOST SUBQUERY
+ | `--SCAN 3-ROW VALUES CLAUSE
+ |--UNION ALL
+ | |--CO-ROUTINE (subquery-xxxxxx)
+ | | `--SCAN CONSTANT ROW
+ | `--SCAN (subquery-xxxxxx)
+ `--UNION ALL
+ `--SCAN 4-ROW VALUES CLAUSE
+}
+do_execsql_test 16.4 {
+ BEGIN;
+ INSERT INTO t1 VALUES
+ (1,row_number()OVER()),
+ (2,3), (4,5), (6,7);
+ SELECT * FROM t1 ORDER BY a, b;
+ ROLLBACK;
+} {1 1 2 3 4 5 6 7}
+do_eqp_test 16.5 {
+ INSERT INTO t1 VALUES
+ (1,row_number()OVER()),
+ (2,3), (4,5), (6,7);
+} {
+ QUERY PLAN
+ `--COMPOUND QUERY
+ |--LEFT-MOST SUBQUERY
+ | |--CO-ROUTINE (subquery-xxxxxx)
+ | | `--SCAN CONSTANT ROW
+ | `--SCAN (subquery-xxxxxx)
+ `--UNION ALL
+ `--SCAN 3-ROW VALUES CLAUSE
+}
+do_execsql_test 16.6 {
+ BEGIN;
+ INSERT INTO t1 VALUES
+ (1,2),(3,4),
+ (5,row_number()OVER()),
+ (7,8),(9,10),(11,12),
+ (13,row_number()OVER()),
+ (15,16),(17,18),(19,20),(21,22);
+ SELECT * FROM t1 ORDER BY a, b;
+ ROLLBACK;
+} { 1 2 3 4 5 1 7 8 9 10 11 12 13 1 15 16 17 18 19 20 21 22}
+do_eqp_test 16.7 {
+ INSERT INTO t1 VALUES
+ (1,2),(3,4),
+ (5,row_number()OVER()),
+ (7,8),(9,10),(11,12),
+ (13,row_number()OVER()),
+ (15,16),(17,18),(19,20),(21,22);
+} {
+ QUERY PLAN
+ `--COMPOUND QUERY
+ |--LEFT-MOST SUBQUERY
+ | `--SCAN 2-ROW VALUES CLAUSE
+ |--UNION ALL
+ | |--CO-ROUTINE (subquery-xxxxxx)
+ | | `--SCAN CONSTANT ROW
+ | `--SCAN (subquery-xxxxxx)
+ |--UNION ALL
+ | `--SCAN 3-ROW VALUES CLAUSE
+ |--UNION ALL
+ | |--CO-ROUTINE (subquery-xxxxxx)
+ | | `--SCAN CONSTANT ROW
+ | `--SCAN (subquery-xxxxxx)
+ `--UNION ALL
+ `--SCAN 4-ROW VALUES CLAUSE
+}
+
+#--------------------------------------------------------------------------
+# 2024-03-23 dbsqlfuzz crash-c2c5e7e08b7e489d270a26d895077a03f678c33b
+#
+do_execsql_test 17.1 {
+ DROP TABLE IF EXISTS t1;
+ CREATE TABLE t1 AS SELECT * FROM (VALUES(1,2), (3,4 IN (1,2,3)));
+}
+
+do_execsql_test 17.2 {
+ SELECT * FROM t1
+} {1 2 3 0}
+
+# 2024-03-25 dbsqlfuzz crash-74cf7c9904360322a6c917e4934b127543d1cd51
+#
+do_catchsql_test 18.1 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY);
+ INSERT INTO t1 VALUES(RAISE(IGNORE)),(0);
+} {1 {RAISE() may only be used within a trigger-program}}
+do_catchsql_test 18.2 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z);
+ CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t1(y) VALUES(RAISE(IGNORE)),(0);
+ END;
+ INSERT INTO t1 VALUES(1,2,3);
+ SELECT * FROM t1;
+} {0 {1 2 3}}
+do_catchsql_test 18.3.1 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z);
+ CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t1(y) VALUES(RAISE(ABORT,'error 18.3')),(0);
+ END;
+ INSERT INTO t1 VALUES(1,2,3);
+} {1 {error 18.3}}
+do_execsql_test 18.3.2 {
+ SELECT * FROM t1;
+} {}
+do_catchsql_test 18.4.1 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z);
+ CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t1(y) VALUES(1),(RAISE(ABORT,'error 18.4')),(0);
+ END;
+ INSERT INTO t1 VALUES(1,2,3);
+} {1 {error 18.4}}
+do_execsql_test 18.4.2 {
+ SELECT * FROM t1;
+} {}
+do_catchsql_test 18.5.1 {
+ DROP TABLE t1;
+ CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z);
+ CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN
+ INSERT INTO t1(y) VALUES(1),
+ (CASE WHEN new.z>7 THEN RAISE(ABORT,'error 18.5') ELSE 2 END);
+ END;
+ INSERT INTO t1 VALUES(1,2,3);
+ SELECT * FROM t1;
+} {0 {1 2 3 2 1 {} 3 2 {}}}
+do_catchsql_test 18.5.2 {
+ DELETE FROM t1;
+ INSERT INTO t1 VALUES(1,2,13);
+} {1 {error 18.5}}
+do_catchsql_test 18.5.3 {
+ SELECT * FROM t1;
+} {0 {}}
+
+# 2024-04-18 dbsqlfuzz crash-bde3bf80aedf25afa56e2997a0545a314765d3f8
+# Verify that the VALUES expressions used as an argument to an outer
+# join work correctly.
+#
+reset_db
+db null NULL
+do_execsql_test 19.1 {
+ CREATE TABLE t1(a INT, b INT);
+ INSERT INTO t1 VALUES(11,22);
+ SELECT * FROM t1 LEFT JOIN (VALUES(33,44),(55,66)) AS t2 ON a=b;
+} {11 22 NULL NULL}
+do_execsql_test 19.2 {
+ SELECT * FROM (VALUES(33,44),(55,66)) AS t2 RIGHT JOIN t1 ON a=b;
+} {NULL NULL 11 22}
+do_execsql_test 19.3 {
+ SELECT *, '|' FROM t1 FULL JOIN (VALUES(33,44),(55,66)) AS t2 ON a=b
+ ORDER BY +column1
+} {11 22 NULL NULL | NULL NULL 33 44 | NULL NULL 55 66 |}
+do_execsql_test 19.4 {
+ SELECT *, '|' FROM (VALUES(33,44),(55,66)) AS t2 FULL JOIN t1 ON a=b
+ ORDER BY +column1
+} {NULL NULL 11 22 | 33 44 NULL NULL | 55 66 NULL NULL |}
+
+# 2024-04-21 dbsqlfuzz 6fd1ff3a64bef4a6c092e8d757548e95698b0df5
+# A continuation of the 2024-04-18 problem above. We have to create
+# Pseudo-cursor that is always NULL on the viaCoroutine loop in case
+# there are OP_Columns generated against it by the sub-WHERE clause.
+#
+db null N
+do_execsql_test 19.5 {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ DROP TABLE IF EXISTS t3;
+ CREATE TABLE t1(a,b); INSERT INTO t1 VALUES(1,2);
+ CREATE TABLE t2(column1,column2); INSERT INTO t2 VALUES(11,22),(33,44);
+ CREATE TABLE t3(d,e); INSERT INTO t3 VALUES(3,4);
+}
+do_execsql_test 19.6 {
+ -- output verify using PG 14.2
+ SELECT *
+ FROM t1 CROSS JOIN t2 FULL JOIN t3 ON a=d
+ ORDER BY +d, +column1;
+} {1 2 11 22 N N
+ 1 2 33 44 N N
+ N N N N 3 4}
+do_execsql_test 19.7 {
+ SELECT *
+ FROM t1 CROSS JOIN (VALUES(11,22),(33,44)) FULL JOIN t3 ON a=d
+ ORDER BY +d, +column1;
+} {1 2 11 22 N N
+ 1 2 33 44 N N
+ N N N N 3 4}
+do_execsql_test 19.8 {
+ -- output verified using PG 14.2
+ SELECT *
+ FROM t1 CROSS JOIN t2 FULL JOIN t3 ON a=d
+ WHERE column1 IS NULL;
+} {N N N N 3 4}
+do_execsql_test 19.9 {
+ SELECT *
+ FROM t1 CROSS JOIN (VALUES(11,22),(33,44)) FULL JOIN t3 ON a=d
+ WHERE column1 IS NULL;
+} {N N N N 3 4}
+
+finish_test
diff --git a/test/valuesfault.test b/test/valuesfault.test
new file mode 100644
index 0000000..bc5dddf
--- /dev/null
+++ b/test/valuesfault.test
@@ -0,0 +1,37 @@
+# 2024 March 3
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# This file implements regression tests for SQLite library.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix valuesfault
+source $testdir/malloc_common.tcl
+
+
+do_execsql_test 1.0 {
+ CREATE TABLE x1(a, b, c);
+}
+faultsim_save_and_close
+
+do_faultsim_test 1 -prep {
+ faultsim_restore_and_reopen
+ sqlite3_limit db SQLITE_LIMIT_COMPOUND_SELECT 2
+} -body {
+ execsql {
+ INSERT INTO x1 VALUES(1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4);
+ }
+} -test {
+ faultsim_test_result {0 {}}
+}
+
+
+finish_test
diff --git a/test/view.test b/test/view.test
index 90c9c99..2417420 100644
--- a/test/view.test
+++ b/test/view.test
@@ -801,4 +801,27 @@ ifcapable schema_pragmas {
} { 0 a INT 0 {} 0 1 b BLOB 0 {} 0 }
}
+#-----------------------------------------------------------------------
+# 2024-04-25 Trying to make type information on compound subqueries
+# more predictable and rational.
+#
+reset_db
+do_execsql_test view-31.1 {
+ CREATE TABLE x2(b TEXT);
+ CREATE TABLE x1(a TEXT);
+ INSERT INTO x1 VALUES('123');
+ -- Two queries get the same result even though the order of terms
+ -- in the CTE is reversed
+ WITH c(x) AS ( SELECT b FROM x2 UNION SELECT 123 )
+ SELECT count(*) FROM x1 WHERE a IN c;
+ WITH c(x) AS ( SELECT 123 UNION SELECT b FROM x2 )
+ SELECT count(*) FROM x1 WHERE a IN c;
+} {0 0}
+do_execsql_test view-31.2 {
+ CREATE TABLE t3(a INTEGER, b TEXT);
+ INSERT INTO t3 VALUES(123, 123);
+ WITH s AS ( VALUES(123), (456) ) SELECT * FROM t3 WHERE b IN s;
+} {123 123}
+
+
finish_test
diff --git a/test/vtabL.test b/test/vtabL.test
new file mode 100644
index 0000000..45528ed
--- /dev/null
+++ b/test/vtabL.test
@@ -0,0 +1,75 @@
+# 2024-03-26
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix vtabL
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+register_tcl_module db
+
+proc vtab_command {method args} {
+ switch -- $method {
+ xConnect {
+ return $::create_table_sql
+ }
+ }
+
+ return {}
+}
+
+foreach {tn cts} {
+ 1 {SELECT 123}
+ 2 {SELECT 123, 456}
+ 3 {INSERT INTO t1 VALUES(5, 6)}
+ 4 {CREATE INDEX i1 ON t1(a)}
+ 5 {CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END;}
+ 6 {DROP TABLE nosuchtable}
+ 7 {DROP TABLE x1}
+ 8 {DROP TABLE t1}
+} {
+ set ::create_table_sql $cts
+ do_catchsql_test 1.$tn {
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
+ } {1 {declare_vtab: syntax error}}
+}
+
+foreach {tn cts} {
+ 9 {CREATE TABLE xyz AS SELECT * FROM sqlite_schema}
+ 10 {CREATE TABLE xyz AS SELECT 1 AS 'col'}
+} {
+ set ::create_table_sql $cts
+ do_catchsql_test 1.$tn {
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
+ } {1 {declare_vtab: SQL logic error}}
+}
+
+foreach {tn cts} {
+ 1 {CREATE TABLE IF NOT EXISTS t1(a, b)}
+ 2 {CREATE TABLE ""(a, b PRIMARY KEY) WITHOUT ROWID}
+} {
+ set ::create_table_sql $cts
+ execsql { DROP TABLE IF EXISTS x1 }
+ do_execsql_test 2.$tn.1 {
+ CREATE VIRTUAL TABLE x1 USING tcl(vtab_command);
+ }
+ do_execsql_test 2.$tn.2 {
+ SELECT a, b FROM x1
+ }
+}
+
+finish_test
+
diff --git a/test/whereL.test b/test/whereL.test
index c3bdcb8..2e9ae21 100644
--- a/test/whereL.test
+++ b/test/whereL.test
@@ -49,6 +49,33 @@ do_eqp_test 120 {
|--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?)
`--SCAN t3
}
+do_eqp_test 121 {
+ SELECT * FROM t1, t2, t3
+ WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=abs(5)
+ ORDER BY t1.a;
+} {
+ QUERY PLAN
+ |--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (a=?)
+ |--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?)
+ `--SCAN t3
+}
+
+# The sqlite3ExprIsConstant() routine does not believe that
+# the expression "coalesce(5,random())" is constant. So the
+# optimization does not apply in this case.
+#
+sqlite3_create_function db
+do_eqp_test 122 {
+ SELECT * FROM t1, t2, t3
+ WHERE t1.a=t2.a AND t2.a=t3.j AND t3.j=coalesce(5,random())
+ ORDER BY t1.a;
+} {
+ QUERY PLAN
+ |--SCAN t3
+ |--SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (a=?)
+ |--SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (a=?)
+ `--USE TEMP B-TREE FOR ORDER BY
+}
# Constant propagation in the face of collating sequences:
#
@@ -209,4 +236,22 @@ do_eqp_test 710 {
`--SEARCH t1 USING INDEX idx (<expr>=?)
}
+# 2024-03-07 https://sqlite.org/forum/forumpost/ecdfc02339
+# A refinement is needed to the enhancements tested by the prior test case
+# to avoid another problem with indexes on constant expressions.
+#
+reset_db
+db null NULL
+do_execsql_test 800 {
+ CREATE TABLE t0(c0, c1);
+ CREATE TABLE t1(c2);
+ CREATE INDEX i0 ON t1(NULL);
+ INSERT INTO t1(c2) VALUES (0.2);
+ CREATE VIEW v0(c3) AS SELECT DISTINCT c2 FROM t1;
+ SELECT * FROM v0 LEFT JOIN t0 ON c3<NULL LEFT JOIN t1 ON 1;
+} {0.2 NULL NULL 0.2}
+do_execsql_test 810 {
+ SELECT * FROM v0 LEFT JOIN t0 ON c3<NULL LEFT JOIN t1 ON 1 WHERE c2/0.1;
+} {0.2 NULL NULL 0.2}
+
finish_test
diff --git a/test/whereN.test b/test/whereN.test
new file mode 100644
index 0000000..b9b889f
--- /dev/null
+++ b/test/whereN.test
@@ -0,0 +1,103 @@
+# 2024-04-02
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#***********************************************************************
+# Tests for the whereInterstageHeuristic() routine in the query planner.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+set testprefix whereN
+
+# The following is a simplified and "sanitized" version of the original
+# real-world query that brought the problem to light.
+#
+# The issue is a slow query. The answer is correct, but it was taking too
+# much time, because it was doing a full table scan rather than an indexed
+# lookup.
+#
+# The problem was that the query planner was overestimating the number of
+# output rows. The estimated number of output rows is accurate if the
+# DSNAME parameter is "ds-one". In that case, a large fraction of the rows
+# in "violation" end up being output. The query planner correctly deduces
+# that it is faster to do a full table scan of the large "violation" table
+# to avoid the after-query sort that implements the ORDER BY clause. However,
+# if the DSNAME is "ds-two", then only a few rows (about 6) are generated,
+# and it is much much faster to do an indexed lookup of "violation" followed
+# by a sort operation to implement ORDER BY
+#
+# The problem, of course, is that the query planner has no way of knowing
+# in advance how many rows will be generated. The query planner tries to
+# estimate a worst case, which is a large number of output rows, and it picks
+# the best plan for that case. However, the plan choosen is very inefficient
+# when the number of output rows is small.
+#
+# The whereInterstageHeuristic() routine in the query planner attempts to
+# correct this by adjusting the query plan such that it avoids the very bad
+# query plan for a small number of rows, at the expense of a slightly less
+# efficient plan for a large number of rows. The large number of rows case
+# is perhaps 5% slower with the revised plan, but the small number of
+# rows case is around 100 times faster. That seems like a good tradeoff.
+#
+do_execsql_test 1.0 {
+ CREATE TABLE datasource(dsid INT, name TEXT);
+ INSERT INTO datasource VALUES(1,'ds-one'),(2,'ds-two'),(3,'ds-three');
+ CREATE INDEX ds1 ON datasource(name, dsid);
+
+ CREATE TABLE rule(rid INT, team_id INT, dsid INT);
+ WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<9)
+ INSERT INTO rule(rid,team_id,dsid) SELECT n, 1, 1 FROM c;
+ WITH RECURSIVE c(n) AS (VALUES(10) UNION ALL SELECT n+1 FROM c WHERE n<24)
+ INSERT INTO rule(rid,team_id,dsid) SELECT n, 2, 2 FROM c;
+ CREATE INDEX rule2 ON rule(dsid, rid);
+
+ CREATE TABLE violation(vid INT, rid INT, vx BLOB);
+ /*** Uncomment to insert actual data
+ WITH src(rid, cnt) AS (VALUES(1,3586),(2,1343),(3,6505),(5,76230),
+ (6,740),(7,287794),(8,457),(12,1),
+ (14,1),(16,1),(17,1),(18,1),(19,1))
+ INSERT INTO violation(vid, rid, vx)
+ SELECT rid*1000000+value, rid, randomblob(15)
+ FROM src, generate_series(1,cnt);
+ ***/
+ CREATE INDEX v1 ON violation(rid, vid);
+ CREATE INDEX v2 ON violation(vid);
+ ANALYZE;
+ DELETE FROM sqlite_stat1;
+ DROP TABLE IF EXISTS sqlite_stat4;
+ INSERT INTO sqlite_stat1 VALUES
+ ('violation','v2','376661 1'),
+ ('violation','v1','376661 28974 1'),
+ ('rule','rule2','24 12 1'),
+ ('datasource','ds1','3 1 1');
+ ANALYZE sqlite_schema;
+}
+set DSNAME ds-two ;# Only a few rows. Change to "ds-one" for many rows.
+do_eqp_test 1.1 {
+ SELECT count(*), length(group_concat(vx)) FROM (
+ SELECT V.*
+ FROM datasource DS, rule R, violation V
+ WHERE V.rid=R.rid
+ AND R.dsid=DS.dsid
+ AND DS.name=$DSNAME
+ ORDER BY V.vid desc
+ );
+} {
+ QUERY PLAN
+ |--CO-ROUTINE (subquery-xxxxxx)
+ | |--SEARCH DS USING COVERING INDEX ds1 (name=?)
+ | |--SEARCH R USING COVERING INDEX rule2 (dsid=?)
+ | |--SEARCH V USING INDEX v1 (rid=?)
+ | `--USE TEMP B-TREE FOR ORDER BY
+ `--SCAN (subquery-xxxxxx)
+}
+# ^^^^---- We want to see three SEARCH terms. No SCAN terms.
+# The ORDER BY is implemented by a separate sorter pass.
+
+finish_test