aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/auth.test13
-rw-r--r--test/bestindexA.test138
-rw-r--r--test/hook.test1
-rw-r--r--test/interrupt.test18
-rw-r--r--test/intreal.test18
-rw-r--r--test/pragma.test53
-rw-r--r--test/symlink.test28
-rw-r--r--test/trustschema1.test11
-rw-r--r--test/view.test8
-rw-r--r--test/zipfile.test10
10 files changed, 291 insertions, 7 deletions
diff --git a/test/auth.test b/test/auth.test
index d8afa2dbf..7df9ad373 100644
--- a/test/auth.test
+++ b/test/auth.test
@@ -2246,6 +2246,19 @@ ifcapable altertable&&vtab {
} {main t1 {} {}}
}
+# 2022-12-28
+# The sqlite3_declare_vtab() call that occurs during pragma_table_list
+# should not cause an authentication failure.
+#
+do_test auth-1.359 {
+ proc auth {code arg1 arg2 arg3 arg4 args} {
+ if {$code=="SQLITE_UPDATE"} {
+ return SQLITE_DENY
+ }
+ return SQLITE_OK
+ }
+ catchsql {SELECT * FROM pragma_table_list WHERE name='xyzzy';}
+} {0 {}}
do_test auth-2.1 {
proc auth {code arg1 arg2 arg3 arg4 args} {
diff --git a/test/bestindexA.test b/test/bestindexA.test
new file mode 100644
index 000000000..650404eaa
--- /dev/null
+++ b/test/bestindexA.test
@@ -0,0 +1,138 @@
+# 2020-01-29
+#
+# 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 bestindexA
+
+ifcapable !vtab {
+ finish_test
+ return
+}
+
+
+proc vtab_command {method args} {
+ switch -- $method {
+ xConnect {
+ return "CREATE TABLE x(a, b, c)"
+ }
+
+ xBestIndex {
+ set hdl [lindex $args 0]
+ set clist [$hdl constraints]
+ foreach c $clist {
+ array set C $c
+ lappend ::vtab_constraints [list $C(op) $C(column)]
+ }
+ return [list]
+ }
+
+ xFilter {
+ return ""
+ }
+
+ xFindFunction {
+ foreach {nArg name} $args {}
+ if {$nArg==2 && $name=="even"} {
+ return 152
+ }
+ return 0
+ }
+
+ }
+
+ return {}
+}
+
+register_tcl_module db
+do_execsql_test 1.0 {
+ CREATE VIRTUAL TABLE t1 USING tcl(vtab_command);
+}
+
+proc do_xbestindex_test {tn sql res} {
+ set script [subst {
+ execsql "$sql"
+ set ::vtab_constraints
+ }]
+
+ uplevel [list do_test $tn $script [list {*}$res]]
+ set ::vtab_constraints [list]
+}
+
+do_xbestindex_test 1.1 {
+ SELECT * FROM t1 WHERE a=?
+} {
+ {eq 0}
+}
+
+do_xbestindex_test 1.2 {
+ SELECT * FROM t1 WHERE a=? LIMIT 10
+} {
+ {eq 0}
+ {limit 0}
+}
+
+do_xbestindex_test 1.3 {
+ SELECT * FROM t1 WHERE a=? AND (b+1)=? LIMIT 10
+} {
+ {eq 0}
+}
+
+proc error_function {args} { error "not a function!" }
+db function even error_function
+
+do_xbestindex_test 1.4 {
+ SELECT * FROM t1 WHERE even(a, ?)
+} {
+ {152 0}
+}
+
+do_xbestindex_test 1.5 {
+ SELECT * FROM t1 WHERE b=10 AND even(a, ?)
+} {
+ {eq 1}
+ {152 0}
+}
+
+do_xbestindex_test 1.6 {
+ SELECT * FROM t1 WHERE b=10 LIMIT 10
+} {
+ {eq 1}
+ {limit 0}
+}
+
+do_xbestindex_test 1.7 {
+ SELECT * FROM t1 WHERE even(b,?) LIMIT 10
+} {
+ {152 1}
+ {limit 0}
+}
+
+do_xbestindex_test 1.8 {
+ SELECT * FROM t1 WHERE b!=? LIMIT 10
+} {
+ {ne 1}
+ {limit 0}
+}
+
+do_xbestindex_test 1.9 {
+ SELECT * FROM t1 WHERE ?=a LIMIT 10
+} {
+ {eq 0}
+ {limit 0}
+}
+
+
+finish_test
+
+
+
diff --git a/test/hook.test b/test/hook.test
index bb868df8b..3d735875d 100644
--- a/test/hook.test
+++ b/test/hook.test
@@ -16,6 +16,7 @@
# sqlite_commit_hook (tests hook-1..hook-3 inclusive)
# sqlite_update_hook (tests hook-4-*)
# sqlite_rollback_hook (tests hook-5.*)
+# sqlite_preupdate_hook (tests hook-7..hook-12)
#
# $Id: hook.test,v 1.15 2009/04/07 14:14:23 danielk1977 Exp $
diff --git a/test/interrupt.test b/test/interrupt.test
index 8774aee86..23d986987 100644
--- a/test/interrupt.test
+++ b/test/interrupt.test
@@ -94,14 +94,28 @@ ifcapable {vacuum && !default_autovacuum} {
} 1
}
ifcapable {explain} {
- do_test interrupt-2.5 {
+ do_test interrupt-2.5.1 {
+ sqlite3_is_interrupted $DB
+ } {0}
+ do_test interrupt-2.5.2 {
+ unset -nocomplain ::interrupt_count
+ set ::interrupt_count 0
set sql {EXPLAIN SELECT max(a,b), a, b FROM t1}
execsql $sql
- set rc [catch {db eval $sql {sqlite3_interrupt $DB}} msg]
+ set rc [catch {db eval $sql {
+ sqlite3_interrupt $DB;
+ incr ::interrupt_count [sqlite3_is_interrupted $DB];
+ }} msg]
lappend rc $msg
} {1 interrupted}
+ do_test interrupt-2.5.3 {
+ set ::interrupt_count
+ } {1}
}
integrity_check interrupt-2.6
+do_test interrupt-2.7 {
+ sqlite3_is_interrupted $DB
+} {0}
# Ticket #594. If an interrupt occurs in the middle of a transaction
# and that transaction is later rolled back, the internal schema tables do
diff --git a/test/intreal.test b/test/intreal.test
index 1a3db0a23..d9ffe9909 100644
--- a/test/intreal.test
+++ b/test/intreal.test
@@ -95,4 +95,22 @@ do_execsql_test 3.0 {
PRAGMA integrity_check;
} {a {} ok}
+
+reset_db
+do_execsql_test 4.0 {
+ CREATE TABLE t1(a REAL, b AS ('expr') );
+}
+do_execsql_test 4.1 {
+ INSERT INTO t1 VALUES( REPLACE(0, '', 'expr') );
+}
+do_execsql_test 4.2 {
+ INSERT INTO t1 SELECT REPLACE(4, '', 'expr');
+}
+do_execsql_test 4.3 {
+ SELECT typeof(a), a FROM t1;
+} {
+ real 0.0
+ real 4.0
+}
+
finish_test
diff --git a/test/pragma.test b/test/pragma.test
index 4fc97648b..32e8fbef6 100644
--- a/test/pragma.test
+++ b/test/pragma.test
@@ -582,6 +582,59 @@ do_test pragma-3.30 {
}
} {}
+# The values stored in indexes must be byte-for-byte identical to the
+# values stored in tables.
+#
+reset_db
+do_execsql_test pragma-3.40 {
+ CREATE TABLE t1(
+ a INTEGER PRIMARY KEY,
+ b TEXT COLLATE nocase,
+ c INT COLLATE nocase,
+ d TEXT
+ );
+ INSERT INTO t1(a,b,c,d) VALUES
+ (1, 'one','one','one'),
+ (2, 'two','two','two'),
+ (3, 'three','three','three'),
+ (4, 'four','four','four'),
+ (5, 'five','five','five');
+ CREATE INDEX t1bcd ON t1(b,c,d);
+ CREATE TABLE t2(
+ a INTEGER PRIMARY KEY,
+ b TEXT COLLATE nocase,
+ c INT COLLATE nocase,
+ d TEXT
+ );
+ INSERT INTO t2(a,b,c,d) VALUES
+ (1, 'one','one','one'),
+ (2, 'two','two','TWO'),
+ (3, 'three','THREE','three'),
+ (4, 'FOUR','four','four'),
+ (5, 'FIVE','FIVE','five');
+ CREATE INDEX t2bcd ON t2(b,c,d);
+ CREATE TEMP TABLE saved_schema AS SELECT name, rootpage FROM sqlite_schema;
+ PRAGMA writable_schema=ON;
+ UPDATE sqlite_schema
+ SET rootpage=(SELECT rootpage FROM saved_schema WHERE name='t2bcd')
+ WHERE name='t1bcd';
+ UPDATE sqlite_schema
+ SET rootpage=(SELECT rootpage FROM saved_schema WHERE name='t1bcd')
+ WHERE name='t2bcd';
+ PRAGMA Writable_schema=RESET;
+ SELECT integrity_check AS x FROM pragma_integrity_check ORDER BY 1;
+} {
+ {row 2 missing from index t1bcd}
+ {row 2 missing from index t2bcd}
+ {row 3 values differ from index t1bcd}
+ {row 3 values differ from index t2bcd}
+ {row 4 values differ from index t1bcd}
+ {row 4 values differ from index t2bcd}
+ {row 5 values differ from index t1bcd}
+ {row 5 values differ from index t2bcd}
+}
+db eval {DROP TABLE t2}
+
# Test modifying the cache_size of an attached database.
ifcapable pager_pragmas&&attach {
do_test pragma-4.1 {
diff --git a/test/symlink.test b/test/symlink.test
index 98b2a32c0..685cae5a4 100644
--- a/test/symlink.test
+++ b/test/symlink.test
@@ -207,4 +207,32 @@ do_test 4.4.2 {
list [file exists x/test.db-wal] [file exists w/test.db-wal]
} {1 0}
+#-------------------------------------------------------------------------
+# Check that extra ".." in a path are ignored.
+reset_db
+do_execsql_test 5.0 {
+ CREATE TABLE xyz(x, y, z);
+ INSERT INTO xyz VALUES(1, 2, 3);
+}
+
+set path [pwd]
+set nLink [llength [split $path /]]
+set path "[string repeat ../ [expr $nLink*2]]..${path}/test.db"
+
+sqlite3 db2 $path
+do_execsql_test -db db2 5.1 {
+ SELECT * FROM xyz;
+} {1 2 3}
+db close
+
+forcedelete test.db2
+file link test.db2 $path
+sqlite3 db2 test.db2
+do_execsql_test -db db2 5.2 {
+ SELECT * FROM xyz;
+} {1 2 3}
+forcedelete test.db2
+
+
+
finish_test
diff --git a/test/trustschema1.test b/test/trustschema1.test
index dba954f14..8edaf8051 100644
--- a/test/trustschema1.test
+++ b/test/trustschema1.test
@@ -247,5 +247,16 @@ do_execsql_test 3.131 {
SELECT * FROM t2;
} {}
+# 2023-01-09 https://sqlite.org/forum/forumpost/c88a671ad083d153
+#
+do_execsql_test 4.1 {
+ PRAGMA trusted_schema=OFF;
+ CREATE VIEW test41(x) AS SELECT json_extract('{"a":123}','$.a');
+ SELECT * FROM test41;
+} 123
+do_execsql_test 4.2 {
+ PRAGMA trusted_schema=ON;
+ SELECT * FROM test41;
+} 123
finish_test
diff --git a/test/view.test b/test/view.test
index 60eb7e527..90c9c9909 100644
--- a/test/view.test
+++ b/test/view.test
@@ -123,16 +123,16 @@ do_execsql_test view-1.10 {
} {}
do_execsql_test view-1.11 {
PRAGMA table_info(v9a);
-} {0 x INT 0 {} 0}
+} {0 x INTEGER 0 {} 0}
do_execsql_test view-1.12 {
PRAGMA table_info(v9b);
-} {0 x INT 0 {} 0}
+} {0 x INTEGER 0 {} 0}
do_execsql_test view-1.13 {
PRAGMA table_info(v9c);
-} {0 x INT 0 {} 0}
+} {0 x INTEGER 0 {} 0}
do_execsql_test view-1.14 {
PRAGMA table_info(v9d);
-} {0 x INT 0 {} 0}
+} {0 x INTEGER 0 {} 0}
do_test view-2.1 {
execsql {
diff --git a/test/zipfile.test b/test/zipfile.test
index 8749f17c3..8b862ae84 100644
--- a/test/zipfile.test
+++ b/test/zipfile.test
@@ -853,6 +853,14 @@ do_execsql_test 17.1 {
)
SELECT DISTINCT typeof(zipfile(0,0,x,0)) FROM vlist;
} {blob}
-
+
+# 2023-01-04
+# https://sqlite.org/forum/forumpost/d1c96a9032e564f8
+# Call to fopen() with a NULL filename.
+#
+do_catchsql_test 18.1 {
+ SELECT * FROM zipfile(NULL);
+} {1 {cannot open file: }}
+
finish_test