diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/8_3_names.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/8_3_names.test new file mode 100644 index 0000000000000000000000000000000000000000..1d63f5dcc96ceeccdcd7d1fa4fbdd6f75eee9268 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/8_3_names.test @@ -0,0 +1,197 @@ +# 2011 May 17 +# +# 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. +# +#*********************************************************************** +# +# Test cases for the SQLITE_ENABLE_8_3_NAMES feature that forces all +# filename extensions to be limited to 3 characters. Some embedded +# systems need this to work around microsoft FAT patents, but this +# feature should be disabled on most deployments. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !8_3_names { + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 + +do_test 8_3_names-1.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db test.db + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 1 +do_test 8_3_names-1.1 { + file exists test.nal +} 0 +do_test 8_3_names-1.2 { + db eval { + ROLLBACK; + SELECT length(x) FROM t1 + } +} 20000 + +db close +do_test 8_3_names-2.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db file:./test.db?8_3_names=1 + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 0 +do_test 8_3_names-2.1 { + file exists test.nal +} 1 +forcedelete test2.db test2.nal test2.db-journal +copy_file test.db test2.db +copy_file test.nal test2.nal +do_test 8_3_names-2.2 { + db eval { + COMMIT; + SELECT length(x) FROM t1 + } +} 15000 +do_test 8_3_names-2.3 { + sqlite3 db2 file:./test2.db?8_3_names=1 + db2 eval { + PRAGMA integrity_check; + SELECT length(x) FROM t1; + } +} {ok 20000} + +db close +do_test 8_3_names-3.0 { + forcedelete test.db test.nal test.db-journal + sqlite3 db file:./test.db?8_3_names=0 + db eval { + PRAGMA cache_size=10; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(20000)); + BEGIN; + DELETE FROM t1; + INSERT INTO t1 VALUES(randomblob(15000)); + } + file exists test.db-journal +} 1 +do_test 8_3_names-3.1 { + file exists test.nal +} 0 +forcedelete test2.db test2.nal test2.db-journal +copy_file test.db test2.db +copy_file test.db-journal test2.db-journal +do_test 8_3_names-3.2 { + db eval { + COMMIT; + SELECT length(x) FROM t1 + } +} 15000 +do_test 8_3_names-3.3 { + sqlite3 db2 file:./test2.db?8_3_names=0 + db2 eval { + PRAGMA integrity_check; + SELECT length(x) FROM t1; + } +} {ok 20000} + +########################################################################## +# Master journals. +# +db close +forcedelete test.db test2.db +do_test 8_3_names-4.0 { + sqlite3 db file:./test.db?8_3_names=1 + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + ATTACH 'file:./test2.db?8_3_names=1' AS db2; + CREATE TABLE db2.t2(y); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t1 VALUES(3); + INSERT INTO t2 VALUES(4); + COMMIT; + SELECT * FROM t1, t2 ORDER BY x, y + } +} {1 2 1 4 3 2 3 4} + + +########################################################################## +# WAL mode. +# +ifcapable !wal { + finish_test + return +} +db close +forcedelete test.db +do_test 8_3_names-5.0 { + sqlite3 db file:./test.db?8_3_names=1 + load_static_extension db wholenumber + db eval { + PRAGMA journal_mode=WAL; + CREATE TABLE t1(x); + CREATE VIRTUAL TABLE nums USING wholenumber; + INSERT INTO t1 SELECT value FROM nums WHERE value BETWEEN 1 AND 1000; + BEGIN; + UPDATE t1 SET x=x*2; + } + sqlite3 db2 file:./test.db?8_3_names=1 + load_static_extension db2 wholenumber + db2 eval { + BEGIN; + SELECT sum(x) FROM t1; + } +} {500500} + +do_test 8_3_names-5.1 { + file exists test.db-wal +} 0 +do_test 8_3_names-5.2 { + file exists test.wal +} 1 +do_test 8_3_names-5.3 { + file exists test.db-shm +} 0 +do_test 8_3_names-5.4 { + file exists test.shm +} 1 + + +do_test 8_3_names-5.5 { + db eval { + COMMIT; + SELECT sum(x) FROM t1; + } +} {1001000} +do_test 8_3_names-5.6 { + db2 eval { + SELECT sum(x) FROM t1; + } +} {500500} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity2.test new file mode 100644 index 0000000000000000000000000000000000000000..6ad257ac36df6dbf2dd2842bd2196ef65769e5c2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity2.test @@ -0,0 +1,136 @@ +# 2015-06-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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is type affinity in comparison operations. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix affinity2 + +do_execsql_test affinity2-100 { + CREATE TABLE t1( + xi INTEGER, + xr REAL, + xb BLOB, + xn NUMERIC, + xt TEXT + ); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(1,1,1,1,1,1); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(2,'2','2','2','2','2'); + INSERT INTO t1(rowid,xi,xr,xb,xn,xt) VALUES(3,'03','03','03','03','03'); + +} {} +do_execsql_test affinity2-110 { + SELECT xi, typeof(xi) FROM t1 ORDER BY rowid; +} {1 integer 2 integer 3 integer} +do_execsql_test affinity2-120 { + SELECT xr, typeof(xr) FROM t1 ORDER BY rowid; +} {1.0 real 2.0 real 3.0 real} +do_execsql_test affinity2-130 { + SELECT xb, typeof(xb) FROM t1 ORDER BY rowid; +} {1 integer 2 text 03 text} +do_execsql_test affinity2-140 { + SELECT xn, typeof(xn) FROM t1 ORDER BY rowid; +} {1 integer 2 integer 3 integer} +do_execsql_test affinity2-150 { + SELECT xt, typeof(xt) FROM t1 ORDER BY rowid; +} {1 text 2 text 03 text} + +do_execsql_test affinity2-200 { + SELECT rowid, xi==xt, xi==xb, xi==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} +do_execsql_test affinity2-210 { + SELECT rowid, xr==xt, xr==xb, xr==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} +do_execsql_test affinity2-220 { + SELECT rowid, xn==xt, xn==xb, xn==+xt FROM t1 ORDER BY rowid; +} {1 1 1 1 2 1 1 1 3 1 1 1} + +do_execsql_test affinity2-300 { + SELECT rowid, xt==+xi, xt==xi, xt==xb FROM t1 ORDER BY rowid; +} {1 1 1 0 2 1 1 1 3 0 1 1} + +#------------------------------------------------------------------------- +do_execsql_test 400 { + CREATE TABLE ttt(c0, c1); + CREATE INDEX ii ON ttt(CAST(c0 AS NUMERIC)); + INSERT INTO ttt VALUES('abc', '-1'); +} +do_execsql_test 410 { + SELECT * FROM ttt WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; +} {abc -1} +do_execsql_test 420 { + SELECT * FROM ttt INDEXED BY ii WHERE CAST(c0 AS NUMERIC) > c1 GROUP BY rowid; +} {abc -1} + +do_execsql_test 430 { + CREATE TABLE t3(a, b, c INTEGER); + CREATE INDEX t3ac ON t3(a, c-1); + INSERT INTO t3 VALUES(1, 1, 1); + INSERT INTO t3 VALUES(2, 1, 0); + INSERT INTO t3 VALUES(3, 1, 1); + INSERT INTO t3 VALUES(4, 1, 0); + INSERT INTO t3 VALUES(5, 1, 1); +} +do_execsql_test 440 { + SELECT * FROM t3 WHERE c='0' ORDER BY a; +} {2 1 0 4 1 0} + +# 2019-08-22 ticket https://sqlite.org/src/info/d99f1ffe836c591ac57f +# False positive in sqlite3ExprNeedsNoAffinityChange() +# +do_execsql_test 500 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 TEXT UNIQUE, c1); + INSERT INTO t0(c0) VALUES (-1); + SELECT quote(- x'ce'), quote(t0.c0), quote(- x'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 501 { + SELECT * FROM t0 WHERE - x'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 502 { + SELECT quote(+-+x'ce'), quote(t0.c0), quote(+-+x'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 503 { + SELECT * FROM t0 WHERE +-+x'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 504 { + SELECT quote(- 'ce'), quote(t0.c0), quote(- 'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 505 { + SELECT * FROM t0 WHERE - 'ce' >= t0.c0; +} {-1 {}} +do_execsql_test 506 { + SELECT quote(+-+'ce'), quote(t0.c0), quote(+-+'ce' >= t0.c0) FROM t0; +} {0 '-1' 1} +do_execsql_test 507 { + SELECT * FROM t0 WHERE +-+'ce' >= t0.c0; +} {-1 {}} + +# 2019-08-30 ticket https://www.sqlite.org/src/info/40812aea1fde9594 +# +# Due to some differences in floating point computations, these tests do not +# work under valgrind. +# +if {![info exists ::G(valgrind)]} { + do_execsql_test 600 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 REAL UNIQUE); + INSERT INTO t0(c0) VALUES (3175546974276630385); + SELECT 3175546974276630385 < c0 FROM t0; + } {1} + do_execsql_test 601 { + SELECT 1 FROM t0 WHERE 3175546974276630385 < c0; + } {1} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity3.test new file mode 100644 index 0000000000000000000000000000000000000000..3695ea84798a5d15a1d243d817cca09e89ed6082 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/affinity3.test @@ -0,0 +1,123 @@ +# 2017-01-16 +# +# 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. +# +#*********************************************************************** +# +# Test cases for bugs: +# +# https://www.sqlite.org/src/info/91e2e8ba6ff2e2 +# https://www.sqlite.org/src/info/7ffd1ca1d2ad4ecf +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Ticket https://www.sqlite.org/src/info/91e2e8ba6ff2e2 (2011-09-19) +# Automatic index causes undesired type conversions +# +do_execsql_test affinity3-100 { + CREATE TABLE customer (id INT PRIMARY KEY); + CREATE TABLE apr (id INT PRIMARY KEY, apr REAL); + + CREATE VIEW v1 AS + SELECT c.id, i.apr + FROM customer c + LEFT JOIN apr i ON i.id=c.id; + + CREATE VIEW v1rj AS + SELECT c.id, i.apr + FROM apr i + RIGHT JOIN customer c ON i.id=c.id; + + CREATE VIEW v2 AS + SELECT c.id, v1.apr + FROM customer c + LEFT JOIN v1 ON v1.id=c.id; + + CREATE VIEW v2rj AS + SELECT c.id, v1.apr + FROM v1 RIGHT JOIN customer c ON v1.id=c.id; + + CREATE VIEW v2rjrj AS + SELECT c.id, v1rj.apr + FROM v1rj RIGHT JOIN customer c ON v1rj.id=c.id; + + INSERT INTO customer (id) VALUES (1); + INSERT INTO apr (id, apr) VALUES (1, 12); + INSERT INTO customer (id) VALUES (2); + INSERT INTO apr (id, apr) VALUES (2, 12.01); +} +do_execsql_test affinity3-110 { + PRAGMA automatic_index=ON; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-111 { + PRAGMA automatic_index=ON; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-120 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-121 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-122 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rjrj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-130 { + PRAGMA automatic_index=OFF; + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-131 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v1rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-140 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-141 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rj; +} {1 0.12 real 2 0.1201 real} +do_execsql_test affinity3-142 { + SELECT id, (apr / 100), typeof(apr) apr_type FROM v2rjrj; +} {1 0.12 real 2 0.1201 real} + +# Ticket https://www.sqlite.org/src/info/7ffd1ca1d2ad4ecf (2017-01-16) +# Incorrect affinity when using automatic indexes +# +do_execsql_test affinity3-200 { + CREATE TABLE map_integer (id INT, name); + INSERT INTO map_integer VALUES(1,'a'); + CREATE TABLE map_text (id TEXT, name); + INSERT INTO map_text VALUES('4','e'); + CREATE TABLE data (id TEXT, name); + INSERT INTO data VALUES(1,'abc'); + INSERT INTO data VALUES('4','xyz'); + CREATE VIEW idmap as + SELECT * FROM map_integer + UNION SELECT * FROM map_text; + CREATE TABLE mzed AS SELECT * FROM idmap; +} + +do_execsql_test affinity3-210 { + PRAGMA automatic_index=ON; + SELECT * FROM data JOIN idmap USING(id); +} {4 xyz e} +do_execsql_test affinity3-220 { + SELECT * FROM data JOIN mzed USING(id); +} {4 xyz e} + +do_execsql_test affinity3-250 { + PRAGMA automatic_index=OFF; + SELECT * FROM data JOIN idmap USING(id); +} {4 xyz e} +do_execsql_test affinity3-260 { + SELECT * FROM data JOIN mzed USING(id); +} {4 xyz e} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/aggfault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggfault.test new file mode 100644 index 0000000000000000000000000000000000000000..7c16b039cee645b8656e3432ec37fb8a2baf10ca --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggfault.test @@ -0,0 +1,43 @@ +# 2023 March 30 +# +# 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 aggfault + + +do_execsql_test 1 { + CREATE TABLE t1(x); + CREATE INDEX t1x ON t1(x, x=0); +} +faultsim_save_and_close + +do_faultsim_test 2 -faults oom* -prep { + faultsim_restore_and_reopen + execsql { SELECT * FROM sqlite_schema } +} -body { + execsql { + SELECT * FROM t1 AS a1 WHERE ( + SELECT count(x AND 0=a1.x) FROM t1 GROUP BY abs(1) + ) AND x=( + SELECT * FROM t1 AS a1 + WHERE (SELECT count(x IS 1 AND a1.x=0) + FROM t1 + GROUP BY abs(1)) AND x=0 + ); + } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/aggnested.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggnested.test new file mode 100644 index 0000000000000000000000000000000000000000..f3539076bddccfbba70304934d8b0e751ba31423 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggnested.test @@ -0,0 +1,487 @@ +# 2012-08-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. +# +# This file implements tests for processing aggregate queries with +# subqueries in which the subqueries hold the aggregate functions +# or in which the subqueries are themselves aggregate queries +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix aggnested + +do_test aggnested-1.1 { + db eval { + CREATE TABLE t1(a1 INTEGER); + INSERT INTO t1 VALUES(1), (2), (3); + CREATE TABLE t2(b1 INTEGER); + INSERT INTO t2 VALUES(4), (5); + SELECT (SELECT string_agg(a1,'x') FROM t2) FROM t1; + } +} {1x2x3} +do_test aggnested-1.2 { + db eval { + SELECT + (SELECT string_agg(a1,'x') || '-' || string_agg(b1,'y') FROM t2) + FROM t1; + } +} {1x2x3-4y5} +do_test aggnested-1.3 { + db eval { + SELECT (SELECT string_agg(b1,a1) FROM t2) FROM t1; + } +} {415 425 435} +do_test aggnested-1.4 { + db eval { + SELECT (SELECT group_concat(a1,b1) FROM t2) FROM t1; + } +} {151 252 353} + + +# This test case is a copy of the one in +# http://www.mail-archive.com/sqlite-users@sqlite.org/msg70787.html +# +do_test aggnested-2.0 { + sqlite3 db2 :memory: + db2 eval { + CREATE TABLE t1 (A1 INTEGER NOT NULL,A2 INTEGER NOT NULL,A3 INTEGER NOT + NULL,A4 INTEGER NOT NULL,PRIMARY KEY(A1)); + REPLACE INTO t1 VALUES(1,11,111,1111); + REPLACE INTO t1 VALUES(2,22,222,2222); + REPLACE INTO t1 VALUES(3,33,333,3333); + CREATE TABLE t2 (B1 INTEGER NOT NULL,B2 INTEGER NOT NULL,B3 INTEGER NOT + NULL,B4 INTEGER NOT NULL,PRIMARY KEY(B1)); + REPLACE INTO t2 VALUES(1,88,888,8888); + REPLACE INTO t2 VALUES(2,99,999,9999); + SELECT (SELECT GROUP_CONCAT(CASE WHEN a1=1 THEN'A' ELSE 'B' END) FROM t2), + t1.* + FROM t1; + } +} {A,B,B 1 11 111 1111} +db2 close + +##################### Test cases for ticket [bfbf38e5e9956ac69f] ############ +# +# This first test case is the original problem report: +do_test aggnested-3.0 { + db eval { + CREATE TABLE AAA ( + aaa_id INTEGER PRIMARY KEY AUTOINCREMENT + ); + CREATE TABLE RRR ( + rrr_id INTEGER PRIMARY KEY AUTOINCREMENT, + rrr_date INTEGER NOT NULL, + rrr_aaa INTEGER + ); + CREATE TABLE TTT ( + ttt_id INTEGER PRIMARY KEY AUTOINCREMENT, + target_aaa INTEGER NOT NULL, + source_aaa INTEGER NOT NULL + ); + insert into AAA (aaa_id) values (2); + insert into TTT (ttt_id, target_aaa, source_aaa) + values (4469, 2, 2); + insert into TTT (ttt_id, target_aaa, source_aaa) + values (4476, 2, 1); + insert into RRR (rrr_id, rrr_date, rrr_aaa) + values (0, 0, NULL); + insert into RRR (rrr_id, rrr_date, rrr_aaa) + values (2, 4312, 2); + SELECT i.aaa_id, + (SELECT sum(CASE WHEN (t.source_aaa == i.aaa_id) THEN 1 ELSE 0 END) + FROM TTT t + ) AS segfault + FROM + (SELECT curr.rrr_aaa as aaa_id + FROM RRR curr + -- you also can comment out the next line + -- it causes segfault to happen after one row is outputted + INNER JOIN AAA a ON (curr.rrr_aaa = aaa_id) + LEFT JOIN RRR r ON (r.rrr_id <> 0 AND r.rrr_date < curr.rrr_date) + GROUP BY curr.rrr_id + HAVING r.rrr_date IS NULL + ) i; + } +} {2 1} + +# Further variants of the test case, as found in the ticket +# +do_test aggnested-3.1 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1 ( + id1 INTEGER PRIMARY KEY AUTOINCREMENT, + value1 INTEGER + ); + INSERT INTO t1 VALUES(4469,2),(4476,1); + CREATE TABLE t2 ( + id2 INTEGER PRIMARY KEY AUTOINCREMENT, + value2 INTEGER + ); + INSERT INTO t2 VALUES(0,1),(2,2); + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT curr.value1 as xyz + FROM t1 AS curr LEFT JOIN t1 AS other + GROUP BY curr.id1); + } +} {1 1} +do_test aggnested-3.1-rj { + db eval { + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT curr.value1 as xyz + FROM t1 AS other RIGHT JOIN t1 AS curr + GROUP BY curr.id1); + } +} {1 1} + +do_test aggnested-3.2 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1 ( + id1 INTEGER, + value1 INTEGER, + x1 INTEGER + ); + INSERT INTO t1 VALUES(4469,2,98),(4469,1,99),(4469,3,97); + CREATE TABLE t2 ( + value2 INTEGER + ); + INSERT INTO t2 VALUES(1); + SELECT + (SELECT sum(value2==xyz) FROM t2) + FROM + (SELECT value1 as xyz, max(x1) AS pqr + FROM t1 + GROUP BY id1); + SELECT + (SELECT sum(value2<>xyz) FROM t2) + FROM + (SELECT value1 as xyz, max(x1) AS pqr + FROM t1 + GROUP BY id1); + } +} {1 0} +do_test aggnested-3.3 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(id1, value1); + INSERT INTO t1 VALUES(4469,2),(4469,1); + CREATE TABLE t2 (value2); + INSERT INTO t2 VALUES(1); + SELECT (SELECT sum(value2=value1) FROM t2), max(value1) + FROM t1 + GROUP BY id1; + } +} {0 2} + +# A batch of queries all doing approximately the same operation involving +# two nested aggregate queries. +# +do_test aggnested-3.11 { + db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(id1, value1); + INSERT INTO t1 VALUES(4469,12),(4469,11),(4470,34); + CREATE INDEX t1id1 ON t1(id1); + CREATE TABLE t2 (value2); + INSERT INTO t2 VALUES(12),(34),(34); + INSERT INTO t2 SELECT value2 FROM t2; + + SELECT max(value1), (SELECT count(*) FROM t2 WHERE value2=max(value1)) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} +do_test aggnested-3.12 { + db eval { + SELECT max(value1), (SELECT count(*) FROM t2 WHERE value2=value1) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} +do_test aggnested-3.13 { + db eval { + SELECT value1, (SELECT sum(value2=value1) FROM t2) + FROM t1; + } +} {12 2 11 0 34 4} +do_test aggnested-3.14 { + db eval { + SELECT value1, (SELECT sum(value2=value1) FROM t2) + FROM t1 + WHERE value1 IN (SELECT max(value1) FROM t1 GROUP BY id1); + } +} {12 2 34 4} +do_test aggnested-3.15 { + # FIXME: If case 3.16 works, then this case really ought to work too... + catchsql { + SELECT max(value1), (SELECT sum(value2=max(value1)) FROM t2) + FROM t1 + GROUP BY id1; + } +} {1 {misuse of aggregate function max()}} +do_test aggnested-3.16 { + db eval { + SELECT max(value1), (SELECT sum(value2=value1) FROM t2) + FROM t1 + GROUP BY id1; + } +} {12 2 34 4} + +# 2019-08-31 +# Problem found by dbsqlfuzz +# +do_execsql_test aggnested-4.1 { + DROP TABLE IF EXISTS aa; + DROP TABLE IF EXISTS bb; + CREATE TABLE aa(x INT); INSERT INTO aa(x) VALUES(123); + CREATE TABLE bb(y INT); INSERT INTO bb(y) VALUES(456); + SELECT (SELECT sum(x+(SELECT y)) FROM bb) FROM aa; +} {579} +do_execsql_test aggnested-4.2 { + SELECT (SELECT sum(x+y) FROM bb) FROM aa; +} {579} +do_execsql_test aggnested-4.3 { + DROP TABLE IF EXISTS tx; + DROP TABLE IF EXISTS ty; + CREATE TABLE tx(x INT); + INSERT INTO tx VALUES(1),(2),(3),(4),(5); + CREATE TABLE ty(y INT); + INSERT INTO ty VALUES(91),(92),(93); + SELECT min((SELECT count(y) FROM ty)) FROM tx; +} {3} +do_execsql_test aggnested-4.4 { + SELECT max((SELECT a FROM (SELECT count(*) AS a FROM ty) AS s)) FROM tx; +} {3} + +#-------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE x1(a, b); + INSERT INTO x1 VALUES(1, 2); + CREATE TABLE x2(x); + INSERT INTO x2 VALUES(NULL), (NULL), (NULL); +} + +# At one point, aggregate "total()" in the query below was being processed +# as part of the outer SELECT, not as part of the sub-select with no FROM +# clause. +do_execsql_test 5.1 { + SELECT ( SELECT total( (SELECT b FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.2 { + SELECT ( SELECT total( (SELECT 2 FROM x1) ) ) FROM x2; +} {2.0 2.0 2.0} + +do_execsql_test 5.3 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); +} + +do_execsql_test 5.4 { + SELECT( + SELECT max(b) LIMIT ( + SELECT total( (SELECT a FROM t1) ) + ) + ) + FROM t2; +} {{}} + +do_execsql_test 5.5 { + CREATE TABLE a(b); + WITH c AS(SELECT a) + SELECT(SELECT(SELECT string_agg(b, b) + LIMIT(SELECT 0.100000 * + AVG(DISTINCT(SELECT 0 FROM a ORDER BY b, b, b)))) + FROM a GROUP BY b, + b, b) FROM a EXCEPT SELECT b FROM a ORDER BY b, + b, b; +} + +#------------------------------------------------------------------------- +# dbsqlfuzz a779227f721a834df95f4f42d0c31550a1f8b8a2 +# +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + + INSERT INTO t1 VALUES('x'); + INSERT INTO t2 VALUES(1); +} + +do_execsql_test 6.1.1 { + SELECT ( + SELECT t2.b FROM (SELECT t2.b AS c FROM t1) GROUP BY 1 HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {1} +do_execsql_test 6.1.2 { + SELECT ( + SELECT c FROM (SELECT t2.b AS c FROM t1) GROUP BY c HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {1} + +do_execsql_test 6.2.0 { + UPDATE t2 SET b=0 +} +do_execsql_test 6.2.1 { + SELECT ( + SELECT t2.b FROM (SELECT t2.b AS c FROM t1) GROUP BY 1 HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {{}} +do_execsql_test 6.2.2 { + SELECT ( + SELECT c FROM (SELECT t2.b AS c FROM t1) GROUP BY c HAVING t2.b + ) + FROM t2 GROUP BY 'constant_string'; +} {{}} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 7.0 { + CREATE TABLE invoice ( + id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + amount DOUBLE PRECISION DEFAULT NULL, + name VARCHAR(100) DEFAULT NULL + ); + + INSERT INTO invoice (amount, name) VALUES + (4.0, 'Michael'), (15.0, 'Bara'), (4.0, 'Michael'), (6.0, 'John'); +} + +do_execsql_test 7.1 { + SELECT sum(amount), name + from invoice + group by name + having (select v > 6 from (select sum(amount) v) t) +} { + 15.0 Bara + 8.0 Michael +} + +do_execsql_test 7.2 { + SELECT (select 1 from (select sum(amount))) FROM invoice +} {1} + +do_execsql_test 8.0 { + CREATE TABLE t1(x INT); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(20); + INSERT INTO t1 VALUES(3); + SELECT (SELECT y FROM (SELECT sum(x) AS y) AS t2 ) FROM t1; +} {123} + +do_execsql_test 8.1 { + SELECT ( + SELECT y FROM ( + SELECT z AS y FROM (SELECT sum(x) AS z) AS t2 + ) + ) FROM t1; +} {123} + +do_execsql_test 8.2 { + SELECT ( + SELECT a FROM ( + SELECT y AS a FROM ( + SELECT z AS y FROM (SELECT sum(x) AS z) AS t2 + ) + ) + ) FROM t1; +} {123} + +#------------------------------------------------------------------------- +# dbsqlfuzz 04408efc51ae46897c4c122b407412045ed221b4 +# +reset_db + +do_execsql_test 9.1 { + WITH out(i, j, k) AS ( + VALUES(1234, 5678, 9012) + ) + SELECT ( + SELECT ( + SELECT min(abc) = ( SELECT ( SELECT 1234 fROM (SELECT abc) ) ) + FROM ( + SELECT sum( out.i ) + ( SELECT sum( out.i ) ) AS abc FROM (SELECT out.j) + ) + ) + ) FROM out; +} {0} + +do_execsql_test 9.2 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + INSERT INTO t1 VALUES(1), (2), (3); + INSERT INTO t2 VALUES(4), (5), (6); + + SELECT ( + SELECT min(y) + (SELECT x) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) + ) + FROM t1; +} {10} + +do_execsql_test 9.3 { + SELECT ( + SELECT min(y) + (SELECT (SELECT x)) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) + ) + FROM t1; +} {10} + +do_execsql_test 9.4 { + SELECT ( + SELECT (SELECT x) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) GROUP BY y + ) + FROM t1; +} {6} + +do_execsql_test 9.5 { + SELECT ( + SELECT (SELECT (SELECT x)) FROM ( + SELECT sum(a) AS x, b AS y FROM t2 + ) GROUP BY y + ) + FROM t1; +} {6} + +# 2023-12-16 +# New test case for check-in [4470f657d2069972] from 2023-11-02 +# https://bugs.chromium.org/p/chromium/issues/detail?id=1511689 +# +do_execsql_test 10.1 { + DROP TABLE IF EXISTS t0; + DROP TABLE IF EXISTS t1; + CREATE TABLE t0(c1, c2); INSERT INTO t0 VALUES(1,2); + CREATE TABLE t1(c3, c4); INSERT INTO t1 VALUES(3,4); + SELECT * FROM t0 WHERE EXISTS (SELECT 1 FROM t1 GROUP BY c3 HAVING ( SELECT count(*) FROM (SELECT 1 UNION ALL SELECT sum(DISTINCT c1) ) ) ) BETWEEN 1 AND 1; +} {1 2} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/aggorderby.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggorderby.test new file mode 100644 index 0000000000000000000000000000000000000000..eed1f83a7e00474f92d6520973a77915531f583b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/aggorderby.test @@ -0,0 +1,162 @@ +# 2023-10-18 +# +# 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 ORDER BY on aggregate functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test aggorderby-1.1 { + CREATE TABLE t1(a TEXT,b INT,c INT,d INT); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<9) + INSERT INTO t1(a,b,c,d) SELECT printf('%d',(x*7)%10),1,x,10-x FROM c; + INSERT INTO t1(a,b,c,d) SELECT a, 2, c, 10-d FROM t1; + CREATE INDEX t1b ON t1(b); +} +do_catchsql_test aggorderby-1.2 { + SELECT b, group_concat(a ORDER BY max(d)) FROM t1 GROUP BY b; +} {1 {misuse of aggregate function max()}} +do_catchsql_test aggorderby-1.3 { + SELECT abs(a ORDER BY max(d)) FROM t1; +} {1 {ORDER BY may not be used with non-aggregate abs()}} + +do_execsql_test aggorderby-2.0 { + SELECT group_concat(a ORDER BY a) FROM t1 WHERE b=1; +} {0,1,2,3,4,5,6,7,8,9} +do_execsql_test aggorderby-2.1 { + SELECT group_concat(a ORDER BY c) FROM t1 WHERE b=1; +} {0,7,4,1,8,5,2,9,6,3} +do_execsql_test aggorderby-2.2 { + SELECT group_concat(a ORDER BY b, d) FROM t1; +} {3,6,9,2,5,8,1,4,7,0,0,7,4,1,8,5,2,9,6,3} +do_execsql_test aggorderby-2.3 { + SELECT string_agg(a, ',' ORDER BY b DESC, d) FROM t1; +} {0,7,4,1,8,5,2,9,6,3,3,6,9,2,5,8,1,4,7,0} +do_execsql_test aggorderby-2.4 { + SELECT b, group_concat(a ORDER BY d) FROM t1 GROUP BY b ORDER BY b; +} {1 3,6,9,2,5,8,1,4,7,0 2 0,7,4,1,8,5,2,9,6,3} + +do_execsql_test aggorderby-3.0 { + SELECT group_concat(DISTINCT a ORDER BY a) FROM t1; +} {0,1,2,3,4,5,6,7,8,9} +do_execsql_test aggorderby-3.1 { + SELECT group_concat(DISTINCT a ORDER BY c) FROM t1; +} {0,7,4,1,8,5,2,9,6,3} + +do_execsql_test aggorderby-4.0 { + SELECT count(ORDER BY a) FROM t1; +} 20 +do_execsql_test aggorderby-4.1 { + SELECT c, max(a ORDER BY a) FROM t1; +} {7 9} + + +do_execsql_test aggorderby-5.0 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t3; + CREATE TABLE t1(a TEXT); INSERT INTO t1 VALUES('aaa'),('bbb'); + CREATE TABLE t3(d TEXT); INSERT INTO t3 VALUES('/'),('-'); + SELECT (SELECT string_agg(a,d) FROM t3) FROM t1; +} {aaa-aaa bbb-bbb} +do_execsql_test aggorderby-5.1 { + SELECT (SELECT group_concat(a,d ORDER BY d) FROM t3) FROM t1; +} {aaa/aaa bbb/bbb} +do_execsql_test aggorderby-5.2 { + SELECT (SELECT string_agg(a,d ORDER BY d DESC) FROM t3) FROM t1; +} {aaa-aaa bbb-bbb} +do_execsql_test aggorderby-5.3 { + SELECT (SELECT string_agg(a,'#' ORDER BY d) FROM t3) FROM t1; +} {aaa#aaa bbb#bbb} + +# COLLATE works on the ORDER BY. +# +do_execsql_test aggorderby-6.0 { + WITH c(x) AS (VALUES('abc'),('DEF'),('xyz'),('ABC'),('XYZ')) + SELECT string_agg(x,',' ORDER BY x COLLATE nocase), + string_agg(x,',' ORDER BY x) FROM c; +} {abc,ABC,DEF,xyz,XYZ ABC,DEF,XYZ,abc,xyz} +do_execsql_test aggorderby-6.1 { + WITH c(x,y) AS (VALUES(1,'a'),(2,'B'),(3,'c'),(4,'D')) + SELECT group_concat(x ORDER BY y COLLATE nocase), + group_concat(x ORDER BY y COLLATE binary) FROM c; +} {1,2,3,4 2,4,1,3} + +# NULLS FIRST and NULLS LAST work on the ORDER BY +# +do_execsql_test aggorderby-7.0 { + WITH c(x) AS (VALUES(1),(NULL),(2.5),(NULL),('three')) + SELECT json_group_array(x ORDER BY x NULLS FIRST), + json_group_array(x ORDER BY x NULLS LAST) FROM c; +} {[null,null,1,2.5,"three"] [1,2.5,"three",null,null]} +do_execsql_test aggorderby-7.1 { + WITH c(x,y) AS (VALUES(1,9),(2,null),(3,5),(4,null),(5,1)) + SELECT json_group_array(x ORDER BY y NULLS FIRST, x), + json_group_array(x ORDER BY y NULLS LAST, x) FROM c; +} {[2,4,5,3,1] [5,3,1,2,4]} + +# The DISTINCT only applies to the function arguments, not to the +# ORDER BY arguments. +# +do_execsql_test aggorderby-8.0 { + WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('c',2,7),('c',1,8)) + SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c; +} {c,b,a} +do_execsql_test aggorderby-8.1 { + WITH c(x,y,z) AS (VALUES('a',4,5),('b',3,6),('b',2,7),('c',1,8)) + SELECT group_concat(DISTINCT x ORDER BY y, z) FROM c; +} {c,b,a} +do_execsql_test aggorderby-8.2 { + WITH c(x,y) AS (VALUES(1,1),(2,2),(3,3),(3,4),(3,5),(3,6)) + SELECT sum(DISTINCT x ORDER BY y) FROM c; +} 6 + +# Subtype information is transfered through the sorter for aggregates +# that make use of subtype info. +# +do_execsql_test aggorderby-9.0 { + WITH c(x,y) AS (VALUES + ('{a:3}', 3), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(json(x) ORDER BY y) FROM c; +} {{[[1,1],{"x":2},{"a":3},[4,4]]}} +do_execsql_test aggorderby-9.1 { + WITH c(x,y) AS (VALUES + ('[4,4]', 4), + ('{a:3}', 3), + ('[4,4]', 4), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(DISTINCT json(x) ORDER BY y) FROM c; +} {{[[1,1],{"x":2},{"a":3},[4,4]]}} +do_execsql_test aggorderby-9.2 { + WITH c(x,y) AS (VALUES + ('{a:3}', 3), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(json(x) ORDER BY json(x)) FROM c; +} {{[[1,1],[4,4],{"a":3},{"x":2}]}} +do_execsql_test aggorderby-9.3 { + WITH c(x,y) AS (VALUES + ('[4,4]', 4), + ('{a:3}', 3), + ('[4,4]', 4), + ('[1,1]', 1), + ('[4,4]', 4), + ('{x:2}', 2)) + SELECT json_group_array(DISTINCT json(x) ORDER BY json(x)) FROM c; +} {{[[1,1],[4,4],{"a":3},{"x":2}]}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alias.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alias.test new file mode 100644 index 0000000000000000000000000000000000000000..290798974b74c2e680d4af75c8e122f6f22ade89 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alias.test @@ -0,0 +1,140 @@ +# 2008 August 28 +# +# 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. The +# focus of this script is correct code generation of aliased result-set +# values. See ticket #3343. +# +# $Id: alias.test,v 1.3 2009/04/23 13:22:44 drh Exp $ +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Aliases are currently evaluated twice. We might try to change this +# in the future. But not now. +return + +# A procedure to return a sequence of increasing integers. +# +namespace eval ::seq { + variable counter 0 + proc value {args} { + variable counter + incr counter + return $counter + } + proc reset {} { + variable counter + set counter 0 + } +} + + +do_test alias-1.1 { + db function sequence ::seq::value + db eval { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(9); + INSERT INTO t1 VALUES(8); + INSERT INTO t1 VALUES(7); + SELECT x, sequence() FROM t1; + } +} {9 1 8 2 7 3} +do_test alias-1.2 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 + } +} {9 1 8 2 7 3} +do_test alias-1.3 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 + } +} {9 1 8 2 7 3} +do_test alias-1.4 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y>0 AND y<99 AND y!=55 + } +} {9 1 8 2 7 3} +do_test alias-1.5 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 + WHERE y>0 AND y<99 AND y!=55 AND y NOT IN (56,57,58) + AND y NOT LIKE 'abc%' AND y%10==2 + } +} {8 2} +do_test alias-1.6 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 WHERE y BETWEEN 0 AND 99 + } +} {9 1 8 2 7 3} +#do_test alias-1.7 { +# ::seq::reset +# db eval { +# SELECT x, sequence() AS y FROM t1 WHERE y IN (55,66,3) +# } +#} {7 3} +do_test alias-1.8 { + ::seq::reset + db eval { + SELECT x, 1-sequence() AS y FROM t1 ORDER BY y + } +} {7 -2 8 -1 9 0} +do_test alias-1.9 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 ORDER BY -y + } +} {7 3 8 2 9 1} +do_test alias-1.10 { + ::seq::reset + db eval { + SELECT x, sequence() AS y FROM t1 ORDER BY x%2, y + } +} {8 2 9 1 7 3} + +unset -nocomplain random_int_list +set random_int_list [db eval { + SELECT random()&2147483647 AS r FROM t1, t1, t1, t1 ORDER BY r +}] +do_test alias-1.11 { + lsort -integer $::random_int_list +} $random_int_list + + +do_test alias-2.1 { + db eval { + SELECT 4 UNION SELECT 1 ORDER BY 1 + } +} {1 4} +do_test alias-2.2 { + db eval { + SELECT 4 UNION SELECT 1 UNION SELECT 9 ORDER BY 1 + } +} {1 4 9} + +if 0 { + # Aliases in the GROUP BY clause cause the expression to be evaluated + # twice in the current implementation. This might change in the future. + # + do_test alias-3.1 { + ::seq::reset + db eval { + SELECT sequence(*) AS y, count(*) AS z FROM t1 GROUP BY y ORDER BY z, y + } + } {1 1 2 1 3 1} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alter.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alter.test new file mode 100644 index 0000000000000000000000000000000000000000..9201f40adcad2c9ec9c399883f293e1a1b2ddd11 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alter.test @@ -0,0 +1,986 @@ +# 2004 November 10 +# +# 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. The +# focus of this script is testing the ALTER TABLE statement. +# +# $Id: alter.test,v 1.32 2009/03/24 15:08:10 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +#---------------------------------------------------------------------- +# Test organization: +# +# alter-1.1.* - alter-1.7.*: Basic tests of ALTER TABLE, including tables +# with implicit and explicit indices. These tests came from an earlier +# fork of SQLite that also supported ALTER TABLE. +# alter-1.8.*: Tests for ALTER TABLE when the table resides in an +# attached database. +# alter-1.9.*: Tests for ALTER TABLE when their is whitespace between the +# table name and left parenthesis token. i.e: +# "CREATE TABLE abc (a, b, c);" +# alter-2.*: Test error conditions and messages. +# alter-3.*: Test ALTER TABLE on tables that have TRIGGERs attached to them. +# alter-4.*: Test ALTER TABLE on tables that have AUTOINCREMENT fields. +# ... +# alter-12.*: Test ALTER TABLE on views. +# + +# Create some tables to rename. Be sure to include some TEMP tables +# and some tables with odd names. +# +do_test alter-1.1 { + ifcapable tempdb { + set ::temp TEMP + } else { + set ::temp {} + } + execsql [subst -nocommands { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + CREATE TABLE [t1'x1](c UNIQUE, b PRIMARY KEY); + INSERT INTO [t1'x1] VALUES(3,4); + CREATE INDEX t1i1 ON T1(B); + CREATE INDEX t1i2 ON t1(a,b); + CREATE INDEX i3 ON [t1'x1](b,c); + CREATE $::temp TABLE "temp table"(e,f,g UNIQUE); + CREATE INDEX i2 ON [temp table](f); + INSERT INTO [temp table] VALUES(5,6,7); + }] + execsql { + SELECT 't1', * FROM t1; + SELECT 't1''x1', * FROM "t1'x1"; + SELECT * FROM [temp table]; + } +} {t1 1 2 t1'x1 3 4 5 6 7} +do_test alter-1.2 { + execsql [subst { + CREATE $::temp TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + }] + ifcapable tempdb { + execsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM temp.sqlite_master WHERE NAME!='objlist'; + } + } + + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table t1 t1 \ + index t1i1 t1 \ + index t1i2 t1 \ + table t1'x1 t1'x1 \ + index i3 t1'x1 \ + index {sqlite_autoindex_t1'x1_1} t1'x1 \ + index {sqlite_autoindex_t1'x1_2} t1'x1 \ + table {temp table} {temp table} \ + index i2 {temp table} \ + index {sqlite_autoindex_temp table_1} {temp table} \ + ] + +# Make some changes +# +integrity_check alter-1.3.0 +do_test alter-1.3 { + execsql { + ALTER TABLE [T1] RENAME to [-t1-]; + ALTER TABLE "t1'x1" RENAME TO T2; + ALTER TABLE [temp table] RENAME to TempTab; + } +} {} +integrity_check alter-1.3.1 +do_test alter-1.4 { + execsql { + SELECT 't1', * FROM [-t1-]; + SELECT 't2', * FROM t2; + SELECT * FROM temptab; + } +} {t1 1 2 t2 3 4 5 6 7} +do_test alter-1.5 { + execsql { + DELETE FROM objlist; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table -t1- -t1- \ + index t1i1 -t1- \ + index t1i2 -t1- \ + table T2 T2 \ + index i3 T2 \ + index {sqlite_autoindex_T2_1} T2 \ + index {sqlite_autoindex_T2_2} T2 \ + table {TempTab} {TempTab} \ + index i2 {TempTab} \ + index {sqlite_autoindex_TempTab_1} {TempTab} \ + ] + +# Make sure the changes persist after restarting the database. +# (The TEMP table will not persist, of course.) +# +ifcapable tempdb { + do_test alter-1.6 { + db close + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + execsql { + CREATE TEMP TABLE objlist(type, name, tbl_name); + INSERT INTO objlist SELECT type, name, tbl_name FROM sqlite_master; + INSERT INTO objlist + SELECT type, name, tbl_name FROM temp.sqlite_master + WHERE NAME!='objlist'; + SELECT type, name, tbl_name FROM objlist + ORDER BY tbl_name, type desc, name; + } + } [list \ + table -t1- -t1- \ + index t1i1 -t1- \ + index t1i2 -t1- \ + table T2 T2 \ + index i3 T2 \ + index {sqlite_autoindex_T2_1} T2 \ + index {sqlite_autoindex_T2_2} T2 \ + ] +} else { + execsql { + DROP TABLE TempTab; + } +} + +# Create bogus application-defined functions for functions used +# internally by ALTER TABLE, to ensure that ALTER TABLE falls back +# to the built-in functions. +# +proc failing_app_func {args} {error "bad function"} +do_test alter-1.7-prep { + db func substr failing_app_func + db func like failing_app_func + db func sqlite_rename_table failing_app_func + db func sqlite_rename_trigger failing_app_func + db func sqlite_rename_parent failing_app_func + catchsql {SELECT substr(name,1,3) FROM sqlite_master} +} {1 {bad function}} + +# Make sure the ALTER TABLE statements work with the +# non-callback API +# +do_test alter-1.7 { + stepsql $DB { + ALTER TABLE [-t1-] RENAME to [*t1*]; + ALTER TABLE T2 RENAME TO []; + } + execsql { + DELETE FROM objlist; + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_master WHERE NAME!='objlist'; + } + catchsql { + INSERT INTO objlist SELECT type, name, tbl_name + FROM sqlite_temp_master WHERE NAME!='objlist'; + } + execsql { + SELECT type, name, tbl_name FROM objlist ORDER BY tbl_name, type desc, name; + } +} [list \ + table *t1* *t1* \ + index t1i1 *t1* \ + index t1i2 *t1* \ + table \ + index i3 \ + index {sqlite_autoindex__1} \ + index {sqlite_autoindex__2} \ + ] + +# Check that ALTER TABLE works on attached databases. +# +ifcapable attach { + do_test alter-1.8.1 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + ATTACH 'test2.db' AS aux; + } + } {} + do_test alter-1.8.2 { + execsql { + CREATE TABLE t4(a PRIMARY KEY, b, c); + CREATE TABLE aux.t4(a PRIMARY KEY, b, c); + CREATE INDEX i4 ON t4(b); + CREATE INDEX aux.i4 ON t4(b); + } + } {} + do_test alter-1.8.3 { + execsql { + INSERT INTO t4 VALUES('main', 'main', 'main'); + INSERT INTO aux.t4 VALUES('aux', 'aux', 'aux'); + SELECT * FROM t4 WHERE a = 'main'; + } + } {main main main} + do_test alter-1.8.4 { + execsql { + ALTER TABLE t4 RENAME TO t5; + SELECT * FROM t4 WHERE a = 'aux'; + } + } {aux aux aux} + do_test alter-1.8.5 { + execsql { + SELECT * FROM t5; + } + } {main main main} + do_test alter-1.8.6 { + execsql { + SELECT * FROM t5 WHERE b = 'main'; + } + } {main main main} + do_test alter-1.8.7 { + execsql { + ALTER TABLE aux.t4 RENAME TO t5; + SELECT * FROM aux.t5 WHERE b = 'aux'; + } + } {aux aux aux} +} + +do_test alter-1.9.1 { + execsql { + CREATE TABLE tbl1 (a, b, c); + INSERT INTO tbl1 VALUES(1, 2, 3); + } +} {} +do_test alter-1.9.2 { + execsql { + SELECT * FROM tbl1; + } +} {1 2 3} +do_test alter-1.9.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + SELECT * FROM tbl2; + } +} {1 2 3} +do_test alter-1.9.4 { + execsql { + DROP TABLE tbl2; + } +} {} + +# Test error messages +# +do_test alter-2.1 { + catchsql { + ALTER TABLE none RENAME TO hi; + } +} {1 {no such table: none}} +do_test alter-2.2 { + execsql { + CREATE TABLE t3(p,q,r); + } + catchsql { + ALTER TABLE [] RENAME TO t3; + } +} {1 {there is already another table or index with this name: t3}} +do_test alter-2.3 { + catchsql { + ALTER TABLE [] RENAME TO i3; + } +} {1 {there is already another table or index with this name: i3}} +do_test alter-2.4 { + catchsql { + ALTER TABLE SqLiTe_master RENAME TO master; + } +} {1 {table sqlite_master may not be altered}} +do_test alter-2.5 { + catchsql { + ALTER TABLE t3 RENAME TO sqlite_t3; + } +} {1 {object name reserved for internal use: sqlite_t3}} +do_test alter-2.6 { + catchsql { + ALTER TABLE t3 ADD COLUMN (ALTER TABLE t3 ADD COLUMN); + } +} {1 {near "(": syntax error}} + +# If this compilation does not include triggers, omit the alter-3.* tests. +ifcapable trigger { + +#----------------------------------------------------------------------- +# Tests alter-3.* test ALTER TABLE on tables that have triggers. +# +# alter-3.1.*: ALTER TABLE with triggers. +# alter-3.2.*: Test that the ON keyword cannot be used as a database, +# table or column name unquoted. This is done because part of the +# ALTER TABLE code (specifically the implementation of SQL function +# "sqlite_alter_trigger") will break in this case. +# alter-3.3.*: ALTER TABLE with TEMP triggers (todo). +# + +# An SQL user-function for triggers to fire, so that we know they +# are working. +proc trigfunc {args} { + set ::TRIGGER $args +} +db func trigfunc trigfunc + +do_test alter-3.1.0 { + execsql { + CREATE TABLE t6(a, b, c); + -- Different case for the table name in the trigger. + CREATE TRIGGER trig1 AFTER INSERT ON T6 BEGIN + SELECT trigfunc('trig1', new.a, new.b, new.c); + END; + } +} {} +do_test alter-3.1.1 { + execsql { + INSERT INTO t6 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig1 1 2 3} +do_test alter-3.1.2 { + execsql { + ALTER TABLE t6 RENAME TO t7; + INSERT INTO t7 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig1 4 5 6} +do_test alter-3.1.3 { + execsql { + DROP TRIGGER trig1; + } +} {} +do_test alter-3.1.4 { + execsql { + CREATE TRIGGER trig2 AFTER INSERT ON main.t7 BEGIN + SELECT trigfunc('trig2', new.a, new.b, new.c); + END; + INSERT INTO t7 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig2 1 2 3} +do_test alter-3.1.5 { + execsql { + ALTER TABLE t7 RENAME TO t8; + INSERT INTO t8 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig2 4 5 6} +do_test alter-3.1.6 { + execsql { + DROP TRIGGER trig2; + } +} {} +do_test alter-3.1.7 { + execsql { + CREATE TRIGGER trig3 AFTER INSERT ON main.'t8'BEGIN + SELECT trigfunc('trig3', new.a, new.b, new.c); + END; + INSERT INTO t8 VALUES(1, 2, 3); + } + set ::TRIGGER +} {trig3 1 2 3} +do_test alter-3.1.8 { + execsql { + ALTER TABLE t8 RENAME TO t9; + INSERT INTO t9 VALUES(4, 5, 6); + } + set ::TRIGGER +} {trig3 4 5 6} + +# Make sure "ON" cannot be used as a database, table or column name without +# quoting. Otherwise the sqlite_alter_trigger() function might not work. +forcedelete test3.db +forcedelete test3.db-journal +ifcapable attach { + do_test alter-3.2.1 { + catchsql { + ATTACH 'test3.db' AS ON; + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.2 { + catchsql { + ATTACH 'test3.db' AS 'ON'; + } + } {0 {}} + do_test alter-3.2.3 { + catchsql { + CREATE TABLE ON.t1(a, b, c); + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.4 { + catchsql { + CREATE TABLE 'ON'.t1(a, b, c); + } + } {0 {}} + do_test alter-3.2.4 { + catchsql { + CREATE TABLE 'ON'.ON(a, b, c); + } + } {1 {near "ON": syntax error}} + do_test alter-3.2.5 { + catchsql { + CREATE TABLE 'ON'.'ON'(a, b, c); + } + } {0 {}} +} +do_test alter-3.2.6 { + catchsql { + CREATE TABLE t10(a, ON, c); + } +} {1 {near "ON": syntax error}} +do_test alter-3.2.7 { + catchsql { + CREATE TABLE t10(a, 'ON', c); + } +} {0 {}} +do_test alter-3.2.8 { + catchsql { + CREATE TRIGGER trig4 AFTER INSERT ON ON BEGIN SELECT 1; END; + } +} {1 {near "ON": syntax error}} +ifcapable attach { + do_test alter-3.2.9 { + catchsql { + CREATE TRIGGER 'on'.trig4 AFTER INSERT ON 'ON' BEGIN SELECT 1; END; + } + } {0 {}} +} +do_test alter-3.2.10 { + execsql { + DROP TABLE t10; + } +} {} + +do_test alter-3.3.1 { + execsql [subst { + CREATE TABLE tbl1(a, b, c); + CREATE $::temp TRIGGER trig1 AFTER INSERT ON tbl1 BEGIN + SELECT trigfunc('trig1', new.a, new.b, new.c); + END; + }] +} {} +do_test alter-3.3.2 { + execsql { + INSERT INTO tbl1 VALUES('a', 'b', 'c'); + } + set ::TRIGGER +} {trig1 a b c} +do_test alter-3.3.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + INSERT INTO tbl2 VALUES('d', 'e', 'f'); + } + set ::TRIGGER +} {trig1 d e f} +do_test alter-3.3.4 { + execsql [subst { + CREATE $::temp TRIGGER trig2 AFTER UPDATE ON tbl2 BEGIN + SELECT trigfunc('trig2', new.a, new.b, new.c); + END; + }] +} {} +do_test alter-3.3.5 { + execsql { + ALTER TABLE tbl2 RENAME TO tbl3; + INSERT INTO tbl3 VALUES('g', 'h', 'i'); + } + set ::TRIGGER +} {trig1 g h i} +do_test alter-3.3.6 { + execsql { + UPDATE tbl3 SET a = 'G' where a = 'g'; + } + set ::TRIGGER +} {trig2 G h i} +do_test alter-3.3.7 { + execsql { + DROP TABLE tbl3; + } +} {} +ifcapable tempdb { + do_test alter-3.3.8 { + execsql { + SELECT * FROM temp.sqlite_master WHERE type = 'trigger'; + } + } {} +} + +} ;# ifcapable trigger + +# If the build does not include AUTOINCREMENT fields, omit alter-4.*. +ifcapable autoinc { + +do_test alter-4.1 { + execsql { + CREATE TABLE tbl1(a INTEGER PRIMARY KEY AUTOINCREMENT); + INSERT INTO tbl1 VALUES(10); + } +} {} +do_test alter-4.2 { + execsql { + INSERT INTO tbl1 VALUES(NULL); + SELECT a FROM tbl1; + } +} {10 11} +do_test alter-4.3 { + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + DELETE FROM tbl2; + INSERT INTO tbl2 VALUES(NULL); + SELECT a FROM tbl2; + } +} {12} +do_test alter-4.4 { + execsql { + DROP TABLE tbl2; + } +} {} + +} ;# ifcapable autoinc + +# Test that it is Ok to execute an ALTER TABLE immediately after +# opening a database. +do_test alter-5.1 { + execsql { + CREATE TABLE tbl1(a, b, c); + INSERT INTO tbl1 VALUES('x', 'y', 'z'); + } +} {} +do_test alter-5.2 { + sqlite3 db2 test.db + execsql { + ALTER TABLE tbl1 RENAME TO tbl2; + SELECT * FROM tbl2; + } db2 +} {x y z} +do_test alter-5.3 { + db2 close +} {} + +foreach tblname [execsql { + SELECT name FROM sqlite_master + WHERE type='table' AND name NOT GLOB 'sqlite*' +}] { + execsql "DROP TABLE \"$tblname\"" +} + +set ::tbl_name "abc\uABCDdef" +do_test alter-6.1 { + string length $::tbl_name +} {7} +do_test alter-6.2 { + execsql " + CREATE TABLE ${tbl_name}(a, b, c); + " + set ::oid [execsql {SELECT max(oid) FROM sqlite_master}] + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid; + " +} "{CREATE TABLE ${::tbl_name}(a, b, c)}" +execsql " + SELECT * FROM ${::tbl_name} +" +set ::tbl_name2 "abcXdef" +do_test alter-6.3 { + execsql " + ALTER TABLE $::tbl_name RENAME TO $::tbl_name2 + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name2}\"(a, b, c)}" +do_test alter-6.4 { + execsql " + ALTER TABLE $::tbl_name2 RENAME TO $::tbl_name + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c)}" +set ::col_name ghi\1234\jkl +do_test alter-6.5 { + execsql " + ALTER TABLE $::tbl_name ADD COLUMN $::col_name VARCHAR + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c, $::col_name VARCHAR)}" +set ::col_name2 B\3421\A +do_test alter-6.6 { + db close + sqlite3 db test.db + execsql " + ALTER TABLE $::tbl_name ADD COLUMN $::col_name2 + " + execsql " + SELECT sql FROM sqlite_master WHERE oid = $::oid + " +} "{CREATE TABLE \"${::tbl_name}\"(a, b, c, $::col_name VARCHAR, $::col_name2)}" +do_test alter-6.7 { + execsql " + INSERT INTO ${::tbl_name} VALUES(1, 2, 3, 4, 5); + SELECT $::col_name, $::col_name2 FROM $::tbl_name; + " +} {4 5} + +# Ticket #1665: Make sure ALTER TABLE ADD COLUMN works on a table +# that includes a COLLATE clause. +# +do_realnum_test alter-7.1 { + execsql { + CREATE TABLE t1(a TEXT COLLATE BINARY); + ALTER TABLE t1 ADD COLUMN b INTEGER COLLATE NOCASE; + INSERT INTO t1 VALUES(1,'-2'); + INSERT INTO t1 VALUES(5.4e-08,'5.4e-08'); + SELECT typeof(a), a, typeof(b), b FROM t1; + } +} {text 1 integer -2 text 5.4e-08 real 5.4e-08} + +# Make sure that when a column is added by ALTER TABLE ADD COLUMN and has +# a default value that the default value is used by aggregate functions. +# +do_test alter-8.1 { + execsql { + CREATE TABLE t2(a INTEGER); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + ALTER TABLE t2 ADD COLUMN b INTEGER DEFAULT 9; + SELECT sum(b) FROM t2; + } +} {27} +do_test alter-8.2 { + execsql { + SELECT a, sum(b) FROM t2 GROUP BY a; + } +} {1 18 2 9} + +#-------------------------------------------------------------------------- +# alter-9.X - Special test: Make sure the sqlite_rename_column() and +# rename_table() functions do not crash when handed bad input. +# +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_test alter-9.1 { + execsql {SELECT SQLITE_RENAME_COLUMN(0,0,0,0,0,0,0,0,0)} +} {{}} +foreach {tn sql} { + 1 { SELECT SQLITE_RENAME_TABLE(0,0,0,0,0,0,0) } + 2 { SELECT SQLITE_RENAME_TABLE(10,20,30,40,50,60,70) } + 3 { SELECT SQLITE_RENAME_TABLE('foo','foo','foo','foo','foo','foo','foo') } +} { + do_test alter-9.2.$tn { + catch { execsql $sql } + } 1 +} +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default), +# then the sqlite_rename_table() SQL function is not accessible to ordinary SQL. +# +do_catchsql_test alter-9.3 { + SELECT sqlite_rename_table(0,0,0,0,0,0,0); +} {1 {no such function: sqlite_rename_table}} + +#------------------------------------------------------------------------ +# alter-10.X - Make sure ALTER TABLE works with multi-byte UTF-8 characters +# in the names. +# +do_test alter-10.1 { + execsql "CREATE TABLE xyz(x UNIQUE)" + execsql "ALTER TABLE xyz RENAME TO xyz\u1234abc" + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} +} [list xyz\u1234abc] +do_test alter-10.2 { + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} +} [list sqlite_autoindex_xyz\u1234abc_1] +do_test alter-10.3 { + execsql "ALTER TABLE xyz\u1234abc RENAME TO xyzabc" + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'xyz*'} +} [list xyzabc] +do_test alter-10.4 { + execsql {SELECT name FROM sqlite_master WHERE name GLOB 'sqlite_autoindex*'} +} [list sqlite_autoindex_xyzabc_1] + +do_test alter-11.1 { + sqlite3_exec db {CREATE TABLE t11(%c6%c6)} + execsql { + ALTER TABLE t11 ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11 ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +set isutf16 [regexp 16 [db one {PRAGMA encoding}]] +if {!$isutf16} { + do_test alter-11.2 { + execsql {INSERT INTO t11 VALUES(1,2)} + sqlite3_exec db {SELECT %c6%c6 AS xyz, abc FROM t11} + } {0 {xyz abc 1 2}} +} +do_test alter-11.3 { + sqlite3_exec db {CREATE TABLE t11b("%81%82%83" text)} + execsql { + ALTER TABLE t11b ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11b ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +if {!$isutf16} { + do_test alter-11.4 { + execsql {INSERT INTO t11b VALUES(3,4)} + sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} + do_test alter-11.5 { + sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} + do_test alter-11.6 { + sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11b} + } {0 {xyz abc 3 4}} +} +do_test alter-11.7 { + sqlite3_exec db {CREATE TABLE t11c(%81%82%83 text)} + execsql { + ALTER TABLE t11c ADD COLUMN abc; + } + catchsql { + ALTER TABLE t11c ADD COLUMN abc; + } +} {1 {duplicate column name: abc}} +if {!$isutf16} { + do_test alter-11.8 { + execsql {INSERT INTO t11c VALUES(5,6)} + sqlite3_exec db {SELECT %81%82%83 AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} + do_test alter-11.9 { + sqlite3_exec db {SELECT [%81%82%83] AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} + do_test alter-11.10 { + sqlite3_exec db {SELECT "%81%82%83" AS xyz, abc FROM t11c} + } {0 {xyz abc 5 6}} +} + +do_test alter-12.1 { + execsql { + CREATE TABLE t12(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t12; + } +} {} +do_test alter-12.2 { + catchsql { + ALTER TABLE v1 RENAME TO v2; + } +} {1 {view v1 may not be altered}} +do_test alter-12.3 { + execsql { SELECT * FROM v1; } +} {} +do_test alter-12.4 { + db close + sqlite3 db test.db + execsql { SELECT * FROM v1; } +} {} +do_test alter-12.5 { + catchsql { + ALTER TABLE v1 ADD COLUMN new_column; + } +} {1 {Cannot add a column to a view}} + +# Ticket #3102: +# Verify that comments do not interfere with the table rename +# algorithm. +# +do_test alter-13.1 { + execsql { + CREATE TABLE /* hi */ t3102a(x); + CREATE TABLE t3102b -- comment + (y); + CREATE INDEX t3102c ON t3102a(x); + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a t3102b t3102c} +do_test alter-13.2 { + execsql { + ALTER TABLE t3102a RENAME TO t3102a_rename; + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a_rename t3102b t3102c} +do_test alter-13.3 { + execsql { + ALTER TABLE t3102b RENAME TO t3102b_rename; + SELECT name FROM sqlite_master WHERE name GLOB 't3102*' ORDER BY 1; + } +} {t3102a_rename t3102b_rename t3102c} + +# Ticket #3651 +do_test alter-14.1 { + catchsql { + CREATE TABLE t3651(a UNIQUE); + INSERT INTO t3651 VALUES(5); + ALTER TABLE t3651 ADD COLUMN b UNIQUE; + } +} {1 {Cannot add a UNIQUE column}} +do_test alter-14.2 { + catchsql { + ALTER TABLE t3651 ADD COLUMN b PRIMARY KEY; + } +} {1 {Cannot add a PRIMARY KEY column}} + + +#------------------------------------------------------------------------- +# Test that it is not possible to use ALTER TABLE on any system table. +# +set system_table_list {1 sqlite_master} +catchsql ANALYZE +ifcapable analyze { lappend system_table_list 2 sqlite_stat1 } +ifcapable stat4 { lappend system_table_list 4 sqlite_stat4 } + +foreach {tn tbl} $system_table_list { + do_test alter-15.$tn.1 { + catchsql "ALTER TABLE $tbl RENAME TO xyz" + } [list 1 "table $tbl may not be altered"] + + do_test alter-15.$tn.2 { + catchsql "ALTER TABLE $tbl ADD COLUMN xyz" + } [list 1 "table $tbl may not be altered"] +} + +#------------------------------------------------------------------------ +# Verify that ALTER TABLE works on tables with the WITHOUT rowid option. +# +do_execsql_test alter-16.1 { + CREATE TABLE t16a(a TEXT, b REAL, c INT, PRIMARY KEY(a,b)) WITHOUT rowid; + INSERT INTO t16a VALUES('abc',1.25,99); + ALTER TABLE t16a ADD COLUMN d TEXT DEFAULT 'xyzzy'; + INSERT INTO t16a VALUES('cba',5.5,98,'fizzle'); + SELECT * FROM t16a ORDER BY a; +} {abc 1.25 99 xyzzy cba 5.5 98 fizzle} +do_execsql_test alter-16.2 { + ALTER TABLE t16a RENAME TO t16a_rn; + SELECT * FROM t16a_rn ORDER BY a; +} {abc 1.25 99 xyzzy cba 5.5 98 fizzle} + +# 2018-09-16 ticket b41031ea2b5372378cb3d2d43cf9fe2a4a5c2510 +# +ifcapable rtree { + db close + sqlite3 db :memory: + do_execsql_test alter-17.100 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE VIRTUAL TABLE t2 USING rtree(id,x0,x1); + INSERT INTO t1 VALUES(1,'apple'),(2,'fig'),(3,'pear'); + INSERT INTO t2 VALUES(1,1.0,2.0),(2,2.0,3.0),(3,1.5,3.5); + CREATE TRIGGER r1 AFTER UPDATE ON t1 BEGIN + DELETE FROM t2 WHERE id = OLD.a; + END; + ALTER TABLE t1 RENAME TO t3; + UPDATE t3 SET b='peach' WHERE a=2; + SELECT * FROM t2 ORDER BY 1; + } {1 1.0 2.0 3 1.5 3.5} +} + +# 2021-03-08 dbsqlfuzz 3f0a7245b69cd08617d7d7781ebaedb0fe765a93 +reset_db +do_catchsql_test alter-18.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE log(a INTEGER PRIMARY KEY,b,c); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO logx(a,b,c) VALUES(new.a,new.b,new.c) + ON CONFLICT(a) DO UPDATE SET c=excluded.c, b=new.b; + END; + ALTER TABLE log RENAME COLUMN a TO x; +} {1 {error in trigger tr1: no such table: main.logx}} + +# 2021-10-13 dbsqlfuzz e89174cbfad2d904f06b5e24df0a22510b6a1c1e +reset_db +do_execsql_test alter-19.1 { + CREATE TABLE t1(x); + CREATE TABLE t2(c); + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + UPDATE t2 SET (c)=( + EXISTS(SELECT 1 WHERE (WITH cte1(a) AS (SELECT 1 FROM t1 WHERE (SELECT 1 WHERE (WITH cte2(b) AS (VALUES(1))SELECT b FROM cte2)))SELECT a FROM cte1)) + ); + END; + ALTER TABLE t2 RENAME TO t3; +} {} +do_execsql_test alter-19.2 { + SELECT name FROM sqlite_schema WHERE sql LIKE '%t2%'; +} {} +do_execsql_test alter-19.3 { + SELECT name FROM sqlite_schema WHERE sql LIKE '%t3%' ORDER BY name; +} {r1 t3} + +# 2023-10-14 +# On an ALTER TABLE ADD COLUMN with a DEFAULT clause on a STRICT table +# make sure that the DEFAULT has a compatible type. +# +reset_db +do_execsql_test alter-20.1 { + CREATE TABLE t1(a INT) STRICT; + INSERT INTO t1(a) VALUES(45); +} {} +do_catchsql_test alter-20.2 { + ALTER TABLE t1 ADD COLUMN b TEXT DEFAULT x'313233'; +} {1 {type mismatch on DEFAULT}} +do_execsql_test alter-20.2 { + DELETE FROM t1; + ALTER TABLE t1 ADD COLUMN b TEXT DEFAULT x'313233'; +} {} +do_catchsql_test alter-20.3 { + INSERT INTO t1(a) VALUES(45); +} {1 {cannot store BLOB value in TEXT column t1.b}} + +# 2023-11-17 dbsqlfuzz e0900262dadd5c78c2226ad6a435c7f0255be2cd +# Assertion fault associated with ALTER TABLE and an +# aggregate ORDER BY within an unknown aggregate function. +# +reset_db +do_execsql_test alter-21.1 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(a,b,c,d,x); + CREATE TRIGGER r1 AFTER INSERT ON t2 BEGIN + SELECT unknown_function(a ORDER BY (SELECT group_concat(DISTINCT a ORDER BY a) FROM t1)) FROM t1; + END; + ALTER TABLE t2 RENAME TO e; +} {} +do_execsql_test alter-21.2 { + SELECT name, type FROM sqlite_schema ORDER BY name; +} {e table r1 trigger t1 table} +do_execsql_test alter-21.3 { + DROP TRIGGER r1; + CREATE TRIGGER r2 AFTER INSERT ON e BEGIN + SELECT unknown_function(a ORDER BY (SELECT group_concat(a ORDER BY a) FROM (SELECT b FROM t1))) FROM t1; + END; + ALTER TABLE e RENAME TO t99; +} +do_execsql_test alter-21.4 { + SELECT name, type FROM sqlite_schema ORDER BY name; +} {r2 trigger t1 table t99 table} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alter2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alter2.test new file mode 100644 index 0000000000000000000000000000000000000000..20b75b59ee52e2e3e4ea8cd2c93a186561e89c1f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alter2.test @@ -0,0 +1,470 @@ +# 2005 February 18 +# +# 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. The +# focus of this script is testing that SQLite can handle a subtle +# file format change that may be used in the future to implement +# "ALTER TABLE ... ADD COLUMN". +# +# $Id: alter2.test,v 1.14 2009/04/07 14:14:22 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# We have to have pragmas in order to do this test +ifcapable {!pragma} return + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts. See proc [set_file_format]. +# +do_not_use_codec + +# The file format change affects the way row-records stored in tables (but +# not indices) are interpreted. Before version 3.1.3, a row-record for a +# table with N columns was guaranteed to contain exactly N fields. As +# of version 3.1.3, the record may contain up to N fields. In this case +# the M fields that are present are the values for the left-most M +# columns. The (N-M) rightmost columns contain NULL. +# +# If any records in the database contain less fields than their table +# has columns, then the file-format meta value should be set to (at least) 2. +# + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +# This procedure sets the SQL statement stored for table $tbl in the +# sqlite_master table of file 'test.db' to $sql. Also set the file format +# to the supplied value. This is 2 if the added column has a default that is +# NULL, or 3 otherwise. +# +proc alter_table {tbl sql {file_format 2}} { + sqlite3 dbat test.db + set s [string map {' ''} $sql] + set t [string map {' ''} $tbl] + sqlite3_db_config dbat DEFENSIVE 0 + dbat eval [subst { + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET sql = '$s' WHERE name = '$t' AND type = 'table'; + PRAGMA writable_schema = 0; + }] + dbat close + set_file_format 2 +} + +# Create bogus application-defined functions for functions used +# internally by ALTER TABLE, to ensure that ALTER TABLE falls back +# to the built-in functions. +# +proc failing_app_func {args} {error "bad function"} +do_test alter2-1.0 { + db func substr failing_app_func + db func like failing_app_func + db func sqlite_rename_table failing_app_func + db func sqlite_rename_trigger failing_app_func + db func sqlite_rename_parent failing_app_func + catchsql {SELECT substr('abcdefg',1,3)} +} {1 {bad function}} + + +#----------------------------------------------------------------------- +# Some basic tests to make sure short rows are handled. +# +sqlite3_db_config db DEFENSIVE 0 +do_test alter2-1.1 { + execsql { + CREATE TABLE abc(a, b); + INSERT INTO abc VALUES(1, 2); + INSERT INTO abc VALUES(3, 4); + INSERT INTO abc VALUES(5, 6); + } +} {} +do_test alter2-1.2 { + # ALTER TABLE abc ADD COLUMN c; + alter_table abc {CREATE TABLE abc(a, b, c);} +} {} +do_test alter2-1.3 { + execsql { + SELECT * FROM abc; + } +} {1 2 {} 3 4 {} 5 6 {}} +do_test alter2-1.4 { + execsql { + UPDATE abc SET c = 10 WHERE a = 1; + SELECT * FROM abc; + } +} {1 2 10 3 4 {} 5 6 {}} +do_test alter2-1.5 { + execsql { + CREATE INDEX abc_i ON abc(c); + } +} {} +do_test alter2-1.6 { + execsql { + SELECT c FROM abc ORDER BY c; + } +} {{} {} 10} +do_test alter2-1.7 { + execsql { + SELECT * FROM abc WHERE c = 10; + } +} {1 2 10} +do_test alter2-1.8 { + execsql { + SELECT sum(a), c FROM abc GROUP BY c; + } +} {8 {} 1 10} +do_test alter2-1.9 { + # ALTER TABLE abc ADD COLUMN d; + alter_table abc {CREATE TABLE abc(a, b, c, d);} + if {[permutation] == "prepare"} { db cache flush } + execsql { SELECT * FROM abc; } + execsql { + UPDATE abc SET d = 11 WHERE c IS NULL AND a<4; + SELECT * FROM abc; + } +} {1 2 10 {} 3 4 {} 11 5 6 {} {}} +do_test alter2-1.10 { + execsql { + SELECT typeof(d) FROM abc; + } +} {null integer null} +do_test alter2-1.99 { + execsql { + DROP TABLE abc; + } +} {} + +#----------------------------------------------------------------------- +# Test that views work when the underlying table structure is changed. +# +ifcapable view { + do_test alter2-2.1 { + execsql { + CREATE TABLE abc2(a, b, c); + INSERT INTO abc2 VALUES(1, 2, 10); + INSERT INTO abc2 VALUES(3, 4, NULL); + INSERT INTO abc2 VALUES(5, 6, NULL); + CREATE VIEW abc2_v AS SELECT * FROM abc2; + SELECT * FROM abc2_v; + } + } {1 2 10 3 4 {} 5 6 {}} + do_test alter2-2.2 { + # ALTER TABLE abc ADD COLUMN d; + alter_table abc2 {CREATE TABLE abc2(a, b, c, d);} + execsql { + SELECT * FROM abc2_v; + } + } {1 2 10 {} 3 4 {} {} 5 6 {} {}} + do_test alter2-2.3 { + execsql { + DROP TABLE abc2; + DROP VIEW abc2_v; + } + } {} +} + +#----------------------------------------------------------------------- +# Test that triggers work when a short row is copied to the old.* +# trigger pseudo-table. +# +ifcapable trigger { + do_test alter2-3.1 { + execsql { + CREATE TABLE abc3(a, b); + CREATE TABLE blog(o, n); + CREATE TRIGGER abc3_t AFTER UPDATE OF b ON abc3 BEGIN + INSERT INTO blog VALUES(old.b, new.b); + END; + } + } {} + do_test alter2-3.2 { + execsql { + INSERT INTO abc3 VALUES(1, 4); + UPDATE abc3 SET b = 2 WHERE b = 4; + SELECT * FROM blog; + } + } {4 2} + do_test alter2-3.3 { + execsql { + INSERT INTO abc3 VALUES(3, 4); + INSERT INTO abc3 VALUES(5, 6); + } + alter_table abc3 {CREATE TABLE abc3(a, b, c);} + execsql { + SELECT * FROM abc3; + } + } {1 2 {} 3 4 {} 5 6 {}} + do_test alter2-3.4 { + execsql { + UPDATE abc3 SET b = b*2 WHERE a<4; + SELECT * FROM abc3; + } + } {1 4 {} 3 8 {} 5 6 {}} + do_test alter2-3.5 { + execsql { + SELECT * FROM blog; + } + } {4 2 2 4 4 8} + + do_test alter2-3.6 { + execsql { + CREATE TABLE clog(o, n); + CREATE TRIGGER abc3_t2 AFTER UPDATE OF c ON abc3 BEGIN + INSERT INTO clog VALUES(old.c, new.c); + END; + UPDATE abc3 SET c = a*2; + SELECT * FROM clog; + } + } {{} 2 {} 6 {} 10} +} else { + execsql { CREATE TABLE abc3(a, b); } +} + +#--------------------------------------------------------------------- +# Check that an error occurs if the database is upgraded to a file +# format that SQLite does not support (in this case 5). Note: The +# file format is checked each time the schema is read, so changing the +# file format requires incrementing the schema cookie. +# +do_test alter2-4.1 { + db close + set_file_format 5 + catch { sqlite3 db test.db } + set {} {} +} {} +do_test alter2-4.2 { + # We have to run two queries here because the Tcl interface uses + # sqlite3_prepare_v2(). In this case, the first query encounters an + # SQLITE_SCHEMA error. Then, when trying to recompile the statement, the + # "unsupported file format" error is encountered. So the error code + # returned is SQLITE_SCHEMA, not SQLITE_ERROR as required by the following + # test case. + # + # When the query is attempted a second time, the same error message is + # returned but the error code is SQLITE_ERROR, because the unsupported + # file format was detected during a call to sqlite3_prepare(), not + # sqlite3_step(). + # + catchsql { SELECT * FROM sqlite_master; } + catchsql { SELECT * FROM sqlite_master; } +} {1 {unsupported file format}} +do_test alter2-4.3 { + sqlite3_errcode db +} {SQLITE_ERROR} +do_test alter2-4.4 { + set ::DB [sqlite3_connection_pointer db] + catchsql { + SELECT * FROM sqlite_master; + } +} {1 {unsupported file format}} +do_test alter2-4.5 { + sqlite3_errcode db +} {SQLITE_ERROR} + +#--------------------------------------------------------------------- +# Check that executing VACUUM on a file with file-format version 2 +# resets the file format to 1. +# +set default_file_format [expr $SQLITE_DEFAULT_FILE_FORMAT==4 ? 4 : 1] +ifcapable vacuum { + do_test alter2-5.1 { + set_file_format 2 + db close + sqlite3 db test.db + execsql {SELECT 1 FROM sqlite_master LIMIT 1;} + get_file_format + } {2} + do_test alter2-5.2 { + execsql { VACUUM } + } {} + do_test alter2-5.3 { + get_file_format + } $default_file_format +} + +#--------------------------------------------------------------------- +# Test that when a database with file-format 2 is opened, new +# databases are still created with file-format 1. +# +do_test alter2-6.1 { + db close + set_file_format 2 + sqlite3 db test.db + get_file_format +} {2} +ifcapable attach { + do_test alter2-6.2 { + forcedelete test2.db-journal + forcedelete test2.db + execsql { + ATTACH 'test2.db' AS aux; + CREATE TABLE aux.t1(a, b); + } + get_file_format test2.db + } $default_file_format +} +do_test alter2-6.3 { + execsql { + CREATE TABLE t1(a, b); + } + get_file_format +} {2} + +#--------------------------------------------------------------------- +# Test that types and values for columns added with default values +# other than NULL work with SELECT statements. +# +do_test alter2-7.1 { + execsql { + DROP TABLE t1; + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(4); + SELECT * FROM t1; + } +} {1 2 3 4} +do_test alter2-7.2 { + set sql {CREATE TABLE t1(a, b DEFAULT '123', c INTEGER DEFAULT '123')} + alter_table t1 $sql 3 + execsql { + SELECT * FROM t1 LIMIT 1; + } +} {1 123 123} +do_test alter2-7.3 { + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer 123 text 123 integer} +do_test alter2-7.4 { + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer 123 text 123 integer} +do_test alter2-7.5 { + set sql {CREATE TABLE t1(a, b DEFAULT -123.0, c VARCHAR(10) default 5)} + alter_table t1 $sql 3 + execsql { + SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1; + } +} {1 integer -123.0 real 5 text} + +#----------------------------------------------------------------------- +# Test that UPDATE trigger tables work with default values, and that when +# a row is updated the default values are correctly transfered to the +# new row. +# +ifcapable trigger { +db function set_val {set ::val} + do_test alter2-8.1 { + execsql { + CREATE TRIGGER trig1 BEFORE UPDATE ON t1 BEGIN + SELECT set_val( + old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c)||' '|| + new.b||' '||typeof(new.b)||' '||new.c||' '||typeof(new.c) + ); + END; + } + list + } {} +} +do_test alter2-8.2 { + execsql { + 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.0 real 10 text} +ifcapable trigger { + do_test alter2-8.3 { + set ::val + } {-123.0 real 5 text -123.0 real 10 text} +} + +#----------------------------------------------------------------------- +# Test that DELETE trigger tables work with default values, and that when +# a row is updated the default values are correctly transfered to the +# new row. +# +ifcapable trigger { + do_test alter2-9.1 { + execsql { + CREATE TRIGGER trig2 BEFORE DELETE ON t1 BEGIN + SELECT set_val( + old.b||' '||typeof(old.b)||' '||old.c||' '||typeof(old.c) + ); + END; + } + list + } {} + do_test alter2-9.2 { + execsql { + DELETE FROM t1 WHERE a = 2; + } + set ::val + } {-123.0 real 5 text} +} + +#----------------------------------------------------------------------- +# Test creating an index on a column added with a default value. +# +ifcapable bloblit { + do_test alter2-10.1 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + INSERT INTO t2 VALUES('c'); + INSERT INTO t2 VALUES('d'); + } + alter_table t2 {CREATE TABLE t2(a, b DEFAULT X'ABCD', c DEFAULT NULL);} 3 + catchsql { + SELECT * FROM sqlite_master; + } + execsql { + SELECT quote(a), quote(b), quote(c) FROM t2 LIMIT 1; + } + } {'a' X'ABCD' NULL} + do_test alter2-10.2 { + execsql { + CREATE INDEX i1 ON t2(b); + SELECT a FROM t2 WHERE b = X'ABCD'; + } + } {a b c d} + do_test alter2-10.3 { + execsql { + DELETE FROM t2 WHERE a = 'c'; + SELECT a FROM t2 WHERE b = X'ABCD'; + } + } {a b d} + do_test alter2-10.4 { + execsql { + SELECT count(b) FROM t2 WHERE b = X'ABCD'; + } + } {3} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth.test new file mode 100644 index 0000000000000000000000000000000000000000..12645b36f0826103413d152eb4943c8bca06bc92 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth.test @@ -0,0 +1,72 @@ +# 2018 September 2 +# +# 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 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} +set testprefix alterauth + +set ::auth [list] +proc xAuth {type args} { + if {$type == "SQLITE_ALTER_TABLE"} { + lappend ::auth [concat $type [lrange $args 0 3]] + } + return SQLITE_OK +} +db auth xAuth + +do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); } + +do_test 1.1 { + set ::auth [list] + execsql { ALTER TABLE t1 RENAME TO t2 } + set ::auth +} {{SQLITE_ALTER_TABLE main t1 {} {}}} + +do_test 1.2 { + set ::auth [list] + execsql { ALTER TABLE t2 RENAME c TO ccc } + set ::auth +} {{SQLITE_ALTER_TABLE main t2 {} {}}} + +do_test 1.3 { + set ::auth [list] + execsql { ALTER TABLE t2 ADD COLUMN d } + set ::auth +} {{SQLITE_ALTER_TABLE main t2 {} {}}} + +proc xAuth {type args} { + if {$type == "SQLITE_ALTER_TABLE"} { + return SQLITE_DENY + } + return SQLITE_OK +} + +do_test 2.1 { + catchsql { ALTER TABLE t2 RENAME TO t3 } +} {1 {not authorized}} + +do_test 2.2 { + catchsql { ALTER TABLE t2 RENAME d TO ddd } +} {1 {not authorized}} + +do_test 2.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e } +} {1 {not authorized}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth2.test new file mode 100644 index 0000000000000000000000000000000000000000..6f9242d364ea249c156862d0ef873c94e2d53d92 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterauth2.test @@ -0,0 +1,119 @@ +# 2018 October 6 +# +# 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 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} +set testprefix alterauth2 + +set ::auth [list] +proc xAuth {type args} { + lappend ::auth [concat $type [lrange $args 0 3]] + if {$type=="SQLITE_READ" && [lindex $args 0] == "t2"} breakpoint + return SQLITE_OK +} +db auth xAuth + +proc do_auth_test {tn sql authcode} { + set script " + set ::auth \[list\] + execsql {$sql} + lsort -unique \[set ::auth\] + " + + set normal [list {*}$authcode] + uplevel [list do_test $tn $script $normal] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + DELETE FROM t1 WHERE a0} + {{CREATE TABLE t1(a, d, c)} {CREATE INDEX t1i ON t1(d+d+d+d, c) WHERE d>0}} + + 13 {CREATE TABLE t1(a, b, c, FOREIGN KEY (b) REFERENCES t2)} + {CREATE TABLE t1(a, d, c, FOREIGN KEY (d) REFERENCES t2)} + + 14 {CREATE TABLE t1(a INTEGER, b TEXT, c BLOB, PRIMARY KEY(b))} + {CREATE TABLE t1(a INTEGER, d TEXT, c BLOB, PRIMARY KEY(d))} + + 15 {CREATE TABLE t1(a INTEGER, b INTEGER, c BLOB, PRIMARY KEY(b))} + {CREATE TABLE t1(a INTEGER, d INTEGER, c BLOB, PRIMARY KEY(d))} + + 16 {CREATE TABLE t1(a INTEGER, b INTEGER PRIMARY KEY, c BLOB)} + {CREATE TABLE t1(a INTEGER, d INTEGER PRIMARY KEY, c BLOB)} + + 17 {CREATE TABLE t1(a INTEGER, b INTEGER PRIMARY KEY, c BLOB, FOREIGN KEY (b) REFERENCES t2)} + {CREATE TABLE t1(a INTEGER, d INTEGER PRIMARY KEY, c BLOB, FOREIGN KEY (d) REFERENCES t2)} + +} { + reset_db + do_execsql_test 1.$tn.0 $before + + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES(1, 2, 3); + } + + do_execsql_test 1.$tn.2 { + ALTER TABLE t1 RENAME COLUMN b TO d; + } + + do_execsql_test 1.$tn.3 { + SELECT * FROM t1; + } {1 2 3} + + if {[string first INDEX $before]>0} { + set res $after + } else { + set res [list $after] + } + do_execsql_test 1.$tn.4 { + SELECT sql FROM sqlite_master WHERE tbl_name='t1' AND sql!='' + } $res +} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.0 { + CREATE TABLE t3(a, b, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (b, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4); +} + +sqlite3 db2 test.db +do_execsql_test -db db2 2.1 { SELECT b FROM t3 } + +do_execsql_test 2.2 { + ALTER TABLE t3 RENAME b TO biglongname; + SELECT sql FROM sqlite_master WHERE name='t3'; +} {{CREATE TABLE t3(a, biglongname, c, d, e, f, g, h, i, j, k, l, m, FOREIGN KEY (biglongname, c, d, e, f, g, h, i, j, k, l, m) REFERENCES t4)}} + +do_execsql_test -db db2 2.3 { SELECT biglongname FROM t3 } + +#------------------------------------------------------------------------- +# +do_execsql_test 3.0 { + CREATE TABLE t4(x, y, z); + CREATE TRIGGER ttt AFTER INSERT ON t4 WHEN new.y<0 BEGIN + SELECT x, y, z FROM t4; + DELETE FROM t4 WHERE y=32; + UPDATE t4 SET x=y+1, y=0 WHERE y=32; + INSERT INTO t4(x, y, z) SELECT 4, 5, 6 WHERE 0; + END; + INSERT INTO t4 VALUES(3, 2, 1); +} + +do_execsql_test 3.1 { + ALTER TABLE t4 RENAME y TO abc; + SELECT sql FROM sqlite_master WHERE name='t4'; +} {{CREATE TABLE t4(x, abc, z)}} + +do_execsql_test 3.2 { + SELECT * FROM t4; +} {3 2 1} + +do_execsql_test 3.3 { INSERT INTO t4 VALUES(6, 5, 4); } {} + +do_execsql_test 3.4 { SELECT sql FROM sqlite_master WHERE type='trigger' } { +{CREATE TRIGGER ttt AFTER INSERT ON t4 WHEN new.abc<0 BEGIN + SELECT x, abc, z FROM t4; + DELETE FROM t4 WHERE abc=32; + UPDATE t4 SET x=abc+1, abc=0 WHERE abc=32; + INSERT INTO t4(x, abc, z) SELECT 4, 5, 6 WHERE 0; + END} +} + +#------------------------------------------------------------------------- +# +do_execsql_test 4.0 { + CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, d)); + CREATE TABLE p1(c, d, PRIMARY KEY(c, d)); + PRAGMA foreign_keys = 1; + INSERT INTO p1 VALUES(1, 2); + INSERT INTO p1 VALUES(3, 4); +} + +do_execsql_test 4.1 { + ALTER TABLE p1 RENAME d TO "silly name"; + SELECT sql FROM sqlite_master WHERE name IN ('c1', 'p1'); +} { + {CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, "silly name"))} + {CREATE TABLE p1(c, "silly name", PRIMARY KEY(c, "silly name"))} +} + +do_execsql_test 4.2 { INSERT INTO c1 VALUES(1, 2); } + +do_execsql_test 4.3 { + CREATE TABLE c2(a, b, FOREIGN KEY (a, b) REFERENCES p1); +} + +do_execsql_test 4.4 { + ALTER TABLE p1 RENAME "silly name" TO reasonable; + SELECT sql FROM sqlite_master WHERE name IN ('c1', 'c2', 'p1'); +} { + {CREATE TABLE c1(a, b, FOREIGN KEY (a, b) REFERENCES p1(c, "reasonable"))} + {CREATE TABLE p1(c, "reasonable", PRIMARY KEY(c, "reasonable"))} + {CREATE TABLE c2(a, b, FOREIGN KEY (a, b) REFERENCES p1)} +} + +#------------------------------------------------------------------------- + +do_execsql_test 5.0 { + CREATE TABLE t5(a, b, c); + CREATE INDEX t5a ON t5(a); + INSERT INTO t5 VALUES(1, 2, 3), (4, 5, 6); + ANALYZE; +} + +do_execsql_test 5.1 { + ALTER TABLE t5 RENAME b TO big; + SELECT big FROM t5; +} {2 5} + +do_catchsql_test 6.1 { + ALTER TABLE sqlite_stat1 RENAME tbl TO thetable; +} {1 {table sqlite_stat1 may not be altered}} + +#------------------------------------------------------------------------- +# +do_execsql_test 6.0 { + CREATE TABLE blob( + rid INTEGER PRIMARY KEY, + rcvid INTEGER, + size INTEGER, + uuid TEXT UNIQUE NOT NULL, + content BLOB, + CHECK( length(uuid)>=40 AND rid>0 ) + ); +} + +do_execsql_test 6.1 { + ALTER TABLE "blob" RENAME COLUMN "rid" TO "a1"; +} + +do_catchsql_test 6.2 { + ALTER TABLE "blob" RENAME COLUMN "a1" TO [where]; +} {0 {}} + +do_execsql_test 6.3 { + SELECT "where" FROM blob; +} {} + +#------------------------------------------------------------------------- +# Triggers. +# +db close +db2 close +reset_db +do_execsql_test 7.0 { + CREATE TABLE c(x); + INSERT INTO c VALUES(0); + CREATE TABLE t6("col a", "col b", "col c"); + CREATE TRIGGER zzz AFTER UPDATE OF "col a", "col c" ON t6 BEGIN + UPDATE c SET x=x+1; + END; +} + +do_execsql_test 7.1.1 { + INSERT INTO t6 VALUES(0, 0, 0); + UPDATE t6 SET "col c" = 1; + SELECT * FROM c; +} {1} + +do_execsql_test 7.1.2 { + ALTER TABLE t6 RENAME "col c" TO "col 3"; +} + +do_execsql_test 7.1.3 { + UPDATE t6 SET "col 3" = 0; + SELECT * FROM c; +} {2} + +#------------------------------------------------------------------------- +# Views. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE a1(x INTEGER, y TEXT, z BLOB, PRIMARY KEY(x)); + CREATE TABLE a2(a, b, c); + CREATE VIEW v1 AS SELECT x, y, z FROM a1; +} + +do_execsql_test 8.1 { + ALTER TABLE a1 RENAME y TO yyy; + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v1 AS SELECT x, yyy, z FROM a1}} + +do_execsql_test 8.2.1 { + DROP VIEW v1; + CREATE VIEW v2 AS SELECT x, x+x, a, a+a FROM a1, a2; +} {} +do_execsql_test 8.2.2 { + ALTER TABLE a1 RENAME x TO xxx; +} +do_execsql_test 8.2.3 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v2 AS SELECT xxx, xxx+xxx, a, a+a FROM a1, a2}} + +do_execsql_test 8.3.1 { + DROP TABLE a2; + DROP VIEW v2; + CREATE TABLE a2(a INTEGER PRIMARY KEY, b, c); + CREATE VIEW v2 AS SELECT xxx, xxx+xxx, a, a+a FROM a1, a2; +} {} +do_execsql_test 8.3.2 { + ALTER TABLE a1 RENAME xxx TO x; +} +do_execsql_test 8.3.3 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW v2 AS SELECT x, x+x, a, a+a FROM a1, a2}} + +do_execsql_test 8.4.0 { + CREATE TABLE b1(a, b, c); + CREATE TABLE b2(x, y, z); +} + +do_execsql_test 8.4.1 { + CREATE VIEW vvv AS SELECT c+c || coalesce(c, c) FROM b1, b2 WHERE x=c GROUP BY c HAVING c>0; + ALTER TABLE b1 RENAME c TO "a;b"; + SELECT sql FROM sqlite_master WHERE name='vvv'; +} {{CREATE VIEW vvv AS SELECT "a;b"+"a;b" || coalesce("a;b", "a;b") FROM b1, b2 WHERE x="a;b" GROUP BY "a;b" HAVING "a;b">0}} + +do_execsql_test 8.4.2 { + CREATE VIEW www AS SELECT b FROM b1 UNION ALL SELECT y FROM b2; + ALTER TABLE b1 RENAME b TO bbb; + SELECT sql FROM sqlite_master WHERE name='www'; +} {{CREATE VIEW www AS SELECT bbb FROM b1 UNION ALL SELECT y FROM b2}} + +db collate nocase {string compare} + +do_execsql_test 8.4.3 { + CREATE VIEW xxx AS SELECT a FROM b1 UNION SELECT x FROM b2 ORDER BY 1 COLLATE nocase; +} + +do_execsql_test 8.4.4 { + ALTER TABLE b2 RENAME x TO hello; + SELECT sql FROM sqlite_master WHERE name='xxx'; +} {{CREATE VIEW xxx AS SELECT a FROM b1 UNION SELECT hello FROM b2 ORDER BY 1 COLLATE nocase}} + +do_catchsql_test 8.4.5 { + CREATE VIEW zzz AS SELECT george, ringo FROM b1; + ALTER TABLE b1 RENAME a TO aaa; +} {1 {error in view zzz: no such column: george}} + +do_execsql_test 8.5 { + DROP VIEW zzz; + CREATE TABLE t5(a TEXT, b INT); + INSERT INTO t5(a,b) VALUES('aaa',7),('bbb',3),('ccc',4); + CREATE VIEW vt5(x) AS SELECT group_concat(a ORDER BY b) FROM t5; + SELECT x FROM vt5; +} {bbb,ccc,aaa} +do_execsql_test 8.5.1 { + ALTER TABLE t5 RENAME COLUMN b TO bbb; + SELECT sql FROM sqlite_schema WHERE name='vt5'; +} {{CREATE VIEW vt5(x) AS SELECT group_concat(a ORDER BY bbb) FROM t5}} +do_execsql_test 8.5.2 { + SELECT x FROM vt5; +} {bbb,ccc,aaa} + +#------------------------------------------------------------------------- +# More triggers. +# +proc do_rename_column_test {tn old new lSchema} { + for {set i 0} {$i < 2} {incr i} { + drop_all_tables_and_views db + + set lSorted [list] + foreach sql $lSchema { + execsql $sql + lappend lSorted [string trim $sql] + } + set lSorted [lsort $lSorted] + + do_execsql_test $tn.$i.1 { + SELECT sql FROM sqlite_master WHERE sql!='' ORDER BY 1 + } $lSorted + + if {$i==1} { + db close + sqlite3 db test.db + } + + do_execsql_test $tn.$i.2 "ALTER TABLE t1 RENAME $old TO $new" + + do_execsql_test $tn.$i.3 { + SELECT sql FROM sqlite_master ORDER BY 1 + } [string map [list $old $new] $lSorted] + } +} + +foreach {tn old new lSchema} { + 1 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT _x_ FROM t1; + END } + } + + 2 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE TABLE t2(c, d, e) } + { CREATE TRIGGER ttt AFTER INSERT ON t2 BEGIN + SELECT _x_ FROM t1; + END } + } + + 3 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TABLE t2(c, d, e) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b, new._x_); + END } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t1 VALUES(new.a, new.b, new._x_) + ON CONFLICT (_x_) WHERE _x_>10 DO UPDATE SET _x_ = _x_+1; + END } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_ INTEGER, PRIMARY KEY(_x_), CHECK(_x_>0)) } + { CREATE TRIGGER ttt AFTER UPDATE ON t1 BEGIN + INSERT INTO t1 VALUES(new.a, new.b, new._x_) + ON CONFLICT (_x_) WHERE _x_>10 DO NOTHING; + END } + } +} { + do_rename_column_test 9.$tn $old $new $lSchema +} + +#------------------------------------------------------------------------- +# Test that views can be edited even if there are missing collation +# sequences or user defined functions. +# +reset_db + +ifcapable vtab { + foreach {tn old new lSchema} { + 1 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW s1 AS SELECT a, b, _x_ FROM t1 WHERE _x_='abc' COLLATE xyz } + } + + 2 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE scalar(_x_) } + } + + 3 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIEW v1 AS SELECT a, b, _x_ FROM t1 WHERE _x_ = unicode(1, 2, 3) } + } + + 4 _x_ _xxx_ { + { CREATE TABLE t1(a, b, _x_) } + { CREATE VIRTUAL TABLE e1 USING echo(t1) } + } + } { + register_echo_module db + do_rename_column_test 10.$tn $old $new $lSchema + } + + #-------------------------------------------------------------------------- + # Test that if a view or trigger refers to a virtual table for which the + # module is not available, RENAME COLUMN cannot proceed. + # + reset_db + register_echo_module db + do_execsql_test 11.0 { + CREATE TABLE x1(a, b, c); + CREATE VIRTUAL TABLE e1 USING echo(x1); + } + db close + sqlite3 db test.db + + do_execsql_test 11.1 { + ALTER TABLE x1 RENAME b TO bbb; + SELECT sql FROM sqlite_master; + } { {CREATE TABLE x1(a, bbb, c)} {CREATE VIRTUAL TABLE e1 USING echo(x1)} } + + do_execsql_test 11.2 { + CREATE VIEW v1 AS SELECT e1.*, x1.c FROM e1, x1; + } + + do_catchsql_test 11.3 { + ALTER TABLE x1 RENAME c TO ccc; + } {1 {error in view v1: no such module: echo}} +} + +#------------------------------------------------------------------------- +# Test some error conditions: +# +# 1. Renaming a column of a system table, +# 2. Renaming a column of a VIEW, +# 3. Renaming a column of a virtual table. +# 4. Renaming a column that does not exist. +# 5. Renaming a column of a table that does not exist. +# +reset_db +do_execsql_test 12.1.1 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a); + INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 4); + ANALYZE; +} +do_catchsql_test 12.1.2 { + ALTER TABLE sqlite_stat1 RENAME idx TO theindex; +} {1 {table sqlite_stat1 may not be altered}} +do_execsql_test 12.1.3 { + SELECT sql FROM sqlite_master WHERE tbl_name = 'sqlite_stat1' +} {{CREATE TABLE sqlite_stat1(tbl,idx,stat)}} + +do_execsql_test 12.2.1 { + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE VIEW v2(c, d) AS SELECT * FROM t1; +} +do_catchsql_test 12.2.2 { + ALTER TABLE v1 RENAME a TO z; +} {1 {cannot rename columns of view "v1"}} +do_catchsql_test 12.2.3 { + ALTER TABLE v2 RENAME c TO y; +} {1 {cannot rename columns of view "v2"}} + +ifcapable fts5 { + do_execsql_test 12.3.1 { + CREATE VIRTUAL TABLE ft USING fts5(a, b, c); + } + do_catchsql_test 12.3.2 { + ALTER TABLE ft RENAME a TO z; + } {1 {cannot rename columns of virtual table "ft"}} +} + +do_execsql_test 12.4.1 { + CREATE TABLE t2(x, y, z); +} +do_catchsql_test 12.4.2 { + ALTER TABLE t2 RENAME COLUMN a TO b; +} {1 {no such column: "a"}} + +do_catchsql_test 12.5.1 { + ALTER TABLE t3 RENAME COLUMN a TO b; +} {1 {no such table: t3}} + +#------------------------------------------------------------------------- +# Test the effect of some parse/resolve errors. +# +reset_db +do_execsql_test 13.1.1 { + CREATE TABLE x1(i INTEGER, t TEXT UNIQUE); + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + SELECT * FROM nosuchtable; + END; +} + +do_catchsql_test 13.1.2 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in trigger tr1: no such table: main.nosuchtable}} + +do_execsql_test 13.1.3 { + DROP TRIGGER tr1; + CREATE INDEX x1i ON x1(i); + SELECT sql FROM sqlite_master WHERE name='x1i'; +} {{CREATE INDEX x1i ON x1(i)}} + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 13.1.4 { + PRAGMA writable_schema = ON; + UPDATE sqlite_master SET sql = 'CREATE INDEX x1i ON x1(j)' WHERE name='x1i'; + PRAGMA writable_schema = OFF; +} {} + +do_catchsql_test 13.1.5 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in index x1i: no such column: j}} + +do_execsql_test 13.1.6 { + PRAGMA writable_schema = ON; + UPDATE sqlite_master SET sql = '' WHERE name='x1i'; + PRAGMA writable_schema = OFF; +} {} + +do_catchsql_test 13.1.7 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; +} {1 {error in index x1i: }} + +do_execsql_test 13.1.8 { + PRAGMA writable_schema = ON; + DELETE FROM sqlite_master WHERE name = 'x1i'; + PRAGMA writable_schema = OFF; +} + +do_execsql_test 13.2.0 { + CREATE TABLE data(x UNIQUE, y, z); +} +foreach {tn trigger error} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + UPDATE data SET x=x+1 WHERE zzz=new.i; + END; + } {no such column: zzz} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO data(x, y) VALUES(new.i, new.t, 1) + ON CONFLICT (x) DO UPDATE SET z=zz+1; + END; + } {no such column: zz} + + 3 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO x1(i, t) VALUES(new.i+1, new.t||'1') + ON CONFLICT (tttttt) DO UPDATE SET t=i+1; + END; + } {no such column: tttttt} + + 4 { + CREATE TRIGGER tr1 AFTER INSERT ON x1 BEGIN + INSERT INTO nosuchtable VALUES(new.i, new.t); + END; + } {no such table: main.nosuchtable} +} { + do_execsql_test 13.2.$tn.1 " + DROP TRIGGER IF EXISTS tr1; + $trigger + " + + do_catchsql_test 13.2.$tn.2 { + ALTER TABLE x1 RENAME COLUMN t TO ttt; + } "1 {error in trigger tr1: $error}" +} + +#------------------------------------------------------------------------- +# Passing invalid parameters directly to sqlite_rename_column(). +# +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_execsql_test 14.1 { + CREATE TABLE ddd(sql, type, object, db, tbl, icol, znew, bquote); + INSERT INTO ddd VALUES( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'x1', -1, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'x1', 2, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'notable', 0, 'zzz', 0 + ), ( + 'CREATE TABLE x1(i INTEGER, t TEXT)', + 'table', 'x1', 'main', 'ddd', -1, 'zzz', 0 + ); +} {} + +do_execsql_test 14.2 { + SELECT + sqlite_rename_column(sql, type, object, db, tbl, icol, znew, bquote, 0) + FROM ddd; +} {{} {} {} {}} +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + +# If the INTERNAL_FUNCTIONS test-control is disabled (which is the default) +# then the sqlite_rename_table() SQL function is not accessible to +# ordinary SQL. +# +do_catchsql_test 14.3 { + SELECT sqlite_rename_column(0,0,0,0,0,0,0,0,0); +} {1 {no such function: sqlite_rename_column}} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 15.0 { + CREATE TABLE xxx(a, b, c); + SELECT a AS d FROM xxx WHERE d=0; +} + +do_execsql_test 15.1 { + CREATE VIEW vvv AS SELECT a AS d FROM xxx WHERE d=0; + ALTER TABLE xxx RENAME a TO xyz; +} + +do_execsql_test 15.2 { + SELECT sql FROM sqlite_master WHERE type='view'; +} {{CREATE VIEW vvv AS SELECT xyz AS d FROM xxx WHERE d=0}} + +#------------------------------------------------------------------------- +# +do_execsql_test 16.1.0 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(d,e,f); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t2 VALUES(4,5,6); + CREATE VIEW v4 AS SELECT a, d FROM t1, t2; + SELECT * FROM v4; +} {1 4} + +do_catchsql_test 16.1.1 { + ALTER TABLE t2 RENAME d TO a; +} {1 {error in view v4 after rename: ambiguous column name: a}} + +do_execsql_test 16.1.2 { + SELECT * FROM v4; +} {1 4} + +do_execsql_test 16.1.3 { + CREATE UNIQUE INDEX t2d ON t2(d); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b, new.c) + ON CONFLICT(d) DO UPDATE SET f = excluded.f; + END; +} + +do_execsql_test 16.1.4 { + INSERT INTO t1 VALUES(4, 8, 456); + SELECT * FROM t2; +} {4 5 456} + +do_execsql_test 16.1.5 { + ALTER TABLE t2 RENAME COLUMN f TO "big f"; + INSERT INTO t1 VALUES(4, 0, 20456); + SELECT * FROM t2; +} {4 5 20456} + +do_execsql_test 16.1.6 { + ALTER TABLE t1 RENAME COLUMN c TO "big c"; + INSERT INTO t1 VALUES(4, 0, 0); + SELECT * FROM t2; +} {4 5 0} + +do_execsql_test 16.2.1 { + CREATE VIEW temp.v5 AS SELECT "big c" FROM t1; + SELECT * FROM v5; +} {3 456 20456 0} + +do_execsql_test 16.2.2 { + ALTER TABLE t1 RENAME COLUMN "big c" TO reallybigc; +} {} + +do_execsql_test 16.2.3 { + SELECT * FROM v5; +} {3 456 20456 0} + +#------------------------------------------------------------------------- +# +do_execsql_test 17.0 { + CREATE TABLE u7(x, y, z); + CREATE TRIGGER u7t AFTER INSERT ON u7 BEGIN + INSERT INTO u8 VALUES(new.x, new.y, new.z); + END; +} {} +do_catchsql_test 17.1 { + ALTER TABLE u7 RENAME x TO xxx; +} {1 {error in trigger u7t: no such table: main.u8}} + +do_execsql_test 17.2 { + CREATE TEMP TABLE uu7(x, y, z); + CREATE TRIGGER uu7t AFTER INSERT ON uu7 BEGIN + INSERT INTO u8 VALUES(new.x, new.y, new.z); + END; +} {} +do_catchsql_test 17.3 { + ALTER TABLE uu7 RENAME x TO xxx; +} {1 {error in trigger uu7t: no such table: u8}} + +reset_db +forcedelete test.db2 +do_execsql_test 18.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a); + CREATE TABLE aux.log(v); + CREATE TEMP TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES(new.a); + END; + INSERT INTO t1 VALUES(111); + SELECT v FROM log; +} {111} + +do_execsql_test 18.1 { + ALTER TABLE t1 RENAME a TO b; +} + +reset_db +do_execsql_test 19.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.a) FROM t1, t2 WHERE t1.b=t2.d; +} + +do_execsql_test 19.1 { + ALTER TABLE t1 RENAME a TO f; + SELECT sql FROM sqlite_master WHERE name = 'v2'; +} { + {CREATE VIEW v2(e) AS SELECT coalesce(t2.c,t1.f) FROM t1, t2 WHERE t1.b=t2.d} +} + +# 2019-01-08: https://www.sqlite.org/src/tktview/bc8d94f0fbd633fd9a051e3 +# +# ALTER TABLE RENAME COLUMN does not work for tables that have redundant +# UNIQUE constraints. +# +sqlite3 db :memory: +do_execsql_test 20.100 { + CREATE TABLE t1(aaa,b,c,UNIQUE(aaA),PRIMARY KEY(aAa),UNIQUE(aAA)); + ALTER TABLE t1 RENAME aaa TO bbb; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(bbb,b,c,UNIQUE(bbb),PRIMARY KEY(bbb),UNIQUE(bbb))}} +do_execsql_test 20.105 { + DROP TABLE t1; + CREATE TABLE t1(aaa,b,c,UNIQUE(aaA),PRIMARY KEY(aAa),UNIQUE(aAA))WITHOUT ROWID; + ALTER TABLE t1 RENAME aaa TO bbb; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(bbb,b,c,UNIQUE(bbb),PRIMARY KEY(bbb),UNIQUE(bbb))WITHOUT ROWID}} +do_execsql_test 20.110 { + DROP TABLE t1; + CREATE TABLE t1(aa UNIQUE,bb UNIQUE,cc UNIQUE,UNIQUE(aA),PRIMARY KEY(bB),UNIQUE(cC)); + ALTER TABLE t1 RENAME aa TO xx; + ALTER TABLE t1 RENAME bb TO yy; + ALTER TABLE t1 RENAME cc TO zz; + SELECT sql FROM sqlite_master WHERE name='t1'; +} {{CREATE TABLE t1(xx UNIQUE,yy UNIQUE,zz UNIQUE,UNIQUE(xx),PRIMARY KEY(yy),UNIQUE(zz))}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 21.0 { + CREATE TABLE t1(a, b, c NOT NULL); + CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.c IS NOT NULL BEGIN + SELECT c NOT NULL FROM t1; + END; +} + +do_execsql_test 21.1 { + ALTER TABLE t1 RENAME c TO d; +} + +do_execsql_test 21.2 { + SELECT sql FROM sqlite_schema WHERE name IS 'tr1' +} {{CREATE TRIGGER tr1 AFTER INSERT ON t1 WHEN new.d IS NOT NULL BEGIN + SELECT d NOT NULL FROM t1; + END} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 22.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, othername, extra AS (c + 1)); + ALTER TABLE t1 RENAME a to othername; + SELECT sql FROM sqlite_schema; +} { + {CREATE TABLE t1(othername, b)} + {CREATE TABLE t2(c, othername, extra AS (c + 1))} +} + +#------------------------------------------------------------------------- +# +reset_db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test 22.0 { + CREATE TABLE t1(a, b); + CREATE INDEX x1 on t1("c"=b); + INSERT INTO t1 VALUES('a', 'a'); + INSERT INTO t1 VALUES('b', 'b'); + INSERT INTO t1 VALUES('c', 'c'); + ALTER TABLE t1 RENAME COLUMN a TO "c"; + PRAGMA integrity_check; +} {ok} + +reset_db +do_execsql_test 23.0 { + CREATE TABLE t1('a'"b",c); + CREATE INDEX i1 ON t1('a'); + INSERT INTO t1 VALUES(1,2), (3,4); + ALTER TABLE t1 RENAME COLUMN a TO x; + PRAGMA integrity_check; + SELECT sql FROM sqlite_schema WHERE name='t1'; + +} {ok {CREATE TABLE t1("x" "b",c)}} + +# 2022-02-04 +# Do not complain about syntax errors in the schema if +# in PRAGMA writable_schema=ON mode. +# +reset_db +do_execsql_test 23.0 { + CREATE TABLE t1(a INT, b REAL, c TEXT, d BLOB, e ANY); + CREATE INDEX t1abx ON t1(a, b, a+b) WHERE c IS NOT NULL; + CREATE VIEW t2 AS SELECT a+10, b*5.0, xyz FROM t1; -- unknown column "xyz" + CREATE TABLE schema_copy(name TEXT, sql TEXT); + INSERT INTO schema_copy(name,sql) SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL; +} {} +do_catchsql_test 23.1 { + ALTER TABLE t1 RENAME COLUMN e TO eeee; +} {1 {error in view t2: no such column: xyz}} +do_execsql_test 23.2 { + SELECT name, sql FROM sqlite_master + EXCEPT SELECT name, sql FROM schema_copy; +} {} +do_execsql_test 23.3 { + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t1 RENAME COLUMN e TO eeee; + PRAGMA writable_schema=OFF; + SELECT name FROM sqlite_master + WHERE (name, sql) NOT IN (SELECT name, sql FROM schema_copy); + ROLLBACK; +} {t1} +do_execsql_test 23.10 { + DROP VIEW t2; + CREATE TRIGGER r3 AFTER INSERT ON t1 BEGIN + INSERT INTO t3(x,y) VALUES(new.a, new.b); + INSERT INTO t4(p) VALUES(new.c); -- no such table "t4" + END; + DELETE FROM schema_copy; + INSERT INTO schema_copy(name,sql) SELECT name, sql FROM sqlite_schema WHERE sql IS NOT NULL; +} {} +do_catchsql_test 23.11 { + ALTER TABLE t1 RENAME COLUMN e TO eeee; +} {1 {error in trigger r3: no such table: main.t3}} +do_execsql_test 23.12 { + SELECT name, sql FROM sqlite_master + EXCEPT SELECT name, sql FROM schema_copy; +} {} +do_execsql_test 23.13 { + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t1 RENAME COLUMN e TO eeee; + PRAGMA writable_schema=OFF; + SELECT name FROM sqlite_master + WHERE (name, sql) NOT IN (SELECT name, sql FROM schema_copy); + ROLLBACK; +} {t1} +do_execsql_test 23.20 { + CREATE TABLE t4(id INTEGER PRIMARY KEY, c1 INT, c2 INT); + CREATE VIEW t4v1 AS SELECT id, c1, c99 FROM t4; + DELETE FROM schema_copy; + INSERT INTO schema_copy SELECT name, sql FROM sqlite_schema; + BEGIN; + PRAGMA writable_schema=ON; + ALTER TABLE t4 RENAME to t4new; + SELECT name FROM sqlite_schema WHERE (name,sql) NOT IN (SELECT * FROM schema_copy); + ROLLBACK; +} {t4new} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/altercorrupt.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/altercorrupt.test new file mode 100644 index 0000000000000000000000000000000000000000..f24cb309a33b71281f8ace482f7a99202ffe39f3 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/altercorrupt.test @@ -0,0 +1,181 @@ +# 2019-01-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 altercorrupt + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +database_may_be_corrupt + +#-------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 24576 pagesize 4096 filename crash-685346d89b5e5f.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 06 .....@ ........ +| 32: 00 00 63 00 00 05 f0 00 00 00 00 04 10 00 00 04 ..c............. +| 48: 00 00 00 00 00 00 0f f0 00 00 00 01 00 00 00 00 ................ +| 64: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 05 0e cf 00 0f 79 0f d3 .............y.. +| 112: 0f 2e 0e f3 0e cf 00 00 00 00 00 00 00 00 00 00 ................ +| 3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 ................ +| 3792: 05 06 17 11 11 01 31 74 61 62 6c 65 74 34 74 34 ......1tablet4t4 +| 3808: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 34 .CREATE TABLE t4 +| 3824: 28 7a 29 39 04 06 17 11 11 01 5f 74 61 62 6c 65 (z)9......_table +| 3840: 74 33 74 33 05 43 52 45 41 54 45 20 54 41 42 4c t3t3.CREATE TABL +| 3856: 45 20 74 33 28 78 20 49 4e 54 45 47 45 52 20 50 E t3(x INTEGER P +| 3872: 52 49 4d 41 52 59 20 4b 45 59 2c 20 79 29 49 03 RIMARY KEY, y)I. +| 3888: 06 17 11 11 01 7f 74 61 62 6c 65 74 32 74 32 04 ......tablet2t2. +| 3904: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 28 CREATE TABLE t2( +| 3920: 61 2c 62 2c 63 20 50 52 49 4d 41 52 59 20 4b 45 a,b,c PRIMARY KE +| 3936: 59 2c 20 64 2c 20 65 2c 20 66 29 20 57 49 54 48 Y, d, e, f) WITH +| 3952: 4f 55 54 20 52 4f 57 49 44 58 03 07 17 11 11 01 OUT ROWIDX...... +| 3968: 81 1b 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 ..tablet1t1.CREA +| 3984: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 2c TE TABLE t1(a,b, +| 4000: 63 20 41 53 20 28 2d 62 29 20 56 49 52 54 55 41 c AS (-b) VIRTUA +| 4016: 4c 2c 64 20 43 48 45 43 4b 28 64 3e 35 29 2c 65 L,d CHECK(d>5),e +| 4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b UNIQUE, f AS (+ +| 4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b))#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 03 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5 ................ +| 16: 0f ca 0f 8f 0f b4 0f a9 0f 9e 0f 93 00 00 00 00 ................ +| 3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09 ...........dn... +| 4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 01 01 01 ......Zm........ +| 4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09 .Pl.........Fk.. +| 4032: 06 05 01 01 01 01 06 3c 6a 0c 09 05 05 01 01 01 .......5),e +| 4032: 20 55 4e 49 51 55 45 2c 20 66 20 41 53 20 28 2b UNIQUE, f AS (+ +| 4048: 62 29 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b))#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 84 31 03 01 00 00 08 00 00 00 00 _t1_1.1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0f 93 00 0f f6 0f eb 0f e0 0f d5 ................ +| 16: 0f ca 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3984: 00 00 00 09 0a 05 01 01 01 01 0a 64 6e 14 09 09 ...........dn... +| 4000: 05 01 01 01 01 09 5a 6d 12 09 08 05 01 00 f1 01 ......Zm........ +| 4016: 08 50 6c 10 09 07 05 01 01 01 01 07 46 6b 0e 09 .Pl.........Fk.. +| 4032: 06 05 01 00 f1 01 06 3c 6a 0c 09 05 05 01 01 01 .......10)); + CREATE TABLE t13(a, b, c CHECK(c>10)); +} +do_catchsql_test 3.1 { + ALTER TABLE t12 DROP COLUMN c; +} {1 {error in table t12 after drop column: no such column: c}} + +do_catchsql_test 3.2 { + ALTER TABLE t13 DROP COLUMN c; +} {0 {}} + +#------------------------------------------------------------------------- +# Test that generated columns can be dropped. And that other columns from +# tables that contain generated columns can be dropped. +# +foreach {tn wo vs} { + 1 "" "" + 2 "" VIRTUAL + 3 "" STORED + 4 "WITHOUT ROWID" STORED + 5 "WITHOUT ROWID" VIRTUAL +} { + reset_db + + do_execsql_test 4.$tn.0 " + CREATE TABLE 'my table'(a, b PRIMARY KEY, c AS (a+b) $vs, d) $wo + " + do_execsql_test 4.$tn.1 { + INSERT INTO "my table"(a, b, d) VALUES(1, 2, 'hello'); + INSERT INTO "my table"(a, b, d) VALUES(3, 4, 'world'); + + SELECT * FROM "my table" + } { + 1 2 3 hello + 3 4 7 world + } + + do_execsql_test 4.$tn.2 { + ALTER TABLE "my table" DROP COLUMN c; + } + do_execsql_test 4.$tn.3 { + SELECT * FROM "my table" + } { + 1 2 hello + 3 4 world + } + + do_execsql_test 4.$tn.4 " + CREATE TABLE x1(a, b, c PRIMARY KEY, d AS (b+c) $vs, e) $wo + " + do_execsql_test 4.$tn.5 { + INSERT INTO x1(a, b, c, e) VALUES(1, 2, 3, 4); + INSERT INTO x1(a, b, c, e) VALUES(5, 6, 7, 8); + INSERT INTO x1(a, b, c, e) VALUES(9, 10, 11, 12); + SELECT * FROM x1; + } { + 1 2 3 5 4 + 5 6 7 13 8 + 9 10 11 21 12 + } + + do_execsql_test 4.$tn.6 { + ALTER TABLE x1 DROP COLUMN a + } + do_execsql_test 4.$tn.7 { + SELECT * FROM x1 + } { + 2 3 5 4 + 6 7 13 8 + 10 11 21 12 + } + do_execsql_test 4.$tn.8 { + ALTER TABLE x1 DROP COLUMN e + } + do_execsql_test 4.$tn.9 { + SELECT * FROM x1 + } { + 2 3 5 + 6 7 13 + 10 11 21 + } +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE p1(a PRIMARY KEY, b UNIQUE); + CREATE TABLE c1(x, y, z REFERENCES p1(c)); + CREATE TABLE c2(x, y, z, w REFERENCES p1(b)); +} +do_execsql_test 5.1 { + ALTER TABLE c1 DROP COLUMN z; + ALTER TABLE c2 DROP COLUMN z; + SELECT sql FROM sqlite_schema WHERE name IN ('c1', 'c2'); +} { + {CREATE TABLE c1(x, y)} + {CREATE TABLE c2(x, y, w REFERENCES p1(b))} +} + +do_execsql_test 5.2.1 { + CREATE VIEW v1 AS SELECT d, e FROM p1 +} +do_catchsql_test 5.2.2 { + ALTER TABLE c1 DROP COLUMN x +} {1 {error in view v1: no such column: d}} +do_execsql_test 5.3.1 { + DROP VIEW v1; + CREATE VIEW v1 AS SELECT x, y FROM c1; +} +do_catchsql_test 5.3.2 { + ALTER TABLE c1 DROP COLUMN x +} {1 {error in view v1 after drop column: no such column: x}} + +do_execsql_test 5.4.1 { + CREATE TRIGGER tr AFTER INSERT ON c1 BEGIN + INSERT INTO p1 VALUES(new.y, new.xyz); + END; +} +do_catchsql_test 5.4.2 { + ALTER TABLE c1 DROP COLUMN y +} {1 {error in trigger tr: no such column: new.xyz}} +do_execsql_test 5.5.1 { + DROP TRIGGER tr; + CREATE TRIGGER tr AFTER INSERT ON c1 BEGIN + INSERT INTO p1 VALUES(new.y, new.z); + END; +} +do_catchsql_test 5.5.2 { + ALTER TABLE c1 DROP COLUMN y +} {1 {error in trigger tr: no such column: new.z}} + +# 2021-03-06 dbsqlfuzz crash-419aa525df93db6e463772c686ac6da27b46da9e +reset_db +do_catchsql_test 6.0 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(x,y,z); + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE INDEX t1b ON t1(b)' WHERE name='t2'; + PRAGMA writable_schema=OFF; + ALTER TABLE t2 DROP COLUMN z; +} {1 {database disk image is malformed}} +reset_db +do_catchsql_test 6.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE t2(x,y,z); + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE VIEW t2(x,y,z) AS SELECT b,a,c FROM t1' + WHERE name='t2'; + PRAGMA writable_schema=OFF; + ALTER TABLE t2 DROP COLUMN z; +} {1 {database disk image is malformed}} + +# 2021-04-06 dbsqlfuzz crash-331c5c29bb76257b198f1318eef3288f9624c8ce +reset_db +do_execsql_test 7.0 { + CREATE TABLE t1(a, b, c, PRIMARY KEY(a COLLATE nocase, a)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); +} +do_execsql_test 7.1 { + ALTER TABLE t1 DROP COLUMN c; +} +do_execsql_test 7.2 { + SELECT sql FROM sqlite_schema; +} {{CREATE TABLE t1(a, b, PRIMARY KEY(a COLLATE nocase, a)) WITHOUT ROWID}} +do_execsql_test 7.3 { + SELECT * FROM t1; +} {1 2 4 5} + +reset_db +do_execsql_test 8.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = 'CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b)' +} +db close +sqlite3 db test.db +do_execsql_test 8.1 { + ALTER TABLE t1 DROP COLUMN b; +} +do_execsql_test 8.2 { + SELECT sql FROM sqlite_schema; +} {{CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT)}} + +#------------------------------------------------------------------------- + +foreach {tn wo} { + 1 {} + 2 {WITHOUT ROWID} +} { + reset_db + do_execsql_test 9.$tn.0 " + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c) $wo; + " + do_execsql_test 9.$tn.1 { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000 + ) + INSERT INTO t1(a, b, c) SELECT i, 123, 456 FROM s; + } + do_execsql_test 9.$tn.2 { + ALTER TABLE t1 DROP COLUMN b; + } + + do_execsql_test 9.$tn.3 { + SELECT count(*), c FROM t1 GROUP BY c; + } {50000 456} +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alterdropcol2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterdropcol2.test new file mode 100644 index 0000000000000000000000000000000000000000..d60e7db44149e1ea717b7be575a332c958967c61 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterdropcol2.test @@ -0,0 +1,222 @@ +# 2021 February 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 alterdropcol2 + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +# EVIDENCE-OF: R-58318-35349 The DROP COLUMN syntax is used to remove an +# existing column from a table. +do_execsql_test 1.0 { + CREATE TABLE t1(c, b, a, PRIMARY KEY(b, a)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2, 3), (4, 5, 6); +} +do_execsql_test 1.1 { + ALTER TABLE t1 DROP c; +} + +# EVIDENCE-OF: The DROP COLUMN command removes the named column from the table, +# and also rewrites the entire table to purge the data associated with that +# column. +do_execsql_test 1.2.1 { + SELECT * FROM t1; +} {2 3 5 6} + +do_execsql_test 1.2.2 { + SELECT sql FROM sqlite_schema; +} { + {CREATE TABLE t1(b, a, PRIMARY KEY(b, a)) WITHOUT ROWID} +} + +proc do_atdc_error_test {tn schema atdc error} { + reset_db + execsql $schema + uplevel [list do_catchsql_test $tn $atdc [list 1 [string trim $error]]] +} + +#------------------------------------------------------------------------- +# Test cases 2.* attempt to verify the following: +# +# EVIDENCE-OF: R-24098-10282 The DROP COLUMN command only works if the column +# is not referenced by any other parts of the schema and is not a PRIMARY KEY +# and does not have a UNIQUE constraint. +# + +# EVIDENCE-OF: R-52436-31752 The column is a PRIMARY KEY or part of one. +# +do_atdc_error_test 2.1.1 { + CREATE TABLE x1(a PRIMARY KEY, b, c); +} { + ALTER TABLE x1 DROP COLUMN a +} { + cannot drop PRIMARY KEY column: "a" +} +do_atdc_error_test 2.1.2 { + CREATE TABLE x1(a,b,c,d,e, PRIMARY KEY(b,c,d)); +} { + ALTER TABLE x1 DROP COLUMN c +} { + cannot drop PRIMARY KEY column: "c" +} + +# EVIDENCE-OF: R-43412-16016 The column has a UNIQUE constraint. +# +do_atdc_error_test 2.2.1 { + CREATE TABLE x1(a PRIMARY KEY, b, c UNIQUE); +} { + ALTER TABLE x1 DROP COLUMN c +} { + cannot drop UNIQUE column: "c" +} +do_atdc_error_test 2.2.2 { + CREATE TABLE x1(a PRIMARY KEY, b, c, UNIQUE(b, c)); +} { + ALTER TABLE x1 DROP COLUMN c +} { + error in table x1 after drop column: no such column: c +} + +# EVIDENCE-OF: R-46731-08965 The column is indexed. +# +do_atdc_error_test 2.3.1 { + CREATE TABLE 'one two'('x y', 'z 1', 'a b'); + CREATE INDEX idx ON 'one two'('z 1'); +} { + ALTER TABLE 'one two' DROP COLUMN 'z 1' +} { + error in index idx after drop column: no such column: z 1 +} +do_atdc_error_test 2.3.2 { + CREATE TABLE x1(a, b, c); + CREATE INDEX idx ON x1(a); +} { + ALTER TABLE x1 DROP COLUMN a; +} { + error in index idx after drop column: no such column: a +} + +# EVIDENCE-OF: R-46731-08965 The column is indexed. +# +do_atdc_error_test 2.4.1 { + CREATE TABLE x1234(a, b, c PRIMARY KEY) WITHOUT ROWID; + CREATE INDEX i1 ON x1234(b) WHERE ((a+5) % 10)==0; +} { + ALTER TABLE x1234 DROP a +} { + error in index i1 after drop column: no such column: a +} + +# EVIDENCE-OF: R-47838-03249 The column is named in a table or column +# CHECK constraint not associated with the column being dropped. +# +do_atdc_error_test 2.5.1 { + CREATE TABLE x1234(a, b, c PRIMARY KEY, CHECK(((a+5)%10)!=0)) WITHOUT ROWID; +} { + ALTER TABLE x1234 DROP a +} { + error in table x1234 after drop column: no such column: a +} + +# EVIDENCE-OF: R-55640-01652 The column is used in a foreign key constraint. +# +do_atdc_error_test 2.6.1 { + CREATE TABLE p1(x, y UNIQUE); + CREATE TABLE c1(u, v, FOREIGN KEY (v) REFERENCES p1(y)) +} { + ALTER TABLE c1 DROP v +} { + error in table c1 after drop column: unknown column "v" in foreign key definition +} + +# EVIDENCE-OF: R-20795-39479 The column is used in the expression of a +# generated column. +do_atdc_error_test 2.7.1 { + CREATE TABLE c1(u, v, w AS (u+v)); +} { + ALTER TABLE c1 DROP v +} { + error in table c1 after drop column: no such column: v +} +do_atdc_error_test 2.7.2 { + CREATE TABLE c1(u, v, w AS (u+v) STORED); +} { + ALTER TABLE c1 DROP u +} { + error in table c1 after drop column: no such column: u +} + +# EVIDENCE-OF: R-01515-49025 The column appears in a trigger or view. +# +do_atdc_error_test 2.8.1 { + CREATE TABLE log(l); + CREATE TABLE c1(u, v, w); + CREATE TRIGGER tr1 AFTER INSERT ON c1 BEGIN + INSERT INTO log VALUES(new.w); + END; +} { + ALTER TABLE c1 DROP w +} { + error in trigger tr1 after drop column: no such column: new.w +} +do_atdc_error_test 2.8.2 { + CREATE TABLE c1(u, v, w); + CREATE VIEW v1 AS SELECT u, v, w FROM c1; +} { + ALTER TABLE c1 DROP w +} { + error in view v1 after drop column: no such column: w +} +do_atdc_error_test 2.8.3 { + CREATE TABLE c1(u, v, w); + CREATE VIEW v1 AS SELECT * FROM c1 WHERE w IS NOT NULL; +} { + ALTER TABLE c1 DROP w +} { + error in view v1 after drop column: no such column: w +} + +#------------------------------------------------------------------------- +# Verify that a column that is part of a CHECK constraint may be dropped +# if the CHECK constraint was specified as part of the column definition. +# + +# STALE-EVIDENCE: R-60924-11170 However, the column being deleted can be used in a +# column CHECK constraint because the column CHECK constraint is dropped +# together with the column itself. +do_execsql_test 3.0 { + CREATE TABLE yyy(q, w, e CHECK (e > 0), r); + INSERT INTO yyy VALUES(1,1,1,1), (2,2,2,2); + + CREATE TABLE zzz(q, w, e, r, CHECK (e > 0)); + INSERT INTO zzz VALUES(1,1,1,1), (2,2,2,2); +} +do_catchsql_test 3.1.1 { + INSERT INTO yyy VALUES(0,0,0,0); +} {1 {CHECK constraint failed: e > 0}} +do_catchsql_test 3.1.2 { + INSERT INTO yyy VALUES(0,0,0,0); +} {1 {CHECK constraint failed: e > 0}} + +do_execsql_test 3.2.1 { + ALTER TABLE yyy DROP e; +} +do_catchsql_test 3.2.2 { + ALTER TABLE zzz DROP e; +} {1 {error in table zzz after drop column: no such column: e}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/alterfault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterfault.test new file mode 100644 index 0000000000000000000000000000000000000000..b6b42973efe727d84d5ba6790e3ebd73688386f5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/alterfault.test @@ -0,0 +1,41 @@ +# 2021 November 16 +# +# 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 alterfault + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a); +} +faultsim_save_and_close + +do_faultsim_test 1.1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + ALTER TABLE t1 ADD COLUMN b CHECK (a!=1) + } +} -test { + faultsim_test_result {0 {}} +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/altermalloc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/altermalloc.test new file mode 100644 index 0000000000000000000000000000000000000000..22ea15846375e995fb4b233f8f3968a5f09ff9d1 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/altermalloc.test @@ -0,0 +1,71 @@ +# 2005 September 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 regression tests for SQLite library. The +# focus of this script is testing the ALTER TABLE statement and +# specifically out-of-memory conditions within that command. +# +# $Id: altermalloc.test,v 1.10 2008/10/30 17:21:13 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +source $testdir/malloc_common.tcl + +do_malloc_test altermalloc-1 -tclprep { + db close +} -tclbody { + if {[catch {sqlite3 db test.db}]} { + error "out of memory" + } + sqlite3_db_config_lookaside db 0 0 0 + sqlite3_extended_result_codes db 1 +} -sqlbody { + CREATE TABLE t1(a int); + ALTER TABLE t1 ADD COLUMN b INTEGER DEFAULT NULL; + ALTER TABLE t1 ADD COLUMN c TEXT DEFAULT 'default-text'; + ALTER TABLE t1 RENAME TO t2; + ALTER TABLE t2 ADD COLUMN d BLOB DEFAULT X'ABCD'; +} + +# Test malloc() failure on an ALTER TABLE on a virtual table. +# +ifcapable vtab { + do_malloc_test altermalloc-vtab -tclprep { + sqlite3 db2 test.db + sqlite3_db_config_lookaside db2 0 0 0 + sqlite3_extended_result_codes db2 1 + register_echo_module [sqlite3_connection_pointer db2] + db2 eval { + CREATE TABLE t1(a, b VARCHAR, c INTEGER); + CREATE VIRTUAL TABLE t1echo USING echo(t1); + } + db2 close + + register_echo_module [sqlite3_connection_pointer db] + } -tclbody { + set rc [catch {db eval { ALTER TABLE t1echo RENAME TO t1_echo }} msg] + if {$msg eq "vtable constructor failed: t1echo"} { + set msg "out of memory" + } + if {$rc} { + error $msg + } + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/altertab.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/altertab.test new file mode 100644 index 0000000000000000000000000000000000000000..9cc43e14de2b67e88e12edb742cc830b3e2ebb2f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/altertab.test @@ -0,0 +1,1002 @@ +# 2018 August 24 +# +# 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 altertab + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, CHECK(t1.a != t1.b)); + + CREATE TABLE t2(a, b); + CREATE INDEX t2expr ON t2(a) WHERE t2.b>0; +} + +do_execsql_test 1.1 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE t1(a, b, CHECK(t1.a != t1.b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + +do_execsql_test 1.2 { + ALTER TABLE t1 RENAME TO t1new; +} + +do_execsql_test 1.3 { + CREATE TABLE t3(c, d); + ALTER TABLE t3 RENAME TO t3new; + DROP TABLE t3new; +} + +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))} + {CREATE TABLE t2(a, b)} + {CREATE INDEX t2expr ON t2(a) WHERE t2.b>0} +} + + +do_execsql_test 1.3 { + ALTER TABLE t2 RENAME TO t2new; +} +do_execsql_test 1.4 { + SELECT sql FROM sqlite_master +} { + {CREATE TABLE "t1new"(a, b, CHECK("t1new".a != "t1new".b))} + {CREATE TABLE "t2new"(a, b)} + {CREATE INDEX t2expr ON "t2new"(a) WHERE "t2new".b>0} +} + + +#------------------------------------------------------------------------- +reset_db +ifcapable vtab { + register_echo_module db + + do_execsql_test 2.0 { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + CREATE VIRTUAL TABLE eee USING echo('abc'); + SELECT * FROM eee; + } {1 2 3} + + do_execsql_test 2.1 { + ALTER TABLE eee RENAME TO fff; + SELECT * FROM fff; + } {1 2 3} + + db close + sqlite3 db test.db + + do_catchsql_test 2.2 { + ALTER TABLE fff RENAME TO ggg; + } {1 {no such module: echo}} +} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 3.0 { + CREATE TABLE txx(a, b, c); + INSERT INTO txx VALUES(1, 2, 3); + CREATE VIEW vvv AS SELECT main.txx.a, txx.b, c FROM txx; + CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM txx AS one; + CREATE VIEW temp.ttt AS SELECT main.txx.a, txx.b, one.b, main.one.a FROM txx AS one, txx; +} + +do_execsql_test 3.1.1 { + SELECT * FROM vvv; +} {1 2 3} +do_execsql_test 3.1.2 { + ALTER TABLE txx RENAME TO "t xx"; + SELECT * FROM vvv; +} {1 2 3} +do_execsql_test 3.1.3 { + SELECT sql FROM sqlite_master WHERE name='vvv'; +} {{CREATE VIEW vvv AS SELECT main."t xx".a, "t xx".b, c FROM "t xx"}} + + +do_execsql_test 3.2.1 { + SELECT * FROM uuu; +} {1 2 3} +do_execsql_test 3.2.2 { + SELECT sql FROM sqlite_master WHERE name='uuu';; +} {{CREATE VIEW uuu AS SELECT main.one.a, one.b, c FROM "t xx" AS one}} + +do_execsql_test 3.3.1 { + SELECT * FROM ttt; +} {1 2 2 1} +do_execsql_test 3.3.2 { + SELECT sql FROM sqlite_temp_master WHERE name='ttt'; +} {{CREATE VIEW ttt AS SELECT main."t xx".a, "t xx".b, one.b, main.one.a FROM "t xx" AS one, "t xx"}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE table t1(x, y); + CREATE table t2(a, b); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + SELECT t1.x, * FROM t1, t2; + INSERT INTO t2 VALUES(new.x, new.y); + END; +} + +do_execsql_test 4.1 { + INSERT INTO t1 VALUES(1, 1); + ALTER TABLE t1 RENAME TO t11; + INSERT INTO t11 VALUES(2, 2); + ALTER TABLE t2 RENAME TO t22; + INSERT INTO t11 VALUES(3, 3); +} + +proc squish {a} { + string trim [regsub -all {[[:space:]][[:space:]]*} $a { }] +} +db func squish squish +do_test 4.2 { + execsql { SELECT squish(sql) FROM sqlite_master WHERE name = 'tr1' } +} [list [squish { + CREATE TRIGGER tr1 AFTER INSERT ON "t11" BEGIN + SELECT "t11".x, * FROM "t11", "t22"; + INSERT INTO "t22" VALUES(new.x, new.y); + END +}]] + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t9(a, b, c); + CREATE TABLE t10(a, b, c); + CREATE TEMP TABLE t9(a, b, c); + + CREATE TRIGGER temp.t9t AFTER INSERT ON temp.t9 BEGIN + INSERT INTO t10 VALUES(new.a, new.b, new.c); + END; + + INSERT INTO temp.t9 VALUES(1, 2, 3); + SELECT * FROM t10; +} {1 2 3} + +do_execsql_test 5.1 { + ALTER TABLE temp.t9 RENAME TO 't1234567890' +} + +do_execsql_test 5.2 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(3, 4); + CREATE VIEW v AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM v; +} {1 2 3 4} + +do_catchsql_test 5.3 { + ALTER TABLE t2 RENAME TO one; +} {1 {error in view v after rename: ambiguous column name: one.a}} + +do_execsql_test 5.4 { + SELECT * FROM v +} {1 2 3 4} + +do_execsql_test 5.5 { + DROP VIEW v; + CREATE VIEW temp.vv AS SELECT one.a, one.b, t2.a, t2.b FROM t1 AS one, t2; + SELECT * FROM vv; +} {1 2 3 4} + +do_catchsql_test 5.6 { + ALTER TABLE t2 RENAME TO one; +} {1 {error in view vv after rename: ambiguous column name: one.a}} + +#------------------------------------------------------------------------- + +ifcapable vtab { + register_tcl_module db + proc tcl_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + } + return {} + } + + do_execsql_test 6.0 { + CREATE VIRTUAL TABLE x1 USING tcl(tcl_command); + } + + do_execsql_test 6.1 { + ALTER TABLE x1 RENAME TO x2; + SELECT sql FROM sqlite_master WHERE name = 'x2' + } {{CREATE VIRTUAL TABLE "x2" USING tcl(tcl_command)}} + + do_execsql_test 7.1 { + CREATE TABLE ddd(db, sql, zOld, zNew, bTemp); + INSERT INTO ddd VALUES( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', 'ddd', NULL, 0 + ), ( + 'main', 'CREATE TABLE x1(i INTEGER, t TEXT)', NULL, 'eee', 0 + ), ( + 'main', NULL, 'ddd', 'eee', 0 + ); + } {} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_execsql_test 7.2 { + SELECT + sqlite_rename_table(db, 0, 0, sql, zOld, zNew, bTemp) + FROM ddd; + } {{} {} {}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +} + +#------------------------------------------------------------------------- +# +reset_db +forcedelete test.db2 +do_execsql_test 8.1 { + ATTACH 'test.db2' AS aux; + PRAGMA foreign_keys = on; + CREATE TABLE aux.p1(a INTEGER PRIMARY KEY, b); + CREATE TABLE aux.c1(x INTEGER PRIMARY KEY, y REFERENCES p1(a)); + INSERT INTO aux.p1 VALUES(1, 1); + INSERT INTO aux.p1 VALUES(2, 2); + INSERT INTO aux.c1 VALUES(NULL, 2); + CREATE TABLE aux.c2(x INTEGER PRIMARY KEY, y REFERENCES c1(a)); +} + +do_execsql_test 8.2 { + ALTER TABLE aux.p1 RENAME TO ppp; +} + +do_execsql_test 8.2 { + INSERT INTO aux.c1 VALUES(NULL, 1); + SELECT sql FROM aux.sqlite_master WHERE name = 'c1'; +} {{CREATE TABLE c1(x INTEGER PRIMARY KEY, y REFERENCES "ppp"(a))}} + +reset_db +do_execsql_test 9.0 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t2; +} +do_catchsql_test 9.1 { + ALTER TABLE t1 RENAME TO t3; +} {1 {error in view v1: no such table: main.t2}} +do_execsql_test 9.2 { + DROP VIEW v1; + CREATE TRIGGER tr AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a); + END; +} +do_catchsql_test 9.3 { + ALTER TABLE t1 RENAME TO t3; +} {1 {error in trigger tr: no such table: main.t2}} + +forcedelete test.db2 +do_execsql_test 9.4 { + DROP TRIGGER tr; + + ATTACH 'test.db2' AS aux; + CREATE TRIGGER tr AFTER INSERT ON t1 WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END; + + CREATE TABLE aux.t1(x); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END; +} +do_execsql_test 9.5 { + ALTER TABLE main.t1 RENAME TO t3; +} +do_execsql_test 9.6 { + SELECT sql FROM sqlite_temp_master; + SELECT sql FROM sqlite_master WHERE type='trigger'; +} { + {CREATE TRIGGER tr AFTER INSERT ON aux.t1 BEGIN SELECT 1, 2, 3; END} + {CREATE TRIGGER tr AFTER INSERT ON "t3" WHEN new.a IS NULL BEGIN SELECT 1, 2, 3; END} +} + +#------------------------------------------------------------------------- +reset_db +ifcapable fts5 { + do_execsql_test 10.0 { + CREATE VIRTUAL TABLE fff USING fts5(x, y, z); + } + + do_execsql_test 10.1 { + BEGIN; + INSERT INTO fff VALUES('a', 'b', 'c'); + ALTER TABLE fff RENAME TO ggg; + COMMIT; + } + + do_execsql_test 10.2 { + SELECT * FROM ggg; + } {a b c} +} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +db func trigger trigger +set ::trigger [list] +proc trigger {args} { + lappend ::trigger $args +} +do_execsql_test 11.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t1(a, b, c); + CREATE TABLE main.t1(a, b, c); + CREATE TEMP TRIGGER tr AFTER INSERT ON aux.t1 BEGIN + SELECT trigger(new.a, new.b, new.c); + END; +} + +do_execsql_test 11.1 { + INSERT INTO main.t1 VALUES(1, 2, 3); + INSERT INTO aux.t1 VALUES(4, 5, 6); +} +do_test 11.2 { set ::trigger } {{4 5 6}} + +do_execsql_test 11.3 { + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.4 { + ALTER TABLE main.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t1} + +do_execsql_test 11.5 { + ALTER TABLE aux.t1 RENAME TO t2; + SELECT name, tbl_name FROM sqlite_temp_master; +} {tr t2} + +do_execsql_test 11.6 { + INSERT INTO aux.t2 VALUES(7, 8, 9); +} +do_test 11.7 { set ::trigger } {{4 5 6} {7 8 9}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.0 { + CREATE TABLE t1(a); + CREATE TABLE t2(w); + CREATE TRIGGER temp.r1 AFTER INSERT ON main.t2 BEGIN + INSERT INTO t1(a) VALUES(new.w); + END; + CREATE TEMP TABLE t2(x); +} + +do_execsql_test 12.1 { + ALTER TABLE main.t2 RENAME TO t3; +} + +do_execsql_test 12.2 { + INSERT INTO t3 VALUES('WWW'); + SELECT * FROM t1; +} {WWW} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.0 { + CREATE TABLE t1(x, y); + CREATE TABLE t2(a, b); + CREATE TABLE log(c); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO log SELECT y FROM t1, t2; + END; +} + +do_execsql_test 13.1 { + INSERT INTO t1 VALUES(1, 2); +} + +do_catchsql_test 13.2 { + ALTER TABLE t2 RENAME b TO y; +} {1 {error in trigger tr1 after rename: ambiguous column name: y}} + +#------------------------------------------------------------------------- +reset_db + +ifcapable rtree { + do_execsql_test 14.0 { + CREATE VIRTUAL TABLE rt USING rtree(id, minx, maxx, miny, maxy); + + CREATE TABLE "mytable" ( "fid" INTEGER PRIMARY KEY, "geom" BLOB); + + CREATE TRIGGER tr1 AFTER UPDATE OF "geom" ON "mytable" + WHEN OLD."fid" = NEW."fid" AND NEW."geom" IS NULL BEGIN + DELETE FROM rt WHERE id = OLD."fid"; + END; + + INSERT INTO mytable VALUES(1, X'abcd'); + } + + do_execsql_test 14.1 { + UPDATE mytable SET geom = X'1234' + } + + do_execsql_test 14.2 { + ALTER TABLE mytable RENAME TO mytable_renamed; + } + + do_execsql_test 14.3 { + CREATE TRIGGER tr2 AFTER INSERT ON mytable_renamed BEGIN + DELETE FROM rt WHERE id=(SELECT min(id) FROM rt); + END; + } + + do_execsql_test 14.4 { + ALTER TABLE mytable_renamed RENAME TO mytable2; + } +} + +reset_db +do_execsql_test 14.5 { + CREATE TABLE t1(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER xyz AFTER INSERT ON t1 BEGIN + SELECT a, b FROM v1; + END; +} +do_execsql_test 14.6 { + ALTER TABLE t1 RENAME TO tt1; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 15.0 { + CREATE TABLE t1(a integer NOT NULL PRIMARY KEY); + CREATE VIEW v1 AS SELECT a FROM t1; + CREATE TRIGGER tr1 INSTEAD OF INSERT ON v1 BEGIN + UPDATE t1 SET a = NEW.a; + END; + CREATE TRIGGER tr2 INSTEAD OF INSERT ON v1 BEGIN + SELECT new.a; + END; + CREATE TABLE t2 (b); +} + +do_execsql_test 15.1 { + INSERT INTO v1 VALUES(1); + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 15.2 { + CREATE TABLE x(f1 integer NOT NULL); + CREATE VIEW y AS SELECT f1 AS f1 FROM x; + CREATE TRIGGER t INSTEAD OF UPDATE OF f1 ON y BEGIN + UPDATE x SET f1 = NEW.f1; + END; + CREATE TABLE z (f1 integer NOT NULL PRIMARY KEY); + ALTER TABLE z RENAME TO z2; +} + +do_execsql_test 15.3 { + INSERT INTO x VALUES(1), (2), (3); + ALTER TABLE x RENAME f1 TO f2; + SELECT * FROM x; +} {1 2 3} + +do_execsql_test 15.4 { + UPDATE y SET f1 = 'x' WHERE f1 = 1; + SELECT * FROM x; +} {x x x} + +do_execsql_test 15.5 { + SELECT sql FROM sqlite_master WHERE name = 'y'; +} {{CREATE VIEW y AS SELECT f2 AS f1 FROM x}} + +#------------------------------------------------------------------------- +# Test that it is not possible to rename a shadow table in DEFENSIVE mode. +# +ifcapable fts3 { + proc vtab_command {method args} { + switch -- $method { + xConnect { + if {[info exists ::vtab_connect_sql]} { + execsql $::vtab_connect_sql + } + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set clist [lindex $args 0] + if {[llength $clist]!=1} { error "unexpected constraint list" } + catch { array unset C } + array set C [lindex $clist 0] + if {$C(usable)} { + return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!" + } else { + return "cost 1000000 rows 0 idxnum 0 idxstr scan..." + } + } + } + + return {} + } + + register_tcl_module db + + sqlite3_db_config db DEFENSIVE 1 + + do_execsql_test 16.0 { + CREATE VIRTUAL TABLE y1 USING fts3; + VACUUM; + } + + do_catchsql_test 16.10 { + INSERT INTO y1_segments VALUES(1, X'1234567890'); + } {1 {table y1_segments may not be modified}} + + do_catchsql_test 16.20 { + DROP TABLE y1_segments; + } {1 {table y1_segments may not be dropped}} + + do_catchsql_test 16.20 { + ALTER TABLE y1_segments RENAME TO abc; + } {1 {table y1_segments may not be altered}} + sqlite3_db_config db DEFENSIVE 0 + do_catchsql_test 16.22 { + ALTER TABLE y1_segments RENAME TO abc; + } {0 {}} + sqlite3_db_config db DEFENSIVE 1 + do_catchsql_test 16.23 { + CREATE TABLE y1_segments AS SELECT * FROM abc; + } {1 {object name reserved for internal use: y1_segments}} + do_catchsql_test 16.24 { + CREATE VIEW y1_segments AS SELECT * FROM abc; + } {1 {object name reserved for internal use: y1_segments}} + sqlite3_db_config db DEFENSIVE 0 + do_catchsql_test 16.25 { + ALTER TABLE abc RENAME TO y1_segments; + } {0 {}} + sqlite3_db_config db DEFENSIVE 1 + + do_execsql_test 16.30 { + ALTER TABLE y1 RENAME TO z1; + } + + do_execsql_test 16.40 { + SELECT * FROM z1_segments; + } +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 17.0 { + CREATE TABLE sqlite1234 (id integer); + ALTER TABLE sqlite1234 RENAME TO User; + SELECT name, sql FROM sqlite_master WHERE sql IS NOT NULL; +} { + User {CREATE TABLE "User" (id integer)} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 18.1.0 { + CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)) WITHOUT ROWID; +} +do_execsql_test 18.1.1 { + ALTER TABLE t0 RENAME COLUMN c0 TO c1; +} +do_execsql_test 18.1.2 { + SELECT sql FROM sqlite_master; +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1)) WITHOUT ROWID}} + +reset_db +do_execsql_test 18.2.0 { + CREATE TABLE t0 (c0 INTEGER, PRIMARY KEY(c0)); +} +do_execsql_test 18.2.1 { + ALTER TABLE t0 RENAME COLUMN c0 TO c1; +} +do_execsql_test 18.2.2 { + SELECT sql FROM sqlite_master; +} {{CREATE TABLE t0 (c1 INTEGER, PRIMARY KEY(c1))}} + +# 2020-02-23 ticket f50af3e8a565776b +reset_db +do_execsql_test 19.100 { + CREATE TABLE t1(x); + CREATE VIEW t2 AS SELECT 1 FROM t1, (t1 AS a0, t1); + ALTER TABLE t1 RENAME TO t3; + SELECT sql FROM sqlite_master; +} {{CREATE TABLE "t3"(x)} {CREATE VIEW t2 AS SELECT 1 FROM "t3", ("t3" AS a0, "t3")}} +do_execsql_test 19.110 { + INSERT INTO t3(x) VALUES(123); + SELECT * FROM t2; +} {1} +do_execsql_test 19.120 { + INSERT INTO t3(x) VALUES('xyz'); + SELECT * FROM t2; +} {1 1 1 1 1 1 1 1} + +# Ticket 4722bdab08cb14 +reset_db +do_execsql_test 20.0 { + CREATE TABLE a(a); + CREATE VIEW b AS SELECT(SELECT *FROM c JOIN a USING(d, a, a, a) JOIN a) IN(); +} +do_execsql_test 20.1 { + ALTER TABLE a RENAME a TO e; +} {} + +reset_db +do_execsql_test 21.0 { + CREATE TABLE a(b); + CREATE VIEW c AS + SELECT NULL INTERSECT + SELECT NULL ORDER BY + likelihood(NULL, (d, (SELECT c))); +} {} +do_catchsql_test 21.1 { + SELECT likelihood(NULL, (d, (SELECT c))); +} {1 {second argument to likelihood() must be a constant between 0.0 and 1.0}} +do_catchsql_test 21.2 { + SELECT * FROM c; +} {1 {1st ORDER BY term does not match any column in the result set}} + +do_catchsql_test 21.3 { + ALTER TABLE a RENAME TO e; +} {1 {error in view c: 1st ORDER BY term does not match any column in the result set}} + +# After forum thread https://sqlite.org/forum/forumpost/ddbe1c7efa +# Ensure that PRAGMA schema_version=N causes a full schema reload. +# +reset_db +do_execsql_test 22.0 { + CREATE TABLE t1(a INT, b TEXT NOT NULL); + INSERT INTO t1 VALUES(1,2),('a','b'); + BEGIN; + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET sql='CREATE TABLE t1(a INT, b TEXT)' WHERE name LIKE 't1'; + PRAGMA schema_version=1234; + COMMIT; + PRAGMA integrity_check; +} {ok} +do_execsql_test 22.1 { + ALTER TABLE t1 ADD COLUMN c INT DEFAULT 78; + SELECT * FROM t1; +} {1 2 78 a b 78} + +#------------------------------------------------------------------------- +reset_db +db collate compare64 compare64 + +do_execsql_test 23.1 { + CREATE TABLE gigo(a text); + CREATE TABLE idx(x text COLLATE compare64); + CREATE VIEW v1 AS SELECT * FROM idx WHERE x='abc'; +} +db close +sqlite3 db test.db + +do_execsql_test 23.2 { + alter table gigo rename to ggiiggoo; + alter table idx rename to idx2; +} + +do_execsql_test 23.3 { + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "ggiiggoo"(a text)} + {CREATE TABLE "idx2"(x text COLLATE compare64)} + {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE x='abc'} +} + +do_execsql_test 23.4 { + ALTER TABLE idx2 RENAME x TO y; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "ggiiggoo"(a text)} + {CREATE TABLE "idx2"(y text COLLATE compare64)} + {CREATE VIEW v1 AS SELECT * FROM "idx2" WHERE y='abc'} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 24.1.0 { + CREATE TABLE t1(a, b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + INSERT INTO nosuchtable VALUES(new.a) ON CONFLICT(a) DO NOTHING; + END; +} +do_catchsql_test 24.1.1 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger AFTER: no such table: main.nosuchtable}} + +reset_db +do_execsql_test 24.2.0 { + CREATE TABLE t1(a, b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + INSERT INTO v1 VALUES(new.a) ON CONFLICT(a) DO NOTHING; + END; + CREATE VIEW v1 AS SELECT * FROM nosuchtable; +} +do_catchsql_test 24.2.1 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger AFTER: no such table: main.nosuchtable}} + +#-------------------------------------------------------------------------- +# +reset_db +do_execsql_test 25.1 { + CREATE TABLE xx(x); + CREATE VIEW v3(b) AS WITH b AS (SELECT b FROM (SELECT * FROM t2)) VALUES(1); +} + +ifcapable json1&&vtab { + do_catchsql_test 25.2 { + ALTER TABLE json_each RENAME TO t4; + } {1 {table json_each may not be altered}} +} + +# 2021-05-01 dbsqlfuzz bc17a306a09329bba0ecc61547077f6178bcf321 +# Remove a NEVER() inserted on 2019-12-09 that is reachable after all. +# +reset_db +do_execsql_test 26.1 { + CREATE TABLE t1(k,v); + CREATE TABLE t2_a(k,v); + CREATE VIEW t2 AS SELECT * FROM t2_a; + CREATE TRIGGER r2 AFTER INSERT ON t1 BEGIN + UPDATE t1 + SET (k,v)=((WITH cte1(a) AS (SELECT 1 FROM t2) SELECT t2.k FROM t2, cte1),1); + END; + ALTER TABLE t1 RENAME TO t1x; + INSERT INTO t2_a VALUES(2,3); + INSERT INTO t1x VALUES(98,99); + SELECT * FROM t1x; +} {2 1} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 27.1 { + + create table t_sa ( + c_muyat INTEGER NOT NULL, + c_d4u TEXT + ); + + create table t2 ( abc ); + + CREATE TRIGGER trig AFTER DELETE ON t_sa + BEGIN + DELETE FROM t_sa WHERE ( + SELECT 123 FROM t2 + WINDOW oamat7fzf AS ( PARTITION BY t_sa.c_d4u ) + ); + END; +} + +do_execsql_test 27.2 { + alter table t_sa rename column c_muyat to c_dg; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 29.1 { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 'b', 'c'); + + CREATE VIEW v0 AS + WITH p AS ( SELECT 1 FROM t1 ), + g AS ( SELECT 1 FROM p, t1 ) + SELECT 1 FROM g; +} + +do_execsql_test 29.2 { + SELECT * FROM v0 +} 1 + +do_execsql_test 29.2 { + ALTER TABLE t1 RENAME TO t2 +} + +do_execsql_test 29.3 { + SELECT sql FROM sqlite_schema WHERE name='v0' +} {{CREATE VIEW v0 AS + WITH p AS ( SELECT 1 FROM "t2" ), + g AS ( SELECT 1 FROM p, "t2" ) + SELECT 1 FROM g}} + +do_execsql_test 29.4 { + CREATE VIEW v2 AS + WITH p AS ( SELECT 1 FROM t2 ), + g AS ( SELECT 1 FROM ( + WITH i AS (SELECT 1 FROM p, t2) + SELECT * FROM i + ) + ) + SELECT 1 FROM g; +} + +do_execsql_test 29.4 { + SELECT * FROM v2; +} 1 + +do_execsql_test 29.5 { + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 29.5 { + SELECT sql FROM sqlite_schema WHERE name='v2' +} {{CREATE VIEW v2 AS + WITH p AS ( SELECT 1 FROM "t3" ), + g AS ( SELECT 1 FROM ( + WITH i AS (SELECT 1 FROM p, "t3") + SELECT * FROM i + ) + ) + SELECT 1 FROM g}} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 28.1 { + CREATE TABLE t1(a); + CREATE TABLE t2(b,c); + CREATE TABLE t4(b,c); + INSERT INTO t2 VALUES(1,2),(1,3),(2,5); + INSERT INTO t4 VALUES(1,2),(1,3),(2,5); + + CREATE VIEW v3 AS + WITH RECURSIVE t3(x,y,z) AS ( + SELECT b,c,NULL FROM t4 + UNION + SELECT x,y,NULL FROM t3, t2 + ) + SELECT * FROM t3 AS xyz; +} + +do_execsql_test 28.2 { + SELECT * FROM v3 +} { + 1 2 {} 1 3 {} 2 5 {} +} + +do_execsql_test 28.3 { + ALTER TABLE t1 RENAME a TO a2; -- fails in v3 +} + +do_execsql_test 28.4 { + ALTER TABLE t2 RENAME TO t5; +} + +do_execsql_test 28.5 { + SELECT sql FROM sqlite_schema WHERE name='v3' +} {{CREATE VIEW v3 AS + WITH RECURSIVE t3(x,y,z) AS ( + SELECT b,c,NULL FROM t4 + UNION + SELECT x,y,NULL FROM t3, "t5" + ) + SELECT * FROM t3 AS xyz}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 30.0 { + CREATE TABLE t1(a,b,c,d,e,f); + CREATE TABLE t2(a,b,c); + CREATE INDEX t1abc ON t1(a,b,c+d+e); + CREATE VIEW v1(x,y) AS + SELECT t1.b,t2.b FROM t1,t2 WHERE t1.a=t2.a + GROUP BY 1 HAVING t2.c NOT NULL LIMIT 10; + CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN 'no' NOT NULL BEGIN + INSERT INTO t2(a,a,b,c) VALUES(new.b,new.a,new.c-7); + WITH c1(x) AS ( + VALUES(0) + UNION ALL + SELECT current_time+x FROM c1 WHERE x + UNION ALL + SELECT 1+x FROM c1 WHERE x<1 + ), c2(x) AS (VALUES(0),(1)) + SELECT * FROM c1 AS x1, c2 AS x2, ( + SELECT x+1 FROM c1 WHERE x IS NOT TRUE + UNION ALL + SELECT 1+x FROM c1 WHERE 1='d' ORDER BY name; + SELECT new.c; + END; +} + +do_execsql_test 2.1 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master WHERE name = 'r1'; +} {{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN + SELECT a,b, a name FROM "t1x" + INTERSECT + SELECT a,b,c FROM "t1x" WHERE b>='d' ORDER BY name; + SELECT new.c; + END}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c, d); + CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ()); +} + +do_execsql_test 3.1 { + ALTER TABLE t1 RENAME b TO bbb; +} + +do_execsql_test 3.2 { + SELECT sql FROM sqlite_master WHERE name = 'v1' +} {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ())}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t3(e, f); + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b); + END; +} + +do_catchsql_test 4.1.2 { + BEGIN; + ALTER TABLE t3 RENAME TO t4; +} {1 {error in trigger tr1: no such table: main.t2}} +do_execsql_test 4.1.2 { + COMMIT; +} +do_execsql_test 4.1.3 { + SELECT type, name, tbl_name, sql + FROM sqlite_master WHERE type='table' AND name!='t1'; +} {table t3 t3 {CREATE TABLE t3(e, f)}} + + +do_catchsql_test 4.2.1 { + BEGIN; + ALTER TABLE t3 RENAME e TO eee; +} {1 {error in trigger tr1: no such table: main.t2}} +do_execsql_test 4.2.2 { + COMMIT; +} +do_execsql_test 4.2.3 { + SELECT type, name, tbl_name, sql + FROM sqlite_master WHERE type='table' AND name!='t1'; +} {table t3 t3 {CREATE TABLE t3(e, f)}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1 ( + c1 integer, c2, PRIMARY KEY(c1 collate rtrim), + UNIQUE(c2) + ) +} +do_execsql_test 5.1 { + ALTER TABLE t1 RENAME c1 TO c3; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TEMPORARY TABLE Table0 ( + Col0 INTEGER, + PRIMARY KEY(Col0 COLLATE RTRIM), + FOREIGN KEY (Col0) REFERENCES Table0 + ); +} + +do_execsql_test 6.1 { + ALTER TABLE Table0 RENAME Col0 TO Col0; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.1.0 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT a, rank() OVER w1 FROM t1 + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1); + END; +} + +do_execsql_test 7.1.2 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "t1x"(a,b,c)} + {CREATE TRIGGER AFTER INSERT ON "t1x" BEGIN + SELECT a, rank() OVER w1 FROM "t1x" + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1); + END} +} + +do_execsql_test 7.2.1 { + DROP TRIGGER after; + CREATE TRIGGER AFTER INSERT ON t1x BEGIN + SELECT a, rank() OVER w1 FROM t1x + WINDOW w1 AS (PARTITION BY b, percent_rank() OVER w1 ORDER BY d); + END; +} + +do_catchsql_test 7.2.2 { + ALTER TABLE t1x RENAME TO t1; +} {1 {error in trigger AFTER: no such column: d}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 8.0 { + CREATE TABLE t0(c0); + CREATE INDEX i0 ON t0('1' IN ()); +} +do_execsql_test 8.1 { + ALTER TABLE t0 RENAME TO t1; + SELECT sql FROM sqlite_master; +} { + {CREATE TABLE "t1"(c0)} + {CREATE INDEX i0 ON "t1"('1' IN ())} +} +do_execsql_test 8.2.1 { + CREATE TABLE t2 (c0); + CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ())); + ALTER TABLE t2 RENAME COLUMN c0 TO c1; +} +do_execsql_test 8.2.2 { + SELECT sql FROM sqlite_master WHERE tbl_name = 't2'; +} { + {CREATE TABLE t2 (c1)} + {CREATE INDEX i2 ON t2((LIKELIHOOD(c0, 100) IN ()))} +} +do_test 8.2.3 { + sqlite3 db2 test.db + db2 eval { INSERT INTO t2 VALUES (1), (2), (3) } + db close +} {} +db2 close + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 9.1 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + SELECT true WHERE (SELECT a, b FROM (t1)) IN (); + END; +} +do_execsql_test 9.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 10.1 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE VIEW v1 AS SELECT * FROM t1 WHERE ( + SELECT t1.a FROM t1, t2 + ) IN () OR t1.a=5; +} + +do_execsql_test 10.2 { + ALTER TABLE t2 RENAME TO t3; + SELECT sql FROM sqlite_master WHERE name='v1'; +} { + {CREATE VIEW v1 AS SELECT * FROM t1 WHERE ( + SELECT t1.a FROM t1, t2 + ) IN () OR t1.a=5} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.1 { + CREATE TABLE t1( + a,b,c,d,e,f,g,h,j,jj,jjb,k,aa,bb,cc,dd,ee DEFAULT 3.14, + ff DEFAULT('hiccup'),Wg NOD NULL DEFAULT(false) + ); + + CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN + SELECT a, sum() w3 FROM t1 + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM abc)); + END; +} + +do_catchsql_test 11.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger b: no such table: main.abc}} + +do_execsql_test 11.3 { + DROP TRIGGER b; + CREATE TRIGGER b AFTER INSERT ON t1 WHEN new.a BEGIN + SELECT a, sum() w3 FROM t1 + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM t1)); + END; +} {} + +do_execsql_test 11.4 { + ALTER TABLE t1 RENAME TO t1x; + SELECT sql FROM sqlite_master WHERE name = 'b'; +} { +{CREATE TRIGGER b AFTER INSERT ON "t1x" WHEN new.a BEGIN + SELECT a, sum() w3 FROM "t1x" + WINDOW b AS (ORDER BY NOT EXISTS(SELECT 1 FROM "t1x")); + END} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 12.1 { +CREATE TABLE t1(a,b,c,d,e,f,g,h,j,jj,Zjj,k,aQ,bb,cc,dd,ee DEFAULT 3.14, +ff DEFAULT('hiccup'),gg NOD NULL DEFAULT(false)); +CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + +SELECT b () OVER , dense_rank() OVER d, d () OVER w1 +FROM t1 +WINDOW +w1 AS +( w1 ORDER BY d +ROWS BETWEEN 2 NOT IN(SELECT a, sum(d) w2,max(d)OVER FROM t1 +WINDOW +w1 AS +(PARTITION BY d +ROWS BETWEEN '' PRECEDING AND false FOLLOWING), +d AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) +) PRECEDING AND 1 FOLLOWING), +w2 AS +(PARTITION BY b ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW), +w3 AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) +; +SELECT a, sum(d) w2,max(d)OVER FROM t1 +WINDOW +w1 AS +(PARTITION BY d +ROWS BETWEEN '' PRECEDING AND false FOLLOWING), +d AS +(PARTITION BY b ORDER BY d +ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) +; + +END; +} + +do_execsql_test 12.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 13.1 { + CREATE TABLE t1(a); + CREATE TRIGGER r1 INSERT ON t1 BEGIN + SELECT a(*) OVER (ORDER BY (SELECT 1)) FROM t1; + END; +} + +do_execsql_test 13.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 14.1 { + CREATE TABLE t1(a); + CREATE TABLE t2(b); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT sum() FILTER (WHERE (SELECT sum() FILTER (WHERE 0)) AND a); + END; +} + +do_catchsql_test 14.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger AFTER: no such column: a}} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 16.1 { + CREATE TABLE t1(x); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + SELECT (WITH t2 AS (WITH t3 AS (SELECT true) + SELECT * FROM t3 ORDER BY true COLLATE nocase) + SELECT 11); + + WITH t4 AS (SELECT * FROM t1) SELECT 33; + END; +} +do_execsql_test 16.2 { + ALTER TABLE t1 RENAME TO t1x; +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 17.1 { + CREATE TABLE t1(a,b,c); + CREATE TRIGGER AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN + SELECT a () FILTER (WHERE a>0) FROM t1; + END; +} + +do_execsql_test 17.2 { + ALTER TABLE t1 RENAME TO t1x; + ALTER TABLE t1x RENAME a TO aaa; + SELECT sql FROM sqlite_master WHERE type='trigger'; +} { +{CREATE TRIGGER AFTER INSERT ON "t1x" WHEN new.aaa NOT NULL BEGIN + SELECT a () FILTER (WHERE aaa>0) FROM "t1x"; + END} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 18.1 { + CREATE TABLE t1(a,b); + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + SELECT a, b FROM t1 + INTERSECT SELECT b,a FROM t1 + ORDER BY b IN ( + SELECT a UNION SELECT b + FROM t1 + ORDER BY b COLLATE nocase + ) + ; + END; +} + +do_catchsql_test 18.2 { + SELECT a, b FROM t1 + INTERSECT + SELECT b,a FROM t1 + ORDER BY b IN ( + SELECT a UNION SELECT b + FROM t1 + ORDER BY b COLLATE nocase + ); +} {1 {1st ORDER BY term does not match any column in the result set}} + +do_catchsql_test 18.3 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger r1: 1st ORDER BY term does not match any column in the result set}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 19.0 { + CREATE TABLE a(a,h CONSTRAINT a UNIQUE ON CONFLICT FAIL,CONSTRAINT a); +} + +foreach {tn v res} { + 1 { + CREATE VIEW q AS SELECT 123 + + WINDOW x AS ( + RANGE BETWEEN UNBOUNDED PRECEDING AND INDEXED() OVER( + PARTITION BY ( WITH x AS(VALUES(col1)) VALUES(453) ) + ) + FOLLOWING + ) + } {1 {error in view q: no such column: col1}} + + 2 { + CREATE VIEW q AS SELECT + CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(CAST(RIGHT + AS)AS)AS)AS)AS)AS)AS)AS)AS)AS)AS)WINDOW x AS(RANGE BETWEEN UNBOUNDED + PRECEDING AND INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,NATURAL,sqlite_master(*)OVER a,(WITH a AS(VALUES(LEFT)UNION + VALUES(LEFT)UNION VALUES(LEFT)UNION VALUES(LEFT)UNION VALUES(LEFT)UNION + VALUES(LEFT)UNION VALUES(LEFT))VALUES(LEFT))IN + STORED,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT)*LEFT FOLLOWING)ORDER BY + LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT LIMIT + LEFT,INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,CROSS,LEFT,INDEXED(*)OVER(PARTITION BY + CROSS,CROSS,CROSS),INDEXED(*)OVER(PARTITION BY + LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT,LEFT), + LEFT,LEFT,INNER,CROSS,CROSS,CROSS,INNER,NATURAL ORDER BY + OUTER,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,NATURAL,INNER, + INNER,INNER NULLS LAST GROUPS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED + FOLLOWING); + } {1 {error in view q: no such column: LEFT}} + + 3 { + CREATE VIEW q AS SELECT 99 WINDOW x AS (RANGE BETWEEN UNBOUNDED PRECEDING + AND count(*)OVER(PARTITION BY (WITH a AS(VALUES(2),(x3))VALUES(0))) + FOLLOWING)ORDER BY x2,sum(1)OVER(PARTITION BY avg(5)OVER(PARTITION BY x1)); + } {1 {error in view q: no such column: x3}} +} { + do_execsql_test 19.$tn.1 " + DROP VIEW IF EXISTS q; + $v + " {} + + do_catchsql_test 19.$tn.2 { + ALTER TABLE a RENAME TO g; + } $res +} + +# Verify that the "if( pParse->nErr ) return WRC_Abort" at the top of the +# renameUnmapSelectCb() routine in alter.c (2019-12-04) is really required. +# +sqlite3 db :memory: +do_catchsql_test 20.10 { + CREATE TABLE s(a, b, c); + CREATE INDEX k ON s( (WITH s AS( SELECT * ) VALUES(2) ) IN () ); + ALTER TABLE s RENAME a TO a2; +} {1 {error in index k: no tables specified}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 21.1 { + CREATE TABLE s(col); + CREATE VIEW v AS SELECT ( + WITH x(a) AS(SELECT * FROM s) VALUES(RIGHT) + ) IN() ; + CREATE TABLE a(a); + ALTER TABLE a RENAME a TO b; +} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 22.1 { + CREATE TABLE t1(a); + CREATE VIEW v2(b) AS SELECT * FROM v2; +} + +do_catchsql_test 22.2 { + ALTER TABLE t1 RENAME TO t4; +} {1 {error in view v2: view v2 is circularly defined}} + +do_execsql_test 22.3 { + DROP VIEW v2; + CREATE VIEW v2(b) AS WITH t3 AS (SELECT b FROM v2) SELECT * FROM t3; +} + +do_catchsql_test 22.4 { + ALTER TABLE t1 RENAME TO t4; +} {1 {error in view v2: view v2 is circularly defined}} + +do_execsql_test 22.5 { + DROP VIEW v2; + CREATE VIEW v2(b) AS WITH t3 AS (SELECT b FROM v2) VALUES(1); +} + +do_catchsql_test 22.6 { + ALTER TABLE t1 RENAME TO t4; +} {0 {}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 23.1 { + CREATE TABLE t1(x); + CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN + UPDATE t1 SET (c,d)=((SELECT 1 FROM t1 JOIN t2 ON b=x),1); + END; +} + +do_catchsql_test 23.2 { + ALTER TABLE t1 RENAME TO t1x; +} {1 {error in trigger r1: no such table: main.t2}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 23.1 { + CREATE TABLE v0 (a); + CREATE VIEW v2 (v3) AS + WITH x1 AS (SELECT * FROM v2) + SELECT v3 AS x, v3 AS y FROM v2; +} + +do_catchsql_test 23.2 { + SELECT * FROM v2 +} {1 {view v2 is circularly defined}} + +db close +sqlite3 db test.db + +do_catchsql_test 23.3 { + ALTER TABLE v0 RENAME TO t3 ; +} {1 {error in view v2: view v2 is circularly defined}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 24.1 { + CREATE TABLE v0 (v1); + CREATE TABLE v2 (v3 INTEGER UNIQUE ON CONFLICT ABORT); + CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + ( SELECT v1 AS PROMO_REVENUE FROM v2 JOIN v0 USING ( VALUE ) ) AND 0 ) + BEGIN + DELETE FROM v2; + END; +} +do_catchsql_test 24.2 { + ALTER TABLE v0 RENAME TO x ; +} {1 {error in trigger x: cannot join using column VALUE - column not present in both tables}} + +do_execsql_test 24.3 { + DROP TRIGGER x; + CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + 0 AND (SELECT rowid FROM v0) + ) BEGIN + DELETE FROM v2; + END; +} + +do_execsql_test 24.4 { + ALTER TABLE v0 RENAME TO xyz; + SELECT sql FROM sqlite_master WHERE type='trigger' +} {{CREATE TRIGGER x AFTER INSERT ON v2 WHEN ( + 0 AND (SELECT rowid FROM "xyz") + ) BEGIN + DELETE FROM v2; + END}} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 25.1 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE TRIGGER ttt AFTER INSERT ON t1 BEGIN + UPDATE t1 SET a=t2.a FROM t2 WHERE t1.a=t2.a; + END; +} +#do_execsql_test 25.2 { +# ALTER TABLE t2 RENAME COLUMN a TO aaa; +#} + +#------------------------------------------------------------------------ +# +reset_db +do_execsql_test 26.1 { + CREATE TABLE t1(x); + + CREATE TABLE t3(y); + CREATE TABLE t4(z); + + CREATE TRIGGER tr1 INSERT ON t3 BEGIN + UPDATE t3 SET y=z FROM (SELECT z FROM t4); + END; + + CREATE TRIGGER tr2 INSERT ON t3 BEGIN + UPDATE t3 SET y=abc FROM (SELECT x AS abc FROM t1); + END; +} + +do_execsql_test 26.2 { + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 26.3 { + ALTER TABLE t2 RENAME x TO xx; +} + +do_execsql_test 26.4 { + SELECT sql FROM sqlite_schema WHERE name='tr2' +} { +{CREATE TRIGGER tr2 INSERT ON t3 BEGIN + UPDATE t3 SET y=abc FROM (SELECT xx AS abc FROM "t2"); + END} +} + +# 2020-11-02 OSSFuzz +# +reset_db +do_execsql_test 26.5 { + CREATE TABLE t1(xx); + CREATE TRIGGER xx INSERT ON t1 BEGIN + UPDATE t1 SET xx=xx FROM(SELECT xx); + END; +} {} +do_catchsql_test 26.6 { + ALTER TABLE t1 RENAME TO t2; +} {1 {error in trigger xx: no such column: xx}} + + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 27.1 { + CREATE TABLE t1(a, b AS ((WITH w1 (xyz) AS ( SELECT t1.b FROM t1 ) SELECT 123) IN ()), c); +} + +do_execsql_test 27.2 { + ALTER TABLE t1 DROP COLUMN c; + SELECT sql FROM sqlite_schema WHERE name = 't1'; +} { + {CREATE TABLE t1(a, b AS ((WITH w1 (xyz) AS ( SELECT t1.b FROM t1 ) SELECT 123) IN ()))} +} + +do_execsql_test 27.3 { + CREATE TABLE t0(c0 , c1 AS (CASE TRUE NOT IN () WHEN NULL THEN CASE + 0xa ISNULL WHEN NOT + 0x9 THEN t0.c1 ELSE CURRENT_TIME LIKE CAST (t0.c1 REGEXP '-([1-9]\d*.\d*|0\.\d*[1-9]\d*)'ESCAPE (c1) COLLATE BINARY BETWEEN c1 AND c1 NOT IN (WITH t4 (c0) AS (WITH t3 (c0) AS NOT MATERIALIZED (WITH RECURSIVE t2 (c0) AS (WITH RECURSIVE t1 AS (VALUES (x'717171ff71717171' ) ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY 0x9 ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c1 ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY typeof(0x9 ) ) SELECT DISTINCT t0.c0 FROM t0 NOT INDEXED WHERE t0.c0 =t0.c0 GROUP BY typeof(typeof(0x9 ) ) ) IN t0 BETWEEN typeof(typeof(typeof(hex(*) FILTER (WHERE + x'5ccd1e68' ) ) ) ) AND 1 >0xa AS BLOB (+4.4E4 , -0xe ) ) END <> c1 IN () END ) VIRTUAL , c35 PRIMARY KEY , c60 , c64 NUMERIC (-6.8 , -0xE ) ) WITHOUT ROWID ; +} {} + +do_execsql_test 27.4 { + ALTER TABLE t0 DROP COLUMN c60; +} {} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 28.1 { + CREATE TABLE t1(a,b,c,d); + CREATE TRIGGER AFTER INSERT ON t1 BEGIN + UPDATE t1 SET (c,d)=(a,b); + END; + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 28.2 { + SELECT sql FROM sqlite_schema WHERE type='trigger' +} {{CREATE TRIGGER AFTER INSERT ON "t2" BEGIN + UPDATE "t2" SET (c,d)=(a,b); + END}} + + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 29.1 { + CREATE TABLE t1(x, y); + CREATE TRIGGER Trigger1 DELETE ON t1 + BEGIN + SELECT t1.*, t1.x FROM t1 ORDER BY t1.x; + END; +} + + +do_execsql_test 29.2 { + ALTER TABLE t1 RENAME x TO z; +} + +do_execsql_test 29.3 { + ALTER TABLE t1 RENAME TO t2; +} + +do_execsql_test 29.4 { + CREATE TRIGGER tr2 AFTER DELETE ON t2 BEGIN + SELECT z, y FROM ( + SELECT t2.* FROM t2 + ); + END; +} + +do_execsql_test 29.5 { + DELETE FROM t2 +} + +do_execsql_test 29.6 { + ALTER TABLE t2 RENAME TO t3; +} + +do_execsql_test 29.7 { + SELECT sql FROM sqlite_schema WHERE type='trigger' +} { + {CREATE TRIGGER Trigger1 DELETE ON "t3" + BEGIN + SELECT "t3".*, "t3".z FROM "t3" ORDER BY "t3".z; + END} + {CREATE TRIGGER tr2 AFTER DELETE ON "t3" BEGIN + SELECT z, y FROM ( + SELECT "t3".* FROM "t3" + ); + 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/local-test-sqlite3-delta-01/afc-sqlite3/test/altertrig.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/altertrig.test new file mode 100644 index 0000000000000000000000000000000000000000..556dc3fea4c21a440b2a2fb6df43f1ea716fd92b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/altertrig.test @@ -0,0 +1,162 @@ +# 2022 May 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. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix altertrig + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable !altertable { + finish_test + return +} + +proc collapse_whitespace {in} { + regsub -all {[ \t\n]+} [string trim $in] { } +} + +proc do_whitespace_sql_test {tn sql res} { + set got [execsql $sql] + set wgot [list] + set wres [list] + foreach g $got { lappend wgot [collapse_whitespace $g] } + foreach r $res { lappend wres [collapse_whitespace $r] } + + uplevel [list do_test $tn [list set {} $wgot] $wres] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(x); + CREATE TABLE t2(y); + CREATE TABLE t3(z); + CREATE TABLE t4(a); + + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, t3; + END; +} + +do_whitespace_sql_test 1.1 { + ALTER TABLE t3 RENAME TO t5; + SELECT sql FROM sqlite_schema WHERE type='trigger'; +} {{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, "t5"; + END +}} + +do_execsql_test 1.2 { + DROP TRIGGER r1; + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t5); + END; +} + +do_whitespace_sql_test 1.3 { + ALTER TABLE t5 RENAME TO t3; + SELECT sql FROM sqlite_schema WHERE type='trigger'; +} {{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t3"); + END +}} + +foreach {tn alter update final} { + 1 { + ALTER TABLE t3 RENAME TO t10 + } { + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM t3) + } { + UPDATE t1 SET d='xyz' FROM t2, (SELECT * FROM "t10") + } + + 2 { + ALTER TABLE t3 RENAME TO t10 + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3)) + } { + UPDATE t1 SET a='xyz' FROM "t10", (SELECT * FROM (SELECT e FROM "t10")) + } + + 3 { + ALTER TABLE t3 RENAME e TO abc + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT e FROM t3)) + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT * FROM (SELECT abc FROM t3)) + } + + 4 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE c) + } { + UPDATE t1 SET a='xyz' FROM t3, (SELECT 1 FROM t2 WHERE abc) + } + + 5 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a=t2.c FROM t2 + } { + UPDATE t1 SET a=t2.abc FROM t2 + } + + 6 { + ALTER TABLE t2 RENAME c TO abc + } { + UPDATE t1 SET a=t2.c FROM t2, t3 + } { + UPDATE t1 SET a=t2.abc FROM t2, t3 + } + + 7 { + ALTER TABLE t4 RENAME e TO abc + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.abc=a + } + + 8 { + ALTER TABLE t4 RENAME TO abc + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN t4 WHERE t4.e=a + } { + UPDATE t1 SET a=1 FROM t3 NATURAL JOIN "abc" WHERE "abc".e=a + } + +} { + reset_db + do_execsql_test 2.$tn.1 { + CREATE TABLE t1(a,b); + CREATE TABLE t2(c,d); + CREATE TABLE t3(e,f); + CREATE TABLE t4(e,f); + } + do_execsql_test 2.$tn.2 " + CREATE TRIGGER r1 INSERT ON t1 BEGIN + $update; + END + " + do_execsql_test 2.$tn.3 $alter + + do_whitespace_sql_test 2.$tn.4 { + SELECT sqL FROM sqlite_schema WHERE type='trigger' + } "{ + CREATE TRIGGER r1 INSERT ON t1 BEGIN + $final; + END + }" +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/amatch1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/amatch1.test new file mode 100644 index 0000000000000000000000000000000000000000..cc0f77af107688e3fa1e6ae906b58f71e8dd11c1 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/amatch1.test @@ -0,0 +1,117 @@ +# 2013-09-30 +# +# 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 "approximate_match" virtual +# table that is in the "amatch.c" extension. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS4 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with +# the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + + + +do_test amatch1-1.0 { + db eval { + CREATE VIRTUAL TABLE t1 USING fts4(words); --, tokenize porter); + } + fts_kjv_genesis + db eval { + INSERT INTO t1(t1) VALUES('optimize'); + CREATE VIRTUAL TABLE temp.t1aux USING fts4aux(main, t1); + SELECT term FROM t1aux WHERE col=0 ORDER BY 1 LIMIT 5 + } +} {a abated abel abelmizraim abidah} +do_test amatch1-1.1 { + db eval { + SELECT term FROM t1aux WHERE term>'b' AND col=0 ORDER BY 1 LIMIT 5 + } +} {baalhanan babel back backward bad} +do_test amatch1-1.2 { + db eval { + SELECT term FROM t1aux WHERE term>'b' AND col=0 LIMIT 5 + } +} {baalhanan babel back backward bad} + +# Load the amatch extension +load_static_extension db amatch + +do_execsql_test amatch1-2.0 { + CREATE TABLE costs(iLang, cFrom, cTo, Cost); + INSERT INTO costs VALUES(0, '', '?', 100); + INSERT INTO costs VALUES(0, '?', '', 100); + INSERT INTO costs VALUES(0, '?', '?', 150); + CREATE TABLE vocab(w TEXT UNIQUE); + INSERT OR IGNORE INTO vocab SELECT term FROM t1aux; + CREATE VIRTUAL TABLE t2 USING approximate_match( + vocabulary_table=t1aux, + vocabulary_word=term, + edit_distances=costs + ); + CREATE VIRTUAL TABLE t3 USING approximate_match( + vocabulary_table=vocab, + vocabulary_word=w, + edit_distances=costs + ); + CREATE VIRTUAL TABLE t4 USING approximate_match( + vocabulary_table=vtemp, + vocabulary_word=w, + edit_distances=costs + ); +} {} +puts "Query against fts4aux: [time { + do_execsql_test amatch1-2.1 { + SELECT word, distance FROM t2 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +puts "Query against ordinary table: [time { + do_execsql_test amatch1-2.2 { + SELECT word, distance FROM t3 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +puts "Temp table initialized from fts4aux: [time { + do_execsql_test amatch1-2.3a { + CREATE TEMP TABLE vtemp(w TEXT UNIQUE); + INSERT OR IGNORE INTO vtemp SELECT term FROM t1aux; + } {}} 1]" +puts "Query against temp table: [time { + do_execsql_test amatch1-2.3b { + SELECT word, distance FROM t4 + WHERE word MATCH 'josxph' AND distance<300; + } {joseph 150}} 1]" +do_execsql_test amatch1-2.11 { + SELECT word, distance FROM t2 + WHERE word MATCH 'joxxph' AND distance<=300; +} {joseph 300} +do_execsql_test amatch1-2.12 { + SELECT word, distance FROM t3 + WHERE word MATCH 'joxxph' AND distance<=300; +} {joseph 300} +do_execsql_test amatch1-2.21 { + SELECT word, distance FROM t2 + WHERE word MATCH 'joxxph' AND distance<300; +} {} +do_execsql_test amatch1-2.22 { + SELECT word, distance FROM t3 + WHERE word MATCH 'joxxph' AND distance<300; +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze.test new file mode 100644 index 0000000000000000000000000000000000000000..f97c78aff1d3a39eb10669e32637ce22ecc0c79e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze.test @@ -0,0 +1,399 @@ +# 2005 July 22 +# +# 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. +# This file implements tests for the ANALYZE command. +# +# $Id: analyze.test,v 1.9 2008/08/11 18:44:58 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# +ifcapable {!analyze} { + finish_test + return +} + +# Basic sanity checks. +# +do_test analyze-1.1 { + catchsql { + ANALYZE no_such_table + } +} {1 {no such table: no_such_table}} +do_test analyze-1.2 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {0} +do_test analyze-1.3 { + catchsql { + ANALYZE no_such_db.no_such_table + } +} {1 {unknown database no_such_db}} +do_test analyze-1.4 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {0} +do_test analyze-1.5.1 { + catchsql { + ANALYZE + } +} {0 {}} +do_test analyze-1.5.2 { + catchsql { + PRAGMA empty_result_callbacks=1; + ANALYZE + } +} {0 {}} +do_test analyze-1.6 { + execsql { + SELECT count(*) FROM sqlite_master WHERE name='sqlite_stat1' + } +} {1} +do_test analyze-1.6.2 { + catchsql { + CREATE INDEX stat1idx ON sqlite_stat1(idx); + } +} {1 {table sqlite_stat1 may not be indexed}} +do_test analyze-1.6.3 { + catchsql { + CREATE INDEX main.stat1idx ON SQLite_stat1(idx); + } +} {1 {table sqlite_stat1 may not be indexed}} +do_test analyze-1.7 { + execsql { + SELECT * FROM sqlite_stat1 WHERE idx NOT NULL + } +} {} +do_test analyze-1.8 { + catchsql { + ANALYZE main + } +} {0 {}} +do_test analyze-1.9 { + execsql { + SELECT * FROM sqlite_stat1 WHERE idx NOT NULL + } +} {} +do_test analyze-1.10 { + catchsql { + CREATE TABLE t1(a,b); + ANALYZE main.t1; + } +} {0 {}} +do_test analyze-1.11 { + execsql { + SELECT * FROM sqlite_stat1 + } +} {} +do_test analyze-1.12 { + catchsql { + ANALYZE t1; + } +} {0 {}} +do_test analyze-1.13 { + execsql { + SELECT * FROM sqlite_stat1 + } +} {} + +# Create some indices that can be analyzed. But do not yet add +# data. Without data in the tables, no analysis is done. +# +do_test analyze-2.1 { + execsql { + CREATE INDEX t1i1 ON t1(a); + ANALYZE main.t1; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-2.2 { + execsql { + CREATE INDEX t1i2 ON t1(b); + ANALYZE t1; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-2.3 { + execsql { + CREATE INDEX t1i3 ON t1(a,b); + ANALYZE main; + SELECT * FROM sqlite_stat1 ORDER BY idx; + } +} {} + +# Start adding data to the table. Verify that the analysis +# is done correctly. +# +do_test analyze-3.1 { + execsql { + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(1,3); + ANALYZE main.t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {2 2} t1i2 {2 1} t1i3 {2 2 1}} +do_test analyze-3.2 { + execsql { + INSERT INTO t1 VALUES(1,4); + INSERT INTO t1 VALUES(1,5); + ANALYZE t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {4 4} t1i2 {4 1} t1i3 {4 4 1}} +do_test analyze-3.3 { + execsql { + INSERT INTO t1 VALUES(2,5); + ANALYZE main; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1}} +do_test analyze-3.4 { + execsql { + CREATE TABLE t2 AS SELECT * FROM t1; + CREATE INDEX t2i1 ON t2(a); + CREATE INDEX t2i2 ON t2(b); + CREATE INDEX t2i3 ON t2(a,b); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2} t2i3 {5 3 1}} +do_test analyze-3.5 { + execsql { + DROP INDEX t2i3; + ANALYZE t1; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}} +do_test analyze-3.6 { + execsql { + ANALYZE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3} t2i2 {5 2}} +do_test analyze-3.7 { + execsql { + DROP INDEX t2i2; + ANALYZE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t1i1 {5 3} t1i2 {5 2} t1i3 {5 3 1} t2i1 {5 3}} +do_test analyze-3.8 { + execsql { + CREATE TABLE t3 AS SELECT a, b, rowid AS c, 'hi' AS d FROM t1; + CREATE INDEX t3i1 ON t3(a); + CREATE INDEX t3i2 ON t3(a,b,c,d); + CREATE INDEX t3i3 ON t3(d,b,c,a); + DROP TABLE t1; + DROP TABLE t2; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {} +do_test analyze-3.9 { + execsql { + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} + +do_test analyze-3.10 { + execsql { + CREATE TABLE [silly " name](a, b, c); + CREATE INDEX 'foolish '' name' ON [silly " name](a, b); + CREATE INDEX 'another foolish '' name' ON [silly " name](c); + INSERT INTO [silly " name] VALUES(1, 2, 3); + INSERT INTO [silly " name] VALUES(4, 5, 6); + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {{another foolish ' name} {2 1} {foolish ' name} {2 1 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} +do_test analyze-3.11 { + execsql { + DROP INDEX "foolish ' name"; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {{another foolish ' name} {2 1} t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} +do_test analyze-3.11 { + execsql { + DROP TABLE "silly "" name"; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1}} + +# Try corrupting the sqlite_stat1 table and make sure the +# database is still able to function. +# +do_test analyze-4.0 { + sqlite3 db2 test.db + db2 eval { + CREATE TABLE t4(x,y,z); + CREATE INDEX t4i1 ON t4(x); + CREATE INDEX t4i2 ON t4(y); + INSERT INTO t4 SELECT a,b,c FROM t3; + } + db2 close + db close + sqlite3 db test.db + execsql { + ANALYZE; + SELECT idx, stat FROM sqlite_stat1 ORDER BY idx; + } +} {t3i1 {5 3} t3i2 {5 3 1 1 1} t3i3 {5 5 2 1 1} t4i1 {5 3} t4i2 {5 2}} +do_test analyze-4.1 { + execsql { + PRAGMA writable_schema=on; + INSERT INTO sqlite_stat1 VALUES(null,null,null); + PRAGMA writable_schema=off; + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} +do_test analyze-4.2 { + execsql { + PRAGMA writable_schema=on; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1 VALUES('t4','t4i1','nonsense'); + INSERT INTO sqlite_stat1 VALUES('t4','t4i2','120897349817238741092873198273409187234918720394817209384710928374109827172901827349871928741910'); + PRAGMA writable_schema=off; + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} +do_test analyze-4.3 { + execsql { + INSERT INTO sqlite_stat1 VALUES('t4','xyzzy','0 1 2 3'); + } + db close + sqlite3 db test.db + execsql { + SELECT * FROM t4 WHERE x=1234; + } +} {} + +# Verify that DROP TABLE and DROP INDEX remove entries from the +# sqlite_stat1 and sqlite_stat4 tables. +# +do_test analyze-5.0 { + execsql { + DELETE FROM t3; + DELETE FROM t4; + INSERT INTO t3 VALUES(1,2,3,4); + INSERT INTO t3 VALUES(5,6,7,8); + INSERT INTO t3 SELECT a+8, b+8, c+8, d+8 FROM t3; + INSERT INTO t3 SELECT a+16, b+16, c+16, d+16 FROM t3; + INSERT INTO t3 SELECT a+32, b+32, c+32, d+32 FROM t3; + INSERT INTO t3 SELECT a+64, b+64, c+64, d+64 FROM t3; + INSERT INTO t4 SELECT a, b, c FROM t3; + ANALYZE; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4} +ifcapable stat4 { + do_test analyze-5.1 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t3i1 t3i2 t3i3 t4i1 t4i2 t3 t4} +} +do_test analyze-5.2 { + execsql { + DROP INDEX t3i2; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t3i1 t3i3 t4i1 t4i2 t3 t4} +ifcapable stat4 { + do_test analyze-5.3 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t3i1 t3i3 t4i1 t4i2 t3 t4} +} +do_test analyze-5.4 { + execsql { + DROP TABLE t3; + SELECT DISTINCT idx FROM sqlite_stat1 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat1 ORDER BY 1; + } +} {t4i1 t4i2 t4} +ifcapable stat4 { + do_test analyze-5.5 { + execsql { + SELECT DISTINCT idx FROM sqlite_stat4 ORDER BY 1; + SELECT DISTINCT tbl FROM sqlite_stat4 ORDER BY 1; + } + } {t4i1 t4i2 t4} +} + +# This test corrupts the database file so it must be the last test +# in the series. +# +do_test analyze-5.99 { + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=on; + UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1'; + } + db close + catch { sqlite3 db test.db } + catchsql { + ANALYZE + } +} {1 {malformed database schema (sqlite_stat1)}} + +# Verify that tables whose names begin with "sqlite" but not +# "sqlite_" are analyzed. +# +db close +sqlite3 db :memory: +do_execsql_test analyze-6.1 { + CREATE TABLE sqliteDemo(a); + INSERT INTO sqliteDemo(a) VALUES(1),(2),(3),(4),(5); + CREATE TABLE SQLiteDemo2(a INTEGER PRIMARY KEY AUTOINCREMENT); + INSERT INTO SQLiteDemo2 SELECT * FROM sqliteDemo; + CREATE TABLE t1(b); + INSERT INTO t1(b) SELECT a FROM sqliteDemo; + ANALYZE; + SELECT tbl FROM sqlite_stat1 WHERE idx IS NULL ORDER BY tbl; +} {SQLiteDemo2 sqliteDemo t1} + +# The following caused a small buffer overread in STAT4 processing prior +# to check-in [b99135288b157044]. +# +ifcapable stat4 { + reset_db + database_may_be_corrupt + do_execsql_test analyze-7.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + INSERT INTO t1 VALUES(1, 7223372036854775); + INSERT INTO t1 VALUES(2, 7223372036854776); + INSERT INTO t1 VALUES(3, 7223372036854777); + CREATE INDEX i1 ON t1(b); + ANALYZE; + UPDATE sqlite_stat4 SET sample = substr(sample, 0, 4); + ANALYZE sqlite_schema; + SELECT * FROM t1 WHERE b>7223372036854775 + } {2 7223372036854776 3 7223372036854777} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze3.test new file mode 100644 index 0000000000000000000000000000000000000000..c5d7a7cb13a38b6f940728f228069639a2e37dda --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze3.test @@ -0,0 +1,766 @@ +# 2009 August 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. +# +#*********************************************************************** +# +# This file implements regression tests for SQLite library. This file +# implements tests for range and LIKE constraints that use bound variables +# instead of literal constant arguments. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix analyze3 + +ifcapable !stat4 { + finish_test + return +} + +# This test cannot be run with the sqlite3_prepare() permutation, as it +# tests that stat4 data can be used to influence the plans of queries +# based on bound variable values. And this is not possible when using +# sqlite3_prepare() - as queries cannot be internally re-prepared after +# binding values are available. +if {[permutation]=="prepare"} { + finish_test + return +} + +#---------------------------------------------------------------------- +# Test Organization: +# +# analyze3-1.*: Test that the values of bound parameters are considered +# in the same way as constants when planning queries that +# use range constraints. +# +# analyze3-2.*: Test that the values of bound parameters are considered +# in the same way as constants when planning queries that +# use LIKE expressions in the WHERE clause. +# +# analyze3-3.*: Test that binding to a variable does not invalidate the +# query plan when there is no way in which replanning the +# query may produce a superior outcome. +# +# analyze3-4.*: Test that SQL or authorization callback errors occuring +# within sqlite3Reprepare() are handled correctly. +# +# analyze3-5.*: Check that the query plans of applicable statements are +# invalidated if the values of SQL parameter are modified +# using the clear_bindings() or transfer_bindings() APIs. +# +# analyze3-6.*: Test that the problem fixed by commit [127a5b776d] is fixed. +# +# analyze3-7.*: Test that some memory leaks discovered by fuzz testing +# have been fixed. +# + +proc getvar {varname} { uplevel #0 set $varname } +db function var getvar + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +proc sf_execsql {sql {db db}} { + set ::sqlite_search_count 0 + set r [uplevel [list execsql $sql $db]] + + concat $::sqlite_search_count [$db status step] $r +} + +#------------------------------------------------------------------------- +# +# analyze3-1.1.1: +# Create a table with two columns. Populate the first column (affinity +# INTEGER) with integer values from 100 to 1100. Create an index on this +# column. ANALYZE the table. +# +# analyze3-1.1.2 - 3.1.3 +# Show that there are two possible plans for querying the table with +# a range constraint on the indexed column - "full table scan" or "use +# the index". When the range is specified using literal values, SQLite +# is able to pick the best plan based on the samples in sqlite_stat3. +# +# analyze3-1.1.4 - 3.1.9 +# Show that using SQL variables produces the same results as using +# literal values to constrain the range scan. +# +# These tests also check that the compiler code considers column +# affinities when estimating the number of rows scanned by the "use +# index strategy". +# +do_test analyze3-1.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(x INTEGER, y); + CREATE INDEX i1 ON t1(x); + } + for {set i 0} {$i < 1000} {incr i} { + execsql { INSERT INTO t1 VALUES($i+100, $i) } + } + execsql { + COMMIT; + ANALYZE; + } + + execsql { SELECT count(*)>0 FROM sqlite_stat4; } +} {1} + +do_execsql_test analyze3-1.1.x { + SELECT count(*) FROM t1 WHERE x>200 AND x<300; + SELECT count(*) FROM t1 WHERE x>0 AND x<1100; +} {99 1000} + +# The first of the following two SELECT statements visits 99 rows. So +# it is better to use the index. But the second visits every row in +# the table (1000 in total) so it is better to do a full-table scan. +# +do_eqp_test analyze3-1.1.2 { + SELECT sum(y) FROM t1 WHERE x>200 AND x<300 +} {SEARCH t1 USING INDEX i1 (x>? AND x0 AND x<1100 +} {SCAN t1} + +# 2017-06-26: Verify that the SQLITE_DBCONFIG_ENABLE_QPSG setting disables +# the use of bound parameters by STAT4 +# +db cache flush +unset -nocomplain l +unset -nocomplain u +do_eqp_test analyze3-1.1.3.100 { + SELECT sum(y) FROM t1 WHERE x>$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SCAN t1} +db cache flush +sqlite3_db_config db ENABLE_QPSG 1 +do_eqp_test analyze3-1.1.3.103 { + SELECT sum(y) FROM t1 WHERE x>$l AND x<$u +} {SEARCH t1 USING INDEX i1 (x>? AND x$l AND x<$u +} {SCAN t1} + +do_test analyze3-1.1.4 { + sf_execsql { SELECT sum(y) FROM t1 WHERE x>200 AND x<300 } +} {199 0 14850} +do_test analyze3-1.1.5 { + set l [string range "200" 0 end] + set u [string range "300" 0 end] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.1.6 { + set l [expr int(200)] + set u [expr int(300)] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.1.7 { + sf_execsql { SELECT sum(y) FROM t1 WHERE x>0 AND x<1100 } +} {999 999 499500} +do_test analyze3-1.1.8 { + set l [string range "0" 0 end] + set u [string range "1100" 0 end] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {999 999 499500} +do_test analyze3-1.1.9 { + set l [expr int(0)] + set u [expr int(1100)] + sf_execsql { SELECT sum(y) FROM t1 WHERE x>$l AND x<$u } +} {999 999 499500} + + +# The following tests are similar to the block above. The difference is +# that the indexed column has TEXT affinity in this case. In the tests +# above the affinity is INTEGER. +# +do_test analyze3-1.2.1 { + execsql { + BEGIN; + CREATE TABLE t2(x TEXT, y); + INSERT INTO t2 SELECT * FROM t1; + CREATE INDEX i2 ON t2(x); + COMMIT; + ANALYZE; + } +} {} +do_execsql_test analyze3-2.1.x { + SELECT count(*) FROM t2 WHERE x>1 AND x<2; + SELECT count(*) FROM t2 WHERE x>0 AND x<99; +} {200 990} +do_eqp_test analyze3-1.2.2 { + SELECT sum(y) FROM t2 WHERE x>1 AND x<2 +} {SEARCH t2 USING INDEX i2 (x>? AND x0 AND x<99 +} {SCAN t2} + +do_test analyze3-1.2.4 { + sf_execsql { SELECT sum(y) FROM t2 WHERE x>12 AND x<20 } +} {161 0 4760} +do_test analyze3-1.2.5 { + set l [string range "12" 0 end] + set u [string range "20" 0 end] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {161 0 text text 4760} +do_test analyze3-1.2.6 { + set l [expr int(12)] + set u [expr int(20)] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {161 0 integer integer 4760} +do_test analyze3-1.2.7 { + sf_execsql { SELECT sum(y) FROM t2 WHERE x>0 AND x<99 } +} {999 999 490555} +do_test analyze3-1.2.8 { + set l [string range "0" 0 end] + set u [string range "99" 0 end] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {999 999 text text 490555} +do_test analyze3-1.2.9 { + set l [expr int(0)] + set u [expr int(99)] + sf_execsql {SELECT typeof($l), typeof($u), sum(y) FROM t2 WHERE x>$l AND x<$u} +} {999 999 integer integer 490555} + +# Same tests a third time. This time, column x has INTEGER affinity and +# is not the leftmost column of the table. This triggered a bug causing +# SQLite to use sub-optimal query plans in 3.6.18 and earlier. +# +do_test analyze3-1.3.1 { + execsql { + BEGIN; + CREATE TABLE t3(y TEXT, x INTEGER); + INSERT INTO t3 SELECT y, x FROM t1; + CREATE INDEX i3 ON t3(x); + COMMIT; + ANALYZE; + } +} {} +do_execsql_test analyze3-1.3.x { + SELECT count(*) FROM t3 WHERE x>200 AND x<300; + SELECT count(*) FROM t3 WHERE x>0 AND x<1100 +} {99 1000} +do_eqp_test analyze3-1.3.2 { + SELECT sum(y) FROM t3 WHERE x>200 AND x<300 +} {SEARCH t3 USING INDEX i3 (x>? AND x0 AND x<1100 +} {SCAN t3} + +do_test analyze3-1.3.4 { + sf_execsql { SELECT sum(y) FROM t3 WHERE x>200 AND x<300 } +} {199 0 14850} +do_test analyze3-1.3.5 { + set l [string range "200" 0 end] + set u [string range "300" 0 end] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.3.6 { + set l [expr int(200)] + set u [expr int(300)] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {199 0 14850} +do_test analyze3-1.3.7 { + sf_execsql { SELECT sum(y) FROM t3 WHERE x>0 AND x<1100 } +} {999 999 499500} +do_test analyze3-1.3.8 { + set l [string range "0" 0 end] + set u [string range "1100" 0 end] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {999 999 499500} +do_test analyze3-1.3.9 { + set l [expr int(0)] + set u [expr int(1100)] + sf_execsql { SELECT sum(y) FROM t3 WHERE x>$l AND x<$u } +} {999 999 499500} + +#------------------------------------------------------------------------- +# Test that the values of bound SQL variables may be used for the LIKE +# optimization. +# +drop_all_tables +do_test analyze3-2.1 { + execsql { + PRAGMA case_sensitive_like=off; + BEGIN; + CREATE TABLE t1(a, b TEXT COLLATE nocase); + CREATE INDEX i1 ON t1(b); + } + for {set i 0} {$i < 1000} {incr i} { + set t "" + append t [lindex {a b c d e f g h i j} [expr $i/100]] + append t [lindex {a b c d e f g h i j} [expr ($i/10)%10]] + append t [lindex {a b c d e f g h i j} [expr ($i%10)]] + execsql { INSERT INTO t1 VALUES($i, $t) } + } + execsql COMMIT +} {} +do_eqp_test analyze3-2.2 { + SELECT count(a) FROM t1 WHERE b LIKE 'a%' +} {SEARCH t1 USING INDEX i1 (b>? AND b?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.2.2 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.2.4 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.2.5 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE b=?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.2.6 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.2.7 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.4.1 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.4.2 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.4.3 { + sqlite3_bind_text $S 2 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.4.4 { + sqlite3_bind_text $S 2 "ghi" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.4.5 { + sqlite3_expired $S +} {1} +do_test analyze3-3.4.6 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.5.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31 + ) AND b>?32; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.5.2 { + sqlite3_bind_text $S 31 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.5.3 { + sqlite3_bind_text $S 32 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.5.5 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.6.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31, ?32 + ) AND b>?33; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.6.2 { + sqlite3_bind_text $S 32 "abc" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.6.3 { + sqlite3_bind_text $S 33 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.6.5 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.7.1 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t1 WHERE a IN ( + ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?33, + ?11, ?12, ?13, ?14, ?15, ?16, ?17, ?18, ?19, ?20, + ?21, ?22, ?23, ?24, ?25, ?26, ?27, ?28, ?29, ?30, ?31, ?32 + ) AND b>?10; + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.7.2 { + sqlite3_bind_text $S 32 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.7.3 { + sqlite3_bind_text $S 33 "def" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.7.4 { + sqlite3_bind_text $S 10 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.7.6 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-3.8.1 { + execsql { + CREATE TABLE t4(x, y TEXT COLLATE NOCASE); + CREATE INDEX i4 ON t4(y); + } +} {} +do_test analyze3-3.8.2 { + set S [sqlite3_prepare_v2 db { + SELECT * FROM t4 WHERE x != ? AND y LIKE ? + } -1 dummy] + sqlite3_expired $S +} {0} +do_test analyze3-3.8.3 { + sqlite3_bind_text $S 1 "abc" 3 + sqlite3_expired $S +} {0} +do_test analyze3-3.8.4 { + sqlite3_bind_text $S 2 "def" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.7 { + sqlite3_bind_text $S 2 "ghi%" 4 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.8 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.9 { + sqlite3_bind_text $S 2 "ghi%def" 7 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.10 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.11 { + sqlite3_bind_text $S 2 "%ab" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.12 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.12 { + sqlite3_bind_text $S 2 "%de" 3 + sqlite3_expired $S +} {1} +do_test analyze3-3.8.13 { + sqlite3_expired $S +} {1} +do_test analyze3-3.8.14 { + sqlite3_finalize $S +} {SQLITE_OK} + +#------------------------------------------------------------------------- +# These tests check that errors encountered while repreparing an SQL +# statement within sqlite3Reprepare() are handled correctly. +# + +# Check a schema error. +# +do_test analyze3-4.1.1 { + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_step $S +} {SQLITE_DONE} +do_test analyze3-4.1.2 { + sqlite3_reset $S + sqlite3_bind_text $S 2 "abc" 3 + execsql { DROP TABLE t1 } + sqlite3_step $S +} {SQLITE_ERROR} +do_test analyze3-4.1.3 { + sqlite3_finalize $S +} {SQLITE_ERROR} + +# Check an authorization error. +# +do_test analyze3-4.2.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(b); + } + for {set i 0} {$i < 100} {incr i} { + execsql { INSERT INTO t1 VALUES($i, $i, $i) } + } + execsql COMMIT + execsql ANALYZE + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + sqlite3_step $S +} {SQLITE_DONE} +db auth auth +proc auth {args} { + if {[lindex $args 0] == "SQLITE_READ"} {return SQLITE_DENY} + return SQLITE_OK +} +do_test analyze3-4.2.2 { + sqlite3_reset $S + sqlite3_bind_text $S 2 "abc" 3 + sqlite3_step $S +} {SQLITE_AUTH} +do_test analyze3-4.2.4 { + sqlite3_finalize $S +} {SQLITE_AUTH} + +# Check the effect of an authorization error that occurs in a re-prepare +# performed by sqlite3_step() is the same as one that occurs within +# sqlite3Reprepare(). +# +do_test analyze3-4.3.1 { + db auth {} + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE a=? AND b>?" -1 dummy] + execsql { CREATE TABLE t2(d, e, f) } + db auth auth + sqlite3_step $S +} {SQLITE_AUTH} +do_test analyze3-4.3.2 { + sqlite3_finalize $S +} {SQLITE_AUTH} +db auth {} + +#------------------------------------------------------------------------- +# Test that modifying bound variables using the clear_bindings() or +# transfer_bindings() APIs works. +# +# analyze3-5.1.*: sqlite3_clear_bindings() +# analyze3-5.2.*: sqlite3_transfer_bindings() +# +do_test analyze3-5.1.1 { + drop_all_tables + execsql { + CREATE TABLE t1(x TEXT COLLATE NOCASE); + CREATE INDEX i1 ON t1(x); + INSERT INTO t1 VALUES('aaa'); + INSERT INTO t1 VALUES('abb'); + INSERT INTO t1 VALUES('acc'); + INSERT INTO t1 VALUES('baa'); + INSERT INTO t1 VALUES('bbb'); + INSERT INTO t1 VALUES('bcc'); + } + + set S [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x LIKE ?" -1 dummy] + sqlite3_bind_text $S 1 "a%" 2 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S] } { + lappend R [sqlite3_column_text $S 0] + } + concat [sqlite3_reset $S] $R +} {SQLITE_OK aaa abb acc} +do_test analyze3-5.1.2 { + sqlite3_clear_bindings $S + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S] } { + lappend R [sqlite3_column_text $S 0] + } + concat [sqlite3_reset $S] $R +} {SQLITE_OK} +do_test analyze3-5.1.3 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test analyze3-5.1.1 { + set S1 [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x LIKE ?" -1 dummy] + sqlite3_bind_text $S1 1 "b%" 2 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S1] } { + lappend R [sqlite3_column_text $S1 0] + } + concat [sqlite3_reset $S1] $R +} {SQLITE_OK baa bbb bcc} + +do_test analyze3-5.1.2 { + set S2 [sqlite3_prepare_v2 db "SELECT * FROM t1 WHERE x = ?" -1 dummy] + sqlite3_bind_text $S2 1 "a%" 2 + sqlite3_transfer_bindings $S2 $S1 + set R [list] + while { "SQLITE_ROW" == [sqlite3_step $S1] } { + lappend R [sqlite3_column_text $S1 0] + } + concat [sqlite3_reset $S1] $R +} {SQLITE_OK aaa abb acc} +do_test analyze3-5.1.3 { + sqlite3_finalize $S2 + sqlite3_finalize $S1 +} {SQLITE_OK} + +#------------------------------------------------------------------------- + +do_test analyze3-6.1 { + execsql { DROP TABLE IF EXISTS t1 } + execsql BEGIN + execsql { CREATE TABLE t1(a, b, c) } + for {set i 0} {$i < 1000} {incr i} { + execsql "INSERT INTO t1 VALUES([expr $i/100], 'x', [expr $i/10])" + } + execsql { + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(c); + } + execsql COMMIT + execsql ANALYZE +} {} + +do_eqp_test analyze3-6-3 { + SELECT * FROM t1 WHERE a = 5 AND c = 13; +} {SEARCH t1 USING INDEX i2 (c=?)} + +do_eqp_test analyze3-6-2 { + SELECT * FROM t1 WHERE a = 5 AND b > 'w' AND c = 13; +} {SEARCH t1 USING INDEX i2 (c=?)} + +#----------------------------------------------------------------------------- +# 2015-04-20. +# Memory leak in sqlite3Stat4ProbeFree(). (Discovered while fuzzing.) +# +do_execsql_test analyze-7.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + INSERT INTO t1 VALUES(1,1,'0000'); + CREATE INDEX t0b ON t1(b); + ANALYZE; + SELECT c FROM t1 WHERE b=3 AND a BETWEEN 30 AND hex(1); +} {} + +# At one point duplicate stat1 entries were causing a memory leak. +# +reset_db +do_execsql_test 7.2 { + CREATE TABLE t1(a,b,c); + CREATE INDEX t1a ON t1(a); + ANALYZE; + SELECT * FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t1','t1a','12000'); + ANALYZE sqlite_master; +} + +# 2023-04-22 https://sqlite.org/forum/info/6c118daad0f1f5ef +# Case differences in the sqlite_stat4.idx field should not matter. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE t1(a PRIMARY KEY, v) WITHOUT ROWID; + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t1','t1','1 1'); + INSERT INTO sqlite_stat4 VALUES('t1','t1','1','0','0',X'021b76657273696f6e'); + INSERT INTO sqlite_stat4 VALUES('T1','T1','1','0','0',X'021b76657273696f6e'); + ANALYZE sqlite_schema; +} {} + +# 2023-05-03 https://sqlite.org/forum/forumpost/537d8ab118 +# Same index appears by two different names in the sqlite_stat4 table. +# +reset_db +do_execsql_test 8.1 { + CREATE TABLE t1(a INT PRIMARY KEY, b INT) WITHOUT ROWID; + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat4 VALUES + ('t1','t1','1','2','2',X'03000103'), + ('t1','sqlite_autoindex_t1_1','1','2','2',X'03000103'); + ANALYZE sqlite_schema; + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze5.test new file mode 100644 index 0000000000000000000000000000000000000000..e58457a6776d534ddf12e0feed56a445871838d3 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze5.test @@ -0,0 +1,247 @@ +# 2011 January 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 SQLite library. The focus of the tests +# in this file is the use of the sqlite_stat4 histogram data on tables +# with many repeated values and only a few distinct values. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze5 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +proc alpha {blob} { + set ret "" + foreach c [split $blob {}] { + if {[string is alpha $c]} {append ret $c} + } + return $ret +} +db func alpha alpha + +db func lindex lindex + +unset -nocomplain i t u v w x y z +do_test analyze5-1.0 { + db eval {CREATE TABLE t1(t,u,v TEXT COLLATE nocase,w,x,y,z)} + for {set i 0} {$i < 1000} {incr i} { + set y [expr {$i>=25 && $i<=50}] + set z [expr {($i>=400) + ($i>=700) + ($i>=875)}] + set x $z + set w $z + set t [expr {$z+0.5}] + switch $z { + 0 {set u "alpha"; unset x} + 1 {set u "bravo"} + 2 {set u "charlie"} + 3 {set u "delta"; unset w} + } + if {$i%2} {set v $u} {set v [string toupper $u]} + db eval {INSERT INTO t1 VALUES($t,$u,$v,$w,$x,$y,$z)} + } + db eval { + CREATE INDEX t1t ON t1(t); -- 0.5, 1.5, 2.5, and 3.5 + CREATE INDEX t1u ON t1(u); -- text + CREATE INDEX t1v ON t1(v); -- mixed case text + CREATE INDEX t1w ON t1(w); -- integers 0, 1, 2 and a few NULLs + CREATE INDEX t1x ON t1(x); -- integers 1, 2, 3 and many NULLs + CREATE INDEX t1y ON t1(y); -- integers 0 and very few 1s + CREATE INDEX t1z ON t1(z); -- integers 0, 1, 2, and 3 + ANALYZE; + } + db eval { + SELECT DISTINCT lindex(test_decode(sample),0) + FROM sqlite_stat4 WHERE idx='t1u' ORDER BY nlt; + } +} {alpha bravo charlie delta} + +do_test analyze5-1.1 { + db eval { + SELECT DISTINCT lower(lindex(test_decode(sample), 0)) + FROM sqlite_stat4 WHERE idx='t1v' ORDER BY 1 + } +} {alpha bravo charlie delta} +do_test analyze5-1.2 { + db eval {SELECT idx, count(*) FROM sqlite_stat4 GROUP BY 1 ORDER BY 1} +} {t1t 8 t1u 8 t1v 8 t1w 8 t1x 8 t1y 9 t1z 8} + +# Verify that range queries generate the correct row count estimates +# +foreach {testid where index rows} { + 1 {z>=0 AND z<=0} t1z 400 + 2 {z>=1 AND z<=1} t1z 300 + 3 {z>=2 AND z<=2} t1z 175 + 4 {z>=3 AND z<=3} t1z 125 + 5 {z>=4 AND z<=4} t1z 1 + 6 {z>=-1 AND z<=-1} t1z 1 + 7 {z>1 AND z<3} t1z 175 + 8 {z>0 AND z<100} t1z 600 + 9 {z>=1 AND z<100} t1z 600 + 10 {z>1 AND z<100} t1z 300 + 11 {z>=2 AND z<100} t1z 300 + 12 {z>2 AND z<100} t1z 125 + 13 {z>=3 AND z<100} t1z 125 + 14 {z>3 AND z<100} t1z 1 + 15 {z>=4 AND z<100} t1z 1 + 16 {z>=-100 AND z<=-1} t1z 1 + 17 {z>=-100 AND z<=0} t1z 400 + 18 {z>=-100 AND z<0} t1z 1 + 19 {z>=-100 AND z<=1} t1z 700 + 20 {z>=-100 AND z<2} t1z 700 + 21 {z>=-100 AND z<=2} t1z 875 + 22 {z>=-100 AND z<3} t1z 875 + + 31 {z>=0.0 AND z<=0.0} t1z 400 + 32 {z>=1.0 AND z<=1.0} t1z 300 + 33 {z>=2.0 AND z<=2.0} t1z 175 + 34 {z>=3.0 AND z<=3.0} t1z 125 + 35 {z>=4.0 AND z<=4.0} t1z 1 + 36 {z>=-1.0 AND z<=-1.0} t1z 1 + 37 {z>1.5 AND z<3.0} t1z 174 + 38 {z>0.5 AND z<100} t1z 599 + 39 {z>=1.0 AND z<100} t1z 600 + 40 {z>1.5 AND z<100} t1z 299 + 41 {z>=2.0 AND z<100} t1z 300 + 42 {z>2.1 AND z<100} t1z 124 + 43 {z>=3.0 AND z<100} t1z 125 + 44 {z>3.2 AND z<100} t1z 1 + 45 {z>=4.0 AND z<100} t1z 1 + 46 {z>=-100 AND z<=-1.0} t1z 1 + 47 {z>=-100 AND z<=0.0} t1z 400 + 48 {z>=-100 AND z<0.0} t1z 1 + 49 {z>=-100 AND z<=1.0} t1z 700 + 50 {z>=-100 AND z<2.0} t1z 700 + 51 {z>=-100 AND z<=2.0} t1z 875 + 52 {z>=-100 AND z<3.0} t1z 875 + + 101 {z=-1} t1z 1 + 102 {z=0} t1z 400 + 103 {z=1} t1z 300 + 104 {z=2} t1z 175 + 105 {z=3} t1z 125 + 106 {z=4} t1z 1 + 107 {z=-10.0} t1z 1 + 108 {z=0.0} t1z 400 + 109 {z=1.0} t1z 300 + 110 {z=2.0} t1z 175 + 111 {z=3.0} t1z 125 + 112 {z=4.0} t1z 1 + 113 {z=1.5} t1z 1 + 114 {z=2.5} t1z 1 + + 201 {z IN (-1)} t1z 1 + 202 {z IN (0)} t1z 400 + 203 {z IN (1)} t1z 300 + 204 {z IN (2)} t1z 175 + 205 {z IN (3)} t1z 125 + 206 {z IN (4)} t1z 1 + 207 {z IN (0.5)} t1z 1 + 208 {z IN (0,1)} t1z 700 + 209 {z IN (0,1,2)} t1z 875 + 210 {z IN (0,1,2,3)} {} 100 + 211 {z IN (0,1,2,3,4,5)} {} 100 + 212 {z IN (1,2)} t1z 475 + 213 {z IN (2,3)} t1z 300 + 214 {z=3 OR z=2} t1z 300 + 215 {z IN (-1,3)} t1z 126 + 216 {z=-1 OR z=3} t1z 126 + + 300 {y=0} t1y 974 + 301 {y=1} t1y 26 + 302 {y=0.1} t1y 1 + + 400 {x IS NULL} t1x 400 + +} { + # Verify that the expected index is used with the expected row count + # No longer valid due to an EXPLAIN QUERY PLAN output format change + # do_test analyze5-1.${testid}a { + # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] + # set idx {} + # regexp {INDEX (t1.) } $x all idx + # regexp {~([0-9]+) rows} $x all nrow + # list $idx $nrow + # } [list $index $rows] + + # Verify that the same result is achieved regardless of whether or not + # the index is used + do_test analyze5-1.${testid}b { + set w2 [string map {y +y z +z} $where] + set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ + ORDER BY +rowid"] + set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] + if {$a1==$a2} { + set res ok + } else { + set res "a1=\[$a1\] a2=\[$a2\]" + } + set res + } {ok} +} + +# Increase the number of NULLs in column x +# +db eval { + UPDATE t1 SET x=NULL; + UPDATE t1 SET x=rowid + WHERE rowid IN (SELECT rowid FROM t1 ORDER BY random() LIMIT 5); + ANALYZE; +} + +# Verify that range queries generate the correct row count estimates +# +foreach {testid where index rows} { + 500 {x IS NULL AND u='charlie'} t1u 17 + 501 {x=1 AND u='charlie'} t1x 1 + 502 {x IS NULL} t1x 995 + 503 {x=1} t1x 1 + 504 {x IS NOT NULL} t1x 2 + 505 {+x IS NOT NULL} {} 500 + 506 {upper(x) IS NOT NULL} {} 500 + +} { + # Verify that the expected index is used with the expected row count + # No longer valid due to an EXPLAIN QUERY PLAN format change + # do_test analyze5-1.${testid}a { + # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] + # set idx {} + # regexp {INDEX (t1.) } $x all idx + # regexp {~([0-9]+) rows} $x all nrow + # list $idx $nrow + # } [list $index $rows] + + # Verify that the same result is achieved regardless of whether or not + # the index is used + do_test analyze5-1.${testid}b { + set w2 [string map {y +y z +z} $where] + set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ + ORDER BY +rowid"] + set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] + if {$a1==$a2} { + set res ok + } else { + set res "a1=\[$a1\] a2=\[$a2\]" + } + set res + } {ok} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze6.test new file mode 100644 index 0000000000000000000000000000000000000000..807fec132a000c833859f62629a474af0bfd412e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze6.test @@ -0,0 +1,126 @@ +# 2011 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 tests for SQLite library. The focus of the tests +# in this file a corner-case query planner optimization involving the +# join order of two tables of different sizes. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze6 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +do_test analyze6-1.0 { + db eval { + CREATE TABLE cat(x INT, yz TEXT); + CREATE UNIQUE INDEX catx ON cat(x); + /* Give cat 16 unique integers */ + INSERT INTO cat(x) VALUES(1); + INSERT INTO cat(x) VALUES(2); + INSERT INTO cat(x) SELECT x+2 FROM cat; + INSERT INTO cat(x) SELECT x+4 FROM cat; + INSERT INTO cat(x) SELECT x+8 FROM cat; + + CREATE TABLE ev(y INT); + CREATE INDEX evy ON ev(y); + /* ev will hold 32 copies of 16 integers found in cat */ + INSERT INTO ev SELECT x FROM cat; + INSERT INTO ev SELECT x FROM cat; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + INSERT INTO ev SELECT y FROM ev; + ANALYZE; + SELECT count(*) FROM cat; + SELECT count(*) FROM ev; + } +} {16 512} + +# The lowest cost plan is to scan CAT and for each integer there, do a single +# lookup of the first corresponding entry in EV then read off the equal values +# in EV. (Prior to the 2011-03-04 enhancement to where.c, this query would +# have used EV for the outer loop instead of CAT - which was about 3x slower.) +# +do_test analyze6-1.1 { + eqp {SELECT count(*) FROM ev, cat WHERE x=y} +} {/*SCAN cat USING COVERING INDEX catx*SEARCH ev USING COVERING INDEX evy (y=?)*/} + +# The same plan is chosen regardless of the order of the tables in the +# FROM clause. +# +do_eqp_test analyze6-1.2 { + SELECT count(*) FROM cat, ev WHERE x=y +} { + QUERY PLAN + |--SCAN cat USING COVERING INDEX catx + `--SEARCH ev USING COVERING INDEX evy (y=?) +} + + +# Ticket [83ea97620bd3101645138b7b0e71c12c5498fe3d] 2011-03-30 +# If ANALYZE is run on an empty table, make sure indices are used +# on the table. +# +do_test analyze6-2.1 { + execsql { + CREATE TABLE t201(x INTEGER PRIMARY KEY, y UNIQUE, z); + CREATE INDEX t201z ON t201(z); + ANALYZE; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.2 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.3 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} +do_test analyze6-2.4 { + execsql { + INSERT INTO t201 VALUES(1,2,3),(2,3,4),(3,4,5); + ANALYZE t201; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.5 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.6 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} +do_test analyze6-2.7 { + execsql { + INSERT INTO t201 VALUES(4,5,7); + INSERT INTO t201 SELECT x+100, y+100, z+100 FROM t201; + INSERT INTO t201 SELECT x+200, y+200, z+200 FROM t201; + INSERT INTO t201 SELECT x+400, y+400, z+400 FROM t201; + ANALYZE t201; + } + eqp {SELECT * FROM t201 WHERE z=5} +} {/*SEARCH t201 USING INDEX t201z (z=?)*/} +do_test analyze6-2.8 { + eqp {SELECT * FROM t201 WHERE y=5} +} {/*SEARCH t201 USING INDEX sqlite_autoindex_t201_1 (y=?)*/} +do_test analyze6-2.9 { + eqp {SELECT * FROM t201 WHERE x=5} +} {/*SEARCH t201 USING INTEGER PRIMARY KEY (rowid=?)*/} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze8.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze8.test new file mode 100644 index 0000000000000000000000000000000000000000..69605fd6f758d2d1d7d55af06480ffa3630891e5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyze8.test @@ -0,0 +1,115 @@ +# 2011 August 13 +# +# 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 SQLite library. The focus of the tests +# in this file is testing the capabilities of sqlite_stat4. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !stat4 { + finish_test + return +} + +set testprefix analyze8 + +proc eqp {sql {db db}} { + uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db +} + +# Scenario: +# +# Two indices. One has mostly singleton entries, but for a few +# values there are hundreds of entries. The other has 10-20 +# entries per value. +# +# Verify that the query planner chooses the first index for the singleton +# entries and the second index for the others. +# +do_test 1.0 { + db eval { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t1c ON t1(c); + } + for {set i 0} {$i<1000} {incr i} { + if {$i%2==0} {set a $i} {set a [expr {($i%8)*100}]} + set b [expr {$i/10}] + set c [expr {$i/8}] + set c [expr {$c*$c*$c}] + db eval {INSERT INTO t1 VALUES($a,$b,$c,$i)} + } + db eval {ANALYZE} +} {} + +# The a==100 comparison is expensive because there are many rows +# with a==100. And so for those cases, choose the t1b index. +# +# Buf ro a==99 and a==101, there are far fewer rows so choose +# the t1a index. +# +do_test 1.1 { + eqp {SELECT * FROM t1 WHERE a=100 AND b=55} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test 1.2 { + eqp {SELECT * FROM t1 WHERE a=99 AND b=55} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.3 { + eqp {SELECT * FROM t1 WHERE a=101 AND b=55} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.4 { + eqp {SELECT * FROM t1 WHERE a=100 AND b=56} +} {/*SEARCH t1 USING INDEX t1b (b=?)*/} +do_test 1.5 { + eqp {SELECT * FROM t1 WHERE a=99 AND b=56} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 1.6 { + eqp {SELECT * FROM t1 WHERE a=101 AND b=56} +} {/*SEARCH t1 USING INDEX t1a (a=?)*/} +do_test 2.1 { + eqp {SELECT * FROM t1 WHERE a=100 AND b BETWEEN 50 AND 54} +} {/*SEARCH t1 USING INDEX t1b (b>? AND b? AND b? AND c? AND c90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES($a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.1.3 { + SELECT * FROM t3 WHERE a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.1.4 { + SELECT * FROM t3 WHERE a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +do_execsql_test 10.2.1 { + DROP TABLE IF EXISTS t3; + CREATE TABLE t3(x, a, b); + CREATE INDEX t3a ON t3(x, a); + CREATE INDEX t3b ON t3(x, b); +} +do_test 10.2.2 { + for {set i 1} {$i < 100} {incr i} { + if {$i>90} { set a $i } else { set a NULL } + set b [expr $i % 5] + execsql "INSERT INTO t3 VALUES('xyz', $a, $b)" + } + execsql ANALYZE +} {} +do_eqp_test 10.2.3 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NULL AND b = 2 +} {/t3 USING INDEX t3b/} +do_eqp_test 10.2.4 { + SELECT * FROM t3 WHERE x = 'xyz' AND a IS NOT NULL AND b = 2 +} {/t3 USING INDEX t3a/} + +#------------------------------------------------------------------------- +# Check that stat4 data is used correctly with non-default collation +# sequences. +# +foreach {tn schema} { + 1 { + CREATE TABLE t4(a COLLATE nocase, b); + CREATE INDEX t4a ON t4(a); + CREATE INDEX t4b ON t4(b); + } + 2 { + CREATE TABLE t4(a, b); + CREATE INDEX t4a ON t4(a COLLATE nocase); + CREATE INDEX t4b ON t4(b); + } +} { + drop_all_tables + do_test 11.$tn.1 { execsql $schema } {} + + do_test 11.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES($a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 11.$tn.3 { + SELECT * FROM t4 WHERE a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE a = 'abc' AND b = 3;" + do_eqp_test 11.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + + set sql "SELECT * FROM t4 WHERE a = 'abc' COLLATE nocase AND b = 3;" + do_eqp_test 11.$tn.5 $sql {/t4 USING INDEX t4a/} + + set sql "SELECT * FROM t4 WHERE a COLLATE nocase = 'abc' AND b = 3;" + do_eqp_test 11.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + +foreach {tn schema} { + 1 { + CREATE TABLE t4(x, a COLLATE nocase, b); + CREATE INDEX t4a ON t4(x, a); + CREATE INDEX t4b ON t4(x, b); + } + 2 { + CREATE TABLE t4(x, a, b); + CREATE INDEX t4a ON t4(x, a COLLATE nocase); + CREATE INDEX t4b ON t4(x, b); + } +} { + drop_all_tables + do_test 12.$tn.1 { execsql $schema } {} + + do_test 12.$tn.2 { + for {set i 0} {$i < 100} {incr i} { + if { ($i % 10)==0 } { set a ABC } else { set a DEF } + set b [expr $i % 5] + execsql { INSERT INTO t4 VALUES(X'abcdef', $a, $b) } + } + execsql ANALYZE + } {} + + do_eqp_test 12.$tn.3 { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'def' AND b = 3; + } {/t4 USING INDEX t4b/} + + if {$tn==1} { + set sql "SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' AND b = 3;" + do_eqp_test 12.$tn.4 $sql {/t4 USING INDEX t4a/} + } else { + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a = 'abc' COLLATE nocase AND b = 3 + } + do_eqp_test 12.$tn.5 $sql {/t4 USING INDEX t4a/} + set sql { + SELECT * FROM t4 WHERE x=X'abcdef' AND a COLLATE nocase = 'abc' AND b = 3 + } + do_eqp_test 12.$tn.6 $sql {/t4 USING INDEX t4a/} + } +} + +#------------------------------------------------------------------------- +# Check that affinities are taken into account when using stat4 data to +# estimate the number of rows scanned by a rowid constraint. +# +drop_all_tables +do_test 13.1 { + execsql { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b, c); + } + for {set i 0} {$i<100} {incr i} { + if {$i %2} {set a abc} else {set a def} + execsql { INSERT INTO t1(rowid, a, b, c) VALUES($i, $a, $i, $i) } + } + execsql ANALYZE +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<15 AND b<12 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'15' AND b<12 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.3.1 { + SELECT * FROM t1 WHERE a='abc' AND rowid<100 AND b<12 +} {/SEARCH t1 USING INDEX i2/} +do_eqp_test 13.3.2 { + SELECT * FROM t1 WHERE a='abc' AND rowid<'100' AND b<12 +} {/SEARCH t1 USING INDEX i2/} + +#------------------------------------------------------------------------- +# Check also that affinities are taken into account when using stat4 data +# to estimate the number of rows scanned by any other constraint on a +# column other than the leftmost. +# +drop_all_tables +do_test 14.1 { + execsql { CREATE TABLE t1(a, b INTEGER, c) } + for {set i 0} {$i<100} {incr i} { + set c [expr $i % 3] + execsql { INSERT INTO t1 VALUES('ott', $i, $c) } + } + execsql { + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(c); + ANALYZE; + } +} {} +do_eqp_test 13.2.1 { + SELECT * FROM t1 WHERE a='ott' AND b<10 AND c=1 +} {/SEARCH t1 USING INDEX i1/} +do_eqp_test 13.2.2 { + SELECT * FROM t1 WHERE a='ott' AND b<'10' AND c=1 +} {/SEARCH t1 USING INDEX i1/} + +#------------------------------------------------------------------------- +# By default, 16 non-periodic samples are collected for the stat4 table. +# The following tests attempt to verify that the most common keys are +# being collected. +# +proc check_stat4 {tn} { + db eval ANALYZE + db eval {SELECT a, b, c, d FROM t1} { + incr k($a) + incr k([list $a $b]) + incr k([list $a $b $c]) + if { [info exists k([list $a $b $c $d])]==0 } { incr nRow } + incr k([list $a $b $c $d]) + } + + set L [list] + foreach key [array names k] { + lappend L [list $k($key) $key] + } + + set nSample $nRow + if {$nSample>16} {set nSample 16} + + set nThreshold [lindex [lsort -decr -integer -index 0 $L] [expr $nSample-1] 0] + foreach key [array names k] { + if {$k($key)>$nThreshold} { + set expect($key) 1 + } + if {$k($key)==$nThreshold} { + set possible($key) 1 + } + } + + + set nPossible [expr $nSample - [llength [array names expect]]] + + #puts "EXPECT: [array names expect]" + #puts "POSSIBLE($nPossible/[array size possible]): [array names possible]" + #puts "HAVE: [db eval {SELECT test_decode(sample) FROM sqlite_stat4 WHERE idx='i1'}]" + + db eval {SELECT test_decode(sample) AS s FROM sqlite_stat4 WHERE idx='i1'} { + set seen 0 + for {set i 0} {$i<4} {incr i} { + unset -nocomplain expect([lrange $s 0 $i]) + if {[info exists possible([lrange $s 0 $i])]} { + set seen 1 + unset -nocomplain possible([lrange $s 0 $i]) + } + } + if {$seen} {incr nPossible -1} + } + if {$nPossible<0} {set nPossible 0} + + set res [list [llength [array names expect]] $nPossible] + uplevel [list do_test $tn [list set {} $res] {0 0}] +} + +drop_all_tables +do_test 14.1.1 { + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX i1 ON t1(a,b,c,d); + } + for {set i 0} {$i < 160} {incr i} { + execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } + if {($i % 10)==0} { execsql { INSERT INTO t1 VALUES($i,$i,$i,$i) } } + } +} {} +check_stat4 14.1.2 + +do_test 14.2.1 { + execsql { DELETE FROM t1 } + for {set i 0} {$i < 1600} {incr i} { + execsql { INSERT INTO t1 VALUES($i/10,$i/17,$i/27,$i/37) } + } +} {} +check_stat4 14.2.2 + +do_test 14.3.1 { + for {set i 0} {$i < 10} {incr i} { + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + execsql { INSERT INTO t1 VALUES($i*50,$i*50,$i*50,$i*50) } + } +} {} +check_stat4 14.3.2 + +do_test 14.4.1 { + execsql {DELETE FROM t1} + for {set i 1} {$i < 160} {incr i} { + set b [expr $i % 10] + if {$b==0 || $b==2} {set b 1} + execsql { INSERT INTO t1 VALUES($i/10,$b,$i,$i) } + } +} {} +check_stat4 14.4.2 +db func lrange lrange +db func lindex lindex +do_execsql_test 14.4.3 { + SELECT lrange(test_decode(sample), 0, 1) AS s FROM sqlite_stat4 + WHERE lindex(s, 1)=='1' ORDER BY rowid +} { + {0 1} {1 1} {2 1} {3 1} + {4 1} {5 1} {6 1} {7 1} + {8 1} {9 1} {10 1} {11 1} + {12 1} {13 1} {14 1} {15 1} +} + +#------------------------------------------------------------------------- +# Test that nothing untoward happens if the stat4 table contains entries +# for indexes that do not exist. Or NULL values in the idx column. +# Or NULL values in any of the other columns. +# +drop_all_tables +do_execsql_test 15.1 { + CREATE TABLE x1(a, b, UNIQUE(a, b)); + INSERT INTO x1 VALUES(1, 2); + INSERT INTO x1 VALUES(3, 4); + INSERT INTO x1 VALUES(5, 6); + ANALYZE; + INSERT INTO sqlite_stat4 VALUES(NULL, NULL, NULL, NULL, NULL, NULL); +} +db close +sqlite3 db test.db +do_execsql_test 15.2 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.3 { + INSERT INTO sqlite_stat4 VALUES(42, 42, 42, 42, 42, 42); +} +db close +sqlite3 db test.db +do_execsql_test 15.4 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.5 { + UPDATE sqlite_stat1 SET stat = NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.6 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.7 { + ANALYZE; + UPDATE sqlite_stat1 SET tbl = 'no such tbl'; +} +db close +sqlite3 db test.db +do_execsql_test 15.8 { SELECT * FROM x1 } {1 2 3 4 5 6} + +do_execsql_test 15.9 { + ANALYZE; + UPDATE sqlite_stat4 SET neq = NULL, nlt=NULL, ndlt=NULL; +} +db close +sqlite3 db test.db +do_execsql_test 15.10 { SELECT * FROM x1 } {1 2 3 4 5 6} + +# This is just for coverage.... +do_execsql_test 15.11 { + ANALYZE; + UPDATE sqlite_stat1 SET stat = stat || ' unordered'; +} +db close +sqlite3 db test.db +do_execsql_test 15.12 { SELECT * FROM x1 } {1 2 3 4 5 6} + +#------------------------------------------------------------------------- +# Test that allocations used for sqlite_stat4 samples are included in +# the quantity returned by SQLITE_DBSTATUS_SCHEMA_USED. +# +set one [string repeat x 1000] +set two [string repeat x 2000] +do_test 16.1 { + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($one); + ANALYZE; + } + set nByte [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + + reset_db + execsql { + CREATE TABLE t1(a, UNIQUE(a)); + INSERT INTO t1 VALUES($two); + ANALYZE; + } + set nByte2 [lindex [sqlite3_db_status db SCHEMA_USED 0] 1] + puts -nonewline " (nByte=$nByte nByte2=$nByte2)" + + expr {$nByte2 > $nByte+900 && $nByte2 < $nByte+1100} +} {1} + +#------------------------------------------------------------------------- +# Test that stat4 data may be used with partial indexes. +# +do_test 17.1 { + reset_db + execsql { + CREATE TABLE t1(a, b, c, d); + CREATE INDEX i1 ON t1(a, b) WHERE d IS NOT NULL; + INSERT INTO t1 VALUES(-1, -1, -1, NULL); + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + INSERT INTO t1 SELECT 2*a,2*b,2*c,d FROM t1; + } + + for {set i 0} {$i < 32} {incr i} { + if {$i<8} {set b 0} else { set b $i } + execsql { INSERT INTO t1 VALUES($i%2, $b, $i/2, 'abc') } + } + execsql {ANALYZE main.t1} +} {} + +do_catchsql_test 17.1.2 { + ANALYZE temp.t1; +} {1 {no such table: temp.t1}} + +do_eqp_test 17.2 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.3 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i1/} + +do_execsql_test 17.4 { + CREATE INDEX i2 ON t1(c, d); + ANALYZE main.i2; +} +do_eqp_test 17.5 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=10 AND c=10; +} {/USING INDEX i1/} +do_eqp_test 17.6 { + SELECT * FROM t1 WHERE d IS NOT NULL AND a=0 AND b=0 AND c=10; +} {/USING INDEX i2/} + +#------------------------------------------------------------------------- +# +do_test 18.1 { + reset_db + execsql { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + for {set i 0} {$i < 9} {incr i} { + execsql { + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + INSERT INTO t1 VALUES($i, 0); + } + } + execsql ANALYZE + execsql { SELECT count(*) FROM sqlite_stat4 } +} {9} + +#------------------------------------------------------------------------- +# For coverage. +# +ifcapable view { + do_test 19.1 { + reset_db + execsql { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + ANALYZE; + } + } {} +} +ifcapable auth { + proc authproc {op args} { + if {$op == "SQLITE_ANALYZE"} { return "SQLITE_DENY" } + return "SQLITE_OK" + } + do_test 19.2 { + reset_db + db auth authproc + execsql { + CREATE TABLE t1(x, y); + CREATE VIEW v1 AS SELECT * FROM t1; + } + catchsql ANALYZE + } {1 {not authorized}} +} + +#------------------------------------------------------------------------- +# +reset_db +proc r {args} { expr rand() } +db func r r +db func lrange lrange +do_test 20.1 { + execsql { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX i1 ON t1(a,b,c,d); + } + for {set i 0} {$i < 16} {incr i} { + execsql { + INSERT INTO t1 VALUES($i, r(), r(), r()); + INSERT INTO t1 VALUES($i, $i, r(), r()); + INSERT INTO t1 VALUES($i, $i, $i, r()); + INSERT INTO t1 VALUES($i, $i, $i, $i); + INSERT INTO t1 VALUES($i, $i, $i, $i); + INSERT INTO t1 VALUES($i, $i, $i, r()); + INSERT INTO t1 VALUES($i, $i, r(), r()); + INSERT INTO t1 VALUES($i, r(), r(), r()); + } + } +} {} +do_execsql_test 20.2 { ANALYZE } +for {set i 0} {$i<16} {incr i} { + set val "$i $i $i $i" + do_execsql_test 20.3.$i { + SELECT count(*) FROM sqlite_stat4 + WHERE lrange(test_decode(sample), 0, 3)=$val + } {1} +} + +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 21.0 { + CREATE TABLE t2(a, b); + CREATE INDEX i2 ON t2(a); +} + +do_test 21.1 { + for {set i 1} {$i < 100} {incr i} { + execsql { + INSERT INTO t2 VALUES(CASE WHEN $i < 80 THEN 'one' ELSE 'two' END, $i) + } + } + execsql ANALYZE +} {} + +# Condition (a='one') matches 80% of the table. (rowid<10) reduces this to +# 10%, but (rowid<50) only reduces it to 50%. So in the first case below +# the index is used. In the second, it is not. +# +do_eqp_test 21.2 { + SELECT * FROM t2 WHERE a='one' AND rowid < 10 +} {/*USING INDEX i2 (a=? AND rowid45 AND x<96) THEN 'B' ELSE 'A' END, /* Column "a" */ + x, /* Column "b" */ + CASE WHEN (x<51) THEN 'one' ELSE 'two' END, /* Column "c" */ + x /* Column "d" */ + FROM r; + + CREATE INDEX i3 ON t3(c); + CREATE INDEX i4 ON t3(d); + ANALYZE; +} + +# Expression (c='one' AND a='B') matches 5 table rows. But (c='one' AND a=A') +# matches 45. Expression (d? AND b=? term. Better than + # (a<20) but not as good as (a<10). + do_eqp_test 25.4.1 { + SELECT * FROM t6 WHERE a < 10 AND (b BETWEEN ? AND 60) + } {SEARCH t6 USING INDEX aa (a? AND b 25) matches 76 rows +# (70 * 2/3 + 30). Before, due to the problem, the planner was estimating +# that this matched 100 rows. +# +reset_db +do_execsql_test 26.2.1 { + BEGIN; + CREATE TABLE t1(x, y, z); + CREATE INDEX i1 ON t1(x, y); + CREATE INDEX i2 ON t1(z); + + WITH + cnt(y) AS (SELECT 0 UNION ALL SELECT y+1 FROM cnt WHERE y<99), + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, y FROM letters, cnt; + + WITH + letters(x) AS ( + SELECT 'A' UNION SELECT 'B' UNION SELECT 'C' UNION SELECT 'D' + ) + INSERT INTO t1(x, y) SELECT x, 70 FROM letters; + + WITH + cnt(i) AS (SELECT 0 UNION ALL SELECT i+1 FROM cnt WHERE i<9999) + INSERT INTO t1(x, y) SELECT i, i FROM cnt; + + UPDATE t1 SET z = (rowid / 95); + ANALYZE; + COMMIT; +} + +do_eqp_test 26.2.2 { + SELECT * FROM t1 WHERE x='B' AND y>25 AND z=?; +} {SEARCH t1 USING INDEX i1 (x=? AND y>?)} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeC.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeC.test new file mode 100644 index 0000000000000000000000000000000000000000..2f43d57a1e500794c460a216fe6b6a3c43f0c6de --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeC.test @@ -0,0 +1,181 @@ +# 2014-07-22 +# +# 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 automated tests used to verify that the text terms +# at the end of sqlite_stat1.stat are processed correctly. +# +# (1) "unordered" means that the index cannot be used for ORDER BY +# or for range queries +# +# (2) "sz=NNN" sets the relative size of the index entries +# +# (3) All other fields are silently ignored +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix analyzeC + +# Baseline case. Range queries work OK. Indexes can be used for +# ORDER BY. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c); + INSERT INTO t1(a,b,c) + VALUES(1,2,3),(7,8,9),(4,5,6),(10,11,12),(4,8,12),(1,11,111); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + ANALYZE; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1a','12345 2'),('t1','t1b','12345 4'); + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 1.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {/.* USING INDEX t1a .a>. AND a<...*/} +do_execsql_test 1.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 1.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*SCAN t1 USING INDEX t1a.*/} +do_execsql_test 1.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*B-TREE FOR ORDER BY.*/} + +# Now mark the t1a index as "unordered". Range queries and ORDER BY no +# longer use the index, but equality queries do. +# +do_execsql_test 2.0 { + UPDATE sqlite_stat1 SET stat='12345 2 unordered' WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 2.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 2.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 2.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 2.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# Ignore extraneous text parameters in the sqlite_stat1.stat field. +# +do_execsql_test 3.0 { + UPDATE sqlite_stat1 SET stat='12345 2 whatever=5 unordered xyzzy=11' + WHERE idx='t1a'; + ANALYZE sqlite_master; + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {4 5 6 # 7 8 9 # 4 8 12 #} +do_execsql_test 3.1 { + EXPLAIN QUERY PLAN + SELECT *, '#' FROM t1 WHERE a BETWEEN 3 AND 8 ORDER BY c; +} {~/.*USING INDEX.*/} +do_execsql_test 3.2 { + SELECT c FROM t1 ORDER BY a; +} {3 111 6 12 9 12} +do_execsql_test 3.3 { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {~/.*USING INDEX.*/} +do_execsql_test 3.3x { + EXPLAIN QUERY PLAN + SELECT c FROM t1 ORDER BY a; +} {/.*B-TREE FOR ORDER BY.*/} + +# The sz=NNN parameter determines which index to scan +# +do_execsql_test 4.0 { + DROP INDEX t1a; + CREATE INDEX t1ab ON t1(a,b); + CREATE INDEX t1ca ON t1(c,a); + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=10'),('t1','t1ca','12345 3 2 sz=20'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 4.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 sz=20'),('t1','t1ca','12345 3 2 sz=10'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 4.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + +# 2019-08-15. +# Ticket https://www.sqlite.org/src/tktview/e4598ecbdd18bd82945f602901 +# The sz=N parameter in the sqlite_stat1 table needs to have a value of +# 2 or more to avoid a division by zero in the query planner. +# +do_execsql_test 4.4 { + DROP TABLE IF EXISTS t44; + CREATE TABLE t44(a PRIMARY KEY); + INSERT INTO sqlite_stat1 VALUES('t44',null,'sz=0'); + ANALYZE sqlite_master; + SELECT 0 FROM t44 WHERE a IN(1,2,3); +} {} + + + +# The sz=NNN parameter works even if there is other extraneous text +# in the sqlite_stat1.stat column. +# +do_execsql_test 5.0 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ab','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ca','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.1 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ab.*/} +do_execsql_test 5.2 { + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1(tbl,idx,stat) + VALUES('t1','t1ca','12345 3 2 x=5 sz=10 y=10'), + ('t1','t1ab','12345 3 2 whatever sz=20 junk'); + ANALYZE sqlite_master; + SELECT count(a) FROM t1; +} {6} +do_execsql_test 5.3 { + EXPLAIN QUERY PLAN + SELECT count(a) FROM t1; +} {/.*INDEX t1ca.*/} + + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeD.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeD.test new file mode 100644 index 0000000000000000000000000000000000000000..7a51785a1ca68257c46519e2d3be7bf872afa2f0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzeD.test @@ -0,0 +1,107 @@ +# 2014-10-04 +# +# 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. +# This file implements tests for the ANALYZE command. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix analyzeD + +ifcapable {!stat4} { + finish_test + return +} + + +# Set up a table with the following properties: +# +# * Contains 1000 rows. +# * Column a contains even integers between 0 and 18, inclusive (so that +# a=? for any such integer matches 100 rows). +# * Column b contains integers between 0 and 9, inclusive. +# * Column c contains integers between 0 and 199, inclusive (so that +# for any such integer, c=? matches 5 rows). +# * Then add 7 rows with a new value for "a" - 3001. The stat4 table will +# not contain any samples with a=3001. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c); +} +do_test 1.1 { + for {set i 1} {$i < 1000} {incr i} { + set c [expr $i % 200] + execsql { INSERT INTO t1(a, b, c) VALUES( 2*($i/100), $i%10, $c ) } + } + + execsql { + INSERT INTO t1 VALUES(3001, 3001, 3001); + INSERT INTO t1 VALUES(3001, 3001, 3002); + INSERT INTO t1 VALUES(3001, 3001, 3003); + INSERT INTO t1 VALUES(3001, 3001, 3004); + INSERT INTO t1 VALUES(3001, 3001, 3005); + INSERT INTO t1 VALUES(3001, 3001, 3006); + INSERT INTO t1 VALUES(3001, 3001, 3007); + + CREATE INDEX t1_ab ON t1(a, b); + CREATE INDEX t1_c ON t1(c); + + ANALYZE; + } +} {} + +# With full ANALYZE data, SQLite sees that c=150 (5 rows) is better than +# a=3001 (7 rows). +# +do_eqp_test 1.2 { + SELECT * FROM t1 WHERE a=3001 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +do_test 1.3 { + execsql { DELETE FROM sqlite_stat1 } + db close + sqlite3 db test.db +} {} + +# Without stat1, because 3001 is larger than all samples in the stat4 +# table, SQLite thinks that a=3001 matches just 1 row. So it (incorrectly) +# chooses it over the c=150 index (5 rows). Even with stat1 data, things +# worked this way before commit [e6f7f97dbc]. +# +do_eqp_test 1.4 { + SELECT * FROM t1 WHERE a=3001 AND c=150; +} {SEARCH t1 USING INDEX t1_ab (a=?)} + +do_test 1.5 { + execsql { + UPDATE t1 SET a=13 WHERE a = 3001; + ANALYZE; + } +} {} + +do_eqp_test 1.6 { + SELECT * FROM t1 WHERE a=13 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +do_test 1.7 { + execsql { DELETE FROM sqlite_stat1 } + db close + sqlite3 db test.db +} {} + +# Same test as 1.4, except this time the 7 rows that match the a=? condition +# do not feature larger values than all rows in the stat4 table. So SQLite +# gets this right, even without stat1 data. +do_eqp_test 1.8 { + SELECT * FROM t1 WHERE a=13 AND c=150; +} {SEARCH t1 USING INDEX t1_c (c=?)} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzer1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzer1.test new file mode 100644 index 0000000000000000000000000000000000000000..51b5f8b6af52b64977798cfe3648faa31cf0a96a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/analyzer1.test @@ -0,0 +1,55 @@ +# 2015-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. +# +#*********************************************************************** +# +# Quick tests for the sqlite3_analyzer tool +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +if {$tcl_platform(platform)=="windows"} { + set PROG "sqlite3_analyzer.exe" +} else { + set PROG "./sqlite3_analyzer" +} +if {![file exe $PROG]} { + set PROG [file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $PROG]] + if {![file exe $PROG]} { + puts "analyzer1 cannot run because $PROG is not available" + finish_test + return + } +} +db close +forcedelete test.db test.db-journal test.db-wal +sqlite3 db test.db + +do_test analyzer1-1.0 { + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INT PRIMARY KEY, b) WITHOUT ROWID; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<250) + INSERT INTO t1(a,b) SELECT x, randomblob(200) FROM c; + INSERT INTO t2(a,b) SELECT a, b FROM t1; + } + set line "exec $PROG test.db" + unset -nocomplain ::MSG + catch {eval $line} ::MSG +} {0} +do_test analyzer1-1.1 { + regexp {^/\*\* Disk-Space Utilization.*COMMIT;\W*$} $::MSG +} {1} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/atof1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/atof1.test new file mode 100644 index 0000000000000000000000000000000000000000..1a5db2cc797e45dc22e26d2c973fd15f76258de8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/atof1.test @@ -0,0 +1,86 @@ +# 2012 June 18 +# +# 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 of the sqlite3AtoF() function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set mxpow 35 +expr srand(1) +for {set i 1} {$i<20000} {incr i} { + set pow [expr {int((rand()-0.5)*$mxpow)}] + set x [expr {pow((rand()-0.5)*2*rand(),$pow)}] + set xf [format %.32e $x] + + # Verify that text->real conversions get exactly same ieee754 floating- + # point value in SQLite as they do in TCL. + # + do_test atof1-1.$i.1 { + set y [db eval "SELECT $xf=\$x"] + if {!$y} { + puts -nonewline \173[db eval "SELECT real2hex($xf), real2hex(\$x)"]\175 + db eval "SELECT $xf+0.0 AS a, \$x AS b" { + puts [format "\n%.60e\n%.60e\n%.60e" $x $a $b] + } + } + set y + } {1} + + # Verify that round-trip real->text->real conversions using the quote() + # function preserve the bits of the numeric value exactly. + # + do_test atof1-1.$i.2 { + set y [db eval {SELECT $x=CAST(quote($x) AS real)}] + if {!$y} { + db eval {SELECT real2hex($x) a, real2hex(CAST(quote($x) AS real)) b} {} + puts "" + if {$x<0} { + puts "[format {!SCALE: %17s 1 23456789 123456789 123456789} {}]" + } else { + puts "[format {!SCALE: %16s 1 23456789 123456789 123456789} {}]" + } + puts "!IN: $a $xf" + puts [format {!QUOTE: %16s %s} {} [db eval {SELECT quote($x)}]] + db eval {SELECT CAST(quote($x) AS real) c} {} + puts "!OUT: $b [format %.32e $c]" + } + set y + } {1} +} + +# 2020-01-08 ticket 9eda2697f5cc1aba +# When running sqlite3AtoF() on a blob with an odd number of bytes using +# UTF16, ignore the last byte so that the string has an integer number of +# UTF16 code points. +# +reset_db +do_execsql_test atof1-2.10 { + PRAGMA encoding = 'UTF16be'; + CREATE TABLE t1(a, b); + INSERT INTO t1(rowid,a) VALUES (1,x'00'),(2,3); + SELECT substr(a,',') is true FROM t1 ORDER BY rowid; +} {0 1} +do_execsql_test atof1-2.20 { + SELECT substr(a,',') is true FROM t1 ORDER BY rowid DESC; +} {1 0} +do_execsql_test atof1-2.30 { + CREATE INDEX i1 ON t1(a); + SELECT count(*) FROM t1 WHERE substr(a,','); +} {1} +# 2020-08-27 OSSFuzz find related to the above. +do_execsql_test atof1-2.40 { + SELECT randomblob(0) - 1; +} {-1} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/atrc.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/atrc.c new file mode 100644 index 0000000000000000000000000000000000000000..673f12cc441b764fb7dd80133ed771df7ab86dc8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/atrc.c @@ -0,0 +1,150 @@ +/* +** This program generates a script that stresses the ALTER TABLE statement. +** Compile like this: +** +** gcc -g -c sqlite3.c +** gcc -g -o atrc atrc.c sqlite3.o -ldl -lpthread +** +** Run the program this way: +** +** ./atrc DATABASE | ./sqlite3 DATABASE +** +** This program "atrc" generates a script that can be fed into an ordinary +** command-line shell. The script performs many ALTER TABLE statements, +** runs ".schema --indent" and "PRAGMA integrity_check;", does more +** ALTER TABLE statements to restore the original schema, and then +** runs "PRAGMA integrity_check" again. Every table and column has its +** name changed. The entire script is contained within BEGIN...ROLLBACK +** so that no changes are ever actually made to the database. +*/ +#include "sqlite3.h" +#include + +/* +** Generate the text of ALTER TABLE statements that will rename +** every column in table zTable to a generic name composed from +** zColPrefix and a sequential number. The generated text is +** appended pConvert. If pUndo is not NULL, then SQL text that +** will undo the change is appended to pUndo. +** +** The table to be converted must be in the "main" schema. +*/ +int rename_all_columns_of_table( + sqlite3 *db, /* Database connection */ + const char *zTab, /* Table whose columns should all be renamed */ + const char *zColPrefix, /* Prefix for new column names */ + sqlite3_str *pConvert, /* Append ALTER TABLE statements here */ + sqlite3_str *pUndo /* SQL to undo the change, if not NULL */ +){ + sqlite3_stmt *pStmt; + int rc; + int cnt = 0; + + rc = sqlite3_prepare_v2(db, + "SELECT name FROM pragma_table_info(?1);", + -1, &pStmt, 0); + if( rc ) return rc; + sqlite3_bind_text(pStmt, 1, zTab, -1, SQLITE_STATIC); + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + const char *zCol = (const char*)sqlite3_column_text(pStmt, 0); + cnt++; + sqlite3_str_appendf(pConvert, + "ALTER TABLE \"%w\" RENAME COLUMN \"%w\" TO \"%w%d\";\n", + zTab, zCol, zColPrefix, cnt + ); + if( pUndo ){ + sqlite3_str_appendf(pUndo, + "ALTER TABLE \"%w\" RENAME COLUMN \"%w%d\" TO \"%w\";\n", + zTab, zColPrefix, cnt, zCol + ); + } + } + sqlite3_finalize(pStmt); + return SQLITE_OK; +} + +/* Rename all tables and their columns in the main database +*/ +int rename_all_tables( + sqlite3 *db, /* Database connection */ + sqlite3_str *pConvert, /* Append SQL to do the rename here */ + sqlite3_str *pUndo /* Append SQL to undo the rename here */ +){ + sqlite3_stmt *pStmt; + int rc; + int cnt = 0; + + rc = sqlite3_prepare_v2(db, + "SELECT name FROM sqlite_schema WHERE type='table'" + " AND name NOT LIKE 'sqlite_%';", + -1, &pStmt, 0); + if( rc ) return rc; + while( sqlite3_step(pStmt)==SQLITE_ROW ){ + const char *zTab = (const char*)sqlite3_column_text(pStmt, 0); + char *zNewTab; + char zPrefix[2]; + + zPrefix[0] = (cnt%26) + 'a'; + zPrefix[1] = 0; + zNewTab = sqlite3_mprintf("tx%d", ++cnt); + if( pUndo ){ + sqlite3_str_appendf(pUndo, + "ALTER TABLE \"%s\" RENAME TO \"%w\";\n", + zNewTab, zTab + ); + } + rename_all_columns_of_table(db, zTab, zPrefix, pConvert, pUndo); + sqlite3_str_appendf(pConvert, + "ALTER TABLE \"%w\" RENAME TO \"%s\";\n", + zTab, zNewTab + ); + sqlite3_free(zNewTab); + } + sqlite3_finalize(pStmt); + return SQLITE_OK; +} + +/* +** Generate a script that does this: +** +** (1) Start a transaction +** (2) Rename all tables and columns to use generic names. +** (3) Print the schema after this rename +** (4) Run pragma integrity_check +** (5) Do more ALTER TABLE statements to change the names back +** (6) Run pragma integrity_check again +** (7) Rollback the transaction +*/ +int main(int argc, char **argv){ + sqlite3 *db; + int rc; + sqlite3_str *pConvert; + sqlite3_str *pUndo; + char *zDbName; + char *zSql1, *zSql2; + if( argc!=2 ){ + fprintf(stderr, "Usage: %s DATABASE\n", argv[0]); + } + zDbName = argv[1]; + rc = sqlite3_open(zDbName, &db); + if( rc ){ + fprintf(stderr, "sqlite3_open() returns %d\n", rc); + return 1; + } + pConvert = sqlite3_str_new(db); + pUndo = sqlite3_str_new(db); + rename_all_tables(db, pConvert, pUndo); + zSql1 = sqlite3_str_finish(pConvert); + zSql2 = sqlite3_str_finish(pUndo); + sqlite3_close(db); + printf("BEGIN;\n"); + printf("%s", zSql1); + sqlite3_free(zSql1); + printf(".schema --indent\n"); + printf("PRAGMA integrity_check;\n"); + printf("%s", zSql2); + sqlite3_free(zSql2); + printf("PRAGMA integrity_check;\n"); + printf("ROLLBACK;\n"); + return 0; +} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/attach.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/attach.test new file mode 100644 index 0000000000000000000000000000000000000000..557201d65437394be4b5b9d803945c6df93903bf --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/attach.test @@ -0,0 +1,928 @@ +# 2003 April 4 +# +# 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. The +# focus of this script is testing the ATTACH and DETACH commands +# and related functionality. +# +# $Id: attach.test,v 1.52 2009/05/29 14:39:08 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +for {set i 2} {$i<=15} {incr i} { + forcedelete test$i.db + forcedelete test$i.db-journal +} + +do_test attach-1.1 { + execsql { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1; + } +} {1 2 3 4} +do_test attach-1.2 { + sqlite3 db2 test2.db + execsql { + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,'x'); + INSERT INTO t2 VALUES(2,'y'); + SELECT * FROM t2; + } db2 +} {1 x 2 y} +do_test attach-1.3 { + execsql { + ATTACH DATABASE 'test2.db' AS two; + SELECT * FROM two.t2; + } +} {1 x 2 y} + +# Tests for the sqlite3_db_filename interface +# +do_test attach-1.3.1 { + file tail [sqlite3_db_filename db main] +} {test.db} +do_test attach-1.3.2 { + file tail [sqlite3_db_filename db MAIN] +} {test.db} +do_test attach-1.3.3 { + file tail [sqlite3_db_filename db temp] +} {} +do_test attach-1.3.4 { + file tail [sqlite3_db_filename db two] +} {test2.db} +do_test attach-1.3.5 { + file tail [sqlite3_db_filename db three] +} {} + +do_test attach-1.4 { + execsql { + SELECT * FROM t2; + } +} {1 x 2 y} +do_test attach-1.5 { + execsql { + DETACH DATABASE two; + SELECT * FROM t1; + } +} {1 2 3 4} +do_test attach-1.6 { + catchsql { + SELECT * FROM t2; + } +} {1 {no such table: t2}} +do_test attach-1.7 { + catchsql { + SELECT * FROM two.t2; + } +} {1 {no such table: two.t2}} +do_test attach-1.8 { + catchsql { + ATTACH DATABASE 'test3.db' AS three; + } +} {0 {}} +do_test attach-1.9 { + catchsql { + SELECT * FROM three.sqlite_master; + } +} {0 {}} +do_test attach-1.10 { + catchsql { + DETACH DATABASE [three]; + } +} {0 {}} +do_test attach-1.11 { + execsql { + ATTACH 'test.db' AS db2; + ATTACH 'test.db' AS db3; + ATTACH 'test.db' AS db4; + ATTACH 'test.db' AS db5; + ATTACH 'test.db' AS db6; + ATTACH 'test.db' AS db7; + ATTACH 'test.db' AS db8; + ATTACH 'test.db' AS db9; + } +} {} +proc db_list {db} { + set list {} + foreach {idx name file} [execsql {PRAGMA database_list} $db] { + lappend list $idx $name + } + return $list +} +ifcapable schema_pragmas { +do_test attach-1.11b { + db_list db +} {0 main 2 db2 3 db3 4 db4 5 db5 6 db6 7 db7 8 db8 9 db9} +} ;# ifcapable schema_pragmas +do_test attach-1.12 { + catchsql { + ATTACH 'test.db' as db2; + } +} {1 {database db2 is already in use}} +do_test attach-1.12.2 { + db errorcode +} {1} +do_test attach-1.13 { + catchsql { + ATTACH 'test.db' as db5; + } +} {1 {database db5 is already in use}} +do_test attach-1.14 { + catchsql { + ATTACH 'test.db' as db9; + } +} {1 {database db9 is already in use}} +do_catchsql_test attach-1.15 { + ATTACH 'test.db' as main; +} {1 {database main is already in use}} +ifcapable tempdb { + do_test attach-1.16 { + catchsql { + ATTACH 'test.db' as temp; + } + } {1 {database temp is already in use}} +} +do_catchsql_test attach-1.17 { + ATTACH 'test.db' as MAIN; +} {1 {database MAIN is already in use}} +do_test attach-1.18 { + catchsql { + ATTACH 'test.db' as db10; + ATTACH 'test.db' as db11; + } +} {0 {}} +if {$SQLITE_MAX_ATTACHED==10} { + do_test attach-1.19 { + catchsql { + ATTACH 'test.db' as db12; + } + } {1 {too many attached databases - max 10}} + do_test attach-1.19.1 { + db errorcode + } {1} +} +do_test attach-1.20.1 { + execsql { + DETACH db5; + } +} {} +ifcapable schema_pragmas { +do_test attach-1.20.2 { + db_list db +} {0 main 2 db2 3 db3 4 db4 5 db6 6 db7 7 db8 8 db9 9 db10 10 db11} +} ;# ifcapable schema_pragmas +integrity_check attach-1.20.3 +ifcapable tempdb { + execsql {select * from temp.sqlite_master} +} +do_test attach-1.21 { + catchsql { + ATTACH 'test.db' as db12; + } +} {0 {}} +if {$SQLITE_MAX_ATTACHED==10} { + do_test attach-1.22 { + catchsql { + ATTACH 'test.db' as db13; + } + } {1 {too many attached databases - max 10}} + do_test attach-1.22.1 { + db errorcode + } {1} +} +do_test attach-1.23 { + catchsql { + DETACH "db14"; + } +} {1 {no such database: db14}} +do_test attach-1.24 { + catchsql { + DETACH db12; + } +} {0 {}} +do_test attach-1.25 { + catchsql { + DETACH db12; + } +} {1 {no such database: db12}} +do_test attach-1.26 { + catchsql { + DETACH main; + } +} {1 {cannot detach database main}} + + +ifcapable tempdb { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {cannot detach database Temp}} +} else { + do_test attach-1.27 { + catchsql { + DETACH Temp; + } + } {1 {no such database: Temp}} +} + +do_test attach-1.28 { + catchsql { + DETACH db11; + DETACH db10; + DETACH db9; + DETACH db8; + DETACH db7; + DETACH db6; + DETACH db4; + DETACH db3; + DETACH db2; + } +} {0 {}} +ifcapable schema_pragmas { + ifcapable tempdb { + do_test attach-1.29 { + db_list db + } {0 main 1 temp} + } else { + do_test attach-1.29 { + db_list db + } {0 main} + } +} ;# ifcapable schema_pragmas + +ifcapable {trigger} { # Only do the following tests if triggers are enabled +do_test attach-2.1 { + execsql { + CREATE TABLE tx(x1,x2,y1,y2); + CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN + INSERT INTO tx(x1,x2,y1,y2) VALUES(OLD.x,NEW.x,OLD.y,NEW.y); + END; + SELECT * FROM tx; + } db2; +} {} +do_test attach-2.2 { + execsql { + UPDATE t2 SET x=x+10; + SELECT * FROM tx; + } db2; +} {1 11 x x 2 12 y y} +do_test attach-2.3 { + execsql { + CREATE TABLE tx(x1,x2,y1,y2); + SELECT * FROM tx; + } +} {} +do_test attach-2.4 { + execsql { + ATTACH 'test2.db' AS db2; + } +} {} +do_test attach-2.5 { + execsql { + UPDATE db2.t2 SET x=x+10; + SELECT * FROM db2.tx; + } +} {1 11 x x 2 12 y y 11 21 x x 12 22 y y} +do_test attach-2.6 { + execsql { + SELECT * FROM main.tx; + } +} {} +do_test attach-2.7 { + execsql { + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2} + +ifcapable schema_pragmas&&tempdb { + do_test attach-2.8 { + db_list db + } {0 main 1 temp 2 db2} +} ;# ifcapable schema_pragmas&&tempdb +ifcapable schema_pragmas&&!tempdb { + do_test attach-2.8 { + db_list db + } {0 main 2 db2} +} ;# ifcapable schema_pragmas&&!tempdb + +do_test attach-2.9 { + execsql { + CREATE INDEX i2 ON t2(x); + SELECT * FROM t2 WHERE x>5; + } db2 +} {21 x 22 y} +do_test attach-2.10 { + execsql { + SELECT type, name, tbl_name FROM sqlite_master; + } db2 +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +#do_test attach-2.11 { +# catchsql { +# SELECT * FROM t2 WHERE x>5; +# } +#} {1 {database schema has changed}} +ifcapable schema_pragmas { + ifcapable tempdb { + do_test attach-2.12 { + db_list db + } {0 main 1 temp 2 db2} + } else { + do_test attach-2.12 { + db_list db + } {0 main 2 db2} + } +} ;# ifcapable schema_pragmas +do_test attach-2.13 { + catchsql { + SELECT * FROM t2 WHERE x>5; + } +} {0 {21 x 22 y}} +do_test attach-2.14 { + execsql { + SELECT type, name, tbl_name FROM sqlite_master; + } +} {table t1 t1 table tx tx} +do_test attach-2.15 { + execsql { + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +do_test attach-2.16 { + db close + sqlite3 db test.db + execsql { + ATTACH 'test2.db' AS db2; + SELECT type, name, tbl_name FROM db2.sqlite_master; + } +} {table t2 t2 table tx tx trigger r1 t2 index i2 t2} +} ;# End of ifcapable {trigger} + +do_test attach-3.1 { + db close + db2 close + sqlite3 db test.db + sqlite3 db2 test2.db + execsql { + SELECT * FROM t1 + } +} {1 2 3 4} + +# If we are testing a version of the code that lacks trigger support, +# adjust the database contents so that they are the same if triggers +# had been enabled. +ifcapable {!trigger} { + db2 eval { + DELETE FROM t2; + INSERT INTO t2 VALUES(21, 'x'); + INSERT INTO t2 VALUES(22, 'y'); + CREATE TABLE tx(x1,x2,y1,y2); + INSERT INTO tx VALUES(1, 11, 'x', 'x'); + INSERT INTO tx VALUES(2, 12, 'y', 'y'); + INSERT INTO tx VALUES(11, 21, 'x', 'x'); + INSERT INTO tx VALUES(12, 22, 'y', 'y'); + CREATE INDEX i2 ON t2(x); + } +} + +do_test attach-3.2 { + catchsql { + SELECT * FROM t2 + } +} {1 {no such table: t2}} +do_test attach-3.3 { + catchsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM t2 + } +} {0 {21 x 22 y}} + +# Even though 'db' has started a transaction, it should not yet have +# a lock on test2.db so 'db2' should be readable. +do_test attach-3.4 { + execsql BEGIN + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +# Reading from test2.db from db within a transaction should not +# prevent test2.db from being read by db2. +do_test attach-3.5 { + execsql {SELECT * FROM t2} + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +# Making a change to test2.db through db causes test2.db to get +# a reserved lock. It should still be accessible through db2. +do_test attach-3.6 { + execsql { + UPDATE t2 SET x=x+1 WHERE x=50; + } + catchsql { + SELECT * FROM t2; + } db2; +} {0 {21 x 22 y}} + +do_test attach-3.7 { + execsql ROLLBACK + execsql {SELECT * FROM t2} db2 +} {21 x 22 y} + +# Start transactions on both db and db2. Once again, just because +# we make a change to test2.db using db2, only a RESERVED lock is +# obtained, so test2.db should still be readable using db. +# +do_test attach-3.8 { + execsql BEGIN + execsql BEGIN db2 + execsql {UPDATE t2 SET x=0 WHERE 0} db2 + catchsql {SELECT * FROM t2} +} {0 {21 x 22 y}} + +# It is also still accessible from db2. +do_test attach-3.9 { + catchsql {SELECT * FROM t2} db2 +} {0 {21 x 22 y}} + +do_test attach-3.10 { + execsql {SELECT * FROM t1} +} {1 2 3 4} + +do_test attach-3.11 { + catchsql {UPDATE t1 SET a=a+1} +} {0 {}} +do_test attach-3.12 { + execsql {SELECT * FROM t1} +} {2 2 4 4} + +# db2 has a RESERVED lock on test2.db, so db cannot write to any tables +# in test2.db. +do_test attach-3.13 { + catchsql {UPDATE t2 SET x=x+1 WHERE x=50} +} {1 {database is locked}} + +# Change for version 3. Transaction is no longer rolled back +# for a locked database. +execsql {ROLLBACK} + +# db is able to reread its schema because db2 still only holds a +# reserved lock. +do_test attach-3.14 { + catchsql {SELECT * FROM t1} +} {0 {1 2 3 4}} +do_test attach-3.15 { + execsql COMMIT db2 + execsql {SELECT * FROM t1} +} {1 2 3 4} + +# Ticket #323 +do_test attach-4.1 { + execsql {DETACH db2} + db2 close + sqlite3 db2 test2.db + execsql { + CREATE TABLE t3(x,y); + CREATE UNIQUE INDEX t3i1 ON t3(x); + INSERT INTO t3 VALUES(1,2); + SELECT * FROM t3; + } db2; +} {1 2} +do_test attach-4.2 { + execsql { + CREATE TABLE t3(a,b); + CREATE UNIQUE INDEX t3i1b ON t3(a); + INSERT INTO t3 VALUES(9,10); + SELECT * FROM t3; + } +} {9 10} +do_test attach-4.3 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM db2.t3; + } +} {1 2} +do_test attach-4.4 { + execsql { + SELECT * FROM main.t3; + } +} {9 10} +do_test attach-4.5 { + execsql { + INSERT INTO db2.t3 VALUES(9,10); + SELECT * FROM db2.t3; + } +} {1 2 9 10} +execsql { + DETACH db2; +} +ifcapable {trigger} { + do_test attach-4.6 { + execsql { + CREATE TABLE t4(x); + CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN + INSERT INTO t4 VALUES('db2.' || NEW.x); + END; + INSERT INTO t3 VALUES(6,7); + SELECT * FROM t4; + } db2 + } {db2.6} + do_test attach-4.7 { + execsql { + CREATE TABLE t4(y); + CREATE TRIGGER t3r3 AFTER INSERT ON t3 BEGIN + INSERT INTO t4 VALUES('main.' || NEW.a); + END; + INSERT INTO main.t3 VALUES(11,12); + SELECT * FROM main.t4; + } + } {main.11} +} +ifcapable {!trigger} { + # When we do not have trigger support, set up the table like they + # would have been had triggers been there. The tests that follow need + # this setup. + execsql { + CREATE TABLE t4(x); + INSERT INTO t3 VALUES(6,7); + INSERT INTO t4 VALUES('db2.6'); + INSERT INTO t4 VALUES('db2.13'); + } db2 + execsql { + CREATE TABLE t4(y); + INSERT INTO main.t3 VALUES(11,12); + INSERT INTO t4 VALUES('main.11'); + } +} + + +# This one is tricky. On the UNION ALL select, we have to make sure +# the schema for both main and db2 is valid before starting to execute +# the first query of the UNION ALL. If we wait to test the validity of +# the schema for main until after the first query has run, that test will +# fail and the query will abort but we will have already output some +# results. When the query is retried, the results will be repeated. +# +ifcapable compound { +do_test attach-4.8 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + INSERT INTO db2.t3 VALUES(13,14); + SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; + } +} {db2.6 db2.13 main.11} + +do_test attach-4.9 { + ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} + execsql { + INSERT INTO main.t3 VALUES(15,16); + SELECT * FROM db2.t4 UNION ALL SELECT * FROM main.t4; + } +} {db2.6 db2.13 main.11 main.15} +} ;# ifcapable compound + +ifcapable !compound { + ifcapable {!trigger} {execsql {INSERT INTO main.t4 VALUES('main.15')}} + execsql { + ATTACH DATABASE 'test2.db' AS db2; + INSERT INTO db2.t3 VALUES(13,14); + INSERT INTO main.t3 VALUES(15,16); + } +} ;# ifcapable !compound + +ifcapable view { +do_test attach-4.10 { + execsql { + DETACH DATABASE db2; + } + execsql { + CREATE VIEW v3 AS SELECT x*100+y FROM t3; + SELECT * FROM v3; + } db2 +} {102 910 607 1314} +do_test attach-4.11 { + execsql { + CREATE VIEW v3 AS SELECT a*100+b FROM t3; + SELECT * FROM v3; + } +} {910 1112 1516} +do_test attach-4.12 { + execsql { + ATTACH DATABASE 'test2.db' AS db2; + SELECT * FROM db2.v3; + } +} {102 910 607 1314} +do_test attach-4.13 { + execsql { + SELECT * FROM main.v3; + } +} {910 1112 1516} +} ;# ifcapable view + +# Tests for the sqliteFix...() routines in attach.c +# +ifcapable {trigger} { +do_test attach-5.1 { + db close + sqlite3 db test.db + db2 close + forcedelete test2.db + sqlite3 db2 test2.db + catchsql { + ATTACH DATABASE 'test.db' AS orig; + CREATE TRIGGER r1 AFTER INSERT ON orig.t1 BEGIN + SELECT 'no-op'; + END; + } db2 +} {1 {trigger r1 cannot reference objects in database orig}} +do_test attach-5.2 { + catchsql { + CREATE TABLE t5(x,y); + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op'; + END; + } db2 +} {0 {}} +do_test attach-5.3 { + catchsql { + DROP TRIGGER r5; + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM orig.t1; + END; + } db2 +} {1 {trigger r5 cannot reference objects in database orig}} +ifcapable tempdb { + do_test attach-5.4 { + catchsql { + CREATE TEMP TABLE t6(p,q,r); + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM temp.t6; + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} +} +ifcapable subquery { + do_test attach-5.5 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' || (SELECT * FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.6 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.7 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT 'no-op' FROM t1 GROUP BY 1 HAVING x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.7 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + SELECT max(1,x,(SELECT min(x) FROM temp.t6)) FROM t1; + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.8 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + INSERT INTO t1 VALUES((SELECT min(x) FROM temp.t6),5); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} + do_test attach-5.9 { + catchsql { + CREATE TRIGGER r5 AFTER INSERT ON t5 BEGIN + DELETE FROM t1 WHERE x<(SELECT min(x) FROM temp.t6); + END; + } db2 + } {1 {trigger r5 cannot reference objects in database temp}} +} ;# endif subquery +ifcapable json1&&vtab { + do_test attach-5.10 { + db close + catch {db2 close} + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t1(x); + CREATE TABLE t2(a,b); + CREATE TRIGGER x1 AFTER INSERT ON t1 BEGIN + INSERT INTO t2(a,b) SELECT key, value FROM json_each(NEW.x); + END; + INSERT INTO t1(x) VALUES('{"a":1}'); + SELECT * FROM t2; + } + } {a 1} + do_test attach-5.11 { + sqlite3 db2 :memory: + db2 eval { + CREATE TABLE t3(y); + ATTACH 'test.db' AS aux; + INSERT INTO aux.t1(x) VALUES('{"b":2}'); + SELECT * FROM aux.t2; + } + } {a 1 b 2} +} ;# endif json1 +} ;# endif trigger + +# Check to make sure we get a sensible error if unable to open +# the file that we are trying to attach. +# +do_test attach-6.1 { + catchsql { + ATTACH DATABASE 'no-such-file' AS nosuch; + } +} {0 {}} +if {$tcl_platform(platform)=="unix"} { + do_test attach-6.2 { + sqlite3 dbx cannot-read + dbx eval {CREATE TABLE t1(a,b,c)} + dbx close + file attributes cannot-read -permission 0000 + if {[file writable cannot-read]} { + puts "\n**** Tests do not work when run as root ****" + forcedelete cannot-read + exit 1 + } + catchsql { + ATTACH DATABASE 'cannot-read' AS noread; + } + } {1 {unable to open database: cannot-read}} + do_test attach-6.2.2 { + db errorcode + } {14} + forcedelete cannot-read +} + +# Check the error message if we try to access a database that has +# not been attached. +do_test attach-6.3 { + catchsql { + CREATE TABLE no_such_db.t1(a, b, c); + } +} {1 {unknown database no_such_db}} +for {set i 2} {$i<=15} {incr i} { + catch {db$i close} +} +db close +forcedelete test2.db +forcedelete no-such-file + +ifcapable subquery { + do_test attach-7.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + catchsql { + DETACH RAISE ( IGNORE ) IN ( SELECT "AAAAAA" . * ORDER BY + REGISTER LIMIT "AAAAAA" . "AAAAAA" OFFSET RAISE ( IGNORE ) NOT NULL ) + } + } {1 {no such table: AAAAAA}} +} + +# Create a malformed file (a file that is not a valid database) +# and try to attach it +# +do_test attach-8.1 { + set fd [open test2.db w] + puts $fd "This file is not a valid SQLite database" + close $fd + catchsql { + ATTACH 'test2.db' AS t2; + } +} {1 {file is not a database}} +do_test attach-8.2 { + db errorcode +} {26} +forcedelete test2.db +do_test attach-8.3 { + sqlite3 db2 test2.db + db2 eval {CREATE TABLE t1(x); BEGIN EXCLUSIVE} + catchsql { + ATTACH 'test2.db' AS t2; + } +} {1 {database is locked}} +do_test attach-8.4 { + db errorcode +} {5} +db2 close +forcedelete test2.db + +# Test that it is possible to attach the same database more than +# once when not in shared-cache mode. That this is not possible in +# shared-cache mode is tested in shared7.test. +do_test attach-9.1 { + forcedelete test4.db + execsql { + ATTACH 'test4.db' AS aux1; + CREATE TABLE aux1.t1(a, b); + INSERT INTO aux1.t1 VALUES(1, 2); + ATTACH 'test4.db' AS aux2; + SELECT * FROM aux2.t1; + } +} {1 2} +do_test attach-9.2 { + catchsql { + BEGIN; + INSERT INTO aux1.t1 VALUES(3, 4); + INSERT INTO aux2.t1 VALUES(5, 6); + } +} {1 {database is locked}} +do_test attach-9.3 { + execsql { + COMMIT; + SELECT * FROM aux2.t1; + } +} {1 2 3 4} + +# Ticket [abe728bbc311d81334dae9762f0db87c07a98f79]. +# Multi-database commit on an attached TEMP database. +# +do_test attach-10.1 { + execsql { + ATTACH '' AS noname; + ATTACH ':memory:' AS inmem; + BEGIN; + CREATE TABLE noname.noname(x); + CREATE TABLE inmem.inmem(y); + CREATE TABLE main.main(z); + COMMIT; + SELECT name FROM noname.sqlite_master; + SELECT name FROM inmem.sqlite_master; + } +} {noname inmem} +do_test attach-10.2 { + lrange [execsql { + PRAGMA database_list; + }] 9 end +} {4 noname {} 5 inmem {}} + +# Attach with a very long URI filename. +# +db close +sqlite3 db test.db -uri 1 +do_execsql_test attach-11.1 { + ATTACH printf('file:%09000x/x.db?mode=memory&cache=shared',1) AS aux1; + CREATE TABLE aux1.t1(x,y); + INSERT INTO aux1.t1(x,y) VALUES(1,2),(3,4); + SELECT * FROM aux1.t1; +} {1 2 3 4} + +# Ticket https://sqlite.org/src/tktview/a4e06e75a9ab61a1 2017-07-15 +# False positive when running integrity_check on a connection with +# attached databases. +# +db close +sqlite3 db :memory: +do_execsql_test attach-12.1 { + CREATE TABLE Table1 (col TEXT NOT NULL PRIMARY KEY); + ATTACH ':memory:' AS db2; + CREATE TABLE db2.Table2(col1 INTEGER, col2 INTEGER, col3 INTEGER, col4); + CREATE UNIQUE INDEX db2.idx_col1_unique ON Table2 (col1); + CREATE UNIQUE INDEX db2.idx_col23_unique ON Table2 (col2, col3); + CREATE INDEX db2.idx_col2 ON Table2 (col2); + INSERT INTO Table2 VALUES(1,2,3,4); + PRAGMA integrity_check; +} {ok} + +# 2021-03-10 Forum post https://sqlite.org/forum/forumpost/a006d86f72 +# +reset_db +do_test attach-13.1 { + sqlite3 db :memory: + db eval {CREATE TABLE base(x);} + for {set i 0} {$i<$SQLITE_MAX_ATTACHED} {incr i} { + db eval "ATTACH ':memory:' AS a$i" + } + set m "a[expr {$SQLITE_MAX_ATTACHED-1}]" + db eval "CREATE TABLE $m.t1(a INTEGER PRIMARY KEY, b);" + db eval "CREATE TABLE $m.t2(a INTEGER PRIMARY KEY, b);" + db eval {SELECT a FROM t1 WHERE b IN (SELECT a FROM t2);} +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/attach3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/attach3.test new file mode 100644 index 0000000000000000000000000000000000000000..1c8601c7b35472b8139a5a1d0b1d8d7848f94ebe --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/attach3.test @@ -0,0 +1,353 @@ +# 2003 July 1 +# +# 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. The +# focus of this script is testing the ATTACH and DETACH commands +# and schema changes to attached databases. +# +# $Id: attach3.test,v 1.18 2007/10/09 08:29:32 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +# The tests in this file were written before SQLite supported recursive +# trigger invocation, and some tests depend on that to pass. So disable +# recursive triggers for this file. +catchsql { pragma recursive_triggers = off } + +# Create tables t1 and t2 in the main database +execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} + +# Create tables t1 and t2 in database file test2.db +forcedelete test2.db +forcedelete test2.db-journal +sqlite3 db2 test2.db +execsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} db2 +db2 close + +# Create a table in the auxilary database. +do_test attach3-1.1 { + execsql { + ATTACH 'test2.db' AS aux; + } +} {} +do_test attach3-1.2 { + execsql { + CREATE TABLE aux.t3(e, f); + } +} {} +do_test attach3-1.3 { + execsql { + SELECT * FROM sqlite_master WHERE name = 't3'; + } +} {} +do_test attach3-1.4 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 't3'; + } +} "table t3 t3 [expr $AUTOVACUUM?5:4] {CREATE TABLE t3(e, f)}" +do_test attach3-1.5 { + execsql { + INSERT INTO t3 VALUES(1, 2); + SELECT * FROM t3; + } +} {1 2} + +# Create an index on the auxilary database table. +do_test attach3-2.1 { + execsql { + CREATE INDEX aux.i1 on t3(e); + } +} {} +do_test attach3-2.2 { + execsql { + SELECT * FROM sqlite_master WHERE name = 'i1'; + } +} {} +do_test attach3-2.3 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}" + +# Drop the index on the aux database table. +do_test attach3-3.1 { + execsql { + DROP INDEX aux.i1; + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} {} +do_test attach3-3.2 { + execsql { + CREATE INDEX aux.i1 on t3(e); + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} "index i1 t3 [expr $AUTOVACUUM?6:5] {CREATE INDEX i1 on t3(e)}" +do_test attach3-3.3 { + execsql { + DROP INDEX i1; + SELECT * FROM aux.sqlite_master WHERE name = 'i1'; + } +} {} + +# Drop tables t1 and t2 in the auxilary database. +do_test attach3-4.1 { + execsql { + DROP TABLE aux.t1; + SELECT name FROM aux.sqlite_master; + } +} {t2 t3} +do_test attach3-4.2 { + # This will drop main.t2 + execsql { + DROP TABLE t2; + SELECT name FROM aux.sqlite_master; + } +} {t2 t3} +do_test attach3-4.3 { + execsql { + DROP TABLE t2; + SELECT name FROM aux.sqlite_master; + } +} {t3} + +# Create a view in the auxilary database. +ifcapable view { +do_test attach3-5.1 { + execsql { + CREATE VIEW aux.v1 AS SELECT * FROM t3; + } +} {} +do_test attach3-5.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'v1'; + } +} {view v1 v1 0 {CREATE VIEW v1 AS SELECT * FROM t3}} +do_test attach3-5.3 { + execsql { + INSERT INTO aux.t3 VALUES('hello', 'world'); + SELECT * FROM v1; + } +} {1 2 hello world} + +# Drop the view +do_test attach3-6.1 { + execsql { + DROP VIEW aux.v1; + } +} {} +do_test attach3-6.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'v1'; + } +} {} +} ;# ifcapable view + +ifcapable {trigger} { +# Create a trigger in the auxilary database. +do_test attach3-7.1 { + execsql { + CREATE TRIGGER aux.tr1 AFTER INSERT ON t3 BEGIN + INSERT INTO t3 VALUES(new.e*2, new.f*2); + END; + } +} {} +do_test attach3-7.2 { + execsql { + DELETE FROM t3; + INSERT INTO t3 VALUES(10, 20); + SELECT * FROM t3; + } +} {10 20 20 40} +do_test attach3-5.3 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'tr1'; + } +} {trigger tr1 t3 0 {CREATE TRIGGER tr1 AFTER INSERT ON t3 BEGIN + INSERT INTO t3 VALUES(new.e*2, new.f*2); + END}} + +# Drop the trigger +do_test attach3-8.1 { + execsql { + DROP TRIGGER aux.tr1; + } +} {} +do_test attach3-8.2 { + execsql { + SELECT * FROM aux.sqlite_master WHERE name = 'tr1'; + } +} {} + +ifcapable tempdb { + # Try to trick SQLite into dropping the wrong temp trigger. + do_test attach3-9.0 { + execsql { + CREATE TABLE main.t4(a, b, c); + CREATE TABLE aux.t4(a, b, c); + CREATE TEMP TRIGGER tst_trigger BEFORE INSERT ON aux.t4 BEGIN + SELECT 'hello world'; + END; + SELECT count(*) FROM temp.sqlite_master; + } + } {1} + do_test attach3-9.1 { + execsql { + DROP TABLE main.t4; + SELECT count(*) FROM sqlite_temp_master; + } + } {1} + do_test attach3-9.2 { + execsql { + DROP TABLE aux.t4; + SELECT count(*) FROM temp.sqlite_master; + } + } {0} +} +} ;# endif trigger + +# Make sure the aux.sqlite_master table is read-only +do_test attach3-10.0 { + catchsql { + INSERT INTO aux.sqlite_master VALUES(1, 2, 3, 4, 5); + } +} {1 {table sqlite_master may not be modified}} + +# Failure to attach leaves us in a workable state. +# Ticket #811 +# +do_test attach3-11.0 { + catchsql { + ATTACH DATABASE '/nodir/nofile.x' AS notadb; + } +} {1 {unable to open database: /nodir/nofile.x}} +do_test attach3-11.1 { + catchsql { + ATTACH DATABASE ':memory:' AS notadb; + } +} {0 {}} +do_test attach3-11.2 { + catchsql { + DETACH DATABASE notadb; + } +} {0 {}} + +# Return a list of attached databases +# +proc db_list {} { + set x [execsql { + PRAGMA database_list; + }] + set y {} + foreach {n id file} $x {lappend y $id} + return $y +} + +ifcapable schema_pragmas&&tempdb { + +ifcapable !trigger { + execsql {create temp table dummy(dummy)} +} + +# Ticket #1825 +# +do_test attach3-12.1 { + db_list +} {main temp aux} +do_test attach3-12.2 { + execsql { + ATTACH DATABASE ? AS ? + } + db_list +} {main temp aux {}} +do_test attach3-12.3 { + execsql { + DETACH aux + } + db_list +} {main temp {}} +do_test attach3-12.4 { + execsql { + DETACH ? + } + db_list +} {main temp} +do_test attach3-12.5 { + execsql { + ATTACH DATABASE '' AS '' + } + db_list +} {main temp {}} +do_test attach3-12.6 { + execsql { + DETACH '' + } + db_list +} {main temp} +do_test attach3-12.7 { + execsql { + ATTACH DATABASE '' AS ? + } + db_list +} {main temp {}} +do_test attach3-12.8 { + execsql { + DETACH '' + } + db_list +} {main temp} +do_test attach3-12.9 { + execsql { + ATTACH DATABASE '' AS NULL + } + db_list +} {main temp {}} +do_test attach3-12.10 { + execsql { + DETACH ? + } + db_list +} {main temp} +do_test attach3-12.11 { + catchsql { + DETACH NULL + } +} {1 {no such database: }} +do_test attach3-12.12 { + catchsql { + ATTACH null AS null; + ATTACH '' AS ''; + } +} {1 {database is already in use}} +do_test attach3-12.13 { + db_list +} {main temp {}} +do_test attach3-12.14 { + execsql { + DETACH ''; + } + db_list +} {main temp} + +} ;# ifcapable pragma + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/attachmalloc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/attachmalloc.test new file mode 100644 index 0000000000000000000000000000000000000000..3c6a075b43bbc2a9b32def3f233b7289257382bb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/attachmalloc.test @@ -0,0 +1,78 @@ +# 2005 September 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 regression tests for SQLite library. The +# focus of this script is testing the ATTACH statement and +# specifically out-of-memory conditions within that command. +# +# $Id: attachmalloc.test,v 1.10 2008/10/22 10:45:38 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !attach { + finish_test + return +} + +source $testdir/malloc_common.tcl + +do_malloc_test attachmalloc-1 -tclprep { + catch { db close } + for {set i 2} {$i<=4} {incr i} { + catch { db$i close } + forcedelete test$i.db + forcedelete test$i.db-journal + } +} -tclbody { + if {[catch {sqlite3 db test.db}]} { + error "out of memory" + } + sqlite3_db_config_lookaside db 0 0 0 + sqlite3_extended_result_codes db 1 +} -sqlbody { + ATTACH 'test2.db' AS two; + CREATE TABLE two.t1(x); + ATTACH 'test3.db' AS three; + CREATE TABLE three.t1(x); + ATTACH 'test4.db' AS four; + CREATE TABLE four.t1(x); +} + +do_malloc_test attachmalloc-2 -tclprep { + forcedelete test2.db + forcedelete test2.db-journal + sqlite3 db2 test2.db + db2 eval { + CREATE TABLE t1(a, b, c); + CREATE INDEX i1 ON t1(a, b); + } + db2 close +} -sqlbody { + CREATE TABLE t1(d, e, f); + ATTACH 'test2.db' AS db1; +} + +ifcapable shared_cache { + set enable_shared_cache [sqlite3_enable_shared_cache 1] + sqlite3 dbaux test3.db + dbaux eval {SELECT * FROM sqlite_master} + do_malloc_test attachmalloc-3 -sqlbody { + SELECT * FROM sqlite_master; + ATTACH 'test3.db' AS three; + } -cleanup { + db eval { DETACH three } + } + dbaux close + sqlite3_enable_shared_cache $enable_shared_cache +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/auth.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth.test new file mode 100644 index 0000000000000000000000000000000000000000..1d56f70343563f026fc0d7d87b4ea57f107ed6a1 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth.test @@ -0,0 +1,2678 @@ +# 2003 April 4 +# +# 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. The +# focus of this script is testing the sqlite3_set_authorizer() API +# and related functionality. +# +# $Id: auth.test,v 1.46 2009/07/02 18:40:35 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +rename proc proc_real +proc_real proc {name arguments script} { + proc_real $name $arguments $script + if {$name=="auth"} { + db authorizer ::auth + } +} + +do_test auth-1.1.1 { + db close + set ::DB [sqlite3 db test.db] + proc authx {code arg1 arg2 arg3 arg4 args} {return SQLITE_DENY} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db authorizer ::authx + # EVIDENCE-OF: R-03993-24285 Only a single authorizer can be in place on + # a database connection at a time. Each call to sqlite3_set_authorizer + # overrides the previous call. + # + # The authx authorizer above is overridden by the auth authorizer below + # authx is never invoked. + db authorizer ::auth + catchsql {CREATE TABLE t1(a,b,c)} +} {1 {not authorized}} +do_test auth-1.1.2 { + db errorcode +} {23} +do_test auth-1.1.3 { + db authorizer +} {::auth} +do_test auth-1.1.4 { + # Ticket #896. + catchsql { + SELECT x; + } +} {1 {no such column: x}} +do_test auth-1.2 { + execsql {SELECT name FROM sqlite_master} +} {} +# EVIDENCE-OF: R-04452-49349 When the callback returns SQLITE_DENY, the +# sqlite3_prepare_v2() or equivalent call that triggered the authorizer +# will fail with an error message explaining that access is denied. +do_test auth-1.3.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {1 {not authorized}} +do_test auth-1.3.2 { + db errorcode +} {23} +do_test auth-1.3.3 { + set ::authargs +} {t1 {} main {}} +do_test auth-1.4 { + execsql {SELECT name FROM sqlite_master} +} {} + +ifcapable tempdb { + do_test auth-1.5 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.6 { + execsql {SELECT name FROM temp.sqlite_master} + } {} + do_test auth-1.7.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {1 {not authorized}} + do_test auth-1.7.2 { + set ::authargs + } {t1 {} temp {}} + do_test auth-1.8 { + execsql {SELECT name FROM sqlite_temp_master} + } {} +} + +do_test auth-1.9 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {0 {}} +do_test auth-1.10 { + execsql {SELECT name FROM sqlite_master} +} {} +do_test auth-1.11 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TABLE t1(a,b,c)} +} {0 {}} +do_test auth-1.12 { + execsql {SELECT name FROM sqlite_master} +} {} + +ifcapable tempdb { + do_test auth-1.13 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.14 { + execsql {SELECT name FROM temp.sqlite_master} + } {} + do_test auth-1.15 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.16 { + execsql {SELECT name FROM sqlite_temp_master} + } {} + + do_test auth-1.17 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMP TABLE t1(a,b,c)} + } {0 {}} + do_test auth-1.18 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.19.1 { + set ::authargs {} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TABLE t2(a,b,c)} +} {0 {}} +do_test auth-1.19.2 { + set ::authargs +} {} +do_test auth-1.20 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +do_test auth-1.21.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.21.2 { + set ::authargs +} {t2 {} main {}} +do_test auth-1.22 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.23.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.23.2 { + set ::authargs +} {t2 {} main {}} +do_test auth-1.24 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.25 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.26 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.27 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.28 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.29 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {1 {not authorized}} +do_test auth-1.30 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.31 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {0 {}} +do_test auth-1.32 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.33 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="t1"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {INSERT INTO t2 VALUES(1,2,3)} +} {0 {}} +do_test auth-1.34 { + execsql {SELECT * FROM t2} +} {1 2 3} + +do_test auth-1.35.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {1 {access to t2.b is prohibited}} +ifcapable attach { + do_test auth-1.35.2 { + execsql {ATTACH DATABASE 'test.db' AS two} + catchsql {SELECT * FROM two.t2} + } {1 {access to two.t2.b is prohibited}} + execsql {DETACH DATABASE two} +} +# EVIDENCE-OF: R-38392-49970 If the action code is SQLITE_READ and the +# callback returns SQLITE_IGNORE then the prepared statement statement +# is constructed to substitute a NULL value in place of the table column +# that would have been read if SQLITE_OK had been returned. +do_test auth-1.36 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {1 {} 3}} +do_test auth-1.37 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b=2} +} {0 {}} +do_test auth-1.38 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b=2} +} {0 {{} 2 3}} +do_test auth-1.39 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2 WHERE b IS NULL} +} {0 {1 {} 3}} +do_test auth-1.40 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT a,c FROM t2 WHERE b IS NULL} +} {1 {access to t2.b is prohibited}} + +do_test auth-1.41 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET a=11} +} {0 {}} +do_test auth-1.42 { + execsql {SELECT * FROM t2} +} {11 2 3} +do_test auth-1.43 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET b=22, c=33} +} {1 {not authorized}} +do_test auth-1.44 { + execsql {SELECT * FROM t2} +} {11 2 3} +do_test auth-1.45 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {UPDATE t2 SET b=22, c=33} +} {0 {}} +do_test auth-1.46 { + execsql {SELECT * FROM t2} +} {11 2 33} + +do_test auth-1.47 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DELETE FROM t2 WHERE a=11} +} {1 {not authorized}} +do_test auth-1.48 { + execsql {SELECT * FROM t2} +} {11 2 33} +do_test auth-1.49 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DELETE FROM t2 WHERE a=11} +} {0 {}} +do_test auth-1.50 { + execsql {SELECT * FROM t2} +} {} +do_test auth-1.50.2 { + execsql {INSERT INTO t2 VALUES(11, 2, 33)} +} {} + +do_test auth-1.51 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {1 {not authorized}} +do_test auth-1.52 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {}} +do_test auth-1.53 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2} +} {0 {11 2 33}} + +# Update for version 3: There used to be a handful of test here that +# tested the authorisation callback with the COPY command. The following +# test makes the same database modifications as they used to. +do_test auth-1.54 { + execsql {INSERT INTO t2 VALUES(7, 8, 9);} +} {} +do_test auth-1.55 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9} + +do_test auth-1.63 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.64 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.65 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {1 {not authorized}} +do_test auth-1.66 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.67 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.68 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.69 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {1 {not authorized}} + do_test auth-1.70 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.71 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.72 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.73 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t2"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t2} +} {0 {}} +do_test auth-1.74 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.75 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.76 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.77 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="t1"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TABLE t1} + } {0 {}} + do_test auth-1.78 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +# Test cases auth-1.79 to auth-1.124 test creating and dropping views. +# Omit these if the library was compiled with views omitted. +ifcapable view { +do_test auth-1.79 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {1 {not authorized}} +do_test auth-1.80 { + set ::authargs +} {v1 {} main {}} +do_test auth-1.81 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.82 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {0 {}} +do_test auth-1.83 { + set ::authargs +} {v1 {} main {}} +do_test auth-1.84 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.85 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.86 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.87 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.88 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.89 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.90 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +do_test auth-1.91 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {1 {not authorized}} +do_test auth-1.92 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.93 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2} +} {0 {}} +do_test auth-1.94 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.95 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {1 {not authorized}} + do_test auth-1.96 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.97 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2} + } {0 {}} + do_test auth-1.98 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} + +do_test auth-1.99 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2; + DROP VIEW v2 + } +} {1 {not authorized}} +do_test auth-1.100 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.101 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {1 {not authorized}} +do_test auth-1.102 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.103 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.104 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.105 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.106 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.107 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.108 { + execsql {SELECT name FROM sqlite_master} +} {t2 v2} +do_test auth-1.109 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP VIEW v2} +} {0 {}} +do_test auth-1.110 { + set ::authargs +} {v2 {} main {}} +do_test auth-1.111 { + execsql {SELECT name FROM sqlite_master} +} {t2} + + +ifcapable tempdb { + do_test auth-1.112 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1; + DROP VIEW v1 + } + } {1 {not authorized}} + do_test auth-1.113 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 v1} + do_test auth-1.114 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {1 {not authorized}} + do_test auth-1.115 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.116 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.117 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.118 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 v1} + do_test auth-1.119 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.120 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.121 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 v1} + do_test auth-1.122 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_VIEW"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP VIEW v1} + } {0 {}} + do_test auth-1.123 { + set ::authargs + } {v1 {} temp {}} + do_test auth-1.124 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} +} +} ;# ifcapable view + +# Test cases auth-1.125 to auth-1.176 test creating and dropping triggers. +# Omit these if the library was compiled with triggers omitted. +# +ifcapable trigger&&tempdb { +do_test auth-1.125 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.126 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.127 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.128 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.129 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.130 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.131 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.132 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.133 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r2 DELETE on t2 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.134 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.135 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + CREATE TABLE tx(id); + CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN + INSERT INTO tx VALUES(NEW.rowid); + END; + } +} {0 {}} +do_test auth-1.136.1 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.136.2 { + execsql { + SELECT name FROM sqlite_master WHERE type='trigger' + } +} {r2} +do_test auth-1.136.3 { + proc auth {code arg1 arg2 arg3 arg4 args} { + lappend ::authargs $code $arg1 $arg2 $arg3 $arg4 + return SQLITE_OK + } + set ::authargs {} + execsql { + INSERT INTO t2 VALUES(1,2,3); + } + set ::authargs +} {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2} +do_test auth-1.136.4 { + execsql { + SELECT * FROM tx; + } +} {3} +do_test auth-1.137 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.138 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.139 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.140 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +do_test auth-1.141 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {1 {not authorized}} +do_test auth-1.142 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1} +do_test auth-1.143 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.144 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.145 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +do_test auth-1.146 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.147 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1} +do_test auth-1.148 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + CREATE TRIGGER r1 DELETE on t1 BEGIN + SELECT NULL; + END; + } +} {0 {}} +do_test auth-1.149 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.150 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} + +do_test auth-1.151 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {1 {not authorized}} +do_test auth-1.152 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.153 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {1 {not authorized}} +do_test auth-1.154 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.155 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.156 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.157 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.158 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.159 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.160 { + execsql {SELECT name FROM sqlite_master} +} {t2 tx r2} +do_test auth-1.161 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r2} +} {0 {}} +do_test auth-1.162 { + set ::authargs +} {r2 t2 main {}} +do_test auth-1.163 { + execsql { + DROP TABLE tx; + DELETE FROM t2 WHERE a=1 AND b=2 AND c=3; + SELECT name FROM sqlite_master; + } +} {t2} + +do_test auth-1.164 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {1 {not authorized}} +do_test auth-1.165 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} +do_test auth-1.166 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {1 {not authorized}} +do_test auth-1.167 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.168 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1 r1} +do_test auth-1.169 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.170 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1 r1} +do_test auth-1.171 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.172 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.173 { + execsql {SELECT name FROM sqlite_temp_master} +} {t1 r1} +do_test auth-1.174 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_TRIGGER"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP TRIGGER r1} +} {0 {}} +do_test auth-1.175 { + set ::authargs +} {r1 t1 temp {}} +do_test auth-1.176 { + execsql {SELECT name FROM temp.sqlite_master} +} {t1} +} ;# ifcapable trigger + +do_test auth-1.177 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {1 {not authorized}} +do_test auth-1.178 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.179 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.180 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {1 {not authorized}} +do_test auth-1.181 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.182 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(b)} +} {0 {}} +do_test auth-1.183 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.184 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.185 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(b)} +} {0 {}} +do_test auth-1.186 { + execsql {SELECT name FROM sqlite_master} +} {t2} +do_test auth-1.187 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {CREATE INDEX i2 ON t2(a)} +} {0 {}} +do_test auth-1.188 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.189 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} + +ifcapable tempdb { + do_test auth-1.190 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(a)} + } {1 {not authorized}} + do_test auth-1.191 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.192 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.193 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {1 {not authorized}} + do_test auth-1.194 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} + do_test auth-1.195 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(b)} + } {0 {}} + do_test auth-1.196 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.197 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.198 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(c)} + } {0 {}} + do_test auth-1.199 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1} + do_test auth-1.200 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_CREATE_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {CREATE INDEX i1 ON t1(a)} + } {0 {}} + do_test auth-1.201 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.202 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} +} + +do_test auth-1.203 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {1 {not authorized}} +do_test auth-1.204 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.205 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {1 {not authorized}} +do_test auth-1.205a { + set ::authargs +} {i2 t2 main {}} +db eval { + ATTACH ':memory:' as di205; + CREATE TABLE di205.t1(x); + CREATE INDEX di205.t1x ON t1(x); +} +do_catchsql_test auth-1.205b { + DROP INDEX di205.t1x; +} {1 {not authorized}} +db eval { + DETACH di205; +} +do_test auth-1.206 { + set ::authargs +} {t1x t1 di205 {}} +do_test auth-1.207 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.208 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.209 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.210 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.211 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.212 { + execsql {SELECT name FROM sqlite_master} +} {t2 i2} +do_test auth-1.213 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP INDEX i2} +} {0 {}} +do_test auth-1.214 { + set ::authargs +} {i2 t2 main {}} +do_test auth-1.215 { + execsql {SELECT name FROM sqlite_master} +} {t2} + +ifcapable tempdb { + do_test auth-1.216 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.217 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.218 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {1 {not authorized}} + do_test auth-1.219 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.220 { + execsql {SELECT name FROM sqlite_temp_master} + } {t1 i1} + do_test auth-1.221 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.222 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} + do_test auth-1.223 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.224 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.225 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1 i1} + do_test auth-1.226 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DROP_TEMP_INDEX"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {DROP INDEX i1} + } {0 {}} + do_test auth-1.227 { + set ::authargs + } {i1 t1 temp {}} + do_test auth-1.228 { + execsql {SELECT name FROM temp.sqlite_master} + } {t1} +} + +do_test auth-1.229 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {1 {not authorized}} +do_test auth-1.230 { + set ::authargs +} {full_column_names on {} {}} +do_test auth-1.231 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} +do_test auth-1.232 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {0 {}} +do_test auth-1.233 { + set ::authargs +} {full_column_names on {} {}} +do_test auth-1.234 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} +do_test auth-1.235 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=on} +} {0 {}} +do_test auth-1.236 { + execsql2 {SELECT a FROM t2} +} {t2.a 11 t2.a 7} +do_test auth-1.237 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql {PRAGMA full_column_names=OFF} +} {0 {}} +do_test auth-1.238 { + set ::authargs +} {full_column_names OFF {} {}} +do_test auth-1.239 { + execsql2 {SELECT a FROM t2} +} {a 11 a 7} + +do_test auth-1.240 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_TRANSACTION"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {BEGIN} +} {1 {not authorized}} +do_test auth-1.241 { + set ::authargs +} {BEGIN {} {} {}} +do_test auth-1.242 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT} +} {1 {not authorized}} +do_test auth-1.243 { + set ::authargs +} {COMMIT {} {} {}} +do_test auth-1.244 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9 44 55 66} +do_test auth-1.245 { + catchsql {ROLLBACK} +} {1 {not authorized}} +do_test auth-1.246 { + set ::authargs +} {ROLLBACK {} {} {}} +do_test auth-1.247 { + catchsql {END TRANSACTION} +} {1 {not authorized}} +do_test auth-1.248 { + set ::authargs +} {COMMIT {} {} {}} +do_test auth-1.249 { + # EVIDENCE-OF: R-52112-44167 Disable the authorizer by installing a NULL + # callback. + db authorizer {} + catchsql {ROLLBACK} +} {0 {}} +do_test auth-1.250 { + execsql {SELECT * FROM t2} +} {11 2 33 7 8 9} + +# ticket #340 - authorization for ATTACH and DETACH. +# +ifcapable attach { + do_test auth-1.251 { + db authorizer ::auth + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1 + } + } {0 {}} + do_test auth-1.252a { + set ::authargs + } {:memory: {} {} {}} + do_test auth-1.252b { + db eval {DETACH test1} + set ::attachfilename :memory: + db eval {ATTACH $::attachfilename AS test1} + set ::authargs + } {{} {} {} {}} + do_test auth-1.252c { + db eval {DETACH test1} + db eval {ATTACH ':mem' || 'ory:' AS test1} + set ::authargs + } {{} {} {} {}} + do_test auth-1.253 { + catchsql {DETACH DATABASE test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1; + } + } {1 {not authorized}} + do_test auth-1.254 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.255 { + catchsql {DETACH DATABASE test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ATTACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ATTACH DATABASE ':memory:' AS test1; + } + } {0 {}} + do_test auth-1.256 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.257 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + execsql {ATTACH DATABASE ':memory:' AS test1} + catchsql { + DETACH DATABASE test1; + } + } {0 {}} + do_test auth-1.258 { + lindex [execsql {PRAGMA database_list}] 7 + } {} + do_test auth-1.259 { + execsql {ATTACH DATABASE ':memory:' AS test1} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + DETACH DATABASE test1; + } + } {0 {}} + ifcapable tempdb { + ifcapable schema_pragmas { + do_test auth-1.260 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + do_test auth-1.261 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DETACH"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + DETACH DATABASE test1; + } + } {1 {not authorized}} + ifcapable schema_pragmas { + do_test auth-1.262 { + lindex [execsql {PRAGMA database_list}] 7 + } {test1} + } ;# ifcapable schema_pragmas + db authorizer {} + execsql {DETACH DATABASE test1} + db authorizer ::auth + + # Authorization for ALTER TABLE. These tests are omitted if the library + # was built without ALTER TABLE support. + ifcapable altertable { + + do_test auth-1.263 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME TO t1x + } + } {0 {}} + do_test auth-1.264 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + do_test auth-1.265 { + set authargs + } {temp t1 {} {}} + do_test auth-1.266 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {0 {}} + do_test auth-1.267 { + execsql {SELECT name FROM temp.sqlite_master WHERE type='table'} + } {t1x} + do_test auth-1.268 { + set authargs + } {temp t1x {} {}} + do_test auth-1.269 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1x RENAME TO t1 + } + } {1 {not authorized}} + do_test auth-1.270 { + execsql {SELECT name FROM sqlite_temp_master WHERE type='table'} + } {t1x} + + do_test auth-1.271 { + set authargs + } {temp t1x {} {}} + } ;# ifcapable altertable + + } else { + db authorizer {} + db eval { + DETACH DATABASE test1; + } + } +} + +ifcapable altertable { +db authorizer {} +catchsql {ALTER TABLE t1x RENAME TO t1} +db authorizer ::auth +do_test auth-1.272 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2 RENAME TO t2x + } +} {0 {}} +do_test auth-1.273 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.274 { + set authargs +} {main t2 {} {}} +do_test auth-1.275 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2x RENAME TO t2 + } +} {0 {}} +do_test auth-1.276 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.277 { + set authargs +} {main t2x {} {}} +do_test auth-1.278 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t2x RENAME TO t2 + } +} {1 {not authorized}} +do_test auth-1.279 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t2x} +do_test auth-1.280 { + set authargs +} {main t2x {} {}} +db authorizer {} +catchsql {ALTER TABLE t2x RENAME TO t2} + +} ;# ifcapable altertable + +# Test the authorization callbacks for the REINDEX command. +ifcapable reindex { + +proc auth {code args} { + if {$code=="SQLITE_REINDEX"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + } + return SQLITE_OK +} +db authorizer auth +do_test auth-1.281 { + execsql { + CREATE TABLE t3(a PRIMARY KEY, b, c); + CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); + CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); + } +} {} +do_test auth-1.282 { + set ::authargs {} + execsql { + REINDEX t3_idx1; + } + set ::authargs +} {t3_idx1 {} main {}} +do_test auth-1.283 { + set ::authargs {} + execsql { + REINDEX BINARY; + } + set ::authargs +} {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}} +do_test auth-1.284 { + set ::authargs {} + execsql { + REINDEX NOCASE; + } + set ::authargs +} {t3_idx2 {} main {}} +do_test auth-1.285 { + set ::authargs {} + execsql { + REINDEX t3; + } + set ::authargs +} {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}} +do_test auth-1.286 { + execsql { + DROP TABLE t3; + } +} {} +ifcapable tempdb { + do_test auth-1.287 { + execsql { + CREATE TEMP TABLE t3(a PRIMARY KEY, b, c); + CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY); + CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE); + } + } {} + do_test auth-1.288 { + set ::authargs {} + execsql { + REINDEX temp.t3_idx1; + } + set ::authargs + } {t3_idx1 {} temp {}} + do_test auth-1.289 { + set ::authargs {} + execsql { + REINDEX BINARY; + } + set ::authargs + } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + do_test auth-1.290 { + set ::authargs {} + execsql { + REINDEX NOCASE; + } + set ::authargs + } {t3_idx2 {} temp {}} + do_test auth-1.291 { + set ::authargs {} + execsql { + REINDEX temp.t3; + } + set ::authargs + } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}} + proc auth {code args} { + if {$code=="SQLITE_REINDEX"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + return SQLITE_DENY + } + return SQLITE_OK + } + do_test auth-1.292 { + set ::authargs {} + catchsql { + REINDEX temp.t3; + } + } {1 {not authorized}} + do_test auth-1.293 { + execsql { + DROP TABLE t3; + } + } {} +} + +} ;# ifcapable reindex + +ifcapable analyze { + proc auth {code args} { + if {$code=="SQLITE_ANALYZE"} { + set ::authargs [concat $::authargs [lrange $args 0 3]] + } + return SQLITE_OK + } + do_test auth-1.294 { + set ::authargs {} + execsql { + CREATE TABLE t4(a,b,c); + CREATE INDEX t4i1 ON t4(a); + CREATE INDEX t4i2 ON t4(b,a,c); + INSERT INTO t4 VALUES(1,2,3); + ANALYZE; + } + set ::authargs + } {t4 {} main {} t2 {} main {}} + do_test auth-1.295 { + execsql { + SELECT count(*) FROM sqlite_stat1; + } + } 3 + proc auth {code args} { + if {$code=="SQLITE_ANALYZE"} { + set ::authargs [concat $::authargs $args] + return SQLITE_DENY + } + return SQLITE_OK + } + do_test auth-1.296 { + set ::authargs {} + catchsql { + ANALYZE; + } + } {1 {not authorized}} + do_test auth-1.297 { + execsql { + SELECT count(*) FROM sqlite_stat1; + } + } 3 +} ;# ifcapable analyze + + +# Authorization for ALTER TABLE ADD COLUMN. +# These tests are omitted if the library +# was built without ALTER TABLE support. +ifcapable {altertable} { + do_test auth-1.300 { + execsql {CREATE TABLE t5(x)} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_1; + } + } {0 {}} + do_test auth-1.301 { + set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}] + regexp new_col_1 $x + } {1} + do_test auth-1.302 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_execsql_test auth-1.302-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + } {} + db eval ROLLBACK + do_test auth-1.302-drop-2 { + set authargs + } {main t5 new_col_1 {}} + do_test auth-1.303 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_2; + } + } {0 {}} + do_test auth-1.304 { + set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}] + regexp new_col_2 $x + } {0} + do_test auth-1.305 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_execsql_test auth-1.305-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%'; + } {1} + db eval ROLLBACK + do_test auth-1.305-drop-2 { + set authargs + } {main t5 new_col_1 {}} + do_test auth-1.306 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t5 ADD COLUMN new_col_3 + } + } {1 {not authorized}} + do_test auth-1.307 { + set x [execsql {SELECT sql FROM temp.sqlite_master WHERE type='t5'}] + regexp new_col_3 $x + } {0} + do_test auth-1.308 { + set authargs + } {main t5 {} {}} + db eval BEGIN + set authargs {} + do_catchsql_test auth-1.308-drop-1 { + ALTER TABLE t5 DROP COLUMN new_col_1; + } {1 {not authorized}} + do_execsql_test auth-1.308-drop-2 { + SELECT 1 FROM sqlite_schema WHERE name='t5' AND sql LIKE '%new_col_1%'; + } {1} + do_test auth-1.308-drop-3 { + set authargs + } {main t5 new_col_1 {}} + db eval ROLLBACK + + execsql {DROP TABLE t5} +} ;# ifcapable altertable + +ifcapable {cte} { + do_test auth-1.310 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_RECURSIVE"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db eval { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,2),(3,4),(5,6); + } + } {} + do_catchsql_test auth-1.311 { + WITH + auth1311(x,y) AS (SELECT a+b, b-a FROM t1) + SELECT * FROM auth1311 ORDER BY x; + } {0 {3 1 7 1 11 1}} + do_catchsql_test auth-1.312 { + WITH RECURSIVE + auth1312(x,y) AS (SELECT a+b, b-a FROM t1) + SELECT x, y FROM auth1312 ORDER BY x; + } {0 {3 1 7 1 11 1}} + do_catchsql_test auth-1.313 { + WITH RECURSIVE + auth1313(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1313 WHERE x<5) + SELECT * FROM t1; + } {0 {1 2 3 4 5 6}} + do_catchsql_test auth-1.314 { + WITH RECURSIVE + auth1314(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM auth1314 WHERE x<5) + SELECT * FROM t1 LEFT JOIN auth1314; + } {1 {not authorized}} +} ;# ifcapable cte + +# +# db eval {SELECT sql FROM temp.sqlite_master} {puts "TEMP: $sql;"} +# db eval {SELECT sql FROM main.sqlite_master} {puts "MAIN: $sql;"} +# +# MAIN: CREATE TABLE "t2"(a,b,c); +# MAIN: CREATE TABLE t4(a,b,c); +# MAIN: CREATE INDEX t4i1 ON t4(a); +# MAIN: CREATE INDEX t4i2 ON t4(b,a,c); +# MAIN: CREATE TABLE sqlite_stat1(tbl,idx,stat); +# MAIN: CREATE TABLE t1(a,b); +# +ifcapable altertable&&vtab { + do_test auth-1.350 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_OK + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN b TO bcdefg; + } + } {0 {}} + do_execsql_test auth-1.351 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.352 { + set authargs + } {main t1 {} {}} + do_test auth-1.353 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN bcdefg TO b; + } + } {0 {}} + do_execsql_test auth-1.354 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.355 { + set authargs + } {main t1 {} {}} + do_test auth-1.356 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_ALTER_TABLE"} { + set ::authargs [list $arg1 $arg2 $arg3 $arg4] + return SQLITE_DENY + } + return SQLITE_OK + } + catchsql { + ALTER TABLE t1 RENAME COLUMN bcdefg TO b; + } + } {1 {not authorized}} + do_execsql_test auth-1.357 { + SELECT name FROM pragma_table_info('t1') ORDER BY cid; + } {a bcdefg} + do_test auth-1.358 { + set authargs + } {main t1 {} {}} +} + +# 2022-12-28 +# The sqlite3_declare_vtab() call that occurs during pragma_table_list +# should not cause an authentication failure. +# +ifcapable vtab { + 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} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} { + return SQLITE_DENY + } + return SQLITE_OK + } + db authorizer ::auth + execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)} + catchsql {SELECT * FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.1 { + catchsql {SELECT y,z FROM t3} +} {0 {}} +do_test auth-2.2 { + catchsql {SELECT ROWID,y,z FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.3 { + catchsql {SELECT OID,y,z FROM t3} +} {1 {access to t3.x is prohibited}} +do_test auth-2.4 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + execsql {INSERT INTO t3 VALUES(44,55,66)} + catchsql {SELECT * FROM t3} +} {0 {{} 55 66}} +do_test auth-2.5 { + catchsql {SELECT rowid,y,z FROM t3} +} {0 {{} 55 66}} +do_test auth-2.6 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t3} +} {0 {44 55 66}} +do_test auth-2.7 { + catchsql {SELECT ROWID,y,z FROM t3} +} {0 {44 55 66}} +do_test auth-2.8 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {0 {{} 2 33 {} 8 9}} +do_test auth-2.9.1 { + # We have to flush the cache here in case the Tcl interface tries to + # reuse a statement compiled with sqlite3_prepare_v2(). In this case, + # the first error encountered is an SQLITE_SCHEMA error. Then, when + # trying to recompile the statement, the authorization error is encountered. + # If we do not flush the cache, the correct error message is returned, but + # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test + # case after this one. + # + db cache flush + + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} { + return bogus + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {1 {authorizer malfunction}} +do_test auth-2.9.2 { + db errorcode +} {1} +do_test auth-2.10 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_SELECT"} { + return bogus + } + return SQLITE_OK + } + catchsql {SELECT ROWID,b,c FROM t2} +} {1 {authorizer malfunction}} +do_test auth-2.11.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg2=="a"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2, t3} +} {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}} +do_test auth-2.11.2 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg2=="x"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + catchsql {SELECT * FROM t2, t3} +} {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}} + +# Make sure the OLD and NEW pseudo-tables of a trigger get authorized. +# +ifcapable trigger { + do_test auth-3.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + return SQLITE_OK + } + execsql { + CREATE TABLE tx(a1,a2,b1,b2,c1,c2); + CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN + INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c); + END; + UPDATE t2 SET a=a+1; + SELECT * FROM tx; + } + } {11 12 2 2 33 33 7 8 8 8 9 9} + do_test auth-3.2 { + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} { + return SQLITE_IGNORE + } + return SQLITE_OK + } + execsql { + DELETE FROM tx; + UPDATE t2 SET a=a+100; + SELECT * FROM tx; + } + } {12 112 2 2 {} {} 8 108 8 8 {} {}} +} ;# ifcapable trigger + +# Make sure the names of views and triggers are passed on on arg4. +# +ifcapable trigger { +do_test auth-4.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + lappend ::authargs $code $arg1 $arg2 $arg3 $arg4 + return SQLITE_OK + } + set authargs {} + execsql { + UPDATE t2 SET a=a+1; + } + set authargs +} [list \ + SQLITE_READ t2 a main {} \ + SQLITE_UPDATE t2 a main {} \ + SQLITE_INSERT tx {} main r1 \ + SQLITE_READ t2 a main r1 \ + SQLITE_READ t2 a main r1 \ + SQLITE_READ t2 b main r1 \ + SQLITE_READ t2 b main r1 \ + SQLITE_READ t2 c main r1 \ + SQLITE_READ t2 c main r1] +} + +ifcapable {view && trigger} { +do_test auth-4.2 { + execsql { + CREATE VIEW v1 AS SELECT a+b AS x FROM t2; + CREATE TABLE v1chng(x1,x2); + CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN + INSERT INTO v1chng VALUES(OLD.x,NEW.x); + END; + SELECT * FROM v1; + } +} {115 117} +do_test auth-4.3 { + set authargs {} + execsql { + UPDATE v1 SET x=1 WHERE x=117 + } + set authargs +} [list \ + SQLITE_UPDATE v1 x main {} \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ t2 a main v1 \ + SQLITE_READ t2 b main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_INSERT v1chng {} main r2 \ + SQLITE_READ v1 x main r2 \ + SQLITE_READ v1 x main r2 \ +] + +do_test auth-4.4 { + execsql { + CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN + INSERT INTO v1chng VALUES(OLD.x,NULL); + END; + SELECT * FROM v1; + } +} {115 117} +do_test auth-4.5 { + set authargs {} + execsql { + DELETE FROM v1 WHERE x=117 + } + set authargs +} [list \ + SQLITE_DELETE v1 {} main {} \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ t2 a main v1 \ + SQLITE_READ t2 b main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_SELECT {} {} {} v1 \ + SQLITE_READ v1 x main v1 \ + SQLITE_INSERT v1chng {} main r3 \ + SQLITE_READ v1 x main r3 \ +] + +} ;# ifcapable view && trigger + +# Ticket #1338: Make sure authentication works in the presence of an AS +# clause. +# +do_test auth-5.1 { + proc auth {code arg1 arg2 arg3 arg4 args} { + return SQLITE_OK + } + execsql { + SELECT count(a) AS cnt FROM t4 ORDER BY cnt + } +} {1} + +# Ticket #1607 +# +ifcapable compound&&subquery { + ifcapable trigger { + execsql { + DROP TABLE tx; + } + ifcapable view { + execsql { + DROP TABLE v1chng; + } + } + } + ifcapable stat4 { + set stat4 "sqlite_stat4 " + } else { + set stat4 "" + } + do_test auth-5.2 { + execsql { + SELECT name FROM ( + SELECT * FROM sqlite_master UNION ALL SELECT * FROM temp.sqlite_master) + WHERE type='table' + ORDER BY name + } + } "sqlite_stat1 ${stat4}t1 t2 t3 t4" +} + +# Ticket #3944 +# +ifcapable trigger { + do_test auth-5.3.1 { + execsql { + CREATE TABLE t5 ( x ); + CREATE TRIGGER t5_tr1 AFTER INSERT ON t5 BEGIN + UPDATE t5 SET x = 1 WHERE NEW.x = 0; + END; + } + } {} + set ::authargs [list] + proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK + } + do_test auth-5.3.2 { + execsql { INSERT INTO t5 (x) values(0) } + set ::authargs + } [list SQLITE_INSERT t5 {} main {} \ + SQLITE_UPDATE t5 x main t5_tr1 \ + SQLITE_READ t5 x main t5_tr1 \ + ] + do_test auth-5.3.2 { + execsql { SELECT * FROM t5 } + } {1} +} + +# Ticket [0eb70d77cb05bb22720]: Invalid pointer passsed to the authorizer +# callback when updating a ROWID. +# +do_test auth-6.1 { + execsql { + CREATE TABLE t6(a,b,c,d,e,f,g,h); + INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8); + } +} {} +set ::authargs [list] +proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK +} +do_test auth-6.2 { + execsql {UPDATE t6 SET rowID=rowID+100} + set ::authargs +} [list SQLITE_READ t6 ROWID main {} \ + SQLITE_UPDATE t6 ROWID main {} \ +] +do_test auth-6.3 { + execsql {SELECT rowid, * FROM t6} +} {101 1 2 3 4 5 6 7 8} + +#------------------------------------------------------------------------- +# Test that view names are included as zArg4. +# +do_execsql_test auth-7.1 { + CREATE TABLE t7(a, b, c); + CREATE VIEW v7 AS SELECT * FROM t7; +} {} +set ::authargs [list] +proc auth {args} { + eval lappend ::authargs [lrange $args 0 4] + return SQLITE_OK +} + +do_test auth-7.2 { + execsql {SELECT a, c FROM v7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main v7 \ + SQLITE_READ t7 b main v7 \ + SQLITE_READ t7 c main v7 \ + SQLITE_READ v7 a main {} \ + SQLITE_READ v7 c main {} \ + SQLITE_SELECT {} {} {} v7 \ +] + +set ::authargs [list] +do_test auth-7.3 { + execsql {SELECT a, c FROM t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main {} \ + SQLITE_READ t7 c main {} \ +] + +set ::authargs [list] +do_test auth-7.4 { + execsql {SELECT a, c FROM t7 AS v7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t7 a main {} \ + SQLITE_READ t7 c main {} \ +] + +# If a table is referenced but no columns are read from the table, +# that causes a single SQLITE_READ authorization with a NULL column +# name. +# +# EVIDENCE-OF: R-31520-16302 When a table is referenced by a SELECT but +# no column values are extracted from that table (for example in a query +# like "SELECT count(*) FROM tab") then the SQLITE_READ authorizer +# callback is invoked once for that table with a column name that is an +# empty string. +# +set ::authargs [list] +do_test auth-8.1 { + execsql {SELECT count(*) FROM t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_FUNCTION {} count {} {} \ + SQLITE_READ t7 {} {} {} \ + ] +set ::authargs [list] + +do_test auth-8.2 { + execsql {SELECT t6.a FROM t6, t7} + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_READ t6 a main {} \ + SQLITE_READ t7 {} {} {} \ + ] + +# Test also that if SQLITE_DENY is returned from an SQLITE_READ authorizer +# invocation with no column name specified, compilation fails. +# +set ::authargs [list] +proc auth {op args} { + foreach {a b c d} $args break + lappend ::authargs $op $a $b $c $d + if {$op == "SQLITE_READ"} { return "SQLITE_DENY" } + return "SQLITE_OK" +} +set ::authargs [list] +do_catchsql_test auth-8.3 { + SELECT count(*) FROM t7 +} {1 {not authorized}} +do_test auth-8.4 { + set ::authargs +} [list \ + SQLITE_SELECT {} {} {} {} \ + SQLITE_FUNCTION {} count {} {} \ + SQLITE_READ t7 {} {} {} \ +] + + +rename proc {} +rename proc_real proc +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/auth2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth2.test new file mode 100644 index 0000000000000000000000000000000000000000..08d46cac57f471324ff99999e655031145bed4c8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth2.test @@ -0,0 +1,160 @@ +# 2006 Aug 24 +# +# 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. The +# focus of this script is testing the sqlite3_set_authorizer() API +# and related functionality. +# +# $Id: auth2.test,v 1.3 2008/07/02 13:13:53 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +do_test auth2-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + } + set ::flist {} + proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_FUNCTION"} { + lappend ::flist $arg2 + if {$arg2=="max"} { + return SQLITE_DENY + } elseif {$arg2=="min"} { + return SQLITE_IGNORE + } else { + return SQLITE_OK + } + } + return SQLITE_OK + } + db authorizer ::auth + catchsql {SELECT max(a,b,c) FROM t1} +} {1 {not authorized to use function: max}} +do_test auth2-1.2 { + set ::flist +} max +do_test auth2-1.3 { + set ::flist {} + catchsql {SELECT min(a,b,c) FROM t1} +} {0 {{}}} +do_test auth2-1.4 { + set ::flist +} min +do_test auth2-1.5 { + set ::flist {} + catchsql {SELECT coalesce(min(a,b,c),999) FROM t1} +} {0 999} +do_test auth2-1.6 { + set ::flist +} {coalesce min} +do_test auth2-1.7 { + set ::flist {} + catchsql {SELECT coalesce(a,b,c) FROM t1} +} {0 1} +do_test auth2-1.8 { + set ::flist +} coalesce + +# Make sure the authorizer is not called when parsing the schema +# and when computing the result set of a view. +# +db close +sqlite3 db test.db +sqlite3 db2 test.db +proc auth {args} { + global authargs + append authargs [lrange $args 0 4]\n + return SQLITE_OK +} +db auth auth +do_test auth2-2.1 { + set ::authargs {} + db eval { + CREATE TABLE t2(x,y,z); + } + set ::authargs +} {SQLITE_INSERT sqlite_master {} main {} +SQLITE_CREATE_TABLE t2 {} main {} +SQLITE_UPDATE sqlite_master type main {} +SQLITE_UPDATE sqlite_master name main {} +SQLITE_UPDATE sqlite_master tbl_name main {} +SQLITE_UPDATE sqlite_master rootpage main {} +SQLITE_UPDATE sqlite_master sql main {} +SQLITE_READ sqlite_master ROWID main {} +} +do_test auth2-2.2 { + set ::authargs {} + db eval { + CREATE VIEW v2 AS SELECT x+y AS a, y+z AS b from t2; + } + set ::authargs +} {SQLITE_INSERT sqlite_master {} main {} +SQLITE_CREATE_VIEW v2 {} main {} +SQLITE_UPDATE sqlite_master type main {} +SQLITE_UPDATE sqlite_master name main {} +SQLITE_UPDATE sqlite_master tbl_name main {} +SQLITE_UPDATE sqlite_master rootpage main {} +SQLITE_UPDATE sqlite_master sql main {} +SQLITE_READ sqlite_master ROWID main {} +} +do_test auth2-2.3 { + set ::authargs {} + db eval { + SELECT a, b FROM v2; + } + set ::authargs +} {SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 a main {} +SQLITE_READ v2 b main {} +SQLITE_SELECT {} {} {} v2 +} +do_test auth2-2.4 { + db2 eval { + CREATE TABLE t3(p,q,r); + } + set ::authargs {} + db eval { + SELECT b, a FROM v2; + } + set ::authargs +} {SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 b main {} +SQLITE_READ v2 a main {} +SQLITE_SELECT {} {} {} v2 +SQLITE_SELECT {} {} {} {} +SQLITE_READ t2 x main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 y main v2 +SQLITE_READ t2 z main v2 +SQLITE_READ v2 b main {} +SQLITE_READ v2 a main {} +SQLITE_SELECT {} {} {} v2 +} +db2 close + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/auth3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth3.test new file mode 100644 index 0000000000000000000000000000000000000000..abc973433ee41f698e94b99d04a3061586e195f2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/auth3.test @@ -0,0 +1,134 @@ +# 2008 October 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. +# +#*********************************************************************** +# +# Test that the truncate optimization is disabled if the SQLITE_DELETE +# authorization callback returns SQLITE_IGNORE. +# +# Test that authorizer is disabled during schema parsing. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# disable this test if the SQLITE_OMIT_AUTHORIZATION macro is +# defined during compilation. +if {[catch {db auth {}} msg]} { + finish_test + return +} + +# Disable the statement cache for these tests. +# +db cache size 0 + +db authorizer ::auth +proc auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_DELETE"} { + return $::authcode + } + return SQLITE_OK +} + +#-------------------------------------------------------------------------- +# The following tests - auth3-1.* - test that return values of SQLITE_DENY, +# SQLITE_IGNORE, SQLITE_OK and are correctly handled when returned +# by an SQLITE_DELETE authorization callback triggered by a +# "DELETE FROM " statement. +# +do_test auth3-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } +} {} +do_test auth3.1.2 { + set ::authcode SQLITE_DENY + catchsql { DELETE FROM t1 } +} {1 {not authorized}} +# EVIDENCE-OF: R-64962-58611 If the authorizer callback returns any +# value other than SQLITE_IGNORE, SQLITE_OK, or SQLITE_DENY then the +# sqlite3_prepare_v2() or equivalent call that triggered the authorizer +# will fail with an error message. +do_test auth3.1.3 { + set ::authcode SQLITE_INVALID + catchsql { DELETE FROM t1 } +} {1 {authorizer malfunction}} +do_test auth3.1.4 { + execsql { SELECT * FROM t1 } +} {1 2 3 4 5 6} +do_test auth3-1.5 { + set ::authcode SQLITE_IGNORE + execsql { + DELETE FROM t1; + SELECT * FROM t1; + } +} {} +do_test auth3-1.6 { + set ::authcode SQLITE_OK + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + DELETE FROM t1; + SELECT * FROM t1; + } +} {} + +#-------------------------------------------------------------------------- +# These tests - auth3-2.* - test that returning SQLITE_IGNORE really does +# disable the truncate optimization. +# +do_test auth3-2.1 { + set ::authcode SQLITE_OK + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } + set sqlite_search_count 0 + execsql { + DELETE FROM t1; + } + set sqlite_search_count +} {0} + +do_test auth3-2.2 { + set ::authcode SQLITE_IGNORE + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + } + set sqlite_search_count 0 + execsql { + DELETE FROM t1; + } + set sqlite_search_count +} {1} + +# 2016-07-28. A problem report from a private client complaining about +# an authorizer failure during an ALTER TABLE. The solution (I think) is +# to disable the authorizer during schema parsing. +# +ifcapable altertable { + proc auth {code args} { + if {$code=="SQLITE_READ" && [regexp {DoNotRead} $args]} { + return SQLITE_DENY + } + return SQLITE_OK + } + do_execsql_test auth3-3.0 { + CREATE TEMPORARY TABLE TempTable ( + key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE, + value TEXT NOT NULL ON CONFLICT FAIL); + ALTER TABLE TempTable RENAME TO DoNotRead; + SELECT name FROM temp.sqlite_master; + } {DoNotRead sqlite_autoindex_DoNotRead_1} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autoanalyze1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoanalyze1.test new file mode 100644 index 0000000000000000000000000000000000000000..71e5d6c163416bcfb60f747a0753096d910c58fc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoanalyze1.test @@ -0,0 +1,123 @@ +# 2017-02-17 +# +# 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 the logic used to estimate when +# running ANALYZE would be beneficial. +# +# Note that this test uses some hard-coded bitmask values from sqliteInt.h. +# If any of the following constants changes: +# +# define TF_HasStat1 0x0010 +# define TF_StatsUsed 0x0100 +# +# then some of the magic numbers in test results below might need to be +# adjusted. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There is nothing to test if ANALYZE is disable for this build. +# These tests also use "PRAGMA stats" which are only enabled for +# debugging builds. +# +ifcapable {!debug || !analyze || !vtab} { + finish_test + return +} + +do_execsql_test autoanalyze1-100 { + -- Build up a test table with some indexes + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); + CREATE UNIQUE INDEX t1bc ON t1(b,c); + CREATE INDEX t1d ON t1(d); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c,d) SELECT x, x, x, x FROM c; + -- Verify that the hasStat1 flag is clear on on indexes + SELECT idx, flgs FROM pragma_stats + WHERE idx IS NOT NULL + ORDER BY idx; + -- Verify that the TF_HasStat1 flag is clear on the table + SELECT tbl, (flgs & 0x10)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {t1bc 0 t1d 0 t1 0} + +# No use of stat1 recorded so far +do_execsql_test autoanalyze1-110 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +# Access using a unique index does not set the TF_StatsUsed flag. +# +do_execsql_test autoanalyze1-200 { + SELECT * FROM t1 WHERE a=55; +} {55 55 55 55} +do_execsql_test autoanalyze1-201 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +do_execsql_test autoanalyze1-210 { + SELECT * FROM t1 WHERE a IN (55,199,299); +} {55 55 55 55} +do_execsql_test autoanalyze1-211 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +do_execsql_test autoanalyze1-220 { + SELECT * FROM t1 WHERE (b,c)=(45,45); +} {45 45 45 45} +do_execsql_test autoanalyze1-221 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +# Any use of the non-unique t1d index triggers the use of stats. +# +sqlite3 db test.db +do_execsql_test autoanalyze1-300 { + SELECT * FROM t1 WHERE d=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-301 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +sqlite3 db test.db +do_execsql_test autoanalyze1-310 { + SELECT * FROM t1 WHERE d=45 AND a=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-311 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} ;# The ROWID lookup short-circuits the d=45 constraint + +sqlite3 db test.db +do_execsql_test autoanalyze1-320 { + SELECT * FROM t1 WHERE d=45 AND a IN (45,46); +} {45 45 45 45} +do_execsql_test autoanalyze1-321 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +# Any use of prefix of a unique index triggers the use of stats +# +sqlite3 db test.db +do_execsql_test autoanalyze1-400 { + SELECT * FROM t1 WHERE b=45; +} {45 45 45 45} +do_execsql_test autoanalyze1-401 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {1} + +# The TF_StatsUsed flag is reset when the database is reopened +# +sqlite3 db test.db +do_execsql_test autoanalyze1-500 { + SELECT (flgs & 0x0100)!=0 FROM pragma_stats WHERE tbl='t1' AND idx IS NULL; +} {0} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autoinc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoinc.test new file mode 100644 index 0000000000000000000000000000000000000000..2c7ee2a7e86504ba92eea49d53553c4b516c3d3c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoinc.test @@ -0,0 +1,883 @@ +# 2004 November 12 +# +# 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. The +# focus of this script is testing the AUTOINCREMENT features. +# +# $Id: autoinc.test,v 1.14 2009/06/23 20:28:54 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix autoinc + +# If the library is not compiled with autoincrement support then +# skip all tests in this file. +# +ifcapable {!autoinc} { + finish_test + return +} + +if {[permutation]=="inmemory_journal"} { + finish_test + return +} + +sqlite3_db_config_lookaside db 0 0 0 + +# The database is initially empty. +# +do_test autoinc-1.1 { + execsql { + SELECT name FROM sqlite_master WHERE type='table'; + } +} {} + +# Add a table with the AUTOINCREMENT feature. Verify that the +# SQLITE_SEQUENCE table gets created. +# +do_test autoinc-1.2 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + SELECT name FROM sqlite_master WHERE type='table'; + } +} {t1 sqlite_sequence} + +# The SQLITE_SEQUENCE table is initially empty +# +do_test autoinc-1.3 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {} +do_test autoinc-1.3.1 { + catchsql { + CREATE INDEX seqidx ON sqlite_sequence(name) + } +} {1 {table sqlite_sequence may not be indexed}} + +# Close and reopen the database. Verify that everything is still there. +# +do_test autoinc-1.4 { + db close + sqlite3 db test.db + execsql { + SELECT * FROM sqlite_sequence; + } +} {} + +# We are not allowed to drop the sqlite_sequence table. +# +do_test autoinc-1.5 { + catchsql {DROP TABLE sqlite_sequence} +} {1 {table sqlite_sequence may not be dropped}} +do_test autoinc-1.6 { + execsql {SELECT name FROM sqlite_master WHERE type='table'} +} {t1 sqlite_sequence} + +# Insert an entries into the t1 table and make sure the largest key +# is always recorded in the sqlite_sequence table. +# +do_test autoinc-2.1 { + execsql { + SELECT * FROM sqlite_sequence + } +} {} +do_test autoinc-2.2 { + execsql { + INSERT INTO t1 VALUES(12,34); + SELECT * FROM sqlite_sequence; + } +} {t1 12} +do_test autoinc-2.3 { + execsql { + INSERT INTO t1 VALUES(1,23); + SELECT * FROM sqlite_sequence; + } +} {t1 12} +do_test autoinc-2.4 { + execsql { + INSERT INTO t1 VALUES(123,456); + SELECT * FROM sqlite_sequence; + } +} {t1 123} +do_test autoinc-2.5 { + execsql { + INSERT INTO t1 VALUES(NULL,567); + SELECT * FROM sqlite_sequence; + } +} {t1 124} +do_test autoinc-2.6 { + execsql { + DELETE FROM t1 WHERE y=567; + SELECT * FROM sqlite_sequence; + } +} {t1 124} +do_test autoinc-2.7 { + execsql { + INSERT INTO t1 VALUES(NULL,567); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.8 { + execsql { + DELETE FROM t1; + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.9 { + execsql { + INSERT INTO t1 VALUES(12,34); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.10 { + execsql { + INSERT INTO t1 VALUES(125,456); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.11 { + execsql { + INSERT INTO t1 VALUES(-1234567,-1); + SELECT * FROM sqlite_sequence; + } +} {t1 125} +do_test autoinc-2.12 { + execsql { + INSERT INTO t1 VALUES(234,5678); + SELECT * FROM sqlite_sequence; + } +} {t1 234} +do_test autoinc-2.13 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(NULL,1); + SELECT * FROM sqlite_sequence; + } +} {t1 235} +do_test autoinc-2.14 { + execsql { + SELECT * FROM t1; + } +} {235 1} + +# Manually change the autoincrement values in sqlite_sequence. +# +do_test autoinc-2.20 { + execsql { + UPDATE sqlite_sequence SET seq=1234 WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,2); + SELECT * FROM t1; + } +} {235 1 1235 2} +do_test autoinc-2.21 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1235} +do_test autoinc-2.22 { + execsql { + UPDATE sqlite_sequence SET seq=NULL WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,3); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3} +do_test autoinc-2.23 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1236} +do_test autoinc-2.24 { + execsql { + UPDATE sqlite_sequence SET seq='a-string' WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,4); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4} +do_test autoinc-2.25 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1237} +do_test autoinc-2.26 { + execsql { + DELETE FROM sqlite_sequence WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,5); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4 1238 5} +do_test autoinc-2.27 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1238} +do_test autoinc-2.28 { + execsql { + UPDATE sqlite_sequence SET seq='-12345678901234567890' + WHERE name='t1'; + INSERT INTO t1 VALUES(NULL,6); + SELECT * FROM t1; + } +} {235 1 1235 2 1236 3 1237 4 1238 5 1239 6} +do_test autoinc-2.29 { + execsql { + SELECT * FROM sqlite_sequence; + } +} {t1 1239} + +# Test multi-row inserts +# +do_test autoinc-2.50 { + execsql { + DELETE FROM t1 WHERE y>=3; + INSERT INTO t1 SELECT NULL, y+2 FROM t1; + SELECT * FROM t1; + } +} {235 1 1235 2 1240 3 1241 4} +do_test autoinc-2.51 { + execsql { + SELECT * FROM sqlite_sequence + } +} {t1 1241} + +ifcapable tempdb { + do_test autoinc-2.52 { + execsql { + CREATE TEMP TABLE t2 AS SELECT y FROM t1; + } + execsql { + INSERT INTO t1 SELECT NULL, y+4 FROM t2; + SELECT * FROM t1; + } + } {235 1 1235 2 1240 3 1241 4 1242 5 1243 6 1244 7 1245 8} + do_test autoinc-2.53 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1245} + do_test autoinc-2.54 { + execsql { + DELETE FROM t1; + INSERT INTO t1 SELECT NULL, y FROM t2; + SELECT * FROM t1; + } + } {1246 1 1247 2 1248 3 1249 4} + do_test autoinc-2.55 { + execsql { + SELECT * FROM sqlite_sequence + } + } {t1 1249} +} + +# Create multiple AUTOINCREMENT tables. Make sure all sequences are +# tracked separately and do not interfere with one another. +# +do_test autoinc-2.70 { + catchsql { + DROP TABLE t2; + } + execsql { + CREATE TABLE t2(d, e INTEGER PRIMARY KEY AUTOINCREMENT, f); + INSERT INTO t2(d) VALUES(1); + SELECT * FROM sqlite_sequence; + } +} [ifcapable tempdb {list t1 1249 t2 1} else {list t1 1241 t2 1}] +do_test autoinc-2.71 { + execsql { + INSERT INTO t2(d) VALUES(2); + SELECT * FROM sqlite_sequence; + } +} [ifcapable tempdb {list t1 1249 t2 2} else {list t1 1241 t2 2}] +do_test autoinc-2.72 { + execsql { + INSERT INTO t1(x) VALUES(10000); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 2} +do_test autoinc-2.73 { + execsql { + CREATE TABLE t3(g INTEGER PRIMARY KEY AUTOINCREMENT, h); + INSERT INTO t3(h) VALUES(1); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 2 t3 1} +do_test autoinc-2.74 { + execsql { + INSERT INTO t2(d,e) VALUES(3,100); + SELECT * FROM sqlite_sequence; + } +} {t1 10000 t2 100 t3 1} + + +# When a table with an AUTOINCREMENT is deleted, the corresponding entry +# in the SQLITE_SEQUENCE table should also be deleted. But the SQLITE_SEQUENCE +# table itself should remain behind. +# +do_test autoinc-3.1 { + execsql {SELECT name FROM sqlite_sequence} +} {t1 t2 t3} +do_test autoinc-3.2 { + execsql { + DROP TABLE t1; + SELECT name FROM sqlite_sequence; + } +} {t2 t3} +do_test autoinc-3.3 { + execsql { + DROP TABLE t3; + SELECT name FROM sqlite_sequence; + } +} {t2} +do_test autoinc-3.4 { + execsql { + DROP TABLE t2; + SELECT name FROM sqlite_sequence; + } +} {} + +# AUTOINCREMENT on TEMP tables. +# +ifcapable tempdb { + do_test autoinc-4.1 { + execsql { + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM temp.sqlite_master WHERE type='table'; + } + } {1 sqlite_sequence} + do_test autoinc-4.2 { + execsql { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + CREATE TEMP TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + SELECT 1, name FROM sqlite_master WHERE type='table'; + SELECT 2, name FROM sqlite_temp_master WHERE type='table'; + } + } {1 sqlite_sequence 1 t1 2 t3 2 sqlite_sequence} + do_test autoinc-4.3 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} + do_test autoinc-4.4 { + execsql { + INSERT INTO t1 VALUES(10,1); + INSERT INTO t3 VALUES(20,2); + INSERT INTO t1 VALUES(NULL,3); + INSERT INTO t3 VALUES(NULL,4); + } + } {} + + ifcapable compound { + do_test autoinc-4.4.1 { + execsql { + SELECT * FROM t1 UNION ALL SELECT * FROM t3; + } + } {10 1 11 3 20 2 21 4} + } ;# ifcapable compound + + do_test autoinc-4.5 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 11 2 t3 21} + do_test autoinc-4.6 { + execsql { + INSERT INTO t1 SELECT * FROM t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 21} + do_test autoinc-4.7 { + execsql { + INSERT INTO t3 SELECT x+100, y FROM t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21 2 t3 121} + do_test autoinc-4.8 { + execsql { + DROP TABLE t3; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {1 t1 21} + do_test autoinc-4.9 { + execsql { + CREATE TEMP TABLE t2(p INTEGER PRIMARY KEY AUTOINCREMENT, q); + INSERT INTO t2 SELECT * FROM t1; + DROP TABLE t1; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {2 t2 21} + do_test autoinc-4.10 { + execsql { + DROP TABLE t2; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + } + } {} +} + +# Make sure AUTOINCREMENT works on ATTACH-ed tables. +# +ifcapable tempdb&&attach { + do_test autoinc-5.1 { + forcedelete test2.db + forcedelete test2.db-journal + sqlite3 db2 test2.db + execsql { + CREATE TABLE t4(m INTEGER PRIMARY KEY AUTOINCREMENT, n); + CREATE TABLE t5(o, p INTEGER PRIMARY KEY AUTOINCREMENT); + } db2; + execsql { + ATTACH 'test2.db' as aux; + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {} + do_test autoinc-5.2 { + execsql { + INSERT INTO t4 VALUES(NULL,1); + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1} + do_test autoinc-5.3 { + execsql { + INSERT INTO t5 VALUES(100,200); + SELECT * FROM sqlite_sequence + } db2 + } {t4 1 t5 200} + do_test autoinc-5.4 { + execsql { + SELECT 1, * FROM main.sqlite_sequence; + SELECT 2, * FROM temp.sqlite_sequence; + SELECT 3, * FROM aux.sqlite_sequence; + } + } {3 t4 1 3 t5 200} +} + +# Requirement REQ00310: Make sure an insert fails if the sequence is +# already at its maximum value. +# +ifcapable {rowid32} { + do_test autoinc-6.1 { + execsql { + CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w); + INSERT INTO t6 VALUES(2147483647,1); + SELECT seq FROM main.sqlite_sequence WHERE name='t6'; + } + } 2147483647 +} +ifcapable {!rowid32} { + do_test autoinc-6.1 { + execsql { + CREATE TABLE t6(v INTEGER PRIMARY KEY AUTOINCREMENT, w); + INSERT INTO t6 VALUES(9223372036854775807,1); + SELECT seq FROM main.sqlite_sequence WHERE name='t6'; + } + } 9223372036854775807 +} +do_test autoinc-6.2 { + catchsql { + INSERT INTO t6 VALUES(NULL,1); + } +} {1 {database or disk is full}} + +# Allow the AUTOINCREMENT keyword inside the parentheses +# on a separate PRIMARY KEY designation. +# +do_test autoinc-7.1 { + execsql { + CREATE TABLE t7(x INTEGER, y REAL, PRIMARY KEY(x AUTOINCREMENT)); + INSERT INTO t7(y) VALUES(123); + INSERT INTO t7(y) VALUES(234); + DELETE FROM t7; + INSERT INTO t7(y) VALUES(345); + SELECT * FROM t7; + } +} {3 345.0} + +# Test that if the AUTOINCREMENT is applied to a non integer primary key +# the error message is sensible. +do_test autoinc-7.2 { + catchsql { + CREATE TABLE t8(x TEXT PRIMARY KEY AUTOINCREMENT); + } +} {1 {AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY}} + + +# Ticket #1283. Make sure that preparing but never running a statement +# that creates the sqlite_sequence table does not mess up the database. +# +do_test autoinc-8.1 { + catch {db2 close} + catch {db close} + forcedelete test.db + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB { + CREATE TABLE t1( + x INTEGER PRIMARY KEY AUTOINCREMENT + ) + } -1 TAIL] + sqlite3_finalize $STMT + set STMT [sqlite3_prepare $DB { + CREATE TABLE t1( + x INTEGER PRIMARY KEY AUTOINCREMENT + ) + } -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql { + INSERT INTO t1 VALUES(NULL); + SELECT * FROM t1; + } +} {1} + +# Ticket #3148 +# Make sure the sqlite_sequence table is not damaged when doing +# an empty insert - an INSERT INTO ... SELECT ... where the SELECT +# clause returns an empty set. +# +do_test autoinc-9.1 { + db eval { + CREATE TABLE t2(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + INSERT INTO t2 VALUES(NULL, 1); + CREATE TABLE t3(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + INSERT INTO t3 SELECT * FROM t2 WHERE y>1; + + SELECT * FROM sqlite_sequence WHERE name='t3'; + } +} {t3 0} + +ifcapable trigger { + catchsql { pragma recursive_triggers = off } + + # Ticket #3928. Make sure that triggers to not make extra slots in + # the SQLITE_SEQUENCE table. + # + do_test autoinc-3928.1 { + db eval { + CREATE TABLE t3928(a INTEGER PRIMARY KEY AUTOINCREMENT, b); + CREATE TRIGGER t3928r1 BEFORE INSERT ON t3928 BEGIN + INSERT INTO t3928(b) VALUES('before1'); + INSERT INTO t3928(b) VALUES('before2'); + END; + CREATE TRIGGER t3928r2 AFTER INSERT ON t3928 BEGIN + INSERT INTO t3928(b) VALUES('after1'); + INSERT INTO t3928(b) VALUES('after2'); + END; + INSERT INTO t3928(b) VALUES('test'); + SELECT * FROM t3928 ORDER BY a; + } + } {1 before1 2 after1 3 after2 4 before2 5 after1 6 after2 7 test 8 before1 9 before2 10 after1 11 before1 12 before2 13 after2} + do_test autoinc-3928.2 { + db eval { + SELECT * FROM sqlite_sequence WHERE name='t3928' + } + } {t3928 13} + + do_test autoinc-3928.3 { + db eval { + DROP TRIGGER t3928r1; + DROP TRIGGER t3928r2; + CREATE TRIGGER t3928r3 BEFORE UPDATE ON t3928 + WHEN typeof(new.b)=='integer' BEGIN + INSERT INTO t3928(b) VALUES('before-int-' || new.b); + END; + CREATE TRIGGER t3928r4 AFTER UPDATE ON t3928 + WHEN typeof(new.b)=='integer' BEGIN + INSERT INTO t3928(b) VALUES('after-int-' || new.b); + END; + DELETE FROM t3928 WHERE a!=1; + UPDATE t3928 SET b=456 WHERE a=1; + SELECT * FROM t3928 ORDER BY a; + } + } {1 456 14 before-int-456 15 after-int-456} + do_test autoinc-3928.4 { + db eval { + SELECT * FROM sqlite_sequence WHERE name='t3928' + } + } {t3928 15} + + do_test autoinc-3928.5 { + db eval { + CREATE TABLE t3928b(x); + INSERT INTO t3928b VALUES(100); + INSERT INTO t3928b VALUES(200); + INSERT INTO t3928b VALUES(300); + DELETE FROM t3928; + CREATE TABLE t3928c(y INTEGER PRIMARY KEY AUTOINCREMENT, z); + CREATE TRIGGER t3928br1 BEFORE DELETE ON t3928b BEGIN + INSERT INTO t3928(b) VALUES('before-del-'||old.x); + INSERT INTO t3928c(z) VALUES('before-del-'||old.x); + END; + CREATE TRIGGER t3928br2 AFTER DELETE ON t3928b BEGIN + INSERT INTO t3928(b) VALUES('after-del-'||old.x); + INSERT INTO t3928c(z) VALUES('after-del-'||old.x); + END; + DELETE FROM t3928b; + SELECT * FROM t3928 ORDER BY a; + } + } {16 before-del-100 17 after-del-100 18 before-del-200 19 after-del-200 20 before-del-300 21 after-del-300} + do_test autoinc-3928.6 { + db eval { + SELECT * FROM t3928c ORDER BY y; + } + } {1 before-del-100 2 after-del-100 3 before-del-200 4 after-del-200 5 before-del-300 6 after-del-300} + do_test autoinc-3928.7 { + db eval { + SELECT * FROM sqlite_sequence WHERE name LIKE 't3928%' ORDER BY name; + } + } {t3928 21 t3928c 6} + + # Ticket [a696379c1f0886615541a48b35bd8181a80e88f8] + do_test autoinc-a69637.1 { + db eval { + CREATE TABLE ta69637_1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + CREATE TABLE ta69637_2(z); + CREATE TRIGGER ra69637_1 AFTER INSERT ON ta69637_2 BEGIN + INSERT INTO ta69637_1(y) VALUES(new.z+1); + END; + INSERT INTO ta69637_2 VALUES(123); + SELECT * FROM ta69637_1; + } + } {1 124} + do_test autoinc-a69637.2 { + db eval { + CREATE VIEW va69637_2 AS SELECT * FROM ta69637_2; + CREATE TRIGGER ra69637_2 INSTEAD OF INSERT ON va69637_2 BEGIN + INSERT INTO ta69637_1(y) VALUES(new.z+10000); + END; + INSERT INTO va69637_2 VALUES(123); + SELECT * FROM ta69637_1; + } + } {1 124 2 10123} +} + +# 2016-10-03 ticket https://www.sqlite.org/src/tktview/7b3328086a5c1 +# Make sure autoincrement plays nicely with the xfer optimization +# +do_execsql_test autoinc-10.1 { + DELETE FROM sqlite_sequence; + CREATE TABLE t10a(a INTEGER PRIMARY KEY AUTOINCREMENT, b UNIQUE); + INSERT INTO t10a VALUES(888,9999); + CREATE TABLE t10b(x INTEGER PRIMARY KEY AUTOINCREMENT, y UNIQUE); + INSERT INTO t10b SELECT * FROM t10a; + SELECT * FROM sqlite_sequence; +} {t10a 888 t10b 888} + +# 2018-04-21 autoincrement does not cause problems for upsert +# +do_execsql_test autoinc-11.1 { + CREATE TABLE t11(a INTEGER PRIMARY KEY AUTOINCREMENT,b UNIQUE); + INSERT INTO t11(a,b) VALUES(2,3),(5,6),(4,3),(1,2) + ON CONFLICT(b) DO UPDATE SET a=a+1000; + SELECT seq FROM sqlite_sequence WHERE name='t11'; +} {5} + +# 2018-05-23 ticket d8dc2b3a58cd5dc2918a1d4acbba4676a23ada4c +# Does not crash if the sqlite_sequence table schema is missing +# or corrupt. +# +do_test autoinc-12.1 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE fake_sequence(name TEXT PRIMARY KEY,seq) WITHOUT ROWID; + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql=replace(sql,'fake_','sqlite_'), + name='sqlite_sequence', + tbl_name='sqlite_sequence' + WHERE name='fake_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +do_test autoinc-12.2 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql=replace(sql,'sqlite_','x_'), + name='x_sequence', + tbl_name='x_sequence' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +ifcapable vtab { + set err "database disk image is malformed" +} else { + set err {malformed database schema (sqlite_sequence) - near "VIRTUAL": syntax error} +} +do_test autoinc-12.3 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE VIRTUAL TABLE sqlite_sequence USING sqlite_dbpage' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} [list 1 $err] +do_test autoinc-12.4 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + CREATE TABLE fake(name TEXT PRIMARY KEY,seq) WITHOUT ROWID; + } + set root1 [db one {SELECT rootpage FROM sqlite_master + WHERE name='sqlite_sequence'}] + set root2 [db one {SELECT rootpage FROM sqlite_master + WHERE name='fake'}] + sqlite3_db_config db DEFENSIVE 0 + db eval { + PRAGMA writable_schema=on; + UPDATE sqlite_master SET rootpage=$root2 + WHERE name='sqlite_sequence'; + UPDATE sqlite_master SET rootpage=$root1 + WHERE name='fake'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +breakpoint +do_test autoinc-12.5 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(x)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'); + }} msg] + lappend res $msg +} {1 {database disk image is malformed}} +do_test autoinc-12.6 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(x,y INTEGER PRIMARY KEY)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'),('three'),('four'); + INSERT INTO t1(b) VALUES('five'); + PRAGMA integrity_check; + }} msg] + lappend res $msg +} {0 ok} +do_test autoinc-12.7 { + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY AUTOINCREMENT, b TEXT); + INSERT INTO t1(b) VALUES('one'); + PRAGMA writable_schema=on; + UPDATE sqlite_master SET + sql='CREATE TABLE sqlite_sequence(y INTEGER PRIMARY KEY,x)' + WHERE name='sqlite_sequence'; + } + db close + sqlite3 db test.db + set res [catch {db eval { + INSERT INTO t1(b) VALUES('two'),('three'),('four'); + INSERT INTO t1(b) VALUES('five'); + PRAGMA integrity_check; + }} msg] + lappend res $msg +} {0 ok} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 13.0 { + CREATE TABLE t1(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, j); + + INSERT INTO t1 VALUES(NULL, 1); + INSERT INTO t2 VALUES(NULL, 2); + INSERT INTO t3 VALUES(NULL, 3); + + SELECT name FROM sqlite_sequence; +} {t1 t2 t3} + +do_execsql_test 13.1 { + UPDATE sqlite_sequence SET name=NULL WHERE name='t2'; + INSERT INTO t3 VALUES(NULL, 4); + DELETE FROM t3; + INSERT INTO t3 VALUES(NULL, 5); + SELECT * FROM t3; +} {3 5} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autoindex1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoindex1.test new file mode 100644 index 0000000000000000000000000000000000000000..b294a2721f5fa637304e9fdc368ad046ec849d3d --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autoindex1.test @@ -0,0 +1,566 @@ +# 2010 April 07 +# +# 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. The +# focus of this script is testing automatic index creation logic. +# +# EVIDENCE-OF: R-34271-33106 PRAGMA automatic_index; PRAGMA +# automatic_index = boolean; Query, set, or clear the automatic indexing +# capability. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If the library is not compiled with automatic index support then +# skip all tests in this file. +# +ifcapable {!autoindex} { + finish_test + return +} + +# Setup for logging +db close +sqlite3_shutdown +test_sqlite3_log [list lappend ::log] +set ::log [list] +sqlite3 db test.db + + +# With automatic index turned off, we do a full scan of the T2 table +do_test autoindex1-100 { + db eval { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,11); + INSERT INTO t1 VALUES(2,22); + INSERT INTO t1 SELECT a+2, b+22 FROM t1; + INSERT INTO t1 SELECT a+4, b+44 FROM t1; + CREATE TABLE t2(c,d); + INSERT INTO t2 SELECT a, 900+b FROM t1; + } + db eval { + PRAGMA automatic_index=OFF; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-101 { + db status step +} {63} +do_test autoindex1-102 { + db status autoindex +} {0} + +# With autoindex turned on, we build an index once and then use that index +# to find T2 values. +do_test autoindex1-110 { + db eval { + PRAGMA automatic_index=ON; + SELECT b, d FROM t1 JOIN t2 ON a=c ORDER BY b; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-111 { + db status step +} {7} +do_test autoindex1-112 { + db status autoindex +} {7} +do_test autoindex1-113 { + set ::log +} {SQLITE_WARNING_AUTOINDEX {automatic index on t2(c)}} + +db close +sqlite3_shutdown +test_sqlite3_log +sqlite3_initialize +sqlite3 db test.db + +# The same test as above, but this time the T2 query is a subquery rather +# than a join. +do_test autoindex1-200 { + db eval { + PRAGMA automatic_index=OFF; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-201 { + db status step +} {35} +do_test autoindex1-202 { + db status autoindex +} {0} +do_test autoindex1-210 { + db eval { + PRAGMA automatic_index=ON; + ANALYZE; + UPDATE sqlite_stat1 SET stat='10000' WHERE tbl='t1'; + -- Table t2 actually contains 8 rows. + UPDATE sqlite_stat1 SET stat='16' WHERE tbl='t2'; + ANALYZE sqlite_master; + SELECT b, (SELECT d FROM t2 WHERE c=a) FROM t1; + } +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-211 { + db status step +} {7} +do_test autoindex1-212 { + db status autoindex +} {7} + + +# Modify the second table of the join while the join is in progress +# +do_execsql_test autoindex1-299 { + UPDATE sqlite_stat1 SET stat='10000' WHERE tbl='t2'; + ANALYZE sqlite_master; + EXPLAIN QUERY PLAN + SELECT b, d FROM t1 CROSS JOIN t2 ON (c=a); +} {/AUTOMATIC COVERING INDEX/} +do_test autoindex1-300 { + set r {} + db eval {SELECT b, d FROM t1 CROSS JOIN t2 ON (c=a)} { + lappend r $b $d + db eval {UPDATE t2 SET d=d+1} + } + set r +} {11 911 22 922 33 933 44 944 55 955 66 966 77 977 88 988} +do_test autoindex1-310 { + db eval {SELECT d FROM t2 ORDER BY d} +} {919 930 941 952 963 974 985 996} + +# The next test does a 10-way join on unindexed tables. Without +# automatic indices, the join will take a long time to complete. +# With automatic indices, it should only take about a second. +# +do_test autoindex1-400 { + db eval { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES(1,2); + INSERT INTO t4 VALUES(2,3); + } + for {set n 2} {$n<4096} {set n [expr {$n+$n}]} { + db eval {INSERT INTO t4 SELECT a+$n, b+$n FROM t4} + } + db eval { + SELECT count(*) FROM t4; + } +} {4096} +do_test autoindex1-401 { + db eval { + SELECT count(*) + FROM t4 AS x1 + JOIN t4 AS x2 ON x2.a=x1.b + JOIN t4 AS x3 ON x3.a=x2.b + JOIN t4 AS x4 ON x4.a=x3.b + JOIN t4 AS x5 ON x5.a=x4.b + JOIN t4 AS x6 ON x6.a=x5.b + JOIN t4 AS x7 ON x7.a=x6.b + JOIN t4 AS x8 ON x8.a=x7.b + JOIN t4 AS x9 ON x9.a=x8.b + JOIN t4 AS x10 ON x10.a=x9.b; + } +} {4087} + +# Ticket [8011086c85c6c404014c947fcf3eb9f42b184a0d] from 2010-07-08 +# Make sure automatic indices are not created for the RHS of an IN expression +# that is not a correlated subquery. +# +do_execsql_test autoindex1-500 { + CREATE TABLE t501(a INTEGER PRIMARY KEY, b); + CREATE TABLE t502(x INTEGER PRIMARY KEY, y); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t501',null,'1000000'); + INSERT INTO sqlite_stat1(tbl,idx,stat) VALUES('t502',null,'1000'); + ANALYZE sqlite_master; +} +do_eqp_test autoindex1-500.1 { + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=?); +} { + QUERY PLAN + |--SEARCH t501 USING INTEGER PRIMARY KEY (rowid=?) + `--LIST SUBQUERY xxxxxx + |--SCAN t502 + `--CREATE BLOOM FILTER +} +do_eqp_test autoindex1-501 { + SELECT b FROM t501 + WHERE t501.a IN (SELECT x FROM t502 WHERE y=t501.b); +} { + QUERY PLAN + |--SCAN t501 + `--CORRELATED LIST SUBQUERY xxxxxx + |--BLOOM FILTER ON t502 (y=?) + `--SEARCH t502 USING AUTOMATIC COVERING INDEX (y=?) +} +do_eqp_test autoindex1-502 { + SELECT b FROM t501 + WHERE t501.a=123 + AND t501.a IN (SELECT x FROM t502 WHERE y=t501.b); +} { + QUERY PLAN + |--SEARCH t501 USING INTEGER PRIMARY KEY (rowid=?) + `--CORRELATED LIST SUBQUERY xxxxxx + `--SCAN t502 +} + +# The following code checks a performance regression reported on the +# mailing list on 2010-10-19. The problem is that the nRowEst field +# of ephermeral tables was not being initialized correctly and so no +# automatic index was being created for the emphemeral table when it was +# used as part of a join. +# +do_execsql_test autoindex1-600 { + CREATE TABLE flock_owner( + owner_rec_id INTEGER CONSTRAINT flock_owner_key PRIMARY KEY, + flock_no VARCHAR(6) NOT NULL REFERENCES flock (flock_no), + owner_person_id INTEGER NOT NULL REFERENCES person (person_id), + owner_change_date TEXT, last_changed TEXT NOT NULL, + CONSTRAINT fo_owner_date UNIQUE (flock_no, owner_change_date) + ); + CREATE TABLE sheep ( + Sheep_No char(7) NOT NULL, + Date_of_Birth char(8), + Sort_DoB text, + Flock_Book_Vol char(2), + Breeder_No char(6), + Breeder_Person integer, + Originating_Flock char(6), + Registering_Flock char(6), + Tag_Prefix char(9), + Tag_No char(15), + Sort_Tag_No integer, + Breeders_Temp_Tag char(15), + Sex char(1), + Sheep_Name char(32), + Sire_No char(7), + Dam_No char(7), + Register_Code char(1), + Colour char(48), + Colour_Code char(2), + Pattern_Code char(8), + Horns char(1), + Litter_Size char(1), + Coeff_of_Inbreeding real, + Date_of_Registration text, + Date_Last_Changed text, + UNIQUE(Sheep_No)); + CREATE INDEX fo_flock_no_index + ON flock_owner (flock_no); + CREATE INDEX fo_owner_change_date_index + ON flock_owner (owner_change_date); + CREATE INDEX fo_owner_person_id_index + ON flock_owner (owner_person_id); + CREATE INDEX sheep_org_flock_index + ON sheep (originating_flock); + CREATE INDEX sheep_reg_flock_index + ON sheep (registering_flock); +} +do_eqp_test autoindex1-600a { + SELECT x.sheep_no, x.registering_flock, x.date_of_registration + FROM sheep x LEFT JOIN + (SELECT s.sheep_no, prev.flock_no, prev.owner_person_id, + s.date_of_registration, prev.owner_change_date + FROM sheep s JOIN flock_owner prev ON s.registering_flock = + prev.flock_no + AND (prev.owner_change_date <= s.date_of_registration || ' 00:00:00') + WHERE NOT EXISTS + (SELECT 'x' FROM flock_owner later + WHERE prev.flock_no = later.flock_no + AND later.owner_change_date > prev.owner_change_date + AND later.owner_change_date <= s.date_of_registration||' 00:00:00') + ) y ON x.sheep_no = y.sheep_no + WHERE y.sheep_no IS NULL + ORDER BY x.registering_flock; +} { + QUERY PLAN + |--MATERIALIZE y + | |--SCAN s + | |--SEARCH prev USING INDEX sqlite_autoindex_flock_owner_1 (flock_no=? AND owner_change_date? AND owner_change_date 1393520400 + AND param3<>9001 + AND t3.flg7 = 1 + AND t1.did = t2.did + AND t2.uid = t3.uid + ORDER BY t1.ptime desc LIMIT 500; +} {~/AUTO/} +# +# ^^^--- Before being fixed, the above was using an automatic covering +# on t3 and reordering the tables so that t3 was in the outer loop and +# implementing the ORDER BY clause using a B-Tree. +# +# This test is sanitized data received from a user. The original unsanitized +# data and STAT4 data is found in the th3private test repository. See one of +# the th3private check-ins on 2016-02-25. The test is much more accurate when +# STAT4 data is used. + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum.test new file mode 100644 index 0000000000000000000000000000000000000000..245ea8b51d4b3b257d1de89eb8f5af55333c94d7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum.test @@ -0,0 +1,715 @@ +# 2001 September 15 +# +# 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. The +# focus of this file is testing the autovacuum feature. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum || !pragma} { + finish_test + return +} + +# Return a string $len characters long. The returned string is $char repeated +# over and over. For example, [make_str abc 8] returns "abcabcab". +proc make_str {char len} { + set str [string repeat $char. $len] + return [string range $str 0 [expr $len-1]] +} + +# Return the number of pages in the file test.db by looking at the file system. +proc file_pages {} { + return [expr [file size test.db] / 1024] +} + +#------------------------------------------------------------------------- +# Test cases autovacuum-1.* work as follows: +# +# 1. A table with a single indexed field is created. +# 2. Approximately 20 rows are inserted into the table. Each row is long +# enough such that it uses at least 2 overflow pages for both the table +# and index entry. +# 3. The rows are deleted in a psuedo-random order. Sometimes only one row +# is deleted per transaction, sometimes more than one. +# 4. After each transaction the table data is checked to ensure it is correct +# and a "PRAGMA integrity_check" is executed. +# 5. Once all the rows are deleted the file is checked to make sure it +# consists of exactly 4 pages. +# +# Steps 2-5 are repeated for a few different psuedo-random delete patterns +# (defined by the $delete_orders list). +set delete_orders [list] +lappend delete_orders {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +lappend delete_orders {20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +lappend delete_orders {8 18 2 4 14 11 13 3 10 7 9 5 12 17 19 15 20 6 16 1} +lappend delete_orders {10 3 11 17 19 20 7 4 13 6 1 14 16 12 9 18 8 15 5 2} +lappend delete_orders {{1 2 3 4 5 6 7 8 9 10} {11 12 13 14 15 16 17 18 19 20}} +lappend delete_orders {{19 8 17 15} {16 11 9 14} {18 5 3 1} {13 20 7 2} {6 12}} + +# The length of each table entry. +# set ENTRY_LEN 3500 +set ENTRY_LEN 3500 + +do_test autovacuum-1.1 { + execsql { + PRAGMA auto_vacuum = 1; + CREATE TABLE av1(a); + CREATE INDEX av1_idx ON av1(a); + } +} {} + +set tn 0 +foreach delete_order $delete_orders { + incr tn + + # Set up the table. + set ::tbl_data [list] + foreach i [lsort -integer [eval concat $delete_order]] { + execsql "INSERT INTO av1 (oid, a) VALUES($i, '[make_str $i $ENTRY_LEN]')" + lappend ::tbl_data [make_str $i $ENTRY_LEN] + } + + # Make sure the integrity check passes with the initial data. + ifcapable {integrityck} { + do_test autovacuum-1.$tn.1 { + execsql { + pragma integrity_check + } + } {ok} + } + + foreach delete $delete_order { + # Delete one set of rows from the table. + do_test autovacuum-1.$tn.($delete).1 { + execsql " + DELETE FROM av1 WHERE oid = [join $delete " OR oid = "] + " + } {} + + # Do the integrity check. + ifcapable {integrityck} { + do_test autovacuum-1.$tn.($delete).2 { + execsql { + pragma integrity_check + } + } {ok} + } + # Ensure the data remaining in the table is what was expected. + foreach d $delete { + set idx [lsearch $::tbl_data [make_str $d $ENTRY_LEN]] + set ::tbl_data [lreplace $::tbl_data $idx $idx] + } + do_test autovacuum-1.$tn.($delete).3 { + execsql { + select a from av1 order by rowid + } + } $::tbl_data + } + + # All rows have been deleted. Ensure the file has shrunk to 4 pages. + do_test autovacuum-1.$tn.3 { + file_pages + } {4} +} + +#--------------------------------------------------------------------------- +# Tests cases autovacuum-2.* test that root pages are allocated +# and deallocated correctly at the start of the file. Operation is roughly as +# follows: +# +# autovacuum-2.1.*: Drop the tables that currently exist in the database. +# autovacuum-2.2.*: Create some tables. Ensure that data pages can be +# moved correctly to make space for new root-pages. +# autovacuum-2.3.*: Drop one of the tables just created (not the last one), +# and check that one of the other tables is moved to +# the free root-page location. +# autovacuum-2.4.*: Check that a table can be created correctly when the +# root-page it requires is on the free-list. +# autovacuum-2.5.*: Check that a table with indices can be dropped. This +# is slightly tricky because dropping one of the +# indices/table btrees could move the root-page of another. +# The code-generation layer of SQLite overcomes this problem +# by dropping the btrees in descending order of root-pages. +# This test ensures that this actually happens. +# +do_test autovacuum-2.1.1 { + execsql { + DROP TABLE av1; + } +} {} +do_test autovacuum-2.1.2 { + file_pages +} {1} + +# Create a table and put some data in it. +do_test autovacuum-2.2.1 { + execsql { + CREATE TABLE av1(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3} +do_test autovacuum-2.2.2 { + execsql " + INSERT INTO av1 VALUES('[make_str abc 3000]'); + INSERT INTO av1 VALUES('[make_str def 3000]'); + INSERT INTO av1 VALUES('[make_str ghi 3000]'); + INSERT INTO av1 VALUES('[make_str jkl 3000]'); + " + set ::av1_data [db eval {select * from av1}] + file_pages +} {15} + +# Create another table. Check it is located immediately after the first. +# This test case moves the second page in an over-flow chain. +do_test autovacuum-2.2.3 { + execsql { + CREATE TABLE av2(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4} +do_test autovacuum-2.2.4 { + file_pages +} {16} + +# Create another table. Check it is located immediately after the second. +# This test case moves the first page in an over-flow chain. +do_test autovacuum-2.2.5 { + execsql { + CREATE TABLE av3(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5} +do_test autovacuum-2.2.6 { + file_pages +} {17} + +# Create another table. Check it is located immediately after the second. +# This test case moves a btree leaf page. +do_test autovacuum-2.2.7 { + execsql { + CREATE TABLE av4(x); + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5 6} +do_test autovacuum-2.2.8 { + file_pages +} {18} +do_test autovacuum-2.2.9 { + execsql { + select * from av1 + } +} $av1_data + +do_test autovacuum-2.3.1 { + execsql { + INSERT INTO av2 SELECT 'av1' || x FROM av1; + INSERT INTO av3 SELECT 'av2' || x FROM av1; + INSERT INTO av4 SELECT 'av3' || x FROM av1; + } + set ::av2_data [execsql {select x from av2}] + set ::av3_data [execsql {select x from av3}] + set ::av4_data [execsql {select x from av4}] + file_pages +} {54} +do_test autovacuum-2.3.2 { + execsql { + DROP TABLE av2; + SELECT rootpage FROM sqlite_master ORDER BY rootpage; + } +} {3 4 5} +do_test autovacuum-2.3.3 { + file_pages +} {41} +do_test autovacuum-2.3.4 { + execsql { + SELECT x FROM av3; + } +} $::av3_data +do_test autovacuum-2.3.5 { + execsql { + SELECT x FROM av4; + } +} $::av4_data + +# Drop all the tables in the file. This puts all pages except the first 2 +# (the sqlite_master root-page and the first pointer map page) on the +# free-list. +do_test autovacuum-2.4.1 { + execsql { + DROP TABLE av1; + DROP TABLE av3; + BEGIN; + DROP TABLE av4; + } + file_pages +} {15} +do_test autovacuum-2.4.2 { + for {set i 3} {$i<=10} {incr i} { + execsql "CREATE TABLE av$i (x)" + } + file_pages +} {15} +do_test autovacuum-2.4.3 { + execsql { + SELECT rootpage FROM sqlite_master ORDER by rootpage + } +} {3 4 5 6 7 8 9 10} + +# Right now there are 5 free pages in the database. Consume and then free +# all 520 pages. Then create 520 tables. This ensures that at least some of the +# desired root-pages reside on the second free-list trunk page, and that the +# trunk itself is required at some point. +do_test autovacuum-2.4.4 { + execsql " + INSERT INTO av3 VALUES ('[make_str abcde [expr 1020*520 + 500]]'); + DELETE FROM av3; + " +} {} +set root_page_list [list] +set pending_byte_page [expr ($::sqlite_pending_byte / 1024) + 1] + +# unusable_pages +# These are either the pending_byte page or the pointer map pages +# +unset -nocomplain unusable_page +if {[sqlite3 -has-codec]} { + array set unusable_page {205 1 408 1} +} else { + array set unusable_page {207 1 412 1} +} +set unusable_page($pending_byte_page) 1 + +for {set i 3} {$i<=532} {incr i} { + if {![info exists unusable_page($i)]} { + lappend root_page_list $i + } +} +if {$i >= $pending_byte_page} { + lappend root_page_list $i +} +do_test autovacuum-2.4.5 { + for {set i 11} {$i<=530} {incr i} { + execsql "CREATE TABLE av$i (x)" + } + execsql { + SELECT rootpage FROM sqlite_master ORDER by rootpage + } +} $root_page_list + +# Just for fun, delete all those tables and see if the database is 1 page. +do_test autovacuum-2.4.6 { + execsql COMMIT; + file_pages +} [expr 561 + (($i >= $pending_byte_page)?1:0)] +integrity_check autovacuum-2.4.6 +do_test autovacuum-2.4.7 { + execsql BEGIN + for {set i 3} {$i<=530} {incr i} { + execsql "DROP TABLE av$i" + } + execsql COMMIT + file_pages +} 1 + +# Create some tables with indices to drop. +do_test autovacuum-2.5.1 { + execsql { + CREATE TABLE av1(a PRIMARY KEY, b, c); + INSERT INTO av1 VALUES('av1 a', 'av1 b', 'av1 c'); + + CREATE TABLE av2(a PRIMARY KEY, b, c); + CREATE INDEX av2_i1 ON av2(b); + CREATE INDEX av2_i2 ON av2(c); + INSERT INTO av2 VALUES('av2 a', 'av2 b', 'av2 c'); + + CREATE TABLE av3(a PRIMARY KEY, b, c); + CREATE INDEX av3_i1 ON av3(b); + INSERT INTO av3 VALUES('av3 a', 'av3 b', 'av3 c'); + + CREATE TABLE av4(a, b, c); + CREATE INDEX av4_i1 ON av4(a); + CREATE INDEX av4_i2 ON av4(b); + CREATE INDEX av4_i3 ON av4(c); + CREATE INDEX av4_i4 ON av4(a, b, c); + INSERT INTO av4 VALUES('av4 a', 'av4 b', 'av4 c'); + } +} {} + +do_test autovacuum-2.5.2 { + execsql { + SELECT name, rootpage FROM sqlite_master; + } +} [list av1 3 sqlite_autoindex_av1_1 4 \ + av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av3 9 sqlite_autoindex_av3_1 10 av3_i1 11 \ + av4 12 av4_i1 13 av4_i2 14 av4_i3 15 av4_i4 16 \ +] + +# The following 4 tests are SELECT queries that use the indices created. +# If the root-pages in the internal schema are not updated correctly when +# a table or indice is moved, these queries will fail. They are repeated +# after each table is dropped (i.e. as test cases 2.5.*.[1..4]). +do_test autovacuum-2.5.2.1 { + execsql { + SELECT * FROM av1 WHERE a = 'av1 a'; + } +} {{av1 a} {av1 b} {av1 c}} +do_test autovacuum-2.5.2.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.2.3 { + execsql { + SELECT * FROM av3 WHERE a = 'av3 a' AND b = 'av3 b'; + } +} {{av3 a} {av3 b} {av3 c}} +do_test autovacuum-2.5.2.4 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av3. Indices av4_i2, av4_i3 and av4_i4 are moved to fill the two +# root pages vacated. The operation proceeds as: +# Step 1: Delete av3_i1 (root-page 11). Move root-page of av4_i4 to page 11. +# Step 2: Delete av3 (root-page 10). Move root-page of av4_i3 to page 10. +# Step 3: Delete sqlite_autoindex_av1_3 (root-page 9). Move av4_i2 to page 9. +do_test autovacuum-2.5.3 { + execsql { + DROP TABLE av3; + SELECT name, rootpage FROM sqlite_master; + } +} [list av1 3 sqlite_autoindex_av1_1 4 \ + av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av4 12 av4_i1 13 av4_i2 9 av4_i3 10 av4_i4 11 \ +] +do_test autovacuum-2.5.3.1 { + execsql { + SELECT * FROM av1 WHERE a = 'av1 a'; + } +} {{av1 a} {av1 b} {av1 c}} +do_test autovacuum-2.5.3.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.3.3 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av1: +# Step 1: Delete av1 (root page 4). Root-page of av4_i1 fills the gap. +# Step 2: Delete sqlite_autoindex_av1_1 (root page 3). Move av4 to the gap. +do_test autovacuum-2.5.4 { + execsql { + DROP TABLE av1; + SELECT name, rootpage FROM sqlite_master; + } +} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 7 av2_i2 8 \ + av4 3 av4_i1 4 av4_i2 9 av4_i3 10 av4_i4 11 \ +] +do_test autovacuum-2.5.4.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} +do_test autovacuum-2.5.4.4 { + execsql { + SELECT * FROM av4 WHERE a = 'av4 a' AND b = 'av4 b' AND c = 'av4 c'; + } +} {{av4 a} {av4 b} {av4 c}} + +# Drop table av4: +# Step 1: Delete av4_i4. +# Step 2: Delete av4_i3. +# Step 3: Delete av4_i2. +# Step 4: Delete av4_i1. av2_i2 replaces it. +# Step 5: Delete av4. av2_i1 replaces it. +do_test autovacuum-2.5.5 { + execsql { + DROP TABLE av4; + SELECT name, rootpage FROM sqlite_master; + } +} [list av2 5 sqlite_autoindex_av2_1 6 av2_i1 3 av2_i2 4] +do_test autovacuum-2.5.5.2 { + execsql { + SELECT * FROM av2 WHERE a = 'av2 a' AND b = 'av2 b' AND c = 'av2 c' + } +} {{av2 a} {av2 b} {av2 c}} + +#-------------------------------------------------------------------------- +# Test cases autovacuum-3.* test the operation of the "PRAGMA auto_vacuum" +# command. +# +do_test autovacuum-3.1 { + execsql { + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-3.2 { + db close + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-3.3 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA auto_vacuum; + } +} {1} + +do_test autovacuum-3.4 { + db close + forcedelete test.db + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum; + } +} $AUTOVACUUM +do_test autovacuum-3.5 { + execsql { + CREATE TABLE av1(x); + PRAGMA auto_vacuum; + } +} $AUTOVACUUM +do_test autovacuum-3.6 { + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA auto_vacuum; + } +} [expr $AUTOVACUUM ? 1 : 0] +do_test autovacuum-3.7 { + execsql { + DROP TABLE av1; + } + file_pages +} [expr $AUTOVACUUM?1:2] + + +#----------------------------------------------------------------------- +# Test that if a statement transaction around a CREATE INDEX statement is +# rolled back no corruption occurs. +# +do_test autovacuum-4.0 { + # The last round of tests may have left the db in non-autovacuum mode. + # Reset everything just in case. + # + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA auto_vacuum; + } +} {1} +do_test autovacuum-4.1 { + execsql { + CREATE TABLE av1(a, b); + BEGIN; + } + for {set i 0} {$i<100} {incr i} { + execsql "INSERT INTO av1 VALUES($i, '[string repeat X 200]');" + } + execsql "INSERT INTO av1 VALUES(99, '[string repeat X 200]');" + execsql { + SELECT sum(a) FROM av1; + } +} {5049} +do_test autovacuum-4.2 { + catchsql { + CREATE UNIQUE INDEX av1_i ON av1(a); + } +} {1 {UNIQUE constraint failed: av1.a}} +do_test autovacuum-4.3 { + execsql { + SELECT sum(a) FROM av1; + } +} {5049} +do_test autovacuum-4.4 { + execsql { + COMMIT; + } +} {} + +ifcapable integrityck { + +# Ticket #1727 +do_test autovacuum-5.1 { + db close + sqlite3 db :memory: + db eval { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a); + CREATE TABLE t2(a); + DROP TABLE t1; + PRAGMA integrity_check; + } +} ok + +} + +# Ticket #1728. +# +# In autovacuum mode, when tables or indices are deleted, the rootpage +# values in the symbol table have to be updated. There was a bug in this +# logic so that if an index/table was moved twice, the second move might +# not occur. This would leave the internal symbol table in an inconsistent +# state causing subsequent statements to fail. +# +# The problem is difficult to reproduce. The sequence of statements in +# the following test are carefully designed make it occur and thus to +# verify that this very obscure bug has been resolved. +# +ifcapable integrityck&&memorydb { + +do_test autovacuum-6.1 { + db close + sqlite3 db :memory: + db eval { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + CREATE TABLE t2(a); + CREATE INDEX i2 ON t2(a); + CREATE TABLE t3(a); + CREATE INDEX i3 ON t2(a); + CREATE INDEX x ON t1(b); + DROP TABLE t3; + PRAGMA integrity_check; + DROP TABLE t2; + PRAGMA integrity_check; + DROP TABLE t1; + PRAGMA integrity_check; + } +} {ok ok ok} + +} + +#--------------------------------------------------------------------- +# Test cases autovacuum-7.X test the case where a page must be moved +# and the destination location collides with at least one other +# entry in the page hash-table (internal to the pager.c module. +# +do_test autovacuum-7.1 { + db close + forcedelete test.db + forcedelete test.db-journal + sqlite3 db test.db + + execsql { + PRAGMA auto_vacuum=1; + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); + INSERT INTO t1 VALUES(randstr(400,400),randstr(400,400)); + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 4 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 8 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 16 + INSERT INTO t1 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 32 + } + + expr {[file size test.db] / 1024} +} {73} + +do_test autovacuum-7.2 { + execsql { + CREATE TABLE t2(a, b, PRIMARY KEY(a, b)); + INSERT INTO t2 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t3(a, b, PRIMARY KEY(a, b)); + INSERT INTO t3 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t4(a, b, PRIMARY KEY(a, b)); + INSERT INTO t4 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + CREATE TABLE t5(a, b, PRIMARY KEY(a, b)); + INSERT INTO t5 SELECT randstr(400,400), randstr(400,400) FROM t1; -- 2 + } + expr {[file size test.db] / 1024} +} {354} + +do_test autovacuum-7.3 { + db close + sqlite3 db test.db + execsql { + BEGIN; + DELETE FROM t4; + COMMIT; + SELECT count(*) FROM t1; + } + expr {[file size test.db] / 1024} +} {286} + +#------------------------------------------------------------------------ +# Additional tests. +# +# Try to determine the autovacuum setting for a database that is locked. +# +do_test autovacuum-8.1 { + db close + sqlite3 db test.db + sqlite3 db2 test.db + db eval {PRAGMA auto_vacuum} +} {1} +if {[permutation] == ""} { + do_test autovacuum-8.2 { + db eval {BEGIN EXCLUSIVE} + catchsql {PRAGMA auto_vacuum} db2 + } {1 {database is locked}} + catch {db2 close} + catch {db eval {COMMIT}} +} + +do_test autovacuum-9.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + DROP TABLE t4; + DROP TABLE t5; + PRAGMA page_count; + } +} {1} +do_test autovacuum-9.2 { + file size test.db +} 1024 +do_test autovacuum-9.3 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(NULL, randstr(50,50)); + } + for {set ii 0} {$ii < 10} {incr ii} { + db eval { INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 } + } + file size test.db +} $::sqlite_pending_byte +do_test autovacuum-9.4 { + execsql { INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 } +} {} +do_test autovacuum-9.5 { + execsql { DELETE FROM t1 WHERE rowid > (SELECT max(a)/2 FROM t1) } + file size test.db +} $::sqlite_pending_byte + +do_execsql_test autovacuum-10.1 { + DROP TABLE t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(25, randomblob(104)); + REPLACE INTO t1 VALUES(25, randomblob(1117)); + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum2.test new file mode 100644 index 0000000000000000000000000000000000000000..a3c409839e3bb3f76800dd37bf0f187bea1acf36 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum2.test @@ -0,0 +1,87 @@ +# 2021-10-15 +# +# 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. The +# focus of this file is testing the sqlite3_autovacuum_pages() interface +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum || !pragma} { + finish_test + return +} + +# Demonstrate basic sqlite3_autovacuum_pages functionality +# +do_execsql_test autovacuum2-1.0 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=FULL; + CREATE TABLE t1(x); + VACUUM; + INSERT INTO t1(x) VALUES(zeroblob(10000)); + PRAGMA page_count; +} {12} +proc autovac_page_callback {schema filesize freesize pagesize} { + global autovac_callback_data + lappend autovac_callback_data $schema $filesize $freesize $pagesize + return [expr {$freesize/2}] +} +sqlite3_autovacuum_pages db autovac_page_callback +set autovac_callback_data {} +do_execsql_test autovacuum2-1.1 { + BEGIN; + DELETE FROM t1; + PRAGMA freelist_count; + PRAGMA page_count; +} {9 12} +do_execsql_test autovacuum2-1.2 { + COMMIT; +} {} +do_test autovacuum2-1.3 { + set autovac_callback_data +} {main 12 9 1024} +do_execsql_test autovacuum2-1.4 { + PRAGMA freelist_count; + PRAGMA page_count; +} {5 8} +do_execsql_test autovacuum2-1.5 { + PRAGMA integrity_check; +} {ok} + +# Disable the autovacuum-pages callback. Then do any transaction. +# The database should shrink to minimal size +# +sqlite3_autovacuum_pages db +do_execsql_test autovacuum2-1.10 { + CREATE TABLE t2(x); + PRAGMA freelist_count; +} {0} + +# Rig the autovacuum-pages callback to always return zero. No +# autovacuum will happen. +# +proc autovac_page_callback_off {schema filesize freesize pagesize} { + return 0 +} +sqlite3_autovacuum_pages db autovac_page_callback_off +do_execsql_test autovacuum2-1.20 { + BEGIN; + INSERT INTO t1(x) VALUES(zeroblob(10000)); + DELETE FROM t1; + PRAGMA freelist_count; + COMMIT; + PRAGMA freelist_count; +} {9 9} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum_ioerr2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum_ioerr2.test new file mode 100644 index 0000000000000000000000000000000000000000..891d00eb06bce225482c4f49a8d573edffa27bcf --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/autovacuum_ioerr2.test @@ -0,0 +1,132 @@ +# 2001 October 12 +# +# 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. The +# focus of this file is testing for correct handling of I/O errors +# such as writes failing because the disk is full. +# +# The tests in this file use special facilities that are only +# available in the SQLite test fixture. +# +# $Id: autovacuum_ioerr2.test,v 1.7 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build of the library does not support auto-vacuum, omit this +# whole file. +ifcapable {!autovacuum} { + finish_test + return +} + +do_ioerr_test autovacuum-ioerr2-1 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1500,1500)); +} -sqlbody { + CREATE TABLE abc2(a); + BEGIN; + DELETE FROM abc; + INSERT INTO abc VALUES(randstr(1500,1500)); + CREATE TABLE abc3(a); + COMMIT; +} + +do_ioerr_test autovacuum-ioerr2-2 -tclprep { + execsql { + PRAGMA auto_vacuum = 1; + PRAGMA cache_size = 10; + BEGIN; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow + } + for {set i 0} {$i<150} {incr i} { + execsql { + INSERT INTO abc VALUES(randstr(100,100)); + } + } + execsql COMMIT +} -sqlbody { + BEGIN; + DELETE FROM abc WHERE length(a)>100; + UPDATE abc SET a = randstr(90,90); + CREATE TABLE abc3(a); + COMMIT; +} + +do_ioerr_test autovacuum-ioerr2-3 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + CREATE TABLE abc2(b); +} -sqlbody { + BEGIN; + INSERT INTO abc2 VALUES(10); + DROP TABLE abc; + COMMIT; + DROP TABLE abc2; +} + +forcedelete backup.db +ifcapable subquery { + do_ioerr_test autovacuum-ioerr2-4 -tclprep { + if {![file exists backup.db]} { + sqlite3 dbb backup.db + execsql { + PRAGMA auto_vacuum = 1; + BEGIN; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 4 is overflow + INSERT INTO abc VALUES(randstr(1100,1100)); -- Page 5 is overflow + } dbb + for {set i 0} {$i<2500} {incr i} { + execsql { + INSERT INTO abc VALUES(randstr(100,100)); + } dbb + } + execsql { + COMMIT; + PRAGMA cache_size = 10; + } dbb + dbb close + } + db close + forcedelete test.db + forcedelete test.db-journal + forcecopy backup.db test.db + set ::DB [sqlite3 db test.db] + execsql { + PRAGMA cache_size = 10; + } + } -sqlbody { + BEGIN; + DELETE FROM abc WHERE oid < 3; + UPDATE abc SET a = randstr(100,100) WHERE oid > 2300; + UPDATE abc SET a = randstr(1100,1100) WHERE oid = + (select max(oid) from abc); + COMMIT; + } +} + +do_ioerr_test autovacuum-ioerr2-1 -sqlprep { + PRAGMA auto_vacuum = 1; + CREATE TABLE abc(a); + INSERT INTO abc VALUES(randstr(1500,1500)); +} -sqlbody { + CREATE TABLE abc2(a); + BEGIN; + DELETE FROM abc; + INSERT INTO abc VALUES(randstr(1500,1500)); + CREATE TABLE abc3(a); + COMMIT; +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/avfs.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/avfs.test new file mode 100644 index 0000000000000000000000000000000000000000..ffd6b309fc80254ef7bcbb57e76e016e17fc757c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/avfs.test @@ -0,0 +1,396 @@ +# 2021-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. +# +#*********************************************************************** +# TESTRUNNER: shell +# +# This file implements tests for the appendvfs extension. +# +# Tests performed: +# avfs-1.0. Test that an appendvfs DB can be added to an empty (ZLF) file. +# avfs-1.1. Test that the DB can be read with correct content upon reopen. +# avfs-1.2. Test that an appendvfs DB can be added to a simple text file. +# avfs-1.3. Test that the DB can be read with correct content upon reopen. +# avfs-1.4. Test that appended DB is aligned to default page boundary. +# avfs-2.1. Test that the simple text file retains its initial text. +# avfs-3.1. Test that the appendvfs can grow and shrink, remaining intact. +# avfs-3.2. Test that appendvfs is intact after grow/shrink/close/reopen. +# avfs-3.3. Test that appendvfs can grow by many pages and be written. +# avfs-3.4. Test that grown appendvfs can be reopened and appear intact. +# avfs-3.5. Test that much grown appendvfs can shrink and reopen intact. +# avfs-4.1. Test shell's ability to append to a non-appendvfs file. +# avfs-4.2. Test shell's ability to append to empty or nonexistent file. +# avfs-4.3. Test shell's ability to reopen and alter an appendvfs file. +# avfs-5.1. Test appendvfs refusal to open too-tiny DB appended onto ZLF. +# avfs-5.2. Test appendvfs refusal to open too-tiny DB appended on other. +# ... +# (more to come) + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix avfs + +# Do not attempt this test if SQLITE_OMIT_VIRTUALTABLE is defined. +# +ifcapable !vtab { + finish_test + return +} + +set CLI [test_find_cli] +db close +# forcedelete test.db + +load_static_extension db appendvfs + +set ::fa avfs.adb +set ::fza avfs.sdb +forcedelete $::fa $::fza +set ::result {} + +proc shellDoesAr {} { + set shdo "sh_app1.sql" + forcedelete $shdo + set fd [open $shdo w] + puts $fd ".help\n.q" + close $fd + set res [catchcmd "-batch -cmd \".read $shdo\""] + return [regexp {^.archive} [lindex $res 1]] +} + +set ::vf "&vfs=apndvfs" + +# Return file offset of appendvfs portion of a file, or {} if none such. +proc fosAvfs {fname} { + if {[file size $fname] < 25} { + return {} + } + if {[catch {set fd [open $fname rb]}]} { + return {} + } + seek $fd -25 end + set am [read $fd 17] + set ao [read $fd 8] + close $fd + if {$am ne "Start-Of-SQLite3-"} { + return {} + } + binary scan $ao "W" rvo + return $rvo +} + +do_test 1.0 { + set results {} + set out [open $::fza wb] + close $out + sqlite3 adb "file:$::fza?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA page_size=1024; + PRAGMA cache_size=10; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + lappend results [fosAvfs $fza] + set ::result [join $results " | "] +} {cat,dog | 0} + +do_test 1.1 { + set results {} + sqlite3 adb "file:$::fza?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + set ::result [join $results " | "] +} {dog,cat} + +do_test 1.2 { + set results {} + set out [open $::fa wb] + set ::tlo { "Just some text," "and more text," "ending at 3 lines." } + puts $out [join $::tlo "\n"] + close $out + set adbSz [file size $::fa] + sqlite3 adb "file:$::fa?mode=rwc$::vf" -uri 1 + adb eval { + PRAGMA auto_vacuum = 0; + PRAGMA page_size=512; + PRAGMA cache_size=0; + CREATE TABLE t1(a TEXT); + INSERT INTO t1 VALUES ('dog'),('cat'),('pig'); + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a); + } { lappend results $pets } + adb close + set adaSz [file size $::fa] + lappend results "Bytes before/after $adbSz/$adaSz" + set ::result [join $results " | "] +} {cat,dog,pig | Bytes before/after 50/5145} + +do_test 1.3 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT group_concat(a) as pets FROM (SELECT a FROM t1 ORDER BY a DESC); + } { lappend results $pets } + adb close + set ::result [join $results " | "] +} {pig,dog,cat} + +do_test 1.4 { + set ::result [fosAvfs $fa] +} {4096} + +do_test 2.1 { + set in [open $::fa r] + set tli {} + for {set i [llength $::tlo]} {$i > 0} {incr i -1} { + lappend tli [gets $in] + } + close $in + if { [join $tli ":"] ne [join $::tlo ":"] } { + set ::result "Appendee changed." + } else { + set ::result "Appendee intact." + } +} {Appendee intact.} + +# Set of repeatable random integers for a couple tests. +set ::nrint 50000 +proc rint {v} { + return [::tcl::mathfunc::int [expr $v * 100000]] +} +array set ::randints [list 0 [rint [::tcl::mathfunc::srand 0]]] +for {set i 1} {$i < $::nrint} {incr i} { + set ::randints($i) [rint [::tcl::mathfunc::rand]] +} + +do_test 3.1 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + DROP TABLE t1; + PRAGMA cache_size=10; + CREATE TABLE ri (i INTEGER); + BEGIN; + } + for {set i 0} {$i < $::nrint} {incr i} { + set r $::randints($i) + set s $::randints([incr i]) + set t $::randints([incr i]) + set u $::randints([incr i]) + set v $::randints([incr i]) + adb eval { + INSERT INTO ri VALUES ($r),($s),($t),($u),($v) + } + } + adb eval { + COMMIT; + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + set adbSz [file size $::fa] + set qr {} + adb eval { + SELECT count(*) as ic FROM ri; + DELETE FROM ri WHERE (i % 50) <> 25; + SELECT integrity_check as ic FROM pragma_integrity_check(); + VACUUM; + SELECT integrity_check as ic FROM pragma_integrity_check(); + SELECT count(*) as ic FROM ri; + } { lappend qr $ic } + adb close + set adaSz [file size $::fa] + set adba [expr ($adbSz + 0.1)/$adaSz] + # lappend results $adba + set results [concat $results [lrange $qr 0 2]] + lappend results [expr {$adba > 10.0}] + set ::result [join $results " | "] +} "ok | $::nrint | ok | ok | 1" + +do_test 3.2 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result [join $results " | "] +} {ok} + +# avfs-3.3. Test that appendvfs can grow by many pages and be written. +do_test 3.3 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + set npages 300 + adb eval { BEGIN } + while {$npages > 0} { + adb eval { INSERT INTO ri VALUES (randomblob(1500)) } + incr npages -1 + } + adb eval { COMMIT } + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set adaSzr [expr [file size $::fa] / 300.0 / 1500 ] + set okSzr [expr $adaSzr > 1.0 && $adaSzr < 1.3 ] + lappend results $okSzr + set ::result [join $results " | "] +} {ok | 1} + +# avfs-3.4. Test that grown appendvfs can be reopened and appear intact. +do_test 3.4 { + set results {} + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result $ic +} {ok} + +# avfs-3.5. Test that much grown appendvfs can shrink and reopen intact. +do_test 3.5 { + set results {} + set adbsz [file size $::fa] + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + DELETE FROM ri WHERE rowid % 8 <> 0; + SELECT integrity_check as ic FROM pragma_integrity_check(); + VACUUM; + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set adasz [file size $::fa] + lappend results [expr {$adbsz/$adasz > 5}] + sqlite3 adb "file:$::fa?mode=rw$::vf" -uri 1 + adb eval { + SELECT integrity_check as ic FROM pragma_integrity_check(); + } { lappend results $ic } + adb close + set ::result [join $results " | "] +} {ok | ok | 1 | ok} + +set ::cliDoesAr [shellDoesAr] + +do_test 4.1 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -c" + } else { + puts $ofd "pragma page_size=512;" + puts $ofd "create table sqlar (a);" + } + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + puts $ofd "Some text." + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo $shod + set ::result [join $res " | "] +} {0 | sqlar | 4096} + +do_test 4.2 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" + forcedelete $shdo $shod + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -c" + } else { + puts $ofd "pragma page_size=512;" + puts $ofd "create table sqlar (a);" + } + puts $ofd ".tables" + puts $ofd ".q" + close $ofd + set ofd [open $shod wb] + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + lappend res [fosAvfs $shod] + forcedelete $shdo ; # Leave $shod for next test. + set ::result [join $res " | "] +} {0 | sqlar | 0} + +do_test 4.3 { + set shdo "sh_app1.sql" + set shod "sh_app1.adb" ; # Same as test 4.2, reusing ADB. + forcedelete $shdo + set ofd [open $shdo w] + if {$::cliDoesAr} { + puts $ofd ".ar -u $shdo" + puts $ofd "select count(*) from sqlar where name = '$shdo';" + } else { + puts $ofd "insert into sqlar values (1);" + puts $ofd "select count(*) from sqlar;" + } + puts $ofd ".q" + close $ofd + set res [catchcmd "-append -batch -init $shdo $shod" ""] + sqlite3 adb "file:$shod?mode=rw$::vf" -uri 1 + adb eval { + SELECT count(*) as n FROM sqlar + } { lappend res $n } + adb close + forcedelete $shdo $shod; + set ::result [join $res " | "] +} {0 | 1 | 1} + +do_test 5.1 { + set fake "faketiny.sdb" + forcedelete $fake + set ofd [open $fake wb] + puts -nonewline $ofd "SQLite format 3" + puts -nonewline $ofd [binary format "c" 0] + puts -nonewline $ofd "Start-Of-SQLite3-" + puts -nonewline $ofd [binary format "W" 0] + close $ofd + if {[catch {sqlite3 adb "file:$fake?mode=rw$::vf" -uri 1}]} { + set res "Open failed." + } else { + adb close + set res "Opened when should not." + } + forcedelete $fake + set ::result $res +} {Open failed.} + +do_test 5.2 { + set fake "faketiny.sdb" + forcedelete $fake + set ofd [open $fake wb] + set fakeAppendee "Dog ate my homework.\n" + puts -nonewline $ofd $fakeAppendee + puts -nonewline $ofd "SQLite format 3" + puts -nonewline $ofd [binary format "c" 0] + puts -nonewline $ofd "Start-Of-SQLite3-" + puts -nonewline $ofd [binary format "W" [string length $fakeAppendee]] + close $ofd + if {[catch {sqlite3 adb "file:$fake?mode=rw$::vf" -uri 1}]} { + set res "Open failed." + } else { + adb close + set res "Opened when should not." + } + forcedelete $fake + set ::result $res +} {Open failed.} + +forcedelete $::fa $::fza + +unset -nocomplain ::fa ::fza ::tlo ::result ::randints ::nrint ::cliDoesAr + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/avtrans.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/avtrans.test new file mode 100644 index 0000000000000000000000000000000000000000..6fc4a3e3937fac8d350fefdfe24587aeb5baff7b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/avtrans.test @@ -0,0 +1,927 @@ +# 2001 September 15 +# +# 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. This +# file is a copy of "trans.test" modified to run under autovacuum mode. +# the point is to stress the autovacuum logic and try to get it to fail. +# +# $Id: avtrans.test,v 1.6 2007/09/12 17:01:45 danielk1977 Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# Create several tables to work with. +# +do_test avtrans-1.0 { + execsql { PRAGMA auto_vacuum=full } + wal_set_journal_mode + execsql { + CREATE TABLE one(a int PRIMARY KEY, b text); + INSERT INTO one VALUES(1,'one'); + INSERT INTO one VALUES(2,'two'); + INSERT INTO one VALUES(3,'three'); + SELECT b FROM one ORDER BY a; + } +} {one two three} +do_test avtrans-1.0.1 { execsql { PRAGMA auto_vacuum } } 1 +do_test avtrans-1.1 { + execsql { + CREATE TABLE two(a int PRIMARY KEY, b text); + INSERT INTO two VALUES(1,'I'); + INSERT INTO two VALUES(5,'V'); + INSERT INTO two VALUES(10,'X'); + SELECT b FROM two ORDER BY a; + } +} {I V X} +do_test avtrans-1.9 { + sqlite3 altdb test.db + execsql {SELECT b FROM one ORDER BY a} altdb +} {one two three} +do_test avtrans-1.10 { + execsql {SELECT b FROM two ORDER BY a} altdb +} {I V X} +integrity_check avtrans-1.11 +wal_check_journal_mode avtrans-1.12 + +# Basic transactions +# +do_test avtrans-2.1 { + set v [catch {execsql {BEGIN}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.2 { + set v [catch {execsql {END}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.3 { + set v [catch {execsql {BEGIN TRANSACTION}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.4 { + set v [catch {execsql {COMMIT TRANSACTION}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.5 { + set v [catch {execsql {BEGIN TRANSACTION 'foo'}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.6 { + set v [catch {execsql {ROLLBACK TRANSACTION 'foo'}} msg] + lappend v $msg +} {0 {}} +do_test avtrans-2.10 { + execsql { + BEGIN; + SELECT a FROM one ORDER BY a; + SELECT a FROM two ORDER BY a; + END; + } +} {1 2 3 1 5 10} +integrity_check avtrans-2.11 +wal_check_journal_mode avtrans-2.12 + +# Check the locking behavior +# +sqlite3_soft_heap_limit 0 +do_test avtrans-3.1 { + execsql { + BEGIN; + UPDATE one SET a = 0 WHERE 0; + SELECT a FROM one ORDER BY a; + } +} {1 2 3} +do_test avtrans-3.2 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.3 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.4 { + catchsql { + INSERT INTO one VALUES(4,'four'); + } +} {0 {}} +do_test avtrans-3.5 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.6 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.7 { + catchsql { + INSERT INTO two VALUES(4,'IV'); + } +} {0 {}} +do_test avtrans-3.8 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 5 10}} +do_test avtrans-3.9 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3}} +do_test avtrans-3.10 { + execsql {END TRANSACTION} +} {} +do_test avtrans-3.11 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-3.12 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 2 3 4}} +do_test avtrans-3.13 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-3.14 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 2 3 4}} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +integrity_check avtrans-3.15 + +do_test avtrans-4.1 { + set v [catch {execsql { + COMMIT; + } db} msg] + lappend v $msg +} {1 {cannot commit - no transaction is active}} +do_test avtrans-4.2 { + set v [catch {execsql { + ROLLBACK; + } db} msg] + lappend v $msg +} {1 {cannot rollback - no transaction is active}} +do_test avtrans-4.3 { + catchsql { + BEGIN TRANSACTION; + UPDATE two SET a = 0 WHERE 0; + SELECT a FROM two ORDER BY a; + } db +} {0 {1 4 5 10}} +do_test avtrans-4.4 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 4 5 10}} +do_test avtrans-4.5 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3 4}} +do_test avtrans-4.6 { + catchsql { + BEGIN TRANSACTION; + SELECT a FROM one ORDER BY a; + } db +} {1 {cannot start a transaction within a transaction}} +do_test avtrans-4.7 { + catchsql { + SELECT a FROM two ORDER BY a; + } altdb +} {0 {1 4 5 10}} +do_test avtrans-4.8 { + catchsql { + SELECT a FROM one ORDER BY a; + } altdb +} {0 {1 2 3 4}} +do_test avtrans-4.9 { + set v [catch {execsql { + END TRANSACTION; + SELECT a FROM two ORDER BY a; + } db} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-4.10 { + set v [catch {execsql { + SELECT a FROM two ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 4 5 10}} +do_test avtrans-4.11 { + set v [catch {execsql { + SELECT a FROM one ORDER BY a; + } altdb} msg] + lappend v $msg +} {0 {1 2 3 4}} +integrity_check avtrans-4.12 +do_test avtrans-4.98 { + altdb close + execsql { + DROP TABLE one; + DROP TABLE two; + } +} {} +integrity_check avtrans-4.99 + +# Check out the commit/rollback behavior of the database +# +do_test avtrans-5.1 { + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.2 { + execsql {BEGIN TRANSACTION} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.3 { + execsql {CREATE TABLE one(a text, b int)} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {one} +do_test avtrans-5.4 { + execsql {SELECT a,b FROM one ORDER BY b} +} {} +do_test avtrans-5.5 { + execsql {INSERT INTO one(a,b) VALUES('hello', 1)} + execsql {SELECT a,b FROM one ORDER BY b} +} {hello 1} +do_test avtrans-5.6 { + execsql {ROLLBACK} + execsql {SELECT name FROM sqlite_master WHERE type='table' ORDER BY name} +} {} +do_test avtrans-5.7 { + set v [catch { + execsql {SELECT a,b FROM one ORDER BY b} + } msg] + lappend v $msg +} {1 {no such table: one}} + +# Test commits and rollbacks of table CREATE TABLEs, CREATE INDEXs +# DROP TABLEs and DROP INDEXs +# +do_test avtrans-5.8 { + execsql { + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name + } +} {} +do_test avtrans-5.9 { + execsql { + BEGIN TRANSACTION; + CREATE TABLE t1(a int, b int, c int); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {t1} +do_test avtrans-5.10 { + execsql { + CREATE INDEX i1 ON t1(a); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.11 { + execsql { + COMMIT; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.12 { + execsql { + BEGIN TRANSACTION; + CREATE TABLE t2(a int, b int, c int); + CREATE INDEX i2a ON t2(a); + CREATE INDEX i2b ON t2(b); + DROP TABLE t1; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2a i2b t2} +do_test avtrans-5.13 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.14 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {t1} +do_test avtrans-5.15 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i1 t1} +do_test avtrans-5.16 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE TABLE t2(x int, y int, z int); + CREATE INDEX i2x ON t2(x); + CREATE INDEX i2y ON t2(y); + INSERT INTO t2 VALUES(1,2,3); + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.17 { + execsql { + COMMIT; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.18 { + execsql { + SELECT * FROM t2; + } +} {1 2 3} +do_test avtrans-5.19 { + execsql { + SELECT x FROM t2 WHERE y=2; + } +} {1} +do_test avtrans-5.20 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + DROP TABLE t2; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {} +do_test avtrans-5.21 { + set r [catch {execsql { + SELECT * FROM t2 + }} msg] + lappend r $msg +} {1 {no such table: t2}} +do_test avtrans-5.22 { + execsql { + ROLLBACK; + SELECT name fROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name; + } +} {i2x i2y t1 t2} +do_test avtrans-5.23 { + execsql { + SELECT * FROM t2; + } +} {1 2 3} +integrity_check avtrans-5.23 + + +# Try to DROP and CREATE tables and indices with the same name +# within a transaction. Make sure ROLLBACK works. +# +do_test avtrans-6.1 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p,q,r); + ROLLBACK; + SELECT * FROM t1; + } +} {a 1 b 2 c 3} +do_test avtrans-6.2 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p,q,r); + COMMIT; + SELECT * FROM t1; + } +} {} +do_test avtrans-6.3 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.4 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.5 { + execsql2 { + ROLLBACK; + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.6 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.7 { + catchsql { + COMMIT; + SELECT * FROM t1; + } +} {1 {no such table: t1}} + +# Repeat on a table with an automatically generated index. +# +do_test avtrans-6.10 { + execsql2 { + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(1,2,3); + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p unique,q,r); + ROLLBACK; + SELECT * FROM t1; + } +} {a 1 b 2 c 3} +do_test avtrans-6.11 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(p unique,q,r); + COMMIT; + SELECT * FROM t1; + } +} {} +do_test avtrans-6.12 { + execsql2 { + INSERT INTO t1 VALUES(1,2,3); + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.13 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.14 { + execsql2 { + ROLLBACK; + SELECT * FROM t1; + } +} {p 1 q 2 r 3} +do_test avtrans-6.15 { + execsql2 { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a unique,b,c); + INSERT INTO t1 VALUES(4,5,6); + SELECT * FROM t1; + DROP TABLE t1; + } +} {a 4 b 5 c 6} +do_test avtrans-6.16 { + catchsql { + COMMIT; + SELECT * FROM t1; + } +} {1 {no such table: t1}} + +do_test avtrans-6.20 { + execsql { + CREATE TABLE t1(a integer primary key,b,c); + INSERT INTO t1 VALUES(1,-2,-3); + INSERT INTO t1 VALUES(4,-5,-6); + SELECT * FROM t1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.21 { + execsql { + CREATE INDEX i1 ON t1(b); + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.22 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT * FROM t1 WHERE b<1; + ROLLBACK; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.23 { + execsql { + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.24 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} + +do_test avtrans-6.25 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE INDEX i1 ON t1(c); + SELECT * FROM t1 WHERE b<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.26 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.27 { + execsql { + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.28 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} + +# The following repeats steps 6.20 through 6.28, but puts a "unique" +# constraint the first field of the table in order to generate an +# automatic index. +# +do_test avtrans-6.30 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + CREATE TABLE t1(a int unique,b,c); + COMMIT; + INSERT INTO t1 VALUES(1,-2,-3); + INSERT INTO t1 VALUES(4,-5,-6); + SELECT * FROM t1 ORDER BY a; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.31 { + execsql { + CREATE INDEX i1 ON t1(b); + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.32 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + SELECT * FROM t1 WHERE b<1; + ROLLBACK; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.33 { + execsql { + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.34 { + execsql { + BEGIN TRANSACTION; + DROP TABLE t1; + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} + +do_test avtrans-6.35 { + execsql { + BEGIN TRANSACTION; + DROP INDEX i1; + CREATE INDEX i1 ON t1(c); + SELECT * FROM t1 WHERE b<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.36 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.37 { + execsql { + DROP INDEX i1; + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} +do_test avtrans-6.38 { + execsql { + ROLLBACK; + SELECT * FROM t1 WHERE b<1; + } +} {4 -5 -6 1 -2 -3} +do_test avtrans-6.39 { + execsql { + SELECT * FROM t1 WHERE c<1; + } +} {1 -2 -3 4 -5 -6} +integrity_check avtrans-6.40 + +ifcapable !floatingpoint { + finish_test + return +} + +# Test to make sure rollback restores the database back to its original +# state. +# +do_test avtrans-7.1 { + execsql {BEGIN} + for {set i 0} {$i<1000} {incr i} { + set r1 [expr {rand()}] + set r2 [expr {rand()}] + set r3 [expr {rand()}] + execsql "INSERT INTO t2 VALUES($r1,$r2,$r3)" + } + execsql {COMMIT} + set ::checksum [execsql {SELECT md5sum(x,y,z) FROM t2}] + set ::checksum2 [ + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} + ] + execsql {SELECT count(*) FROM t2} +} {1001} +do_test avtrans-7.2 { + execsql {SELECT md5sum(x,y,z) FROM t2} +} $checksum +do_test avtrans-7.2.1 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +do_test avtrans-7.3 { + execsql { + BEGIN; + DELETE FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.4 { + execsql { + BEGIN; + INSERT INTO t2 SELECT * FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.5 { + execsql { + BEGIN; + DELETE FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.6 { + execsql { + BEGIN; + INSERT INTO t2 SELECT * FROM t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.7 { + execsql { + BEGIN; + CREATE TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } +} $checksum +do_test avtrans-7.8 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.9 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.10 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.11 { + execsql { + BEGIN; + CREATE TEMP TABLE t3 AS SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t3; + DROP INDEX i2x; + DROP INDEX i2y; + CREATE INDEX i3a ON t3(x); + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.12 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +ifcapable tempdb { + do_test avtrans-7.13 { + execsql { + BEGIN; + DROP TABLE t2; + ROLLBACK; + SELECT md5sum(x,y,z) FROM t2; + } + } $checksum +} +do_test avtrans-7.14 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +integrity_check avtrans-7.15 + +# Arrange for another process to begin modifying the database but abort +# and die in the middle of the modification. Then have this process read +# the database. This process should detect the journal file and roll it +# back. Verify that this happens correctly. +# +set fd [open test.tcl w] +puts $fd { + sqlite3 db test.db + db eval { + PRAGMA default_cache_size=20; + BEGIN; + CREATE TABLE t3 AS SELECT * FROM t2; + DELETE FROM t2; + } + sqlite_abort +} +close $fd +do_test avtrans-8.1 { + catch {exec [info nameofexec] test.tcl} + execsql {SELECT md5sum(x,y,z) FROM t2} +} $checksum +do_test avtrans-8.2 { + execsql {SELECT md5sum(type,name,tbl_name,rootpage,sql) FROM sqlite_master} +} $checksum2 +integrity_check avtrans-8.3 + +# In the following sequence of tests, compute the MD5 sum of the content +# of a table, make lots of modifications to that table, then do a rollback. +# Verify that after the rollback, the MD5 checksum is unchanged. +# +do_test avtrans-9.1 { + execsql { + PRAGMA default_cache_size=10; + } + db close + sqlite3 db test.db + execsql { + BEGIN; + CREATE TABLE t3(x TEXT); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + COMMIT; + SELECT count(*) FROM t3; + } +} {1024} + +# The following procedure computes a "signature" for table "t3". If +# T3 changes in any way, the signature should change. +# +# This is used to test ROLLBACK. We gather a signature for t3, then +# make lots of changes to t3, then rollback and take another signature. +# The two signatures should be the same. +# +proc signature {} { + return [db eval {SELECT count(*), md5sum(x) FROM t3}] +} + +# Repeat the following group of tests 20 times for quick testing and +# 40 times for full testing. Each iteration of the test makes table +# t3 a little larger, and thus takes a little longer, so doing 40 tests +# is more than 2.0 times slower than doing 20 tests. Considerably more. +# +if {[info exists G(isquick)]} { + set limit 20 +} else { + set limit 40 +} + +# Do rollbacks. Make sure the signature does not change. +# +for {set i 2} {$i<=$limit} {incr i} { + set ::sig [signature] + set cnt [lindex $::sig 0] + if {$i%2==0} { + execsql {PRAGMA fullfsync=ON} + } else { + execsql {PRAGMA fullfsync=OFF} + } + set sqlite_sync_count 0 + set sqlite_fullsync_count 0 + do_test avtrans-9.$i.1-$cnt { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature + } $sig + do_test avtrans-9.$i.2-$cnt { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature + } $sig + if {$i<$limit} { + do_test avtrans-9.$i.3-$cnt { + execsql { + INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; + } + } {} + if {$tcl_platform(platform)=="unix"} { + do_test avtrans-9.$i.4-$cnt { + expr {$sqlite_sync_count>0} + } 1 + ifcapable pager_pragmas { + do_test avtrans-9.$i.5-$cnt { + expr {$sqlite_fullsync_count>0} + } [expr {$i%2==0}] + } else { + do_test avtrans-9.$i.5-$cnt { + expr {$sqlite_fullsync_count==0} + } {1} + } + } + wal_check_journal_mode avtrans-9.$i-6.$cnt + } + set ::pager_old_format 0 +} +integrity_check avtrans-10.1 +wal_check_journal_mode avtrans-10.2 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/backcompat.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/backcompat.test new file mode 100644 index 0000000000000000000000000000000000000000..d477d4466c4dde3dd118ccc4e949d40c8ec4ca14 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/backcompat.test @@ -0,0 +1,524 @@ +# 2010 August 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 regression tests for SQLite library. The +# focus of this file is testing that the current version of SQLite +# is capable of reading and writing databases created by previous +# versions, and vice-versa. +# +# To use this test, old versions of the testfixture process should be +# copied into the working directory alongside the new version. The old +# versions should be named "testfixtureXXX" (or testfixtureXXX.exe on +# windows), where XXX can be any string. +# +# This test file uses the tcl code for controlling a second testfixture +# process located in lock_common.tcl. See the commments in lock_common.tcl +# for documentation of the available commands. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl +source $testdir/bc_common.tcl +db close + +if {"" == [bc_find_binaries backcompat.test]} { + finish_test + return +} + +proc do_backcompat_test {rv bin1 bin2 script} { + + forcedelete test.db + + if {$bin1 != ""} { set ::bc_chan1 [launch_testfixture $bin1] } + set ::bc_chan2 [launch_testfixture $bin2] + + if { $rv } { + proc code2 {tcl} { uplevel #0 $tcl } + if {$bin1 != ""} { proc code2 {tcl} { testfixture $::bc_chan1 $tcl } } + proc code1 {tcl} { testfixture $::bc_chan2 $tcl } + } else { + proc code1 {tcl} { uplevel #0 $tcl } + if {$bin1 != ""} { proc code1 {tcl} { testfixture $::bc_chan1 $tcl } } + proc code2 {tcl} { testfixture $::bc_chan2 $tcl } + } + + proc sql1 sql { code1 [list db eval $sql] } + proc sql2 sql { code2 [list db eval $sql] } + + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + foreach c {code1 code2} { + $c { + set v [split [db version] .] + if {[llength $v]==3} {lappend v 0} + set ::sqlite_libversion [format \ + "%d%.2d%.2d%.2d" [lindex $v 0] [lindex $v 1] [lindex $v 2] [lindex $v 3] + ] + } + } + + uplevel $script + + catch { code1 { db close } } + catch { code2 { db close } } + catch { close $::bc_chan2 } + catch { close $::bc_chan1 } + + +} + +array set ::incompatible [list] +proc do_allbackcompat_test {script} { + + foreach bin $::BC(binaries) { + set nErr [set_test_counter errors] + foreach dir {0 1} { + + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag + set bintag [string map {\.exe {}} $bintag] + if {$bintag == ""} {set bintag self} + set ::bcname ".$bintag.$dir." + + rename do_test _do_test + proc do_test {nm sql res} { + set nm [regsub {\.} $nm $::bcname] + uplevel [list _do_test $nm $sql $res] + } + + do_backcompat_test $dir {} $bin $script + + rename do_test {} + rename _do_test do_test + } + if { $nErr < [set_test_counter errors] } { + set ::incompatible([get_version $bin]) 1 + } + } +} + +proc read_file {zFile} { + set zData {} + if {[file exists $zFile]} { + set fd [open $zFile] + fconfigure $fd -translation binary + + if {[file size $zFile]<=$::sqlite_pending_byte || $zFile != "test.db"} { + set zData [read $fd] + } else { + set zData [read $fd $::sqlite_pending_byte] + append zData [string repeat x 512] + seek $fd [expr $::sqlite_pending_byte+512] start + append zData [read $fd] + } + + close $fd + } + return $zData +} +proc write_file {zFile zData} { + set fd [open $zFile w] + fconfigure $fd -translation binary + puts -nonewline $fd $zData + close $fd +} +proc read_file_system {} { + set ret [list] + foreach f {test.db test.db-journal test.db-wal} { lappend ret [read_file $f] } + set ret +} +proc write_file_system {data} { + foreach f {test.db test.db-journal test.db-wal} d $data { + if {[string length $d] == 0} { + forcedelete $f + } else { + write_file $f $d + } + } +} + +#------------------------------------------------------------------------- +# Actual tests begin here. +# +# This first block of tests checks to see that the same database and +# journal files can be used by old and new versions. WAL and wal-index +# files are tested separately below. +# +do_allbackcompat_test { + + # Test that database files are backwards compatible. + # + do_test backcompat-1.1.1 { sql1 { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('abc', 'def'); + } } {} + do_test backcompat-1.1.2 { sql2 { SELECT * FROM t1; } } {abc def} + do_test backcompat-1.1.3 { sql2 { INSERT INTO t1 VALUES('ghi', 'jkl'); } } {} + do_test backcompat-1.1.4 { sql1 { SELECT * FROM t1; } } {abc def ghi jkl} + do_test backcompat-1.1.5 { sql1 { PRAGMA integrity_check } } {ok} + do_test backcompat-1.1.6 { sql2 { PRAGMA integrity_check } } {ok} + + # Test that one version can roll back a hot-journal file left in the + # file-system by the other version. + # + # Each test case is named "backcompat-1.X...", where X is either 0 or + # 1. If it is 0, then the current version creates a journal file that + # the old versions try to read. Otherwise, if X is 1, then the old version + # creates the journal file and we try to read it with the current version. + # + do_test backcompat-1.2.1 { sql1 { + PRAGMA cache_size = 10; + BEGIN; + INSERT INTO t1 VALUES(randomblob(400), randomblob(400)); + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + INSERT INTO t1 SELECT randomblob(400), randomblob(400) FROM t1; + COMMIT; + } } {} + set cksum1 [sql1 {SELECT md5sum(a), md5sum(b) FROM t1}] + set cksum2 [sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] + do_test backcompat-1.2.2 [list string compare $cksum1 $cksum2] 0 + + do_test backcompat-1.2.3 { sql1 { + BEGIN; + UPDATE t1 SET a = randomblob(500); + } } {} + set data [read_file_system] + + do_test backcompat-1.2.4 { sql1 { COMMIT } } {} + + set same [expr {[sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] == $cksum2}] + do_test backcompat-1.2.5 [list set {} $same] 0 + + code1 { db close } + code2 { db close } + write_file_system $data + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + set same [expr {[sql2 {SELECT md5sum(a), md5sum(b) FROM t1}] == $cksum2}] + do_test backcompat-1.2.6 [list set {} $same] 1 + + do_test backcompat-1.2.7 { sql1 { PRAGMA integrity_check } } {ok} + do_test backcompat-1.2.8 { sql2 { PRAGMA integrity_check } } {ok} + + do_test backcompat-2.1 { + sql1 { + CREATE TABLE t2(a UNIQUE, b PRIMARY KEY, c UNIQUE); + INSERT INTO t2 VALUES(1,9,5); + INSERT INTO t2 VALUES(5,5,1); + INSERT INTO t2 VALUES(9,1,9); + SELECT * FROM t2 ORDER BY a; + } + } {1 9 5 5 5 1 9 1 9} + do_test backcompat-2.2 { + sql2 { + SELECT * FROM sqlite_master WHERE rootpage=-1; + SELECT * FROM t2 ORDER BY a; + } + } {1 9 5 5 5 1 9 1 9} + do_test backcompat-2.3 { + sql1 { + SELECT * FROM t2 ORDER BY b; + } + } {9 1 9 5 5 1 1 9 5} + do_test backcompat-2.4 { + sql2 { + SELECT * FROM t2 ORDER BY b; + } + } {9 1 9 5 5 1 1 9 5} + do_test backcompat-2.5 { + sql1 { + SELECT * FROM t2 ORDER BY c; + } + } {5 5 1 1 9 5 9 1 9} + do_test backcompat-2.6 { + sql2 { + SELECT * FROM t2 ORDER BY c; + } + } {5 5 1 1 9 5 9 1 9} +} +foreach k [lsort [array names ::incompatible]] { + puts "ERROR: Detected journal incompatibility with version $k" +} +unset ::incompatible + + +#------------------------------------------------------------------------- +# Test that WAL and wal-index files may be shared between different +# SQLite versions. +# +do_allbackcompat_test { + if {[code1 {sqlite3 -version}] >= "3.7.0" + && [code1 {set ::sqlite_options(wal)}] + && [code2 {sqlite3 -version}] >= "3.7.0" + && [code2 {set ::sqlite_options(wal)}] + } { + + do_test backcompat-2.1.1 { sql1 { + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('I', 1); + INSERT INTO t1 VALUES('II', 2); + INSERT INTO t1 VALUES('III', 3); + SELECT * FROM t1; + } } {wal I 1 II 2 III 3} + do_test backcompat-2.1.2 { sql2 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + + set data [read_file_system] + code1 {db close} + code2 {db close} + write_file_system $data + code1 {sqlite3 db test.db} + code2 {sqlite3 db test.db} + + # The WAL file now in the file-system was created by the [code1] + # process. Check that the [code2] process can recover the log. + # + do_test backcompat-2.1.3 { sql2 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + do_test backcompat-2.1.4 { sql1 { + SELECT * FROM t1; + } } {I 1 II 2 III 3} + } +} + +#------------------------------------------------------------------------- +# Test that FTS3 tables may be read/written by different versions of +# SQLite. +# +ifcapable fts3 { + set contents { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + } + foreach {num doc} { + one "jk zm jk eczkjblu urvysbnykk sk gnl jk ttvgf hmjf" + two "jk bnhc jjrxpjkb mjpavjuhw fibokdry igju jk zm zm xh" + three "wxe ogttbykvt uhzq xr iaf zf urvysbnykk aayxpmve oacaxgjoo mjpavjuhw" + four "gazrt jk ephknonq myjp uenvbm wuvajhwqz jk zm xnxhf nvfasfh" + five "zm aayxpmve csjqxhgj xnxhf xr jk aayxpmve xnxhf zm zm" + six "sokcyf zm ogyavjvv jk zm fibokdry zm jk igju igju" + seven "vgsld bvgimjik xuprtlyle jk akmikrqyt jk aayxpmve hkfoudzftq ddjj" + eight "zm uhzq ovkyevlgv zk uenvbm csjqxhgj jk vgsld pgybs jk" + nine "zm agmckuiu zexh fibokdry jk uhzq bu tugflixoex xnxhf sk" + } { + append contents "INSERT INTO t1 VALUES('$num', '$doc');" + } + do_allbackcompat_test { + if {[code1 {set ::sqlite_options(fts3)}] + && [code2 {set ::sqlite_options(fts3)}] + } { + + do_test backcompat-3.1 { sql1 $contents } {} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + } { + do_test backcompat-3.2 [list sql1 $q] [sql2 $q] + } + + do_test backcompat-3.3 { sql1 { + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + } } {} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + } { + do_test backcompat-3.4 [list sql1 $q] [sql2 $q] + } + + set alphabet "a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4" + for {set i 0} {$i < 900} {incr i} { + set term "[lindex $alphabet [expr $i/30]][lindex $alphabet [expr $i%30]] " + sql1 "INSERT INTO t1 VALUES($i, '[string repeat $term 14]')" + } + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + + 6 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'aa'" + 7 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH '44'" + 8 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'a*'" + } { + do_test backcompat-3.5 [list sql1 $q] [sql2 $q] + } + + do_test backcompat-3.6 { + sql1 "SELECT optimize(t1) FROM t1 LIMIT 1" + } {{Index optimized}} + + foreach {n q} { + 1 "SELECT * FROM t1 ORDER BY a, b" + 2 "SELECT rowid FROM t1 WHERE a MATCH 'five'" + 3 "SELECT * FROM t1 WHERE a MATCH 'five'" + 4 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'jk'" + 5 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'tug* OR eight'" + + 6 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'aa'" + 7 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH '44'" + 8 "SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'a*'" + } { + do_test backcompat-3.7 [list sql1 $q] [sql2 $q] + } + + # Now test that an incremental merge can be started by one version + # and finished by another. And that the integrity-check still + # passes. + do_test backcompat-3.8 { + sql1 { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE t2 USING fts3(words); + } + code1 [list source $testdir/genesis.tcl] + code1 { fts_kjv_genesis } + sql1 { + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + INSERT INTO t2 SELECT words FROM t1; + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level; + } + } {0 {0 1 2 3 4 5}} + + if {[code1 { set ::sqlite_libversion }] >=3071200 + && [code2 { set ::sqlite_libversion }] >=3071200 + } { + if {[code1 { set ::sqlite_libversion }]<3120000} { + set res {0 {0 1} 1 0} + } else { + set res {1 0} + } + + do_test backcompat-3.9 { + sql1 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql2 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql1 { INSERT INTO t2(t2) VALUES('merge=100,4'); } + sql2 { INSERT INTO t2(t2) VALUES('merge=2500,4'); } + sql2 { + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level; + } + } $res + + do_test backcompat-3.10 { + sql1 { INSERT INTO t2(t2) VALUES('integrity-check') } + sql2 { INSERT INTO t2(t2) VALUES('integrity-check') } + } {} + } + } + } +} + +#------------------------------------------------------------------------- +# Test that Rtree tables may be read/written by different versions of +# SQLite. +# +ifcapable rtree { + set contents { + CREATE VIRTUAL TABLE t1 USING rtree(id, x1, x2, y1, y2); + } + foreach {id x1 x2 y1 y2} { + 1 -47.64 43.87 33.86 34.42 2 -21.51 17.32 2.05 31.04 + 3 -43.67 -38.33 -19.79 3.43 4 32.41 35.16 9.12 19.82 + 5 33.28 34.87 14.78 28.26 6 49.31 116.59 -9.87 75.09 + 7 -14.93 34.51 -17.64 64.09 8 -43.05 23.43 -1.19 69.44 + 9 44.79 133.56 28.09 80.30 10 -2.66 81.47 -41.38 -10.46 + 11 -42.89 -3.54 15.76 71.63 12 -3.50 84.96 -11.64 64.95 + 13 -45.69 26.25 11.14 55.06 14 -44.09 11.23 17.52 44.45 + 15 36.23 133.49 -19.38 53.67 16 -17.89 81.54 14.64 50.61 + 17 -41.97 -24.04 -39.43 28.95 18 -5.85 7.76 -6.38 47.02 + 19 18.82 27.10 42.82 100.09 20 39.17 113.45 26.14 73.47 + 21 22.31 103.17 49.92 106.05 22 -43.06 40.38 -1.75 76.08 + 23 2.43 57.27 -14.19 -3.83 24 -47.57 -4.35 8.93 100.06 + 25 -37.47 49.14 -29.11 8.81 26 -7.86 75.72 49.34 107.42 + 27 1.53 45.49 20.36 49.74 28 -48.48 32.54 28.81 54.45 + 29 2.67 39.77 -4.05 13.67 30 4.11 62.88 -47.44 -5.72 + 31 -21.47 51.75 37.25 116.09 32 45.59 111.37 -6.43 43.64 + 33 35.23 48.29 23.54 113.33 34 16.61 68.35 -14.69 65.97 + 35 13.98 16.60 48.66 102.87 36 19.74 23.84 31.15 77.27 + 37 -27.61 24.43 7.96 94.91 38 -34.77 12.05 -22.60 -6.29 + 39 -25.83 8.71 -13.48 -12.53 40 -17.11 -1.01 18.06 67.89 + 41 14.13 71.72 -3.78 39.25 42 23.75 76.00 -16.30 8.23 + 43 -39.15 28.63 38.12 125.88 44 48.62 86.09 36.49 102.95 + 45 -31.39 -21.98 2.52 89.78 46 5.65 56.04 15.94 89.10 + 47 18.28 95.81 46.46 143.08 48 30.93 102.82 -20.08 37.36 + 49 -20.78 -3.48 -5.58 35.46 50 49.85 90.58 -24.48 46.29 + } { + if {$x1 >= $x2 || $y1 >= $y2} { error "$x1 $x2 $y1 $y2" } + append contents "INSERT INTO t1 VALUES($id, $x1, $x2, $y1, $y2);" + } + set queries { + 1 "SELECT id FROM t1 WHERE x1>10 AND x2<44" + 2 "SELECT id FROM t1 WHERE y1<100" + 3 "SELECT id FROM t1 WHERE y1<100 AND x1>0" + 4 "SELECT id FROM t1 WHERE y1>10 AND x1>0 AND x2<50 AND y2<550" + } + do_allbackcompat_test { + if {[code1 {set ::sqlite_options(fts3)}] + && [code2 {set ::sqlite_options(fts3)}] + } { + + do_test backcompat-4.1 { sql1 $contents } {} + + foreach {n q} $::queries { + do_test backcompat-4.2.$n [list sql1 $q] [sql2 $q] + } + + do_test backcompat-4.3 { sql1 { + INSERT INTO t1 SELECT id+100, x1+10.0, x2+10.0, y1-10.0, y2-10.0 FROM t1; + } } {} + + foreach {n q} $::queries { + do_test backcompat-4.4.$n [list sql1 $q] [sql2 $q] + } + + do_test backcompat-4.5 { sql2 { + INSERT INTO t1 SELECT id+200, x1+20.0, x2+20.0, y1-20.0, y2-20.0 FROM t1; + } } {} + + foreach {n q} $::queries { + do_test backcompat-4.6.$n [list sql1 $q] [sql2 $q] + } + + } + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/backup.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/backup.test new file mode 100644 index 0000000000000000000000000000000000000000..ad1a383a087aae9d64a38be7690f06655547ce60 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/backup.test @@ -0,0 +1,1004 @@ +# 2009 January 30 +# +# 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. The +# focus of this file is testing the sqlite3_backup_XXX API. +# +# $Id: backup.test,v 1.11 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_not_use_codec + +#--------------------------------------------------------------------- +# Test organization: +# +# backup-1.*: Warm-body tests. +# +# backup-2.*: Test backup under various conditions. To and from in-memory +# databases. To and from empty/populated databases. etc. +# +# backup-3.*: Verify that the locking-page (pending byte page) is handled. +# +# backup-4.*: Test various error conditions. +# +# backup-5.*: Test the source database being modified during a backup. +# +# backup-6.*: Test the backup_remaining() and backup_pagecount() APIs. +# +# backup-7.*: Test SQLITE_BUSY and SQLITE_LOCKED errors. +# +# backup-8.*: Test multiple simultaneous backup operations. +# +# backup-9.*: Test that passing a negative argument to backup_step() is +# interpreted as "copy the whole file". +# +# backup-10.*: Test writing the source database mid backup. +# + +proc data_checksum {db file} { $db one "SELECT md5sum(a, b) FROM ${file}.t1" } +proc test_contents {name db1 file1 db2 file2} { + $db2 eval {select * from sqlite_master} + $db1 eval {select * from sqlite_master} + set checksum [data_checksum $db2 $file2] + uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] +} + +do_test backup-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } +} {} + +# Sanity check to verify that the [test_contents] proc works. +# +test_contents backup-1.2 db main db main + +# Check that it is possible to create and finish backup operations. +# +do_test backup-1.3.1 { + delete_file test2.db + sqlite3 db2 test2.db + sqlite3_backup B db2 main db main +} {B} +do_test backup-1.3.2 { + B finish +} {SQLITE_OK} +do_test backup-1.3.3 { + info commands B +} {} + +# Simplest backup operation. Backup test.db to test2.db. test2.db is +# initially empty. test.db uses the default page size. +# +do_test backup-1.4.1 { + sqlite3_backup B db2 main db main +} {B} +do_test backup-1.4.2 { + B step 200 +} {SQLITE_DONE} +do_test backup-1.4.3 { + B finish +} {SQLITE_OK} +do_test backup-1.4.4 { + info commands B +} {} +test_contents backup-1.4.5 db2 main db main +db close +db2 close +# +# End of backup-1.* tests. +#--------------------------------------------------------------------- + + +#--------------------------------------------------------------------- +# The following tests, backup-2.*, are based on the following procedure: +# +# 1) Populate the source database. +# 2) Populate the destination database. +# 3) Run the backup to completion. (backup-2.*.1) +# 4) Integrity check the destination db. (backup-2.*.2) +# 5) Check that the contents of the destination db is the same as that +# of the source db. (backup-2.*.3) +# +# The test is run with all possible combinations of the following +# input parameters, except that if the destination is an in-memory +# database, the only page size tested is 1024 bytes (the same as the +# source page-size). +# +# * Source database is an in-memory database, OR +# * Source database is a file-backed database. +# +# * Target database is an in-memory database, OR +# * Target database is a file-backed database. +# +# * Destination database is a main file, OR +# * Destination database is an attached file, OR +# * Destination database is a temp database. +# +# * Target database is empty (zero bytes), OR +# * Target database is larger than the source, OR +# * Target database is smaller than the source. +# +# * Target database page-size is the same as the source, OR +# * Target database page-size is larger than the source, OR +# * Target database page-size is smaller than the source. +# +# * Each call to step copies a single page, OR +# * A single call to step copies the entire source database. +# +set iTest 1 +foreach zSrcFile {test.db :memory:} { +foreach zDestFile {test2.db :memory:} { +foreach zOpenScript [list { + sqlite3 db $zSrcFile + sqlite3 db2 $zSrcFile + db2 eval "ATTACH '$zDestFile' AS bak" + set db_dest db2 + set file_dest bak +} { + sqlite3 db $zSrcFile + sqlite3 db2 $zDestFile + set db_dest db2 + set file_dest main +} { + sqlite3 db $zSrcFile + sqlite3 db2 $zDestFile + set db_dest db2 + set file_dest temp +}] { +foreach rows_dest {0 3 10} { +foreach pgsz_dest {512 1024 2048 4096} { +foreach nPagePerStep {1 200} { + + # Open the databases. + catch { delete_file test.db } + catch { delete_file test2.db } + eval $zOpenScript + + # Set to true if copying to an in-memory destination. Copying to an + # in-memory destination is only possible if the initial destination + # page size is the same as the source page size (in this case 1024 bytes). + # + set isMemDest [expr { $zDestFile eq ":memory:" || $file_dest eq "temp" }] + + if 0 { + puts -nonewline "Test $iTest: src=$zSrcFile dest=$zDestFile" + puts -nonewline " (as $db_dest.$file_dest)" + puts -nonewline " rows_dest=$rows_dest pgsz_dest=$pgsz_dest" + puts "" + } + + if { $isMemDest==0 || $pgsz_dest==1024 || $rows_dest==0 } { + + # Set up the content of the source database. + execsql { + PRAGMA page_size = 1024; + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + + + + # Set up the content of the target database. + execsql "PRAGMA ${file_dest}.page_size = ${pgsz_dest}" $db_dest + if {$rows_dest != 0} { + execsql " + BEGIN; + CREATE TABLE ${file_dest}.t1(a, b); + CREATE INDEX ${file_dest}.i1 ON t1(a, b); + " $db_dest + for {set ii 0} {$ii < $rows_dest} {incr ii} { + execsql " + INSERT INTO ${file_dest}.t1 VALUES(1, randstr(1000,1000)) + " $db_dest + } + execsql COMMIT $db_dest + } + + # Backup the source database. + do_test backup-2.$iTest.1 { + sqlite3_backup B $db_dest $file_dest db main + while {[B step $nPagePerStep]=="SQLITE_OK"} {} + B finish + } {SQLITE_OK} + + # Run integrity check on the backup. + do_test backup-2.$iTest.2 { + execsql "PRAGMA ${file_dest}.integrity_check" $db_dest + } {ok} + + test_contents backup-2.$iTest.3 db main $db_dest $file_dest + + } + + db close + catch {db2 close} + incr iTest + +} } } } } } +# +# End of backup-2.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# These tests, backup-3.*, ensure that nothing goes wrong if either +# the source or destination database are large enough to include the +# the locking-page (the page that contains the range of bytes that +# the locks are applied to). These tests assume that the pending +# byte is at offset 0x00010000 (64KB offset), as set by tester.tcl, +# not at the 1GB offset as it usually is. +# +# The test procedure is as follows (same procedure as used for +# the backup-2.* tests): +# +# 1) Populate the source database. +# 2) Populate the destination database. +# 3) Run the backup to completion. (backup-3.*.1) +# 4) Integrity check the destination db. (backup-3.*.2) +# 5) Check that the contents of the destination db is the same as that +# of the source db. (backup-3.*.3) +# +# The test procedure is run with the following parameters varied: +# +# * Source database includes pending-byte page. +# * Source database does not include pending-byte page. +# +# * Target database includes pending-byte page. +# * Target database does not include pending-byte page. +# +# * Target database page-size is the same as the source, OR +# * Target database page-size is larger than the source, OR +# * Target database page-size is smaller than the source. +# +set iTest 1 +foreach nSrcPg {10 64 65 66 100} { +foreach nDestRow {10 100} { +foreach nDestPgsz {512 1024 2048 4096} { + + catch { delete_file test.db } + catch { delete_file test2.db } + sqlite3 db test.db + sqlite3 db2 test2.db + + # Set up the content of the two databases. + # + execsql { PRAGMA page_size = 1024 } + execsql "PRAGMA page_size = $nDestPgsz" db2 + foreach db {db db2} { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + COMMIT; + } $db + } + while {[file size test.db]/1024 < $nSrcPg} { + execsql { INSERT INTO t1 VALUES($ii, randstr(200,200)) } + } + + for {set ii 0} {$ii < $nDestRow} {incr ii} { + execsql { INSERT INTO t1 VALUES($ii, randstr(1000,1000)) } db2 + } + + # Backup the source database. + do_test backup-3.$iTest.1 { + sqlite3_backup B db main db2 main + while {[B step 10]=="SQLITE_OK"} {} + B finish + } {SQLITE_OK} + + # Run integrity check on the backup. + do_test backup-3.$iTest.2 { + execsql "PRAGMA integrity_check" db2 + } {ok} + + test_contents backup-3.$iTest.3 db main db2 main + + db close + db2 close + incr iTest +} +} +} + +#-------------------------------------------------------------------- +do_test backup-3.$iTest.1 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db test.db + set iTab 1 + + db eval { PRAGMA page_size = 512 } + while {[file size test.db] <= $::sqlite_pending_byte} { + db eval "CREATE TABLE t${iTab}(a, b, c)" + incr iTab + } + + sqlite3 db2 test2.db + db2 eval { PRAGMA page_size = 4096 } + while {[file size test2.db] < $::sqlite_pending_byte} { + db2 eval "CREATE TABLE t${iTab}(a, b, c)" + incr iTab + } + + sqlite3_backup B db2 main db main + B step -1 +} {SQLITE_DONE} + +do_test backup-3.$iTest.2 { + B finish +} {SQLITE_OK} + +# +# End of backup-3.* tests. +#--------------------------------------------------------------------- + + +#--------------------------------------------------------------------- +# The following tests, backup-4.*, test various error conditions: +# +# backup-4.1.*: Test invalid database names. +# +# backup-4.2.*: Test that the source database cannot be detached while +# a backup is in progress. +# +# backup-4.3.*: Test that the source database handle cannot be closed +# while a backup is in progress. +# +# backup-4.4.*: Test an attempt to specify the same handle for the +# source and destination databases. +# +# backup-4.5.*: Test that an in-memory destination with a different +# page-size to the source database is an error. +# +sqlite3 db test.db +sqlite3 db2 test2.db + +do_test backup-4.1.1 { + catch { sqlite3_backup B db aux db2 main } +} {1} +do_test backup-4.1.2 { + sqlite3_errmsg db +} {unknown database aux} +do_test backup-4.1.3 { + catch { sqlite3_backup B db main db2 aux } +} {1} +do_test backup-4.1.4 { + sqlite3_errmsg db +} {unknown database aux} + +do_test backup-4.2.1 { + catch { forcedelete test3.db } + catch { forcedelete test4.db } + execsql { + ATTACH 'test3.db' AS aux1; + CREATE TABLE aux1.t1(a, b); + } + execsql { + ATTACH 'test4.db' AS aux2; + CREATE TABLE aux2.t2(a, b); + } db2 + sqlite3_backup B db aux1 db2 aux2 +} {B} +do_test backup-4.2.2 { + catchsql { DETACH aux2 } db2 +} {1 {database aux2 is locked}} +do_test backup-4.2.3 { + B step 50 +} {SQLITE_DONE} +do_test backup-4.2.4 { + B finish +} {SQLITE_OK} + +do_test backup-4.3.1 { + sqlite3_backup B db aux1 db2 aux2 +} {B} +do_test backup-4.3.2 { + db2 cache flush + sqlite3_close db2 +} {SQLITE_BUSY} +do_test backup-4.3.3 { + sqlite3_errmsg db2 +} {unable to close due to unfinalized statements or unfinished backups} +do_test backup-4.3.4 { + B step 50 +} {SQLITE_DONE} +do_test backup-4.3.5 { + B finish +} {SQLITE_OK} + +do_test backup-4.4.1 { + set rc [catch {sqlite3_backup B db main db aux1}] + list $rc [sqlite3_errcode db] [sqlite3_errmsg db] +} {1 SQLITE_ERROR {source and destination must be distinct}} +db close +db2 close + +do_test backup-4.5.1 { + catch { forcedelete test.db } + sqlite3 db test.db + sqlite3 db2 :memory: + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + execsql { + PRAGMA page_size = 4096; + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES(3, 4); + } db2 + sqlite3_backup B db2 main db main +} {B} +do_test backup-4.5.2 { + B step 5000 +} {SQLITE_READONLY} +do_test backup-4.5.3 { + B finish +} {SQLITE_READONLY} + +db close +db2 close +# +# End of backup-4.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# The following tests, backup-5.*, test that the backup works properly +# when the source database is modified during the backup. Test cases +# are organized as follows: +# +# backup-5.x.1.*: Nothing special. Modify the database mid-backup. +# +# backup-5.x.2.*: Modify the database mid-backup so that one or more +# pages are written out due to cache stress. Then +# rollback the transaction. +# +# backup-5.x.3.*: Database is vacuumed. +# +# backup-5.x.4.*: Database is vacuumed and the page-size modified. +# +# backup-5.x.5.*: Database is shrunk via incr-vacuum. +# +# Each test is run three times, in the following configurations: +# +# 1) Backing up file-to-file. The writer writes via an external pager. +# 2) Backing up file-to-file. The writer writes via the same pager as +# is used by the backup operation. +# 3) Backing up memory-to-file. +# +set iTest 0 +forcedelete bak.db-wal +foreach {writer file} {db test.db db3 test.db db :memory:} { + incr iTest + catch { delete_file bak.db } + sqlite3 db2 bak.db + catch { delete_file $file } + sqlite3 db $file + sqlite3 db3 $file + + do_test backup-5.$iTest.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + expr {[execsql {PRAGMA page_count}] > 10} + } {1} + do_test backup-5.$iTest.1.2 { + sqlite3_backup B db2 main db main + B step 5 + } {SQLITE_OK} + do_test backup-5.$iTest.1.3 { + execsql { UPDATE t1 SET a = a + 1 } $writer + B step 50 + } {SQLITE_DONE} + do_test backup-5.$iTest.1.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.1.5 db2 + test_contents backup-5.$iTest.1.6 db main db2 main + + do_test backup-5.$iTest.2.1 { + execsql { + PRAGMA cache_size = 10; + BEGIN; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT '', randstr(1000,1000) FROM t1; + COMMIT; + } + } {} + do_test backup-5.$iTest.2.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.2.3 { + execsql { + BEGIN; + UPDATE t1 SET a = a + 1; + ROLLBACK; + } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.2.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.2.5 db2 + test_contents backup-5.$iTest.2.6 db main db2 main + + do_test backup-5.$iTest.3.1 { + execsql { UPDATE t1 SET b = randstr(1000,1000) } + } {} + do_test backup-5.$iTest.3.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.3.3 { + execsql { VACUUM } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.3.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.3.5 db2 + test_contents backup-5.$iTest.3.6 db main db2 main + + do_test backup-5.$iTest.4.1 { + execsql { UPDATE t1 SET b = randstr(1000,1000) } + } {} + do_test backup-5.$iTest.4.2 { + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + do_test backup-5.$iTest.4.3 { + execsql { + PRAGMA page_size = 2048; + VACUUM; + } $writer + B step 5000 + } {SQLITE_DONE} + do_test backup-5.$iTest.4.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.4.5 db2 + test_contents backup-5.$iTest.4.6 db main db2 main + + catch {db close} + catch {db2 close} + catch {db3 close} + catch { delete_file bak.db } + sqlite3 db2 bak.db + catch { delete_file $file } + sqlite3 db $file + sqlite3 db3 $file + do_test backup-5.$iTest.5.1 { + execsql { + PRAGMA auto_vacuum = incremental; + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } + } {} + do_test backup-5.$iTest.5.2 { + sqlite3_backup B db2 main db main + B step 8 + } {SQLITE_OK} + do_test backup-5.$iTest.5.3 { + execsql { + DELETE FROM t1; + PRAGMA incremental_vacuum; + } $writer + B step 50 + } {SQLITE_DONE} + do_test backup-5.$iTest.5.4 { + B finish + } {SQLITE_OK} + integrity_check backup-5.$iTest.5.5 db2 + test_contents backup-5.$iTest.5.6 db main db2 main + catch {db close} + catch {db2 close} + catch {db3 close} +} +# +# End of backup-5.* tests. +#--------------------------------------------------------------------- + +#--------------------------------------------------------------------- +# Test the sqlite3_backup_remaining() and backup_pagecount() APIs. +# +do_test backup-6.1 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db test.db + sqlite3 db2 test2.db + execsql { + BEGIN; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + COMMIT; + } +} {} +do_test backup-6.2 { + set nTotal [expr {[file size test.db]/1024}] + sqlite3_backup B db2 main db main + B step 1 +} {SQLITE_OK} +do_test backup-6.3 { + B pagecount +} $nTotal +do_test backup-6.4 { + B remaining +} [expr $nTotal-1] +do_test backup-6.5 { + B step 5 + list [B remaining] [B pagecount] +} [list [expr $nTotal-6] $nTotal] +do_test backup-6.6 { + execsql { CREATE TABLE t2(a PRIMARY KEY, b) } + B step 1 + list [B remaining] [B pagecount] +} [list [expr $nTotal-5] [expr $nTotal+2]] + +do_test backup-6.X { + B finish +} {SQLITE_OK} + +catch {db close} +catch {db2 close} + +#--------------------------------------------------------------------- +# Test cases backup-7.* test that SQLITE_BUSY and SQLITE_LOCKED errors +# are returned correctly: +# +# backup-7.1.*: Source database is externally locked (return SQLITE_BUSY). +# +# backup-7.2.*: Attempt to step the backup process while a +# write-transaction is underway on the source pager (return +# SQLITE_LOCKED). +# +# backup-7.3.*: Destination database is externally locked (return SQLITE_BUSY). +# +do_test backup-7.0 { + catch { forcedelete test.db } + catch { forcedelete test2.db } + sqlite3 db2 test2.db + sqlite3 db test.db + execsql { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1; + } +} {} + +do_test backup-7.1.1 { + sqlite3_backup B db2 main db main + B step 5 +} {SQLITE_OK} +do_test backup-7.1.2 { + sqlite3 db3 test.db + execsql { BEGIN EXCLUSIVE } db3 + B step 5 +} {SQLITE_BUSY} +do_test backup-7.1.3 { + execsql { ROLLBACK } db3 + B step 5 +} {SQLITE_OK} +do_test backup-7.2.1 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(1, 4); + } +} {} +do_test backup-7.2.2 { + B step 5000 +} {SQLITE_BUSY} +do_test backup-7.2.3 { + execsql { ROLLBACK } + B step 5000 +} {SQLITE_DONE} +do_test backup-7.2.4 { + B finish +} {SQLITE_OK} +test_contents backup-7.2.5 db main db2 main +integrity_check backup-7.3.6 db2 + +do_test backup-7.3.1 { + db2 close + db3 close + forcedelete test2.db + sqlite3 db2 test2.db + sqlite3 db3 test2.db + + sqlite3_backup B db2 main db main + execsql { BEGIN ; CREATE TABLE t2(a, b); } db3 + + B step 5 +} {SQLITE_BUSY} +do_test backup-7.3.2 { + execsql { COMMIT } db3 + B step 5000 +} {SQLITE_DONE} +do_test backup-7.3.3 { + B finish +} {SQLITE_OK} +test_contents backup-7.3.4 db main db2 main +integrity_check backup-7.3.5 db2 +catch { db2 close } +catch { db3 close } + +#----------------------------------------------------------------------- +# The following tests, backup-8.*, test attaching multiple backup +# processes to the same source database. Also, reading from the source +# database while a read transaction is active. +# +# These tests reuse the database "test.db" left over from backup-7.*. +# +do_test backup-8.1 { + catch { forcedelete test2.db } + catch { forcedelete test3.db } + sqlite3 db2 test2.db + sqlite3 db3 test3.db + + sqlite3_backup B2 db2 main db main + sqlite3_backup B3 db3 main db main + list [B2 finish] [B3 finish] +} {SQLITE_OK SQLITE_OK} +do_test backup-8.2 { + sqlite3_backup B3 db3 main db main + sqlite3_backup B2 db2 main db main + list [B2 finish] [B3 finish] +} {SQLITE_OK SQLITE_OK} +do_test backup-8.3 { + sqlite3_backup B2 db2 main db main + sqlite3_backup B3 db3 main db main + B2 step 5 +} {SQLITE_OK} +do_test backup-8.4 { + execsql { + BEGIN; + SELECT * FROM sqlite_master; + } + B3 step 5 +} {SQLITE_OK} +do_test backup-8.5 { + list [B3 step 5000] [B3 finish] +} {SQLITE_DONE SQLITE_OK} +do_test backup-8.6 { + list [B2 step 5000] [B2 finish] +} {SQLITE_DONE SQLITE_OK} +test_contents backup-8.7 db main db2 main +test_contents backup-8.8 db main db3 main +do_test backup-8.9 { + execsql { PRAGMA lock_status } +} {main shared temp closed} +do_test backup-8.10 { + execsql COMMIT +} {} +catch { db2 close } +catch { db3 close } + +#----------------------------------------------------------------------- +# The following tests, backup-9.*, test that: +# +# * Passing 0 as an argument to sqlite3_backup_step() means no pages +# are backed up (backup-9.1.*), and +# * Passing a negative value as an argument to sqlite3_backup_step() means +# all pages are backed up (backup-9.2.*). +# +# These tests reuse the database "test.db" left over from backup-7.*. +# +do_test backup-9.1.1 { + sqlite3 db2 test2.db + sqlite3_backup B db2 main db main + B step 1 +} {SQLITE_OK} +do_test backup-9.1.2 { + set nRemaining [B remaining] + expr {$nRemaining>100} +} {1} +do_test backup-9.1.3 { + B step 0 +} {SQLITE_OK} +do_test backup-9.1.4 { + B remaining +} $nRemaining + +do_test backup-9.2.1 { + B step -1 +} {SQLITE_DONE} +do_test backup-9.2.2 { + B remaining +} {0} +do_test backup-9.2.3 { + B finish +} {SQLITE_OK} +catch {db2 close} + +ifcapable memorymanage { + db close + forcedelete test.db + forcedelete bak.db + + sqlite3 db test.db + sqlite3 db2 test.db + sqlite3 db3 bak.db + + do_test backup-10.1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + CREATE INDEX i1 ON t1(a, b); + COMMIT; + } + } {} + do_test backup-10.1.2 { + sqlite3_backup B db3 main db2 main + B step 5 + } {SQLITE_OK} + do_test backup-10.1.3 { + execsql { + UPDATE t1 SET b = randstr(500,500); + } + } {} + sqlite3_release_memory [expr 1024*1024] + do_test backup-10.1.3 { + B step 50 + } {SQLITE_DONE} + do_test backup-10.1.4 { + B finish + } {SQLITE_OK} + do_test backup-10.1.5 { + execsql { PRAGMA integrity_check } db3 + } {ok} + + db2 close + db3 close +} + + +#----------------------------------------------------------------------- +# Test that if the database is written to via the same database handle being +# used as the source by a backup operation: +# +# 10.1.*: If the db is in-memory, the backup is restarted. +# 10.2.*: If the db is a file, the backup is not restarted. +# +db close +forcedelete test.db test.db-journal +foreach {tn file rc} { + 1 test.db SQLITE_DONE + 2 :memory: SQLITE_OK +} { + do_test backup-10.$tn.1 { + sqlite3 db $file + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB); + BEGIN; + INSERT INTO t1 VALUES(NULL, randomblob(200)); + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(200) FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } + } {256} + + do_test backup-10.$tn.2 { + set pgs [execsql {pragma page_count}] + expr {$pgs > 50 && $pgs < 75} + } {1} + + do_test backup-10.$tn.3 { + forcedelete bak.db bak.db-journal + sqlite3 db2 bak.db + sqlite3_backup B db2 main db main + B step 50 + } {SQLITE_OK} + + do_test backup-10.$tn.4 { + execsql { UPDATE t1 SET b = randomblob(200) WHERE a IN (1, 250) } + } {} + + do_test backup-10.$tn.5 { + B step 50 + } $rc + + do_test backup-10.$tn.6 { + B finish + } {SQLITE_OK} + + db2 close +} + +# 2021-01-31 https://sqlite.org/forum/forumpost/8b39fbf3e7 +# +do_test backup-11.1 { + sqlite3 db1 :memory: + sqlite3 db2 :memory: + sqlite3_backup B db1 main db2 temp + B finish +} {SQLITE_OK} +db1 close +db2 close + +#------------------------------------------------------------------------- +do_test backup-12.1 { + sqlite3 db1 :memory: + sqlite3 db2 :memory: + db1 eval { + PRAGMA page_size = 8192; + CREATE TABLE t1(x); + } + db2 eval { + PRAGMA page_size = 1024; + CREATE TABLE t2(x); + } + + sqlite3_backup B db1 main db2 temp + B step 100 + B finish +} {SQLITE_READONLY} + + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/backup_ioerr.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/backup_ioerr.test new file mode 100644 index 0000000000000000000000000000000000000000..ca3fd3240d778d1b6fd19b59a66ffcf7a66b9f78 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/backup_ioerr.test @@ -0,0 +1,286 @@ +# 2009 January 30 +# +# 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. The +# focus of this file is testing the handling of IO errors by the +# sqlite3_backup_XXX APIs. +# +# $Id: backup_ioerr.test,v 1.3 2009/04/10 18:41:01 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc data_checksum {db file} { + $db one "SELECT md5sum(a, b) FROM ${file}.t1" +} +proc test_contents {name db1 file1 db2 file2} { + $db2 eval {select * from sqlite_master} + $db1 eval {select * from sqlite_master} + set checksum [data_checksum $db2 $file2] + uplevel [list do_test $name [list data_checksum $db1 $file1] $checksum] +} + +#-------------------------------------------------------------------- +# This proc creates a database of approximately 290 pages. Depending +# on whether or not auto-vacuum is configured. Test cases backup_ioerr-1.* +# verify nothing more than this assumption. +# +proc populate_database {db {xtra_large 0}} { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 SELECT a+ 1, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 2, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 4, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+ 8, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+16, randstr(1000,1000) FROM t1; + INSERT INTO t1 SELECT a+32, randstr(1000,1000) FROM t1; + CREATE INDEX i1 ON t1(b); + COMMIT; + } $db + if {$xtra_large} { + execsql { INSERT INTO t1 SELECT a+64, randstr(1000,1000) FROM t1 } $db + } +} +do_test backup_ioerr-1.1 { + populate_database db + set nPage [expr {[file size test.db] / 1024}] + expr {$nPage>130 && $nPage<160} +} {1} +do_test backup_ioerr-1.2 { + expr {[file size test.db] > $sqlite_pending_byte} +} {1} +do_test backup_ioerr-1.3 { + db close + forcedelete test.db +} {} + +# Turn off IO error simulation. +# +proc clear_ioerr_simulation {} { + set ::sqlite_io_error_hit 0 + set ::sqlite_io_error_hardhit 0 + set ::sqlite_io_error_pending 0 + set ::sqlite_io_error_persist 0 +} + +#-------------------------------------------------------------------- +# The following procedure runs with SQLite's IO error simulation +# enabled. +# +# 1) Start with a reasonably sized database. One that includes the +# pending-byte (locking) page. +# +# 2) Open a backup process. Set the cache-size for the destination +# database to 10 pages only. +# +# 3) Step the backup process N times to partially backup the database +# file. If an IO error is reported, then the backup process is +# concluded with a call to backup_finish(). +# +# If an IO error occurs, verify that: +# +# * the call to backup_step() returns an SQLITE_IOERR_XXX error code. +# +# * after the failed call to backup_step() but before the call to +# backup_finish() the destination database handle error code and +# error message remain unchanged. +# +# * the call to backup_finish() returns an SQLITE_IOERR_XXX error code. +# +# * following the call to backup_finish(), the destination database +# handle has been populated with an error code and error message. +# +# 4) Write to the database via the source database connection. Check +# that: +# +# * If an IO error occurs while writing the source database, the +# write operation should report an IO error. The backup should +# proceed as normal. +# +# * If an IO error occurs while updating the backup, the write +# operation should proceed normally. The error should be reported +# from the next call to backup_step() (in step 5 of this test +# procedure). +# +# 5) Step the backup process to finish the backup. If an IO error is +# reported, then the backup process is concluded with a call to +# backup_finish(). +# +# Test that if an IO error occurs, or if one occurred while updating +# the backup database during step 4, then the conditions listed +# under step 3 are all true. +# +# 6) Finish the backup process. +# +# * If the backup succeeds (backup_finish() returns SQLITE_OK), then +# the contents of the backup database should match that of the +# source database. +# +# * If the backup fails (backup_finish() returns other than SQLITE_OK), +# then the contents of the backup database should be as they were +# before the operation was started. +# +# The following factors are varied: +# +# * Destination database is initially larger than the source database, OR +# * Destination database is initially smaller than the source database. +# +# * IO errors are transient, OR +# * IO errors are persistent. +# +# * Destination page-size is smaller than the source. +# * Destination page-size is the same as the source. +# * Destination page-size is larger than the source. +# + +set iTest 1 +foreach bPersist {0 1} { +foreach iDestPagesize {512 1024 4096} { +foreach zSetupBak [list "" {populate_database ddb 1}] { + + incr iTest + set bStop 0 +for {set iError 1} {$bStop == 0} {incr iError} { + # Disable IO error simulation. + clear_ioerr_simulation + + catch { ddb close } + catch { sdb close } + catch { forcedelete test.db } + catch { forcedelete bak.db } + + # Open the source and destination databases. + sqlite3 sdb test.db + sqlite3 ddb bak.db + + # Step 1: Populate the source and destination databases. + populate_database sdb + ddb eval "PRAGMA page_size = $iDestPagesize" + ddb eval "PRAGMA cache_size = 10" + eval $zSetupBak + + # Step 2: Open the backup process. + sqlite3_backup B ddb main sdb main + + # Enable IO error simulation. + set ::sqlite_io_error_pending $iError + set ::sqlite_io_error_persist $bPersist + + # Step 3: Partially backup the database. If an IO error occurs, check + # a few things then skip to the next iteration of the loop. + # + set rc [B step 100] + if {$::sqlite_io_error_hardhit} { + + do_test backup_ioerr-$iTest.$iError.1 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.2 { + list [sqlite3_errcode ddb] [sqlite3_errmsg ddb] + } {SQLITE_OK {not an error}} + + set rc [B finish] + do_test backup_ioerr-$iTest.$iError.3 { + string match SQLITE_IOERR* $rc + } {1} + + do_test backup_ioerr-$iTest.$iError.4 { + sqlite3_errmsg ddb + } {disk I/O error} + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.5 ddb + + continue + } + + # No IO error was encountered during step 3. Check that backup_step() + # returned SQLITE_OK before proceding. + do_test backup_ioerr-$iTest.$iError.6 { + expr {$rc eq "SQLITE_OK"} + } {1} + + # Step 4: Write to the source database. + set rc [catchsql { UPDATE t1 SET b = randstr(1000,1000) WHERE a < 50 } sdb] + + if {[lindex $rc 0] && $::sqlite_io_error_persist==0} { + # The IO error occurred while updating the source database. In this + # case the backup should be able to continue. + set rc [B step 5000] + if { $rc != "SQLITE_IOERR_UNLOCK" } { + do_test backup_ioerr-$iTest.$iError.7 { + list [B step 5000] [B finish] + } {SQLITE_DONE SQLITE_OK} + + clear_ioerr_simulation + test_contents backup_ioerr-$iTest.$iError.8 ddb main sdb main + integrity_check backup_ioerr-$iTest.$iError.9 ddb + } else { + do_test backup_ioerr-$iTest.$iError.10 { + B finish + } {SQLITE_IOERR_UNLOCK} + } + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.11 ddb + + continue + } + + # Step 5: Finish the backup operation. If an IO error occurs, check that + # it is reported correctly and skip to the next iteration of the loop. + # + set rc [B step 5000] + if {$rc != "SQLITE_DONE"} { + do_test backup_ioerr-$iTest.$iError.12 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.13 { + list [sqlite3_errcode ddb] [sqlite3_errmsg ddb] + } {SQLITE_OK {not an error}} + + set rc [B finish] + do_test backup_ioerr-$iTest.$iError.14 { + string match SQLITE_IOERR* $rc + } {1} + do_test backup_ioerr-$iTest.$iError.15 { + sqlite3_errmsg ddb + } {disk I/O error} + + clear_ioerr_simulation + sqlite3 ddb bak.db + integrity_check backup_ioerr-$iTest.$iError.16 ddb + + continue + } + + # The backup was successfully completed. + # + do_test backup_ioerr-$iTest.$iError.17 { + list [set rc] [B finish] + } {SQLITE_DONE SQLITE_OK} + + clear_ioerr_simulation + sqlite3 sdb test.db + sqlite3 ddb bak.db + + test_contents backup_ioerr-$iTest.$iError.18 ddb main sdb main + integrity_check backup_ioerr-$iTest.$iError.19 ddb + + set bStop [expr $::sqlite_io_error_pending<=0] +}}}} + +catch { sdb close } +catch { ddb close } +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/badutf2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/badutf2.test new file mode 100644 index 0000000000000000000000000000000000000000..64a730d6facd3f60dd65a8fc36f5a44e0f51d496 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/badutf2.test @@ -0,0 +1,127 @@ +# 2011 March 15 +# +# 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. +# +# This file checks to make sure SQLite is able to gracEFully +# handle malformed UTF-8. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc utf8_to_ustr2 {s} { + set r "" + foreach i [split $s ""] { + scan $i %c c + append r [format \\u%04.4X $c] + } + set r +} + +proc utf8_to_hstr {in} { + regsub -all -- {(..)} $in {%[format "%s" \1]} out + subst $out +} + +proc utf8_to_xstr {in} { + regsub -all -- {(..)} $in {\\\\x[format "%s" \1]} out + subst $out +} + +proc utf8_to_ustr {in} { + regsub -all -- {(..)} $in {\\\\u[format "%04.4X" 0x\1]} out + subst $out +} + +do_test badutf2-1.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = 'UTF-8'" +} {} + +do_test badutf2-4.0 { + set S [sqlite3_prepare_v2 db "SELECT ?" -1 dummy] + sqlite3_expired $S +} {0} + +foreach { i len uval xstr ustr u2u } { +1 1 00 \x00 {} {} +2 1 01 \x01 "\\u0001" 01 +3 1 3F \x3F "\\u003F" 3F +4 1 7F \x7F "\\u007F" 7F +5 1 80 \x80 "\\u0080" C280 +6 1 C3BF \xFF "\\u00FF" C3BF +7 3 EFBFBD \xEF\xBF\xBD "\\uFFFD" {} +} { + + set hstr [ utf8_to_hstr $uval ] + + ifcapable bloblit { + if {$hstr != "%00"} { + do_test badutf2-2.1.$i { + set sql "SELECT '$hstr'=CAST(x'$uval' AS text) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } {1} + do_test badutf2-2.2.$i { + set sql "SELECT CAST('$hstr' AS blob)=x'$uval' AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } {1} + } + do_test badutf2-2.3.$i { + set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + do_test badutf2-2.4.$i { + set sql "SELECT hex(CAST(x'$uval' AS text)) AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + } + + if {$hstr != "%00"} { + do_test badutf2-3.1.$i { + set sql "SELECT hex('$hstr') AS x;" + set res [ sqlite3_exec db $sql ] + lindex [ lindex $res 1] 1 + } $uval + } + + # Tcl 8.7 and later do automatic bad-utf8 correction for + # characters 0x80 thru 0x9f so test case 5 does not work here. + if {$i==5 && $tcl_version>=8.7} { + # no-op + } else { + do_test badutf2-4.1.$i { + sqlite3_reset $S + sqlite3_bind_text $S 1 $xstr $len + sqlite3_step $S + utf8_to_ustr2 [ sqlite3_column_text $S 0 ] + } $ustr + } + + ifcapable debug { + do_test badutf2-5.1.$i { + utf8_to_utf8 $uval + } $u2u + } + +} + +do_test badutf2-4.2 { + sqlite3_finalize $S +} {SQLITE_OK} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/base85.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/base85.test new file mode 100644 index 0000000000000000000000000000000000000000..bb723b3720a582c03465646893ef1a4f0b64905a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/base85.test @@ -0,0 +1,24 @@ +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix basexx + +if {[catch {load_static_extension db basexx} error]} { + puts "Skipping basexx tests, hit load error: $error" + finish_test; return +} + +# Test the 'z' expansion functionality +# (SQL-006) +do_execsql_test basexx-z-test-1 { + select hex(base85('z')); +} {00000000} + +do_execsql_test basexx-z-test-3 { + select hex(base85('KHkS=z0I1c-$6')); +} {74657374000000002066740C65} + +do_execsql_test basexx-z-test-4 { + select hex(base85('KHkS=0I1c-$6')); +} {746573742066740C65} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/basexx1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/basexx1.test new file mode 100644 index 0000000000000000000000000000000000000000..9030b51915323e3976847c1e4aa0e59e5908023a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/basexx1.test @@ -0,0 +1,168 @@ +# 2022 November 22 +# +# 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 basexx + +if {[catch {load_static_extension db basexx} error]} { + puts "Skipping basexx tests, hit load error: $error" + finish_test; return +} + +# Empty blobs encode to empty strings. +do_execsql_test 100 { + SELECT base64(x'')||base85(x''); +} {{}} + +# Empty strings decode to empty blobs. +do_execsql_test 101 { + SELECT hex(x'01'||base64('')||base85('')||x'02'); +} {0102} + +# Basic base64 encoding +do_execsql_test 102 { + SELECT base64(x'000102030405'); + SELECT base64(x'0001020304'); + SELECT base64(x'00010203'); +} {{AAECAwQF +} {AAECAwQ= +} {AAECAw== +}} + +# Basic base64 decoding with pad chars +do_execsql_test 103 { + SELECT hex(base64('AAECAwQF')); + SELECT hex(base64('AAECAwQ=')); + SELECT hex(base64('AAECAw==')); +} {000102030405 0001020304 00010203} + +# Basic base64 decoding without pad chars and with whitespace +do_execsql_test 104 { + SELECT hex(base64(' AAECAwQF ')); + SELECT hex(base64(' AAECAwQ')); + SELECT hex(base64('AAECAw ')); +} {000102030405 0001020304 00010203} + +# Basic base85 encoding +do_execsql_test 105 { + SELECT base85(x'000102030405'); + SELECT base85(x'0001020304'); + SELECT base85(x'00010203'); +} {{##/2,#2/ +} {##/2,#* +} {##/2, +}} + +# Basic base85 decoding with and without whitespace +do_execsql_test 106 { + SELECT hex(base85('##/2,#2/')); + SELECT hex(base85('##/2,#*')); + SELECT hex(base85('##/2,')); + SELECT hex(base85(' ##/2,#2/ ')); + SELECT hex(base85(' ##/2,#*')); + SELECT hex(base85('##/2, ')); +} {000102030405 0001020304 00010203 000102030405 0001020304 00010203} + +# Round-trip some random blobs. +do_execsql_test 107 { + CREATE TEMP TABLE rb( len int, b blob ) STRICT; + INSERT INTO rb(len) VALUES (1),(2),(3),(4),(5),(150),(151),(152),(153),(1054); + UPDATE rb SET b = randomblob(len); + SELECT len, base64(base64(b))=b, base85(base85(b))=b + FROM rb ORDER BY len; +} {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} + +# Same round-trip but with space or junk prepended and/or appended or not. +do_execsql_test 108 { + CREATE TEMP TABLE junk(j text, rank int); + INSERT INTO junk VALUES ('',0),(' ',1),('~',2); + SELECT len, base64(j.j||base64(b)||j.j)=b, base85(j.j||base85(b)||j.j)=b + FROM rb r, junk j WHERE j.rank=(r.len+r.len/25)%3 ORDER BY len; +} {1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 150 1 1 151 1 1 152 1 1 153 1 1 1054 1 1} + +# Exercise the fail-on-too-large result feature. + +set inLimit [sqlite3_limit db SQLITE_LIMIT_LENGTH -1] +sqlite3_limit db SQLITE_LIMIT_LENGTH 1300 + +do_catchsql_test 109 { + SELECT len, base64(b) FROM rb WHERE len>200; +} {1 {blob expanded to base64 too big}} + +do_catchsql_test 110 { + SELECT len, base85(b) FROM rb WHERE len>200; +} {1 {blob expanded to base85 too big}} + +do_catchsql_test 111 { + SELECT length(base85(b))=1335 FROM rb WHERE len=1054; +} {1 {blob expanded to base85 too big}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH $inLimit + +# Exercise is_base85(t) + +do_execsql_test 112 { + SELECT is_base85(' '||base85(x'123456')||char(10)), + is_base85('#$%&*+,-./0123456789:;<=>?@' + ||'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + ||'[\]^_`' + ||'abcdefghijklmnopqrstuvwxyz'), + is_base85('!'), is_base85('"'), is_base85(''''), is_base85('('), + is_base85(')'), is_base85(char(123)), is_base85('|'), is_base85(char(125)), + is_base85('~'), is_base85(char(127)); +} {1 1 0 0 0 0 0 0 0 0 0 0} + +do_execsql_test 113 { + SELECT is_base85(NULL) IS NULL; +} {1} + +do_catchsql_test 114 { + SELECT is_base85(1); +} {1 {is_base85 accepts only text or NULL}} + +do_catchsql_test 115 { + SELECT is_base85(1.1); +} {1 {is_base85 accepts only text or NULL}} + +do_catchsql_test 116 { + SELECT is_base85(x'00'); +} {1 {is_base85 accepts only text or NULL}} + +# Round-trip many bigger random blobs. + +do_execsql_test 117 { + CREATE TABLE bs(b blob, num); + INSERT INTO bs SELECT randomblob(4000 + n%3), n + FROM ( + WITH RECURSIVE seq(n) AS ( + VALUES(1) UNION ALL SELECT n+1 + FROM seq WHERE n<100 + ) SELECT n FROM seq); + SELECT num FROM bs WHERE base64(base64(b))!=b; + SELECT num FROM bs WHERE base85(base85(b))!=b; +} {} + +# Test the 'z' expansion functionality +do_execsql_test basexx-z-test-1 { + select hex(base85('z')); +} {00000000} + +do_execsql_test basexx-z-test-3 { + select hex(base85('KHkS=z0I1c-$6')); +} {74657374000000002066740C65} + +do_execsql_test basexx-z-test-4 { + select hex(base85('KHkS=0I1c-$6')); +} {746573742066740C65} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bc_common.tcl b/local-test-sqlite3-delta-01/afc-sqlite3/test/bc_common.tcl new file mode 100644 index 0000000000000000000000000000000000000000..c47f99681fb7d61c40afe6c8ef64384968daa935 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bc_common.tcl @@ -0,0 +1,75 @@ + + + +proc bc_find_binaries {zCaption} { + # Search for binaries to test against. Any executable files that match + # our naming convention are assumed to be testfixture binaries to test + # against. + # + set binaries [list] + set self [info nameofexec] + set pattern "$self?*" + if {$::tcl_platform(platform)=="windows"} { + set pattern [string map {\.exe {}} $pattern] + } + foreach file [glob -nocomplain $pattern] { + if {$file==$self} continue + if {[file executable $file] && [file isfile $file]} {lappend binaries $file} + } + + if {[llength $binaries]==0} { + puts "WARNING: No historical binaries to test against." + puts "WARNING: Omitting backwards-compatibility tests" + } + + foreach bin $binaries { + puts -nonewline "Testing against $bin - " + flush stdout + puts "version [get_version $bin]" + } + + set ::BC(binaries) $binaries + return $binaries +} + +proc get_version {binary} { + set chan [launch_testfixture $binary] + set v [testfixture $chan { sqlite3 -version }] + close $chan + set v +} + +proc do_bc_test {bin script} { + + forcedelete test.db + set ::bc_chan [launch_testfixture $bin] + + proc code1 {tcl} { uplevel #0 $tcl } + proc code2 {tcl} { testfixture $::bc_chan $tcl } + proc sql1 sql { code1 [list db eval $sql] } + proc sql2 sql { code2 [list db eval $sql] } + + code1 { sqlite3 db test.db } + code2 { sqlite3 db test.db } + + set bintag $bin + regsub {.*testfixture\.} $bintag {} bintag + set bintag [string map {\.exe {}} $bintag] + if {$bintag == ""} {set bintag self} + set saved_prefix $::testprefix + append ::testprefix ".$bintag" + + uplevel $script + + set ::testprefix $saved_prefix + + catch { code1 { db close } } + catch { code2 { db close } } + catch { close $::bc_chan } +} + +proc do_all_bc_test {script} { + foreach bin $::BC(binaries) { + uplevel [list do_bc_test $bin $script] + } +} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex1.test new file mode 100644 index 0000000000000000000000000000000000000000..e505a8bc4c45512b9f00572dda88c91333d038ea --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex1.test @@ -0,0 +1,344 @@ +# 2016-03-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 bestindex1 + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + if {[llength $clist]!=1} { error "unexpected constraint list" } + catch { array unset C } + array set C [lindex $clist 0] + if {$C(usable)} { + return "omit 0 cost 0 rows 1 idxnum 555 idxstr eq!" + } else { + return "cost 1000000 rows 0 idxnum 0 idxstr scan..." + } + } + + } + + return {} +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); +} {} + +do_eqp_test 1.1 { + SELECT * FROM x1 WHERE a = 'abc' +} {SCAN x1 VIRTUAL TABLE INDEX 555:eq!} + +do_eqp_test 1.2 { + SELECT * FROM x1 WHERE a IN ('abc', 'def'); +} {SCAN x1 VIRTUAL TABLE INDEX 555:eq!} + +#------------------------------------------------------------------------- +# +reset_db +register_tcl_module db + +# Parameter $mode may be one of: +# +# "omit" - Implement filtering. Set the omit flag. +# "use" - Implement filtering. Use the constraint, but do not set omit. +# "use2" - Do not implement filtering. Use the constraint anyway. +# +# +proc t1_vtab {mode method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + set SQL_FILTER {SELECT * FROM t1x WHERE a='%1%'} + set SQL_SCAN {SELECT * FROM t1x} + + set idx 0 + for {set idx 0} {$idx < [llength $clist]} {incr idx} { + array unset C + array set C [lindex $clist $idx] + if {$C(column)==0 && $C(op)=="eq" && $C(usable)} { + switch -- $mode { + "omit" { + return [list omit $idx rows 10 cost 10 idxstr $SQL_FILTER] + } + "use" { + return [list use $idx rows 10 cost 10 idxstr $SQL_FILTER] + } + "use2" { + return [list use $idx rows 10 cost 10 idxstr $SQL_SCAN] + } + default { + error "Bad mode - $mode" + } + } + } + } + + return [list idxstr {SELECT * FROM t1x}] + } + + xFilter { + set map [list %1% [lindex $args 2 0]] + set sql [string map $map [lindex $args 1]] + return [list sql $sql] + } + } + + return {} +} + +do_execsql_test 2.1 { + CREATE TABLE t1x(i INTEGER PRIMARY KEY, a, b); + INSERT INTO t1x VALUES(1, 'one', 1); + INSERT INTO t1x VALUES(2, 'two', 2); + INSERT INTO t1x VALUES(3, 'three', 3); + INSERT INTO t1x VALUES(4, 'four', 4); +} + +foreach {tn mode} { + 1 use 2 omit 3 use2 +} { + do_execsql_test 2.2.$mode.1 " + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING tcl(t1_vtab $mode); + " + + do_execsql_test 2.2.$mode.2 {SELECT * FROM t1} {one 1 two 2 three 3 four 4} + do_execsql_test 2.2.$mode.3 {SELECT rowid FROM t1} {1 2 3 4} + do_execsql_test 2.2.$mode.4 {SELECT rowid FROM t1 WHERE a='two'} {2} + + do_execsql_test 2.2.$mode.5 { + SELECT rowid FROM t1 WHERE a IN ('one', 'four') ORDER BY +rowid + } {1 4} + + set plan(use) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x WHERE a='%1%' + `--USE TEMP B-TREE FOR ORDER BY + } + set plan(omit) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x WHERE a='%1%' + `--USE TEMP B-TREE FOR ORDER BY + } + set plan(use2) { + QUERY PLAN + |--SCAN t1 VIRTUAL TABLE INDEX 0:SELECT * FROM t1x + `--USE TEMP B-TREE FOR ORDER BY + } + + do_eqp_test 2.2.$mode.6 { + SELECT rowid FROM t1 WHERE a IN ('one', 'four') ORDER BY +rowid + } [string map {"\n " "\n"} $plan($mode)] +} + +# 2016-04-09. +# Demonstrate a register overwrite problem when using two virtual +# tables where the outer loop uses the IN operator. +# +set G(collist) [list PrimaryKey flagA columnA] +set G(cols) [join $G(collist) ,] +set G(nulls) "NULL" + +proc vtab_command {method args} { + global G + + switch -- $method { + xConnect { + return "CREATE TABLE t1($G(cols))" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + #puts $clist + set W [list] + set U [list] + + set i 0 + for {set idx 0} {$idx < [llength $clist]} {incr idx} { + array set c [lindex $clist $idx] + if {$c(op)=="eq" && $c(usable)} { + lappend W "[lindex $G(collist) $c(column)] = %$i%" + lappend U use $idx + incr i + } + } + + if {$W==""} { + set sql "SELECT rowid, * FROM t1" + } else { + set sql "SELECT rowid, * FROM t1 WHERE [join $W { AND }]" + } + + return [concat [list idxstr $sql] $U] + } + + xFilter { + foreach {idxnum idxstr vals} $args {} + + set map [list] + for {set i 0} {$i < [llength $vals]} {incr i} { + lappend map "%$i%" + set v [lindex $vals $i] + if {[string is integer $v]} { + lappend map $v + } else { + lappend map "'$v'" + } + } + set sql [string map $map $idxstr] + + #puts "SQL: $sql" + return [list sql $sql] + } + } + + return {} +} + +db close +forcedelete test.db +sqlite3 db test.db +register_tcl_module db + +do_execsql_test 3.1 " + CREATE TABLE t1($G(cols)); + INSERT INTO t1 VALUES(1, 0, 'ValueA'); + INSERT INTO t1 VALUES(2, 0, 'ValueA'); + INSERT INTO t1 VALUES(3, 0, 'ValueB'); + INSERT INTO t1 VALUES(4, 0, 'ValueB'); +" + +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE VirtualTableA USING tcl(vtab_command); + CREATE VIRTUAL TABLE VirtualTableB USING tcl(vtab_command); +} + +do_execsql_test 3.3 { SELECT primarykey FROM VirtualTableA } {1 2 3 4} + +do_execsql_test 3.4 { + SELECT * FROM + VirtualTableA a CROSS JOIN VirtualTableB b ON b.PrimaryKey=a.PrimaryKey + WHERE a.ColumnA IN ('ValueA', 'ValueB') AND a.FlagA=0 +} { + 1 0 ValueA 1 0 ValueA + 2 0 ValueA 2 0 ValueA + 3 0 ValueB 3 0 ValueB + 4 0 ValueB 4 0 ValueB +} + +do_execsql_test 3.5 { + SELECT * FROM + VirtualTableA a CROSS JOIN VirtualTableB b ON b.PrimaryKey=a.PrimaryKey + WHERE a.FlagA=0 AND a.ColumnA IN ('ValueA', 'ValueB') +} { + 1 0 ValueA 1 0 ValueA + 2 0 ValueA 2 0 ValueA + 3 0 ValueB 3 0 ValueB + 4 0 ValueB 4 0 ValueB +} + +#------------------------------------------------------------------------- +# If there is an IN(..) condition in the WHERE clause of a query on a +# virtual table, the xBestIndex method is first invoked with the IN(...) +# represented by a "usable" SQLITE_INDEX_CONSTRAINT_EQ constraint. If +# the virtual table elects to use the IN(...) constraint, then the +# xBestIndex method is invoked again, this time with the IN(...) marked +# as "not usable". Depending on the relative costs of the two plans as +# defined by the virtual table implementation, and the cardinality of the +# IN(...) operator, SQLite chooses the most efficient plan. +# +# At one point the second invocation of xBestIndex() was only being made +# for join queries. The following tests check that this problem has been +# fixed. +# +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c, d)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + lappend ::bestindex_calls $clist + set ret "cost 1000000 idxnum 555" + for {set i 0} {$i < [llength $clist]} {incr i} { + array set C [lindex $clist $i] + if {$C(usable)} { + lappend ret use $i + } + } + return $ret + } + } + return {} +} + +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); +} {} + +do_test 4.1 { + set ::bestindex_calls [list] + execsql { + SELECT * FROM x1 WHERE a=? AND b BETWEEN ? AND ? AND c IN (1, 2, 3, 4); + } + set ::bestindex_calls +} [list \ + [list {op eq column 0 usable 1} \ + {op eq column 2 usable 1} \ + {op ge column 1 usable 1} \ + {op le column 1 usable 1} \ + ] \ + [list {op eq column 0 usable 1} \ + {op eq column 2 usable 0} \ + {op ge column 1 usable 1} \ + {op le column 1 usable 1} + ] +] + +do_catchsql_test 5.0 { + SELECT * FROM tcl('abc'); +} {1 {wrong number of arguments}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex3.test new file mode 100644 index 0000000000000000000000000000000000000000..6aa3321c7b56bf57f9ec669143459886e2ae2700 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex3.test @@ -0,0 +1,185 @@ +# 2016 May 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 bestindex3 + +ifcapable !vtab { + finish_test + return +} + +#------------------------------------------------------------------------- +# Virtual table callback for a virtual table named $tbl. +# +# The table created is: +# +# "CREATE TABLE t1 (a, b, c)" +# +# This virtual table supports both LIKE and = operators on all columns. +# +proc vtab_cmd {bOmit method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + set mask [$hdl mask] + + set ret [list] + set use use + if {$bOmit} {set use omit} + + for {set i 0} {$i < [llength $clist]} {incr i} { + array unset C + array set C [lindex $clist $i] + if {$C(usable) && ($C(op)=="like" || $C(op)=="eq")} { + lappend ret $use $i + lappend ret idxstr + lappend ret "[lindex {a b c} $C(column)] [string toupper $C(op)] ?" + break + } + } + + if {$ret==""} { + lappend ret cost 1000000 rows 1000000 + } else { + lappend ret cost 100 rows 10 + } + return $ret + } + + xFilter { + foreach {idxnum idxstr param} $args {} + set where "" + if {$bOmit && $idxstr != ""} { + set where " WHERE [string map [list ? '$param' EQ =] $idxstr]" + } + return [list sql "SELECT rowid, * FROM ttt$where"] + } + } + return "" +} + +register_tcl_module db + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING tcl("vtab_cmd 0"); +} + +do_eqp_test 1.1 { + SELECT * FROM t1 WHERE a LIKE 'abc'; +} {SCAN t1 VIRTUAL TABLE INDEX 0:a LIKE ?} + +do_eqp_test 1.2 { + SELECT * FROM t1 WHERE a = 'abc'; +} {SCAN t1 VIRTUAL TABLE INDEX 0:a EQ ?} + +do_eqp_test 1.3 { + SELECT * FROM t1 WHERE a = 'abc' OR b = 'def'; +} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SCAN t1 VIRTUAL TABLE INDEX 0:a EQ ? + `--INDEX 2 + `--SCAN t1 VIRTUAL TABLE INDEX 0:b EQ ? +} + +do_eqp_test 1.4 { + SELECT * FROM t1 WHERE a LIKE 'abc%' OR b = 'def'; +} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SCAN t1 VIRTUAL TABLE INDEX 0:a LIKE ? + `--INDEX 2 + `--SCAN t1 VIRTUAL TABLE INDEX 0:b EQ ? +} + +do_execsql_test 1.5 { + CREATE TABLE ttt(a, b, c); + + INSERT INTO ttt VALUES(1, 'two', 'three'); + INSERT INTO ttt VALUES(2, 'one', 'two'); + INSERT INTO ttt VALUES(3, 'three', 'one'); + INSERT INTO ttt VALUES(4, 'y', 'one'); + INSERT INTO ttt VALUES(5, 'x', 'two'); + INSERT INTO ttt VALUES(6, 'y', 'three'); +} + +foreach omit {0 1} { + do_execsql_test 1.6.$omit.0 " + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING tcl('vtab_cmd $omit'); + " + do_execsql_test 1.6.$omit.1 { + SELECT rowid FROM t1 WHERE c LIKE 'o%' + } {3 4} + + do_execsql_test 1.6.$omit.2 { + SELECT rowid FROM t1 WHERE c LIKE 'o%' OR b='y' + } {3 4 6} + + do_execsql_test 1.6.$omit.3 { + SELECT rowid FROM t1 WHERE c = 'three' OR c LIKE 'o%' + } {1 6 3 4} +} + +#------------------------------------------------------------------------- +# Test the same pattern works with ordinary tables. +# +# This test does not work if the ICU extension is enabled. ICU overrides +# LIKE - and this optimization only works with the built-in LIKE function. +# +ifcapable !icu { + do_execsql_test 2.1 { + CREATE TABLE t2(x TEXT COLLATE nocase, y TEXT); + CREATE INDEX t2x ON t2(x COLLATE nocase); + CREATE INDEX t2y ON t2(y); + } + + do_eqp_test 2.2 { + SELECT * FROM t2 WHERE x LIKE 'abc%' OR y = 'def' + } [string map {"\n " \n} { + QUERY PLAN + `--MULTI-INDEX OR + |--INDEX 1 + | `--SEARCH t2 USING INDEX t2x (x>? AND x=0} + } $idxinsert + do_test 1.$tn.4 { + set ::lOrderByConsumed + } $bConsumed +} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set ret [list] + + set iCons 0 + foreach cons [$hdl constraints] { + array set C $cons + if {($C(op)=="limit" || $C(op)=="offset") && $C(usable)} { + lappend ret use $iCons + } + incr iCons + } + + return $ret + } + + xFilter { + lappend ::lFilterArgs [lindex $args 2] + return [list sql "SELECT rowid, a, b FROM $src"] + } + + } + + return {} +} + +do_execsql_test 2.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +do_test 2.1 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 LIMIT 10 } + set ::lFilterArgs +} {10} + +do_test 2.2 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 LIMIT 5 OFFSET 50 } + set ::lFilterArgs +} {{50 5}} + +do_test 2.3 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 ORDER BY a, b LIMIT 1 OFFSET 1 } + set ::lFilterArgs +} {{1 1}} + +do_test 2.4 { + set ::lFilterArgs [list] + execsql { SELECT * FROM vt1 ORDER BY a, +b LIMIT 1 OFFSET 1 } + set ::lFilterArgs +} {{}} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b)" + } + + xBestIndex { + set hdl [lindex $args 0] + set lCons [$hdl constraints] + + set ret [list] + for {set i 0} {$i < [llength $lCons]} {incr i} { + array set C [lindex $lCons $i] + if {$C(usable)} { + lappend ret use $i + $hdl in $i 1 + } + } + return $ret + } + + xFilter { + set lArg [lindex $args 2] + lappend ::lFilterArg {*}$lArg + return [list sql "SELECT rowid, a, b FROM $src"] + } + + } + + return {} +} + +do_execsql_test 3.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +foreach {tn sql lfa} { + 1 "SELECT * FROM vt1 WHERE b IN (10, 20, 30)" {{10 20 30}} + 2 "SELECT * FROM vt1 WHERE b IN ('abc', 'def')" {{abc def}} + 3 "SELECT * FROM vt1 WHERE a IS NULL AND b IN ('abc', 'def')" {{} {abc def}} + 4 "SELECT * FROM vt1 WHERE a IN (1,2,3) AND b IN ('abc', 'def')" + {{1 2 3} {abc def}} + + 5 "SELECT * FROM vt1 + WHERE a IN (SELECT 1 UNION SELECT 2) AND b IN ('abc', 'def')" + {{1 2} {abc def}} + + 6 "SELECT * FROM vt1 + WHERE b IN ('abc', 'def') AND a IN (SELECT 1 UNION SELECT 2)" + {{abc def} {1 2}} +} { + do_test 3.$tn { + set ::lFilterArg [list] + execsql $sql + set ::lFilterArg + } $lfa +} + +#explain_i { SELECT * FROM vt1 WHERE b IN (10, 20, 30) } + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set lCons [$hdl constraints] + + set ret [list] + for {set i 0} {$i < [llength $lCons]} {incr i} { + lappend ::lBestIndexRhs [$hdl rhs_value $i -] + } + return $ret + } + + xFilter { + return [list sql "SELECT rowid, a, b, c FROM $src"] + } + + } + + return {} +} + +do_execsql_test 4.0 { + CREATE TABLE t1(a, b, c); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); +} + +foreach {tn sql lbir} { + 1 "SELECT * FROM vt1 WHERE b = 10" {10} + 2 "SELECT * FROM vt1 WHERE a = 'abc' AND b < 30" {abc 30} + 3 "SELECT * FROM vt1 WHERE a = 'abc' AND b < 30+2" {abc -} + 4 "SELECT * FROM vt1 WHERE a IN (1,2,3) AND b < 30+2" {- -} + 5 "SELECT * FROM vt1 WHERE a IS 111 AND b < 30+2" {111 -} +} { + do_test 4.$tn { + set ::lBestIndexRhs [list] + execsql $sql + set ::lBestIndexRhs + } $lbir +} + +#------------------------------------------------------------------------- +reset_db +db cache size 0 +register_tcl_module db + +set ::vtab_handle_in 1 +proc vtab_command {src method args} { + switch -- $method { + xConnect { + return "CREATE TABLE xxx(a, b, c)" + } + + xBestIndex { + set lCols [list a b c] + + set hdl [lindex $args 0] + set lCons [$hdl constraints] + set lOrder [$hdl order] + + set L "" + set O "" + set W [list] + set a 0 + for {set i 0} {$i < [llength $lCons]} {incr i} { + array set C [lindex $lCons $i] + if {$C(usable)} { + if { $C(op)=="eq" } { + set bIn 0 + if {$::vtab_handle_in} { set bIn [$hdl in $i 1] } + if {$bIn} { + lappend W "[lindex $lCols $C(column)] IN (%I$a%)" + } else { + lappend W "[lindex $lCols $C(column)] = %$a%" + } + lappend ret omit $i + } + if { $C(op)=="limit" } { set L " LIMIT %$a%" ; lappend ret use $i } + if { $C(op)=="offset" } { set O " OFFSET %$a%" ; lappend ret use $i } + incr a + } + } + + set order "" + set selectlist "rowid, a, b, c" + if {[llength $lOrder]} { + array set sl [list] + set lO [list] + foreach s $lOrder { + array set C $s + set ad "" + if {$C(desc)} { set ad " DESC" } + lappend lO "[lindex $lCols $C(column)]$ad" + set sl($C(column)) 1 + } + if {[$hdl distinct]==2} { + set selectlist "DISTINCT 0" + foreach i {0 1 2} { + if {[info exists sl($i)]} { + append selectlist ", [lindex $lCols $i]" + } else { + append selectlist ", 0" + } + } + } else { + set order " ORDER BY [join $lO ,]" + } + } + + set where "" + if {[llength $W]} { set where " WHERE [join $W { AND }]" } + set sql "SELECT $selectlist FROM $src$where$order$L$O" + + lappend ret idxStr $sql + return $ret + } + + xFilter { + foreach {idxnum idxstr lArg} $args {} + set ii 0 + set sql $idxstr + foreach a $lArg { + set sql [string map [list %$ii% $a] $sql] + set sql [string map [list %I$ii% [join $a ,]] $sql] + incr ii + } + lappend ::lFilterSql $sql + + if {[regexp {OFFSET (.*)$} $sql -> off]} { + set real_sql " + WITH c(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<$off ) + SELECT 0,0,0,0 FROM c + UNION ALL SELECT * FROM ( + $sql + ) + " + } else { + set real_sql $sql + } + + return [list sql $real_sql] + } + + } + + return {} +} + +do_execsql_test 5.0 { + CREATE TABLE t1(a, b, c); + CREATE VIRTUAL TABLE vt1 USING tcl(vtab_command t1); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(2, 3, 4); + INSERT INTO t1 VALUES(3, 4, 5); + INSERT INTO t1 VALUES(1, 5, 6); + INSERT INTO t1 VALUES(2, 6, 7); + INSERT INTO t1 VALUES(3, 7, 8); + INSERT INTO t1 VALUES(1, 8, 9); + INSERT INTO t1 VALUES(2, 9, 0); +} + +proc do_vtab_test {tn sql vtsql {res {}}} { + set ::lFilterSql [list] + uplevel [list do_execsql_test $tn.1 $sql $res] + uplevel [list do_test $tn.2 {set ::lFilterSql} [list {*}$vtsql]] +} + +do_vtab_test 5.1.1 { + SELECT DISTINCT a FROM vt1 +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1} +} {1 2 3} + +do_vtab_test 5.1.2 { + SELECT DISTINCT a FROM vt1 ORDER BY a +} { + {SELECT rowid, a, b, c FROM t1 ORDER BY a} +} {1 2 3} + +do_vtab_test 5.1.3 { + SELECT DISTINCT a FROM vt1 WHERE c IN (4,5,6,7,8) +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c IN (4,5,6,7,8)} +} {2 3 1} + +set ::vtab_handle_in 0 +do_vtab_test 5.1.4 { + SELECT DISTINCT a FROM vt1 WHERE c IN (4,5,6,7,8) +} { + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 4} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 5} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 6} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 7} + {SELECT DISTINCT 0, a, 0, 0 FROM t1 WHERE c = 8} +} {2 3 1} + +set ::vtab_handle_in 1 +do_vtab_test 5.1.5a { + SELECT a, b, c FROM vt1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2 +} { + {SELECT rowid, a, b, c FROM t1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2} +} {1 5 6 2 6 7} + +set ::vtab_handle_in 0 +do_vtab_test 5.1.5b { + SELECT a, b, c FROM vt1 WHERE c IN (4,5,6,7,8) LIMIT 2 OFFSET 2 +} { + {SELECT rowid, a, b, c FROM t1 WHERE c = 4} + {SELECT rowid, a, b, c FROM t1 WHERE c = 5} + {SELECT rowid, a, b, c FROM t1 WHERE c = 6} + {SELECT rowid, a, b, c FROM t1 WHERE c = 7} +} {1 5 6 2 6 7} +set ::vtab_handle_in 1 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex9.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex9.test new file mode 100644 index 0000000000000000000000000000000000000000..d591b30efe507ba20b480d231f16a34713d90d29 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindex9.test @@ -0,0 +1,104 @@ +# 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 bestindex9 + +ifcapable !vtab { + finish_test + return +} + + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return $::create_table + } + + xBestIndex { + set hdl [lindex $args 0] + set ::vtab_orderby [$hdl orderby] + set ::vtab_distinct [$hdl distinct] + + return [list orderby 1] + } + + xFilter { + return "" + } + } + + return {} +} + +proc do_bestindex9_test {tn create select orderby distinct} { + forcedelete test.db2 + sqlite3 dbtest test.db2 + register_tcl_module dbtest + + set ::create_table $create + dbtest eval { CREATE VIRTUAL TABLE t1 USING tcl(vtab_command); } + dbtest eval $select + + do_test $tn.orderby [list set {} $::vtab_orderby] $orderby + do_test $tn.distinct [list set {} $::vtab_distinct] $distinct + + dbtest close +} + +#------------------------------------------------------------------------- +# +do_bestindex9_test 1.0 { + CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) +} { + SELECT DISTINCT k1, k2 FROM t1 +} {{column 0 desc 0} {column 1 desc 0}} 2 + +do_bestindex9_test 1.1 { + CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) WITHOUT ROWID +} { + SELECT DISTINCT k1, k2 FROM t1 +} {} 0 + +do_bestindex9_test 1.2 { + CREATE TABLE x(k1 NOT NULL, k2 NOT NULL, v1, PRIMARY KEY(k1, k2)) +} { + SELECT DISTINCT k1, k2 FROM t1 +} {} 0 + +#------------------------------------------------------------------------- +# +do_bestindex9_test 2 { + CREATE TABLE x(c1, c2, c3); +} { + SELECT DISTINCT c1 FROM t1 ORDER BY c1 +} {{column 0 desc 0}} 3 + +#------------------------------------------------------------------------- +# +do_bestindex9_test 3 { + CREATE TABLE x(c1, c2, c3); +} { + SELECT DISTINCT c1 FROM t1 GROUP BY c1 +} {{column 0 desc 0}} 1 + +do_bestindex9_test 4 { + CREATE TABLE x(c1, c2, c3); +} { + CREATE TABLE t2(balls); + SELECT DISTINCT c1 FROM t1, t2 +} {{column 0 desc 0}} 2 + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexB.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexB.test new file mode 100644 index 0000000000000000000000000000000000000000..b50e74fee3e29309fa389f97281ad6f4dc0d2fa2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexB.test @@ -0,0 +1,87 @@ +# 2023-10-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 bestindexB + +ifcapable !vtab { + finish_test + return +} + +register_tcl_module db + +proc vtab_command {method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + set orderby [$hdl orderby] + + if {[info exists ::xbestindex_sql]} { + explain_i $::xbestindex_sql + set ::xbestindex_res [ execsql $::xbestindex_sql ] + } + + return "cost 1000000 rows 1000000 idxnum 0 idxstr hello" + } + + xFilter { + return "sql {SELECT 0, 1, 2, 3}" + } + } + + return {} +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command); + CREATE TABLE y1(a, b); + CREATE TABLE y2(a, b); +} {} + +do_execsql_test 1.1 { + SELECT * FROM x1 +} {1 2 3} + +do_execsql_test 1.2 { + INSERT INTO y1 VALUES(1, 2) RETURNING rowid; +} {1} + +do_execsql_test 1.3 { + CREATE TRIGGER y1tr BEFORE INSERT ON y1 BEGIN + SELECT * FROM x1; + END; + INSERT INTO y1 VALUES(3, 4) RETURNING rowid; +} {2} + + +# This time, rig the xBestIndex() method of the vtab to invoke an SQL +# statement that uses RETURNING. +set ::xbestindex_sql { + INSERT INTO y2 VALUES(NULL, NULL) RETURNING rowid; +} +do_execsql_test 1.4 { + INSERT INTO y1 VALUES(5, 6) RETURNING rowid; +} {3} + +do_test 1.5 { + set ::xbestindex_res +} {1} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexC.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexC.test new file mode 100644 index 0000000000000000000000000000000000000000..48f3a2765597c3854f1ed58078d3ad0a9a885ac5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bestindexC.test @@ -0,0 +1,352 @@ +# 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}} + +#------------------------------------------------------------------------- +reset_db +register_tcl_module db + +proc quote {str} { + return "'[string map {' ''} $str]'" +} + +proc vtab_command {lVal method args} { + switch -- $method { + xConnect { + return "CREATE TABLE t1(a, b, c, d)" + } + + xBestIndex { + set hdl [lindex $args 0] + set clist [$hdl constraints] + + set res [list] + set idx 0 + set idxnum 0 + + set cols(0) a + set cols(1) b + set cols(2) c + + set lCons [list] + + foreach c $clist { + array set a $c + if {$a(usable)==0} continue + + if {($a(op)=="eq" || $a(op)=="is") && [info exists cols($a(column))]} { + lappend res omit $idx + set coll [$hdl collation $idx] + lappend lCons "$cols($a(column)) = %[llength $lCons]% COLLATE $coll" + + set idxnum [expr {$idx + (1 << $a(column))}] + catch { unset cols($a(column)) } + } + + incr idx + } + + if {[llength [array names cols]]>0} { + set missing [list] + for {set i 0} {$i < 3} {incr i} { + catch { lappend missing $cols($i) } + } + set msg "missing required constraints: [join $missing ,]" + return [list constraint $msg] + } + + set idxstr [join $lCons " AND "] + return "cost 1000 rows 1000 idxnum $idxnum $res idxstr {$idxstr}" + } + + xFilter { + foreach {idxnum idxstr lArg} $args {} + set i 0 + set where $idxstr + foreach a $lArg { + set where [string map [list %$i% [quote $a]] $where] + incr i + } + # puts $where + return [list sql "SELECT rowid, * FROM $lVal WHERE $where"] + } + } + + return {} +} + +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE x1 USING tcl(vtab_command t1); + CREATE TABLE t1(a, b, c, d); +} + +foreach {tn where ok} { + 0 "WHERE a=? AND b=? AND c=? AND c=?" 1 + 1 "WHERE a=? AND b=? AND c=?" 1 + 2 "WHERE a=? AND b=? AND (c=? OR c=?)" 1 + 3 "WHERE a=? AND b=? AND (c=? OR c=? OR c=?)" 1 + 4 "WHERE a=? AND b=? AND (c IS ? OR c IS ?)" 1 + 5 "WHERE a=? AND ((b=? AND c=?) OR (c=? AND b=?))" 1 + 6 "WHERE a=? AND ((b=? AND c=?) OR (c=?))" 0 +} { + do_test 5.2.$tn { + catch { execsql "SELECT * FROM x1 $::where" } msg +# if {$tn==0 || $tn==2 || $tn==3} { puts "MSG: $msg" } + } [expr !$ok] +} + +do_execsql_test 5.3 { + SELECT * FROM x1 WHERE (a, b, c) = (?, ?, ?); +} + +do_execsql_test 5.4 { + INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'z', 'one'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'X', 'Y', 'Z', 'two'); + SELECT * FROM x1 WHERE (a, b, c) = ('X', 'Y', 'Z'); +} {X Y Z two} +do_execsql_test 5.5 { + SELECT * FROM x1 WHERE a='x' AND b='y' AND c='z'; +} {x y z one} +do_execsql_test 5.6 { + SELECT * FROM x1 + WHERE a='x' COLLATE nocase AND b='y' COLLATE nocase AND c='z'COLLATE nocase; +} {x y z one X Y Z two} + +do_execsql_test 5.7 { + DELETE FROM t1; + + INSERT INTO t1(rowid, a, b, c, d) VALUES(0, 'x', 'y', 'z', 'zero'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(1, 'x', 'y', 'Z', 'one'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(2, 'x', 'Y', 'z', 'two'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(3, 'x', 'Y', 'Z', 'three'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(4, 'X', 'y', 'z', 'four'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(5, 'X', 'y', 'Z', 'five'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(6, 'X', 'Y', 'z', 'six'); + INSERT INTO t1(rowid, a, b, c, d) VALUES(7, 'X', 'Y', 'z', 'seven'); +} + +do_execsql_test 5.8 { + SELECT d FROM x1 + WHERE a='x' AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase)) +} { + zero two three +} + +do_execsql_test 5.9 { + SELECT d FROM x1 + WHERE a='x' COLLATE nocase + AND ((b='y' AND c='z') OR (b='Y' AND c='z' COLLATE nocase)) +} { + zero four two + three six seven +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/between.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/between.test new file mode 100644 index 0000000000000000000000000000000000000000..16c3913d12b913f9de89233b6f3d96b73b76dc59 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/between.test @@ -0,0 +1,143 @@ +# 2005 July 28 +# +# 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. The +# focus of this file is testing the use of indices in WHERE clauses +# when the WHERE clause contains the BETWEEN operator. +# +# $Id: between.test,v 1.2 2006/01/17 09:35:02 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Build some test data +# +do_test between-1.0 { + execsql { + BEGIN; + CREATE TABLE t1(w int, x int, y int, z int); + } + for {set i 1} {$i<=100} {incr i} { + set w $i + set x [expr {int(log($i)/log(2))}] + set y [expr {$i*$i + 2*$i + 1}] + set z [expr {$x+$y}] + ifcapable tclvar { + # Random unplanned test of the $varname variable syntax. + execsql {INSERT INTO t1 VALUES($::w,$::x,$::y,$::z)} + } else { + # If the $varname syntax is not available, use the regular variable + # declaration syntax. + execsql {INSERT INTO t1 VALUES(:w,:x,:y,:z)} + } + } + execsql { + CREATE UNIQUE INDEX i1w ON t1(w); + CREATE INDEX i1xy ON t1(x,y); + CREATE INDEX i1zyx ON t1(z,y,x); + COMMIT; + } +} {} + +# This procedure executes the SQL. Then it appends to the result the +# "sort" or "nosort" keyword depending on whether or not any sorting +# is done. Then it appends the names of the table and index used. +# +proc queryplan {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + set eqp [execsql "EXPLAIN QUERY PLAN $sql"] + # puts eqp=$eqp + foreach {a b c x} $eqp { + if {[regexp {(SCAN|SEARCH) (\w+ AS )?(\w+) USING.* INDEX (\w+)\y} \ + $x all ss as tab idx]} { + lappend data $tab $idx + } elseif {[regexp {(SCAN|SEARCH) (\w+ AS )?(\w+)\y} $x all ss as tab]} { + lappend data $tab * + } + } + return $data +} + +do_test between-1.1.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 5 AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.1.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 5 AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.2.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 5 AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.2.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 5 AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.3.1 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 41-y AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 i1w} +do_test between-1.3.2 { + queryplan { + SELECT * FROM t1 WHERE +w BETWEEN 41-y AND 6 ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.4 { + queryplan { + SELECT * FROM t1 WHERE w BETWEEN 41-y AND 65-y ORDER BY +w + } +} {5 2 36 38 6 2 49 51 sort t1 *} +do_test between-1.5.1 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN y AND z ORDER BY +w + } +} {4 2 25 27 sort t1 i1zyx} +do_test between-1.5.2 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN +y AND z ORDER BY +w + } +} {4 2 25 27 sort t1 i1zyx} +do_test between-1.5.3 { + queryplan { + SELECT * FROM t1 WHERE 26 BETWEEN y AND +z ORDER BY +w + } +} {4 2 25 27 sort t1 *} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test between-2.0 { + CREATE TABLE t1(x TEXT, y TEXT COLLATE nocase); + INSERT INTO t1 VALUES('0', 'abc'); +} + +foreach {tn expr res} { + 1 "x BETWEEN 1 AND '5'" 0 + 2 "x COLLATE binary BETWEEN 1 AND '5'" 0 + 3 "x COLLATE nocase BETWEEN 1 AND '5'" 0 + + 4 "y BETWEEN 'A' AND 'B'" 1 + 5 "y COLLATE nocase BETWEEN 'A' AND 'B'" 1 + 6 "y COLLATE binary BETWEEN 'A' AND 'B'" 0 + 7 "(y COLLATE binary) BETWEEN 'A' AND 'B'" 0 +} { + set sql "SELECT $expr FROM t1" + do_execsql_test between-2.1.$tn $sql $res +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bigfile.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigfile.test new file mode 100644 index 0000000000000000000000000000000000000000..31c632322c726b085a543fde874aeaa63b3cb472 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigfile.test @@ -0,0 +1,203 @@ +# 2002 November 30 +# +# 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. The +# focus of this script testing the ability of SQLite to handle database +# files larger than 4GB. +# +# $Id: bigfile.test,v 1.12 2009/03/05 04:27:08 shane Exp $ +# + +if {[file exists skip-big-file]} return +if {$tcl_platform(os)=="Darwin"} return + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for this file, as the database is manipulated using +# external methods (the [fake_big_file] and [hexio_write] commands). +# +do_not_use_codec + +# If SQLITE_DISABLE_LFS is defined, omit this file. +ifcapable !lfs { + finish_test + return +} + +# These tests only work for Tcl version 8.4 and later. Prior to 8.4, +# Tcl was unable to handle large files. +# +scan $::tcl_version %f vx +if {$vx<8.4} return + +# Mac OS X does not handle large files efficiently. So skip this test +# on that platform. +if {$tcl_platform(os)=="Darwin"} return + +# This is the md5 checksum of all the data in table t1 as created +# by the first test. We will use this number to make sure that data +# never changes. +# +set MAGIC_SUM {593f1efcfdbe698c28b4b1b693f7e4cf} + +do_test bigfile-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('abcdefghijklmnopqrstuvwxyz'); + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + INSERT INTO t1 SELECT rowid || ' ' || x FROM t1; + COMMIT; + } + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +# Try to create a large file - a file that is larger than 2^32 bytes. +# If this fails, it means that the system being tested does not support +# large files. So skip all of the remaining tests in this file. +# +db close +if {[catch {fake_big_file 4096 [get_pwd]/test.db} msg]} { + puts "**** Unable to create a file larger than 4096 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.2 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +# The previous test may fail on some systems because they are unable +# to handle large files. If that is so, then skip all of the following +# tests. We will know the above test failed because the "db" command +# does not exist. +# +if {[llength [info command db]]<=0} { + puts "**** Large file support appears to be broken. *****" + finish_test + return +} + +do_test bigfile-1.3 { + execsql { + CREATE TABLE t2 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.4 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM + +db close +if {[catch {fake_big_file 8192 [get_pwd]/test.db}]} { + puts "**** Unable to create a file larger than 8192 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.5 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.6 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.7 { + execsql { + CREATE TABLE t3 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM +do_test bigfile-1.8 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.9 { + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM + +db close +if {[catch {fake_big_file 16384 [get_pwd]/test.db}]} { + puts "**** Unable to create a file larger than 16384 MB. *****" + finish_test + return +} +hexio_write test.db 28 00000000 + +do_test bigfile-1.10 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.11 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.12 { + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM +do_test bigfile-1.13 { + execsql { + CREATE TABLE t4 AS SELECT * FROM t1; + SELECT md5sum(x) FROM t4; + } +} $::MAGIC_SUM +do_test bigfile-1.14 { + db close + sqlite3 db test.db + execsql { + SELECT md5sum(x) FROM t1; + } +} $::MAGIC_SUM +do_test bigfile-1.15 { + execsql { + SELECT md5sum(x) FROM t2; + } +} $::MAGIC_SUM +do_test bigfile-1.16 { + execsql { + SELECT md5sum(x) FROM t3; + } +} $::MAGIC_SUM + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bigmmap.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigmmap.test new file mode 100644 index 0000000000000000000000000000000000000000..ba9f8425242786e15c17fb4926b772f6f946f6d5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigmmap.test @@ -0,0 +1,108 @@ +# 2017 August 07 +# +# 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. The +# focus of this script testing the ability of SQLite to use mmap +# to access files larger than 4GiB. +# + +if {[file exists skip-big-file]} return +if {$tcl_platform(os)=="Darwin"} return + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix bigmmap + +ifcapable !mmap||!vtab { + finish_test + return +} + +set mmap_limit 0 +db eval { + SELECT compile_options AS x FROM pragma_compile_options + WHERE x LIKE 'max_mmap_size=%' +} { + regexp {MAX_MMAP_SIZE=([0-9]*)} $x -> mmap_limit +} +if {$mmap_limit < [expr 8 * 1<<30]} { + puts "Skipping bigmmap.test - requires SQLITE_MAX_MMAP_SIZE >= 8G" + finish_test + return +} + + +#------------------------------------------------------------------------- +# Create the database file roughly 8GiB in size. Most pages are unused, +# except that there is a table and index clustered around each 1GiB +# boundary. +# +do_execsql_test 1.0 { + PRAGMA page_size = 4096; + CREATE TABLE t0(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 ) + INSERT INTO t0 SELECT i, 't0', randomblob(800) FROM s; +} + +for {set i 1} {$i < 8} {incr i} { + if {[catch {fake_big_file [expr $i*1024] [get_pwd]/test.db}]} { + puts "Cannot create ${i}MB sparse file" + finish_test + return + } + hexio_write test.db 28 [format %.8x [expr ($i*1024*1024*1024/4096) - 5]] + + do_execsql_test 1.$i " + CREATE TABLE t$i (a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s LIMIT 100 ) + INSERT INTO t$i SELECT i, 't$i', randomblob(800) FROM s; + " +} + +#------------------------------------------------------------------------- +# Check that data can be retrieved from the db with a variety of +# configured mmap size limits. +# +for {set i 0} {$i < 9} {incr i} { + + # Configure a memory mapping $i GB in size. + # + set val [expr $i*1024*1024*1024] + execsql "PRAGMA main.mmap_size = $val" + do_execsql_test 2.$i.0 { + PRAGMA main.mmap_size + } $val + + for {set t 0} {$t < 8} {incr t} { + do_execsql_test 2.$i.$t.1 " + SELECT count(*) FROM t$t; + SELECT count(b || c) FROM t$t GROUP BY b; + " {100 100} + + do_execsql_test 2.$i.$t.2 " + SELECT * FROM t$t AS o WHERE + NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) + ORDER BY b, c; + " {} + + do_eqp_test 2.$i.$t.3 " + SELECT * FROM t$t AS o WHERE + NOT EXISTS( SELECT * FROM t$t AS i WHERE a=o.a AND +b=o.b AND +c=o.c ) + ORDER BY b, c; + " [string map {"\n " "\n"} " + QUERY PLAN + |--SCAN o USING COVERING INDEX sqlite_autoindex_t${t}_1 + `--CORRELATED SCALAR SUBQUERY xxxxxx + `--SEARCH i USING INTEGER PRIMARY KEY (rowid=?) + "] + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bigrow.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigrow.test new file mode 100644 index 0000000000000000000000000000000000000000..fa59c3625240a582a1d38e3826d895264e68c7ef --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bigrow.test @@ -0,0 +1,223 @@ +# 2001 September 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. The +# focus of this file is stressing the library by putting large amounts +# of data in a single row of a table. +# +# $Id: bigrow.test,v 1.5 2004/08/07 23:54:48 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Make a big string that we can use for test data +# +do_test bigrow-1.0 { + set ::bigstr {} + for {set i 1} {$i<=9999} {incr i} { + set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]] + append ::bigstr "$sep [format %04d $i] " + } + string length $::bigstr +} {69993} + +# Make a table into which we can insert some but records. +# +do_test bigrow-1.1 { + execsql { + CREATE TABLE t1(a text, b text, c text); + SELECT name FROM sqlite_master + WHERE type='table' OR type='index' + ORDER BY name + } +} {t1} + +do_test bigrow-1.2 { + set ::big1 [string range $::bigstr 0 65519] + set sql "INSERT INTO t1 VALUES('abc'," + append sql "'$::big1', 'xyz');" + execsql $sql + execsql {SELECT a, c FROM t1} +} {abc xyz} +do_test bigrow-1.3 { + execsql {SELECT b FROM t1} +} [list $::big1] +do_test bigrow-1.4 { + set ::big2 [string range $::bigstr 0 65520] + set sql "INSERT INTO t1 VALUES('abc2'," + append sql "'$::big2', 'xyz2');" + set r [catch {execsql $sql} msg] + lappend r $msg +} {0 {}} +do_test bigrow-1.4.1 { + execsql {SELECT b FROM t1 ORDER BY c} +} [list $::big1 $::big2] +do_test bigrow-1.4.2 { + execsql {SELECT c FROM t1 ORDER BY c} +} {xyz xyz2} +do_test bigrow-1.4.3 { + execsql {DELETE FROM t1 WHERE a='abc2'} + execsql {SELECT c FROM t1} +} {xyz} + +do_test bigrow-1.5 { + execsql { + UPDATE t1 SET a=b, b=a; + SELECT b,c FROM t1 + } +} {abc xyz} +do_test bigrow-1.6 { + execsql { + SELECT * FROM t1 + } +} [list $::big1 abc xyz] +do_test bigrow-1.7 { + execsql { + INSERT INTO t1 VALUES('1','2','3'); + INSERT INTO t1 VALUES('A','B','C'); + SELECT b FROM t1 WHERE a=='1'; + } +} {2} +do_test bigrow-1.8 { + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +do_test bigrow-1.9 { + execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a" +} {2 B} + +# Try doing some indexing on big columns +# +do_test bigrow-2.1 { + execsql { + CREATE INDEX i1 ON t1(a) + } + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +do_test bigrow-2.2 { + execsql { + UPDATE t1 SET a=b, b=a + } + execsql "SELECT b FROM t1 WHERE a=='abc'" +} [list $::big1] +do_test bigrow-2.3 { + execsql { + UPDATE t1 SET a=b, b=a + } + execsql "SELECT b FROM t1 WHERE a=='$::big1'" +} {abc} +catch {unset ::bigstr} +catch {unset ::big1} +catch {unset ::big2} + +# Mosts of the tests above were created back when rows were limited in +# size to 64K. Now rows can be much bigger. Test that logic. Also +# make sure things work correctly at the transition boundries between +# row sizes of 256 to 257 bytes and from 65536 to 65537 bytes. +# +# We begin by testing the 256..257 transition. +# +do_test bigrow-3.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +do_test bigrow-3.2 { + execsql { + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + } + execsql {SELECT a,length(b),c FROM t1} +} {one 240 hi} +for {set i 1} {$i<10} {incr i} { + do_test bigrow-3.3.$i { + execsql "UPDATE t1 SET b=b||'$i'" + execsql {SELECT a,length(b),c FROM t1} + } "one [expr {240+$i}] hi" +} + +# Now test the 65536..65537 row-size transition. +# +do_test bigrow-4.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +do_test bigrow-4.2 { + execsql { + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + UPDATE t1 SET b=b||b; + } + execsql {SELECT a,length(b),c FROM t1} +} {one 122880 hi} +do_test bigrow-4.3 { + execsql { + UPDATE t1 SET b=substr(b,1,65515) + } + execsql {SELECT a,length(b),c FROM t1} +} {one 65515 hi} +for {set i 1} {$i<10} {incr i} { + do_test bigrow-4.4.$i { + execsql "UPDATE t1 SET b=b||'$i'" + execsql {SELECT a,length(b),c FROM t1} + } "one [expr {65515+$i}] hi" +} + +# Check to make sure the library recovers safely if a row contains +# too much data. +# +do_test bigrow-5.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi'); + } + execsql {SELECT a,length(b),c FROM t1} +} {one 30 hi} +set i 1 +for {set sz 60} {$sz<1048560} {incr sz $sz} { + do_test bigrow-5.2.$i { + execsql { + UPDATE t1 SET b=b||b; + SELECT a,length(b),c FROM t1; + } + } "one $sz hi" + incr i +} +do_test bigrow-5.3 { + catchsql {UPDATE t1 SET b=b||b} +} {0 {}} +do_test bigrow-5.4 { + execsql {SELECT length(b) FROM t1} +} 1966080 +do_test bigrow-5.5 { + catchsql {UPDATE t1 SET b=b||b} +} {0 {}} +do_test bigrow-5.6 { + execsql {SELECT length(b) FROM t1} +} 3932160 +do_test bigrow-5.99 { + execsql {DROP TABLE t1} +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bind.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bind.test new file mode 100644 index 0000000000000000000000000000000000000000..8cafaab2bcaafbf0a8571ad233567a735696409b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bind.test @@ -0,0 +1,758 @@ +# 2003 September 6 +# +# 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. The +# focus of this script testing the sqlite_bind API. +# +# $Id: bind.test,v 1.48 2009/07/22 07:27:57 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc sqlite_step {stmt N VALS COLS} { + upvar VALS vals + upvar COLS cols + set vals [list] + set cols [list] + + set rc [sqlite3_step $stmt] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend cols [sqlite3_column_name $stmt $i] + } + for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} { + lappend vals [sqlite3_column_text $stmt $i] + } + + return $rc +} + +do_test bind-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c);} + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:1,?,:abc)} -1 TAIL] + set TAIL +} {} +do_test bind-1.1.1 { + sqlite3_bind_parameter_count $VM +} 3 +do_test bind-1.1.2 { + sqlite3_bind_parameter_name $VM 1 +} {:1} +do_test bind-1.1.3 { + sqlite3_bind_parameter_name $VM 2 +} {} +do_test bind-1.1.4 { + sqlite3_bind_parameter_name $VM 3 +} {:abc} +do_test bind-1.2 { + sqlite_step $VM N VALUES COLNAMES +} {SQLITE_DONE} +do_test bind-1.3 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {}} +do_test bind-1.4 { + sqlite3_reset $VM + sqlite_bind $VM 1 {test value 1} normal + sqlite_step $VM N VALUES COLNAMES +} SQLITE_DONE +do_test bind-1.5 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {} 2 {test value 1} {} {}} +do_test bind-1.6 { + sqlite3_reset $VM + sqlite_bind $VM 3 {'test value 2'} normal + sqlite_step $VM N VALUES COLNAMES +} SQLITE_DONE +do_test bind-1.7 { + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {} 2 {test value 1} {} {} 3 {test value 1} {} {'test value 2'}} +do_test bind-1.8 { + sqlite3_reset $VM + set sqlite_static_bind_value 123 + sqlite_bind $VM 1 {} static + sqlite_bind $VM 2 {abcdefg} normal + sqlite_bind $VM 3 {} null + execsql {DELETE FROM t1} + sqlite_step $VM N VALUES COLNAMES + execsql {SELECT rowid, * FROM t1} +} {1 123 abcdefg {}} +do_test bind-1.9 { + sqlite3_reset $VM + sqlite_bind $VM 1 {456} normal + sqlite_step $VM N VALUES COLNAMES + execsql {SELECT rowid, * FROM t1} +} {1 123 abcdefg {} 2 456 abcdefg {}} + +do_test bind-1.10 { + set rc [catch { + sqlite3_prepare db {INSERT INTO t1 VALUES($abc:123,?,:abc)} -1 TAIL + } msg] + lappend rc $msg +} {1 {(1) near ":123": syntax error}} +do_test bind-1.11 { + set rc [catch { + sqlite3_prepare db {INSERT INTO t1 VALUES(@abc:xyz,?,:abc)} -1 TAIL + } msg] + lappend rc $msg +} {1 {(1) near ":xyz": syntax error}} + +do_test bind-1.99 { + sqlite3_finalize $VM +} SQLITE_OK + +# Prepare the statement in different ways depending on whether or not +# the $var processing is compiled into the library. +# +ifcapable {tclvar} { + do_test bind-2.1 { + execsql { + DELETE FROM t1; + } + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES($one,$::two,$x(-z-))}\ + -1 TX] + set TX + } {} + set v1 {$one} + set v2 {$::two} + set v3 {$x(-z-)} +} +ifcapable {!tclvar} { + do_test bind-2.1 { + execsql { + DELETE FROM t1; + } + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(:one,:two,:_)} -1 TX] + set TX + } {} + set v1 {:one} + set v2 {:two} + set v3 {:_} +} + +do_test bind-2.1.1 { + sqlite3_bind_parameter_count $VM +} 3 +do_test bind-2.1.2 { + sqlite3_bind_parameter_name $VM 1 +} $v1 +do_test bind-2.1.3 { + sqlite3_bind_parameter_name $VM 2 +} $v2 +do_test bind-2.1.4 { + sqlite3_bind_parameter_name $VM 3 +} $v3 +do_test bind-2.1.5 { + sqlite3_bind_parameter_index $VM $v1 +} 1 +do_test bind-2.1.6 { + sqlite3_bind_parameter_index $VM $v2 +} 2 +do_test bind-2.1.7 { + sqlite3_bind_parameter_index $VM $v3 +} 3 +do_test bind-2.1.8 { + sqlite3_bind_parameter_index $VM {:hi} +} 0 + +# 32 bit Integers +do_test bind-2.2 { + sqlite3_bind_int $VM 1 123 + sqlite3_bind_int $VM 2 456 + sqlite3_bind_int $VM 3 789 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 123 456 789} +do_test bind-2.3 { + sqlite3_bind_int $VM 2 -2000000000 + sqlite3_bind_int $VM 3 2000000000 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 123 456 789 2 123 -2000000000 2000000000} +do_test bind-2.4 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer integer integer integer} +do_test bind-2.5 { + execsql { + DELETE FROM t1; + } +} {} + +# 64 bit Integers +do_test bind-3.1 { + sqlite3_bind_int64 $VM 1 32 + sqlite3_bind_int64 $VM 2 -2000000000000 + sqlite3_bind_int64 $VM 3 2000000000000 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 32 -2000000000000 2000000000000} +do_test bind-3.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {integer integer integer} +do_test bind-3.3 { + execsql { + DELETE FROM t1; + } +} {} + +# Doubles +do_test bind-4.1 { + sqlite3_bind_double $VM 1 1234.1234 + sqlite3_bind_double $VM 2 0.00001 + sqlite3_bind_double $VM 3 123456789 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + set x [execsql {SELECT rowid, * FROM t1}] + regsub {1e-005} $x {1e-05} y + set y +} {1 1234.1234 1e-05 123456789.0} +do_test bind-4.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {real real real} +do_test bind-4.3 { + execsql { + DELETE FROM t1; + } +} {} +do_test bind-4.4 { + sqlite3_bind_double $VM 1 NaN + sqlite3_bind_double $VM 2 1e300 + sqlite3_bind_double $VM 3 -1e-300 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + set x [execsql {SELECT rowid, * FROM t1}] + regsub {1e-005} $x {1e-05} y + set y +} {1 {} 1e+300 -1e-300} +do_test bind-4.5 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {null real real} +do_test bind-4.6 { + execsql { + DELETE FROM t1; + } +} {} + +# NULL +do_test bind-5.1 { + sqlite3_bind_null $VM 1 + sqlite3_bind_null $VM 2 + sqlite3_bind_null $VM 3 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 {} {} {}} +do_test bind-5.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {null null null} +do_test bind-5.3 { + execsql { + DELETE FROM t1; + } +} {} + +# UTF-8 text +do_test bind-6.1 { + sqlite3_bind_text $VM 1 hellothere 5 + sqlite3_bind_text $VM 2 ".." 1 + sqlite3_bind_text $VM 3 world\000 -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} +} {1 hello . world} +do_test bind-6.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} +do_test bind-6.3 { + execsql { + DELETE FROM t1; + } +} {} + +# Make sure zeros in a string work. +# +do_test bind-6.4 { + db eval {DELETE FROM t1} + sqlite3_bind_text $VM 1 hello\000there\000 12 + sqlite3_bind_text $VM 2 hello\000there\000 11 + sqlite3_bind_text $VM 3 hello\000there\000 -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT * FROM t1} +} {hello hello hello} +set enc [db eval {PRAGMA encoding}] +if {$enc=="UTF-8" || $enc==""} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {68656C6C6F00746865726500 68656C6C6F007468657265 68656C6C6F} +} elseif {$enc=="UTF-16le"} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {680065006C006C006F000000740068006500720065000000 680065006C006C006F00000074006800650072006500 680065006C006C006F00} +} elseif {$enc=="UTF-16be"} { + do_test bind-6.5 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {00680065006C006C006F0000007400680065007200650000 00680065006C006C006F000000740068006500720065 00680065006C006C006F} +} else { + do_test bind-6.5 { + set "Unknown database encoding: $::enc" + } {} +} +do_test bind-6.6 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} +} {text text text} +do_test bind-6.7 { + execsql { + DELETE FROM t1; + } +} {} + +# UTF-16 text +ifcapable {utf16} { + do_test bind-7.1 { + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hellothere] 10 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode ""] 0 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode world] 10 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT rowid, * FROM t1} + } {1 hello {} world} + do_test bind-7.2 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} + } {text text text} + do_test bind-7.3 { + db eval {DELETE FROM t1} + sqlite3_bind_text16 $VM 1 [encoding convertto unicode hi\000yall\000] 16 + sqlite3_bind_text16 $VM 2 [encoding convertto unicode hi\000yall\000] 14 + sqlite3_bind_text16 $VM 3 [encoding convertto unicode hi\000yall\000] -1 + sqlite_step $VM N VALUES COLNAMES + sqlite3_reset $VM + execsql {SELECT * FROM t1} + } {hi hi hi} + if {$enc=="UTF-8"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {68690079616C6C00 68690079616C6C 6869} + } elseif {$enc=="UTF-16le"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {680069000000790061006C006C000000 680069000000790061006C006C00 68006900} + } elseif {$enc=="UTF-16be"} { + do_test bind-7.4 { + execsql {SELECT hex(a), hex(b), hex(c) FROM t1} + } {00680069000000790061006C006C0000 00680069000000790061006C006C 00680069} + } + do_test bind-7.5 { + execsql {SELECT typeof(a), typeof(b), typeof(c) FROM t1} + } {text text text} +} +do_test bind-7.99 { + execsql {DELETE FROM t1;} +} {} + +# Test that the 'out of range' error works. +do_test bind-8.1 { + catch { sqlite3_bind_null $VM 0 } +} {1} +do_test bind-8.2 { + sqlite3_errmsg $DB +} {column index out of range} +ifcapable {utf16} { + do_test bind-8.3 { + encoding convertfrom unicode [sqlite3_errmsg16 $DB] + } {column index out of range} +} +do_test bind-8.4 { + sqlite3_bind_null $VM 1 + sqlite3_errmsg $DB +} {not an error} +do_test bind-8.5 { + catch { sqlite3_bind_null $VM 4 } +} {1} +do_test bind-8.6 { + sqlite3_errmsg $DB +} {column index out of range} +ifcapable {utf16} { + do_test bind-8.7 { + encoding convertfrom unicode [sqlite3_errmsg16 $DB] + } {column index out of range} +} + +do_test bind-8.8 { + catch { sqlite3_bind_blob $VM 0 "abc" 3 } +} {1} +do_test bind-8.9 { + catch { sqlite3_bind_blob $VM 4 "abc" 3 } +} {1} +do_test bind-8.10 { + catch { sqlite3_bind_text $VM 0 "abc" 3 } +} {1} +ifcapable {utf16} { + do_test bind-8.11 { + catch { sqlite3_bind_text16 $VM 4 "abc" 2 } + } {1} +} +do_test bind-8.12 { + catch { sqlite3_bind_int $VM 0 5 } +} {1} +do_test bind-8.13 { + catch { sqlite3_bind_int $VM 4 5 } +} {1} +do_test bind-8.14 { + catch { sqlite3_bind_double $VM 0 5.0 } +} {1} +do_test bind-8.15 { + catch { sqlite3_bind_double $VM 4 6.0 } +} {1} + +do_test bind-8.99 { + sqlite3_finalize $VM +} SQLITE_OK + +set iMaxVar $SQLITE_MAX_VARIABLE_NUMBER +set zError "(1) variable number must be between ?1 and ?$iMaxVar" +do_test bind-9.1 { + execsql { + CREATE TABLE t2(a,b,c,d,e,f); + } + set rc [catch { + sqlite3_prepare $DB { + INSERT INTO t2(a) VALUES(?0) + } -1 TAIL + } msg] + lappend rc $msg +} [list 1 $zError] +do_test bind-9.2 { + set rc [catch { + sqlite3_prepare $DB "INSERT INTO t2(a) VALUES(?[expr $iMaxVar+1])" -1 TAIL + } msg] + lappend rc $msg +} [list 1 $zError] +do_test bind-9.3.1 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b) VALUES(?1,?$iMaxVar) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} $iMaxVar +catch {sqlite3_finalize $VM} +do_test bind-9.3.2 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b) VALUES(?2,?[expr $iMaxVar - 1]) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} [expr {$iMaxVar - 1}] +catch {sqlite3_finalize $VM} +do_test bind-9.4 { + set VM [ + sqlite3_prepare $DB " + INSERT INTO t2(a,b,c,d) VALUES(?1,?[expr $iMaxVar - 2],?,?) + " -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} $iMaxVar +do_test bind-9.5 { + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM [expr $iMaxVar - 2] 999 + sqlite3_bind_int $VM [expr $iMaxVar - 1] 1000 + sqlite3_bind_int $VM $iMaxVar 1001 + sqlite3_step $VM +} SQLITE_DONE +do_test bind-9.6 { + sqlite3_finalize $VM +} SQLITE_OK +do_test bind-9.7 { + execsql {SELECT * FROM t2} +} {1 999 1000 1001 {} {}} + +ifcapable {tclvar} { + do_test bind-10.1 { + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,$abc,:abc,$ab,$abc,:abc) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM + } 3 + set v1 {$abc} + set v2 {$ab} +} +ifcapable {!tclvar} { + do_test bind-10.1 { + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,:xyz,:abc,:xy,:xyz,:abc) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM + } 3 + set v1 {:xyz} + set v2 {:xy} +} +do_test bind-10.2 { + sqlite3_bind_parameter_index $VM :abc +} 1 +do_test bind-10.3 { + sqlite3_bind_parameter_index $VM $v1 +} 2 +do_test bind-10.4 { + sqlite3_bind_parameter_index $VM $v2 +} 3 +do_test bind-10.5 { + sqlite3_bind_parameter_name $VM 1 +} :abc +do_test bind-10.6 { + sqlite3_bind_parameter_name $VM 2 +} $v1 +do_test bind-10.7 { + sqlite3_bind_parameter_name $VM 3 +} $v2 +do_test bind-10.7.1 { + sqlite3_bind_parameter_name 0 1 ;# Ignore if VM is NULL +} {} +do_test bind-10.7.2 { + sqlite3_bind_parameter_name $VM 0 ;# Ignore if index too small +} {} +do_test bind-10.7.3 { + sqlite3_bind_parameter_name $VM 4 ;# Ignore if index is too big +} {} +do_test bind-10.8 { + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_step $VM +} SQLITE_DONE +do_test bind-10.8.1 { + # Binding attempts after program start should fail + set rc [catch { + sqlite3_bind_int $VM 1 1 + } msg] + lappend rc $msg +} {1 {}} +do_test bind-10.9 { + sqlite3_finalize $VM +} SQLITE_OK +do_test bind-10.10 { + execsql {SELECT * FROM t2} +} {1 999 1000 1001 {} {} 1 2 1 3 2 1} + +# Ticket #918 +# +do_test bind-10.11 { + # catch {sqlite3_finalize $VM} + set VM [ + sqlite3_prepare $DB { + INSERT INTO t2(a,b,c,d,e,f) VALUES(:abc,?,?4,:pqr,:abc,?4) + } -1 TAIL + ] + sqlite3_bind_parameter_count $VM +} 5 +do_test bind-10.11.1 { + sqlite3_bind_parameter_index 0 :xyz ;# ignore NULL VM arguments +} 0 +do_test bind-10.12 { + sqlite3_bind_parameter_index $VM :xyz +} 0 +do_test bind-10.13 { + sqlite3_bind_parameter_index $VM {} +} 0 +do_test bind-10.14 { + sqlite3_bind_parameter_index $VM :pqr +} 5 +do_test bind-10.15 { + sqlite3_bind_parameter_index $VM ?4 +} 4 +do_test bind-10.16 { + sqlite3_bind_parameter_name $VM 1 +} :abc +do_test bind-10.17 { + sqlite3_bind_parameter_name $VM 2 +} {} +do_test bind-10.18 { + sqlite3_bind_parameter_name $VM 3 +} {} +do_test bind-10.19 { + sqlite3_bind_parameter_name $VM 4 +} {?4} +do_test bind-10.20 { + sqlite3_bind_parameter_name $VM 5 +} :pqr +catch {sqlite3_finalize $VM} + +# Make sure we catch an unterminated "(" in a Tcl-style variable name +# +ifcapable tclvar { + do_test bind-11.1 { + catchsql {SELECT * FROM sqlite_master WHERE name=$abc(123 and sql NOT NULL;} + } {1 {unrecognized token: "$abc(123"}} +} + +if {[execsql {pragma encoding}]=="UTF-8"} { + # Test the ability to bind text that contains embedded '\000' characters. + # Make sure we can recover the entire input string. + # + do_test bind-12.1 { + execsql { + CREATE TABLE t3(x BLOB); + } + set VM [sqlite3_prepare $DB {INSERT INTO t3 VALUES(?)} -1 TAIL] + sqlite_bind $VM 1 not-used blob10 + sqlite3_step $VM + sqlite3_finalize $VM + execsql { + SELECT typeof(x), length(x), quote(x), + length(cast(x AS BLOB)), quote(cast(x AS BLOB)) FROM t3 + } + } {text 3 'abc' 10 X'6162630078797A007071'} + do_test bind-12.2 { + sqlite3_create_function $DB + execsql { + SELECT quote(cast(x_coalesce(x) AS blob)) FROM t3 + } + } {X'6162630078797A007071'} +} + +# Test the operation of sqlite3_clear_bindings +# +do_test bind-13.1 { + set VM [sqlite3_prepare $DB {SELECT ?,?,?} -1 TAIL] + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {NULL NULL NULL} +do_test bind-13.2 { + sqlite3_reset $VM + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {INTEGER INTEGER INTEGER} +do_test bind-13.3 { + sqlite3_reset $VM + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {INTEGER INTEGER INTEGER} +do_test bind-13.4 { + sqlite3_reset $VM + sqlite3_clear_bindings $VM + sqlite3_step $VM + list [sqlite3_column_type $VM 0] [sqlite3_column_type $VM 1] \ + [sqlite3_column_type $VM 2] +} {NULL NULL NULL} +sqlite3_finalize $VM + +#-------------------------------------------------------------------- +# These tests attempt to reproduce bug #3463. +# +proc param_names {db zSql} { + set ret [list] + set VM [sqlite3_prepare db $zSql -1 TAIL] + for {set ii 1} {$ii <= [sqlite3_bind_parameter_count $VM]} {incr ii} { + lappend ret [sqlite3_bind_parameter_name $VM $ii] + } + sqlite3_finalize $VM + set ret +} + +do_test bind-14.1 { + param_names db { SELECT @a, @b } +} {@a @b} +do_test bind-14.2 { + param_names db { SELECT NULL FROM (SELECT NULL) WHERE @a = @b } +} {@a @b} +do_test bind-14.3 { + param_names db { SELECT @a FROM (SELECT NULL) WHERE 1 = @b } +} {@a @b} +do_test bind-14.4 { + param_names db { SELECT @a, @b FROM (SELECT NULL) } +} {@a @b} + +#-------------------------------------------------------------------------- +# Tests of the OP_Variable opcode where P3>1 +# +do_test bind-15.1 { + db eval {CREATE TABLE t4(a,b,c,d,e,f,g,h);} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,f,g,h,e) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 8 5 6 7} +do_test bind-15.2 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,e,f,g,h) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 5 6 7 8} +do_test bind-15.3 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(h,g,f,e,d,c,b,a) VALUES(?,?,?,?,?,?,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {8 7 6 5 4 3 2 1} +do_test bind-15.4 { + db eval {DELETE FROM t4} + set VM [sqlite3_prepare db { + INSERT INTO t4(a,b,c,d,e,f,g,h) VALUES(?,?,?,?4,?,?6,?,?) + } -1 TAIL] + sqlite3_bind_int $VM 1 1 + sqlite3_bind_int $VM 2 2 + sqlite3_bind_int $VM 3 3 + sqlite3_bind_int $VM 4 4 + sqlite3_bind_int $VM 5 5 + sqlite3_bind_int $VM 6 6 + sqlite3_bind_int $VM 7 7 + sqlite3_bind_int $VM 8 8 + sqlite3_step $VM + sqlite3_finalize $VM + db eval {SELECT * FROM t4} +} {1 2 3 4 5 6 7 8} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bind2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bind2.test new file mode 100644 index 0000000000000000000000000000000000000000..1ebf35c2e006cd9f5d8468146faf6374360b2650 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bind2.test @@ -0,0 +1,63 @@ +# 2022 Feb 10 +# +# 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 bind2 + + +# Test that using bind_value() on a REAL sqlite3_value that was stored +# as an INTEGER works properly. +# +# 1.1: An IntReal value read from a table, +# 1.2: IntReal values obtained via the sqlite3_preupdate_old|new() +# interfaces. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a REAL); + INSERT INTO t1 VALUES(42.0); + SELECT * FROM t1; +} {42.0} + +do_test 1.1 { + set stmt [sqlite3_prepare db "SELECT ?" -1 tail] + sqlite3_bind_value_from_select $stmt 1 "SELECT a FROM t1" + sqlite3_step $stmt + sqlite3_column_text $stmt 0 +} {42.0} +sqlite3_finalize $stmt + +ifcapable !preupdate { + finish_test + return +} + +proc preup {args} { + set stmt [sqlite3_prepare db "SELECT ?" -1 tail] + sqlite3_bind_value_from_preupdate $stmt 1 old 0 + sqlite3_step $stmt + lappend ::reslist [sqlite3_column_text $stmt 0] + sqlite3_reset $stmt + sqlite3_bind_value_from_preupdate $stmt 1 new 0 + sqlite3_step $stmt + lappend ::reslist [sqlite3_column_text $stmt 0] + sqlite3_finalize $stmt +} +db preupdate hook preup + +do_test 1.2 { + set ::reslist [list] + execsql { UPDATE t1 SET a=43; } + set ::reslist +} {42.0 43.0} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bindxfer.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bindxfer.test new file mode 100644 index 0000000000000000000000000000000000000000..393aab96d4e4132fab75f01d91fa3badf72db7af --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bindxfer.test @@ -0,0 +1,76 @@ +# 2005 April 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 implements regression tests for SQLite library. The +# focus of this script testing the sqlite_transfer_bindings() API. +# +# $Id: bindxfer.test,v 1.9 2009/04/17 11:56:28 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc sqlite_step {stmt VALS COLS} { + upvar #0 $VALS vals + upvar #0 $COLS cols + set vals [list] + set cols [list] + + set rc [sqlite3_step $stmt] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend cols [sqlite3_column_name $stmt $i] + } + for {set i 0} {$i < [sqlite3_data_count $stmt]} {incr i} { + lappend vals [sqlite3_column_text $stmt $i] + } + + return $rc +} + +do_test bindxfer-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c);} + set VM1 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL] + set TAIL +} {} +do_test bindxfer-1.2 { + sqlite3_bind_parameter_count $VM1 +} 3 +do_test bindxfer-1.3 { + set VM2 [sqlite3_prepare $DB {SELECT ?, ?, ?} -1 TAIL] + set TAIL +} {} +do_test bindxfer-1.4 { + sqlite3_bind_parameter_count $VM2 +} 3 +ifcapable deprecated { + do_test bindxfer-1.5 { + sqlite_bind $VM1 1 one normal + set sqlite_static_bind_value two + sqlite_bind $VM1 2 {} static + sqlite_bind $VM1 3 {} null + sqlite3_transfer_bindings $VM1 $VM2 + sqlite_step $VM1 VALUES COLNAMES + } SQLITE_ROW + do_test bindxfer-1.6 { + set VALUES + } {{} {} {}} + do_test bindxfer-1.7 { + sqlite_step $VM2 VALUES COLNAMES + } SQLITE_ROW + do_test bindxfer-1.8 { + set VALUES + } {one two {}} +} +catch {sqlite3_finalize $VM1} +catch {sqlite3_finalize $VM2} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/blob.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/blob.test new file mode 100644 index 0000000000000000000000000000000000000000..b1aae381a9f16b5c1688a812f6725a795f14ed98 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/blob.test @@ -0,0 +1,147 @@ +# 2001 September 15 +# +# 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. +# +# $Id: blob.test,v 1.8 2009/04/28 18:00:27 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!bloblit} { + finish_test + return +} + +proc bin_to_hex {blob} { + set bytes {} + binary scan $blob \c* bytes + set bytes2 [list] + foreach b $bytes {lappend bytes2 [format %02X [expr $b & 0xFF]]} + join $bytes2 {} +} + +# Simplest possible case. Specify a blob literal +do_test blob-1.0 { + set blob [execsql {SELECT X'01020304';}] + bin_to_hex [lindex $blob 0] +} {01020304} +do_test blob-1.1 { + set blob [execsql {SELECT x'ABCDEF';}] + bin_to_hex [lindex $blob 0] +} {ABCDEF} +do_test blob-1.2 { + set blob [execsql {SELECT x'';}] + bin_to_hex [lindex $blob 0] +} {} +do_test blob-1.3 { + set blob [execsql {SELECT x'abcdEF12';}] + bin_to_hex [lindex $blob 0] +} {ABCDEF12} +do_test blob-1.3.2 { + set blob [execsql {SELECT x'0123456789abcdefABCDEF';}] + bin_to_hex [lindex $blob 0] +} {0123456789ABCDEFABCDEF} + +# Try some syntax errors in blob literals. +do_test blob-1.4 { + catchsql {SELECT X'01020k304', 100} +} {1 {unrecognized token: "X'01020k304'"}} +do_test blob-1.5 { + catchsql {SELECT X'01020, 100} +} {1 {unrecognized token: "X'01020, 100"}} +do_test blob-1.6 { + catchsql {SELECT X'01020 100'} +} {1 {unrecognized token: "X'01020 100'"}} +do_test blob-1.7 { + catchsql {SELECT X'01001'} +} {1 {unrecognized token: "X'01001'"}} +do_test blob-1.8 { + catchsql {SELECT x'012/45'} +} {1 {unrecognized token: "x'012/45'"}} +do_test blob-1.9 { + catchsql {SELECT x'012:45'} +} {1 {unrecognized token: "x'012:45'"}} +do_test blob-1.10 { + catchsql {SELECT x'012@45'} +} {1 {unrecognized token: "x'012@45'"}} +do_test blob-1.11 { + catchsql {SELECT x'012G45'} +} {1 {unrecognized token: "x'012G45'"}} +do_test blob-1.12 { + catchsql {SELECT x'012`45'} +} {1 {unrecognized token: "x'012`45'"}} +do_test blob-1.13 { + catchsql {SELECT x'012g45'} +} {1 {unrecognized token: "x'012g45'"}} + + +# Insert a blob into a table and retrieve it. +do_test blob-2.0 { + execsql { + CREATE TABLE t1(a BLOB, b BLOB); + INSERT INTO t1 VALUES(X'123456', x'7890ab'); + INSERT INTO t1 VALUES(X'CDEF12', x'345678'); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} + +# An index on a blob column +do_test blob-2.1 { + execsql { + CREATE INDEX i1 ON t1(a); + } + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB CDEF12 345678} +do_test blob-2.2 { + set blobs [execsql {SELECT * FROM t1 where a = X'123456'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {123456 7890AB} +do_test blob-2.3 { + set blobs [execsql {SELECT * FROM t1 where a = X'CDEF12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} +do_test blob-2.4 { + set blobs [execsql {SELECT * FROM t1 where a = X'CD12'}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {} + +# Try to bind a blob value to a prepared statement. +do_test blob-3.0 { + sqlite3 db2 test.db + set DB [sqlite3_connection_pointer db2] + set STMT [sqlite3_prepare $DB "DELETE FROM t1 WHERE a = ?" -1 DUMMY] + sqlite3_bind_blob $STMT 1 "\x12\x34\x56" 3 + sqlite3_step $STMT +} {SQLITE_DONE} +do_test blob-3.1 { + sqlite3_finalize $STMT + db2 close +} {} +do_test blob-3.2 { + set blobs [execsql {SELECT * FROM t1}] + set blobs2 [list] + foreach b $blobs {lappend blobs2 [bin_to_hex $b]} + set blobs2 +} {CDEF12 345678} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/bloom1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/bloom1.test new file mode 100644 index 0000000000000000000000000000000000000000..151f364ae0a66343199e3567124232bd67bfe915 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/bloom1.test @@ -0,0 +1,188 @@ +# 2022 October 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. +# +#*********************************************************************** +# +# Tests for queries that use bloom filters + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl + +set testprefix bloom1 + +# Tests 1.* verify that the bloom filter code correctly handles the +# case where the RHS of an ( = ?) expression must be coerced +# to an integer before the comparison made. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('hello', 'world'); + INSERT INTO t2 VALUES(14, 'fourteen'); +} + +do_execsql_test 1.2 { + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6'); + ANALYZE sqlite_schema; +} + +do_execsql_test 1.3 { + SELECT 'affinity!' FROM t1 CROSS JOIN t2 WHERE t2.c = '14'; +} {affinity!} + + +reset_db +do_execsql_test 1.4 { + CREATE TABLE t1(a, b TEXT); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d); + CREATE TABLE t3(e INTEGER PRIMARY KEY, f); + + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t1','idx1','600 6'); + INSERT INTO sqlite_stat1 VALUES('t2','idx1','6 6'); + INSERT INTO sqlite_stat1 VALUES('t3','idx2','6 6'); + ANALYZE sqlite_schema; + + INSERT INTO t1 VALUES(1, '123'); + INSERT INTO t2 VALUES(123, 'one'); + INSERT INTO t3 VALUES(123, 'two'); +} + +do_execsql_test 1.5 { + SELECT 'result' FROM t1, t2, t3 + WHERE t2.c=t1.b AND t2.d!='silly' + AND t3.e=t1.b AND t3.f!='silly' +} {result} + +# 2023-02-05 +# https://sqlite.org/forum/forumpost/56de336385 +# +# Do not employ a Bloom filter if the table being filtered or any table +# wo the left of the table being filtered lacks STAT1 data, since we +# cannot make a good Bloom filter usefulness determination without STAT1 +# data. +# +reset_db +do_execsql_test 2.0 { + CREATE TABLE objs(c INTEGER, s INTEGER, p INTEGER, o INTEGER); + CREATE UNIQUE INDEX objs_cspo ON objs(o,p,c,s); + ANALYZE; + DELETE FROM sqlite_stat1; + INSERT INTO sqlite_stat1 VALUES('objs','objs_cspo','520138 21 20 19 1'); + ANALYZE sqlite_schema; +} +do_eqp_test 2.1 { + WITH RECURSIVE transit(x) AS ( + SELECT s FROM objs WHERE p=9 AND o=32805 + UNION + SELECT objs.s FROM objs, transit WHERE objs.p=9 AND objs.o=transit.x + ) + SELECT x FROM transit; +} { + QUERY PLAN + |--CO-ROUTINE transit + | |--SETUP + | | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?) + | `--RECURSIVE STEP + | |--SCAN transit + | `--SEARCH objs USING COVERING INDEX objs_cspo (o=? AND p=?) + `--SCAN transit +} + +# 2023-02-28 +# https://sqlite.org/forum/forumpost/0846211821 +# +# Bloom filter gives an incorrect result if the collating sequence is +# anything other than binary. +# +reset_db +do_execsql_test 3.1 { + CREATE TABLE t0(x TEXT COLLATE rtrim); + INSERT INTO t0(x) VALUES ('a'), ('b'), ('c'); + CREATE VIEW v0(y) AS SELECT DISTINCT x FROM t0; + SELECT count(*) FROM t0, v0 WHERE x='b '; +} 3 +do_eqp_test 3.2 { + SELECT count(*) FROM t0, v0 WHERE x='b '; +} { + QUERY PLAN + |--CO-ROUTINE v0 + | |--SCAN t0 + | `--USE TEMP B-TREE FOR DISTINCT + |--SCAN v0 + `--SEARCH t0 USING AUTOMATIC PARTIAL COVERING INDEX (x=?) +} +# ^^^^^--- The key feature in the previous result is that no Bloom filter +# is used. In the following, a Bloom filter is used because the data type +# is INT instead of TEXT. +do_execsql_test 3.3 { + CREATE TABLE t1(x INT COLLATE rtrim); + INSERT INTO t1(x) VALUES ('a'), ('b'), ('c'); + CREATE VIEW v1(y) AS SELECT DISTINCT x FROM t1; + SELECT count(*) FROM t1, v1 WHERE x='b '; +} 3 +do_eqp_test 3.4 { + SELECT count(*) FROM t1, v1 WHERE x='b '; +} { + QUERY PLAN + |--CO-ROUTINE v1 + | |--SCAN t1 + | `--USE TEMP B-TREE FOR DISTINCT + |--SCAN v1 + |--BLOOM FILTER ON t1 (x=?) + `--SEARCH t1 USING AUTOMATIC PARTIAL COVERING INDEX (x=?) +} + +# 2023-03-14 +# https://sqlite.org/forum/forumpost/d47a0e8e3a +# https://sqlite.org/forum/forumpost/2e427099d5 +# +# Both reports are for the same problem - using a Bloom filter on an +# expression index can cause issues. +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(x TEXT, y INT, z TEXT); + INSERT INTO t1(rowid,x,y,z) VALUES(12,'aa','bb','aa'); + CREATE INDEX i1x ON t1(1 IS true,z); + CREATE TABLE t0(x TEXT); + INSERT INTO t0(rowid,x) VALUES(4,'aa'); + ANALYZE sqlite_schema; + INSERT INTO sqlite_stat1 VALUES('t0',NULL,'20'); + INSERT INTO sqlite_stat1 VALUES('t1','i1x','18 18 2'); + ANALYZE sqlite_schema; +} +do_execsql_test 4.2 { + SELECT * FROM t0 NATURAL JOIN t1 WHERE z=t1.x; +} {aa bb aa} +do_execsql_test 4.3 { + DROP TABLE t0; + CREATE TABLE t0(a TEXT); + INSERT INTO t0 VALUES ('xyz'); + CREATE INDEX t0x ON t0(a IS FALSE) WHERE false; + DROP TABLE t1; + CREATE TABLE t1(b INT); + INSERT INTO t1 VALUES('aaa'),('bbb'),('ccc'),('ddd'),(NULL); + CREATE TABLE t2(c REAL); + INSERT INTO t2 VALUES(7); + ANALYZE; + CREATE INDEX t2x ON t2(true IN ()); +} +do_execsql_test 4.4 { + SELECT * FROM t0 LEFT JOIN t1 LEFT JOIN t2 ON (b NOTNULL)==(c IN ()) WHERE c; +} {xyz {} 7.0} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.tcl b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.tcl new file mode 100644 index 0000000000000000000000000000000000000000..3896b50463844ecf2bdb2110990e40fe0aa60e14 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.tcl @@ -0,0 +1,289 @@ +puts {# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary1.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0 + 1 + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 1} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary1 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(a,x);" +set a 0 +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');" +} +puts " CREATE INDEX t1i1 ON t1(a);" +puts " CREATE INDEX t1i2 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {64}" + +set nums3 $nums2 +lappend nums3 9.22337303685477580800e+18 +lappend nums3 -9.22337303685477580800e+18 + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-2.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE rowid=$r" + puts " \175" + puts "\175 {$a $x}" + puts "do_test $tname-2.$i.2 \173" + puts " db eval \173" + puts " SELECT rowid, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-2.$i.3 \173" + puts " db eval \173" + puts " SELECT rowid, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-2.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-2.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r0 ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE rowid $op $r5 ORDER BY rowid DESC" + puts " \175" + puts "\175 {$aset}" + } + +} + + +puts {finish_test} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.test new file mode 100644 index 0000000000000000000000000000000000000000..0e2458c15e31c440d0f22e7d3e99497db81e6e59 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary1.test @@ -0,0 +1,7645 @@ +# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary1.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary1-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(127,4,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(3,5,'0000000000000003'); + INSERT INTO t1(oid,a,x) VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1(oid,a,x) VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1(oid,a,x) VALUES(16384,16,'0000000000004000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1(oid,a,x) VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(255,30,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(4,31,'0000000000000004'); + INSERT INTO t1(oid,a,x) VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1(oid,a,x) VALUES(2,41,'0000000000000002'); + INSERT INTO t1(oid,a,x) VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1(oid,a,x) VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(128,49,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(32768,50,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1(oid,a,x) VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(0,59,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(1,60,'0000000000000001'); + INSERT INTO t1(oid,a,x) VALUES(256,61,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(65536,62,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary1-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary1-2.1.1 { + db eval { + SELECT * FROM t1 WHERE rowid=72057594037927935 + } +} {17 00ffffffffffffff} +do_test boundary1-2.1.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary1-2.1.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary1-2.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary1-2.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary1-2.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY rowid + } +} {28 3} +do_test boundary1-2.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY rowid DESC + } +} {3 28} +do_test boundary1-2.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary1-2.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary1-2.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary1-2.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY rowid + } +} {17 28 3} +do_test boundary1-2.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY rowid DESC + } +} {3 28 17} +do_test boundary1-2.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary1-2.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary1-2.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.1.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.1.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.1.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary1-2.1.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.1.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.2.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16384 + } +} {16 0000000000004000} +do_test boundary1-2.2.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary1-2.2.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary1-2.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary1-2.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary1-2.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary1-2.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary1-2.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.2.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.2.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary1-2.2.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary1-2.2.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.2.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.3.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4294967296 + } +} {36 0000000100000000} +do_test boundary1-2.3.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary1-2.3.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary1-2.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary1-2.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary1-2.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary1-2.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary1-2.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.3.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.3.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.3.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary1-2.3.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.3.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.4.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16777216 + } +} {6 0000000001000000} +do_test boundary1-2.4.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary1-2.4.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary1-2.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary1-2.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary1-2.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary1-2.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary1-2.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary1-2.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary1-2.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.4.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.4.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary1-2.4.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary1-2.4.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.4.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.5.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-32769 + } +} {29 ffffffffffff7fff} +do_test boundary1-2.5.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary1-2.5.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary1-2.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary1-2.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary1-2.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary1-2.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary1-2.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary1-2.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary1-2.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.5.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary1-2.5.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary1-2.5.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.5.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.5.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.6.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-140737488355329 + } +} {21 ffff7fffffffffff} +do_test boundary1-2.6.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary1-2.6.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary1-2.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary1-2.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary1-2.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary1-2.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary1-2.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY rowid + } +} {55 2 64} +do_test boundary1-2.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY rowid DESC + } +} {64 2 55} +do_test boundary1-2.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary1-2.6.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary1-2.6.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary1-2.6.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY rowid + } +} {55 2 64 21} +do_test boundary1-2.6.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY rowid DESC + } +} {21 64 2 55} +do_test boundary1-2.6.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary1-2.7.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2 + } +} {41 0000000000000002} +do_test boundary1-2.7.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary1-2.7.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary1-2.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary1-2.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary1-2.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary1-2.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.7.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.7.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.7.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary1-2.7.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.7.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.8.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4 + } +} {31 0000000000000004} +do_test boundary1-2.8.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary1-2.8.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary1-2.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary1-2.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary1-2.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary1-2.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary1-2.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.8.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.8.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary1-2.8.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary1-2.8.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.8.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.9.1 { + db eval { + SELECT * FROM t1 WHERE rowid=562949953421311 + } +} {13 0001ffffffffffff} +do_test boundary1-2.9.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary1-2.9.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary1-2.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary1-2.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary1-2.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY rowid + } +} {43 27 45 17 28 3} +do_test boundary1-2.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary1-2.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary1-2.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary1-2.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary1-2.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY rowid + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary1-2.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary1-2.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.9.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.9.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.9.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary1-2.9.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.9.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.10.1 { + db eval { + SELECT * FROM t1 WHERE rowid=256 + } +} {61 0000000000000100} +do_test boundary1-2.10.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary1-2.10.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary1-2.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary1-2.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary1-2.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary1-2.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.10.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.10.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.10.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary1-2.10.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.10.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.11.1 { + db eval { + SELECT * FROM t1 WHERE rowid=34359738368 + } +} {22 0000000800000000} +do_test boundary1-2.11.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary1-2.11.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary1-2.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary1-2.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary1-2.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary1-2.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.11.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.11.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.11.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary1-2.11.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.11.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.12.1 { + db eval { + SELECT * FROM t1 WHERE rowid=65536 + } +} {62 0000000000010000} +do_test boundary1-2.12.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary1-2.12.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary1-2.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary1-2.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary1-2.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary1-2.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary1-2.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.12.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.12.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.12.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary1-2.12.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.12.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.13.1 { + db eval { + SELECT * FROM t1 WHERE rowid=268435456 + } +} {40 0000000010000000} +do_test boundary1-2.13.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary1-2.13.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary1-2.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary1-2.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary1-2.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary1-2.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.13.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.13.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.13.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary1-2.13.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.13.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-140737488355328 + } +} {44 ffff800000000000} +do_test boundary1-2.14.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary1-2.14.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary1-2.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary1-2.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary1-2.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary1-2.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary1-2.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY rowid + } +} {55 2 64 21} +do_test boundary1-2.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY rowid DESC + } +} {21 64 2 55} +do_test boundary1-2.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary1-2.14.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary1-2.14.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary1-2.14.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY rowid + } +} {55 2 64 21 44} +do_test boundary1-2.14.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY rowid DESC + } +} {44 21 64 2 55} +do_test boundary1-2.14.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary1-2.15.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1099511627776 + } +} {19 0000010000000000} +do_test boundary1-2.15.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary1-2.15.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary1-2.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary1-2.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary1-2.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary1-2.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary1-2.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary1-2.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.15.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.15.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.15.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary1-2.15.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.15.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary1-2.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary1-2.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY rowid + } +} {} +do_test boundary1-2.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary1-2.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary1-2.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary1-2.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY rowid + } +} {3} +do_test boundary1-2.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY rowid DESC + } +} {3} +do_test boundary1-2.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary1-2.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary1-2.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.16.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.16.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.16.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.16.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.16.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.17.1 { + db eval { + SELECT * FROM t1 WHERE rowid=32768 + } +} {50 0000000000008000} +do_test boundary1-2.17.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary1-2.17.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary1-2.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary1-2.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary1-2.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary1-2.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary1-2.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.17.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.17.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.17.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary1-2.17.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.17.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-36028797018963968 + } +} {64 ff80000000000000} +do_test boundary1-2.18.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary1-2.18.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary1-2.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary1-2.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary1-2.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary1-2.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary1-2.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY rowid + } +} {55 2} +do_test boundary1-2.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY rowid DESC + } +} {2 55} +do_test boundary1-2.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary1-2.18.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary1-2.18.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary1-2.18.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY rowid + } +} {55 2 64} +do_test boundary1-2.18.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY rowid DESC + } +} {64 2 55} +do_test boundary1-2.18.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary1-2.19.1 { + db eval { + SELECT * FROM t1 WHERE rowid=65535 + } +} {48 000000000000ffff} +do_test boundary1-2.19.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary1-2.19.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary1-2.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary1-2.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary1-2.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary1-2.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary1-2.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary1-2.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.19.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.19.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.19.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary1-2.19.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.19.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.20.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4294967295 + } +} {14 00000000ffffffff} +do_test boundary1-2.20.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary1-2.20.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary1-2.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary1-2.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary1-2.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary1-2.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.20.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.20.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.20.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary1-2.20.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.20.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.21.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1099511627775 + } +} {57 000000ffffffffff} +do_test boundary1-2.21.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary1-2.21.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary1-2.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary1-2.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary1-2.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary1-2.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary1-2.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary1-2.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.21.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.21.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.21.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary1-2.21.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.21.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.22.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-8388608 + } +} {37 ffffffffff800000} +do_test boundary1-2.22.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary1-2.22.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary1-2.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary1-2.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary1-2.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary1-2.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary1-2.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary1-2.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary1-2.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.22.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary1-2.22.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary1-2.22.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.22.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.22.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary1-2.23.1 { + db eval { + SELECT * FROM t1 WHERE rowid=549755813888 + } +} {35 0000008000000000} +do_test boundary1-2.23.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary1-2.23.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary1-2.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary1-2.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary1-2.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary1-2.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary1-2.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary1-2.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.23.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.23.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.23.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary1-2.23.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.23.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.24.1 { + db eval { + SELECT * FROM t1 WHERE rowid=8388607 + } +} {18 00000000007fffff} +do_test boundary1-2.24.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary1-2.24.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary1-2.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary1-2.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary1-2.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary1-2.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.24.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.24.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.24.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary1-2.24.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.24.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.25.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-3 + } +} {52 fffffffffffffffd} +do_test boundary1-2.25.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary1-2.25.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary1-2.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary1-2.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary1-2.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary1-2.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary1-2.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary1-2.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary1-2.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.25.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.25.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.25.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.25.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.25.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.26.1 { + db eval { + SELECT * FROM t1 WHERE rowid=0 + } +} {59 0000000000000000} +do_test boundary1-2.26.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary1-2.26.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary1-2.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary1-2.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary1-2.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary1-2.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.26.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary1-2.26.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.26.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary1-2.26.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.26.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.27.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-1 + } +} {38 ffffffffffffffff} +do_test boundary1-2.27.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary1-2.27.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary1-2.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary1-2.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary1-2.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary1-2.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary1-2.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.27.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.27.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.27.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.27.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.27.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.28.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2 + } +} {33 fffffffffffffffe} +do_test boundary1-2.28.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary1-2.28.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary1-2.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary1-2.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary1-2.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary1-2.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary1-2.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary1-2.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary1-2.28.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary1-2.28.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary1-2.28.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.28.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.28.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary1-2.29.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2097152 + } +} {42 0000000000200000} +do_test boundary1-2.29.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary1-2.29.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary1-2.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary1-2.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary1-2.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary1-2.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.29.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.29.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.29.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary1-2.29.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.29.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.30.1 { + db eval { + SELECT * FROM t1 WHERE rowid=128 + } +} {49 0000000000000080} +do_test boundary1-2.30.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary1-2.30.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary1-2.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary1-2.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary1-2.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary1-2.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.30.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.30.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.30.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary1-2.30.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.30.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.31.1 { + db eval { + SELECT * FROM t1 WHERE rowid=255 + } +} {30 00000000000000ff} +do_test boundary1-2.31.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary1-2.31.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary1-2.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary1-2.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary1-2.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary1-2.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary1-2.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.31.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.31.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.31.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary1-2.31.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.31.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2147483648 + } +} {11 ffffffff80000000} +do_test boundary1-2.32.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary1-2.32.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary1-2.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary1-2.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary1-2.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary1-2.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary1-2.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary1-2.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.32.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary1-2.32.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary1-2.32.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.32.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary1-2.32.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.33.1 { + db eval { + SELECT * FROM t1 WHERE rowid=34359738367 + } +} {39 00000007ffffffff} +do_test boundary1-2.33.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary1-2.33.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary1-2.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary1-2.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary1-2.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary1-2.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary1-2.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary1-2.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.33.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.33.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.33.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary1-2.33.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.33.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-549755813889 + } +} {58 ffffff7fffffffff} +do_test boundary1-2.34.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary1-2.34.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary1-2.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary1-2.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary1-2.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary1-2.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary1-2.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary1-2.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary1-2.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY rowid + } +} {55 2 64 21 44} +do_test boundary1-2.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY rowid DESC + } +} {44 21 64 2 55} +do_test boundary1-2.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary1-2.34.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary1-2.34.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary1-2.34.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY rowid + } +} {55 2 64 21 44 58} +do_test boundary1-2.34.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary1-2.34.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary1-2.35.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-32768 + } +} {32 ffffffffffff8000} +do_test boundary1-2.35.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary1-2.35.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary1-2.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary1-2.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary1-2.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary1-2.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary1-2.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary1-2.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary1-2.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary1-2.35.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary1-2.35.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.35.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.35.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.35.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.36.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2147483647 + } +} {20 000000007fffffff} +do_test boundary1-2.36.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary1-2.36.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary1-2.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary1-2.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary1-2.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary1-2.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.36.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.36.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.36.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary1-2.36.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.36.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.37.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-129 + } +} {54 ffffffffffffff7f} +do_test boundary1-2.37.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary1-2.37.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary1-2.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary1-2.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary1-2.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary1-2.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary1-2.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary1-2.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary1-2.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary1-2.37.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary1-2.37.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.37.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.37.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.37.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-128 + } +} {53 ffffffffffffff80} +do_test boundary1-2.38.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary1-2.38.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary1-2.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary1-2.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary1-2.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary1-2.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary1-2.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary1-2.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary1-2.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary1-2.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary1-2.38.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary1-2.38.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary1-2.38.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.38.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.38.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary1-2.39.1 { + db eval { + SELECT * FROM t1 WHERE rowid=72057594037927936 + } +} {28 0100000000000000} +do_test boundary1-2.39.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary1-2.39.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary1-2.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary1-2.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary1-2.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY rowid + } +} {3} +do_test boundary1-2.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY rowid DESC + } +} {3} +do_test boundary1-2.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary1-2.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary1-2.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary1-2.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY rowid + } +} {28 3} +do_test boundary1-2.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY rowid DESC + } +} {3 28} +do_test boundary1-2.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary1-2.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary1-2.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.39.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.39.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.39.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary1-2.39.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.39.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.40.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2147483648 + } +} {51 0000000080000000} +do_test boundary1-2.40.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary1-2.40.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary1-2.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary1-2.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary1-2.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary1-2.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary1-2.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary1-2.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary1-2.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.40.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.40.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.40.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary1-2.40.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.40.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.41.1 { + db eval { + SELECT * FROM t1 WHERE rowid=549755813887 + } +} {46 0000007fffffffff} +do_test boundary1-2.41.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary1-2.41.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary1-2.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary1-2.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary1-2.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary1-2.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary1-2.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary1-2.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary1-2.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.41.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.41.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.41.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary1-2.41.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.41.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-549755813888 + } +} {63 ffffff8000000000} +do_test boundary1-2.42.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary1-2.42.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary1-2.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary1-2.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary1-2.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary1-2.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary1-2.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary1-2.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58} +do_test boundary1-2.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary1-2.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary1-2.42.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary1-2.42.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary1-2.42.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY rowid + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.42.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary1-2.42.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.43.1 { + db eval { + SELECT * FROM t1 WHERE rowid=281474976710655 + } +} {10 0000ffffffffffff} +do_test boundary1-2.43.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary1-2.43.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary1-2.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary1-2.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary1-2.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary1-2.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary1-2.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary1-2.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary1-2.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary1-2.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.43.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.43.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.43.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary1-2.43.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.43.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.44.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4398046511103 + } +} {7 000003ffffffffff} +do_test boundary1-2.44.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary1-2.44.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary1-2.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary1-2.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary1-2.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary1-2.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary1-2.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.44.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.44.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.44.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary1-2.44.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.44.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.45.1 { + db eval { + SELECT * FROM t1 WHERE rowid=268435455 + } +} {12 000000000fffffff} +do_test boundary1-2.45.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary1-2.45.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary1-2.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary1-2.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary1-2.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary1-2.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary1-2.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary1-2.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary1-2.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.45.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.45.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary1-2.45.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary1-2.45.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.45.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-9223372036854775808 + } +} {55 8000000000000000} +do_test boundary1-2.46.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary1-2.46.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary1-2.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary1-2.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary1-2.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary1-2.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY rowid + } +} {} +do_test boundary1-2.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary1-2.46.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary1-2.46.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary1-2.46.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY rowid + } +} {55} +do_test boundary1-2.46.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY rowid DESC + } +} {55} +do_test boundary1-2.46.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary1-2.47.1 { + db eval { + SELECT * FROM t1 WHERE rowid=562949953421312 + } +} {43 0002000000000000} +do_test boundary1-2.47.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary1-2.47.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary1-2.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary1-2.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary1-2.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY rowid + } +} {27 45 17 28 3} +do_test boundary1-2.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY rowid DESC + } +} {3 28 17 45 27} +do_test boundary1-2.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary1-2.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary1-2.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary1-2.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY rowid + } +} {43 27 45 17 28 3} +do_test boundary1-2.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary1-2.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary1-2.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary1-2.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.47.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.47.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.47.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary1-2.47.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.47.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-8388609 + } +} {1 ffffffffff7fffff} +do_test boundary1-2.48.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary1-2.48.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary1-2.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary1-2.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary1-2.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary1-2.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary1-2.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary1-2.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary1-2.48.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary1-2.48.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary1-2.48.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.48.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.48.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary1-2.49.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16777215 + } +} {9 0000000000ffffff} +do_test boundary1-2.49.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary1-2.49.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary1-2.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary1-2.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary1-2.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary1-2.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary1-2.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.49.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.49.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary1-2.49.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary1-2.49.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.49.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.50.1 { + db eval { + SELECT * FROM t1 WHERE rowid=8388608 + } +} {24 0000000000800000} +do_test boundary1-2.50.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary1-2.50.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary1-2.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary1-2.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary1-2.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary1-2.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary1-2.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.50.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.50.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary1-2.50.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary1-2.50.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.50.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.51.1 { + db eval { + SELECT * FROM t1 WHERE rowid=16383 + } +} {8 0000000000003fff} +do_test boundary1-2.51.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary1-2.51.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary1-2.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary1-2.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary1-2.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary1-2.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary1-2.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.51.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.51.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary1-2.51.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary1-2.51.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.51.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.52.1 { + db eval { + SELECT * FROM t1 WHERE rowid=140737488355328 + } +} {34 0000800000000000} +do_test boundary1-2.52.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary1-2.52.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary1-2.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary1-2.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary1-2.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary1-2.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary1-2.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary1-2.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary1-2.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary1-2.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.52.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.52.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.52.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary1-2.52.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.52.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.53.1 { + db eval { + SELECT * FROM t1 WHERE rowid=2097151 + } +} {15 00000000001fffff} +do_test boundary1-2.53.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary1-2.53.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary1-2.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary1-2.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary1-2.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary1-2.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary1-2.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary1-2.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.53.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary1-2.53.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary1-2.53.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary1-2.53.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.53.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.54.1 { + db eval { + SELECT * FROM t1 WHERE rowid=140737488355327 + } +} {25 00007fffffffffff} +do_test boundary1-2.54.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary1-2.54.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary1-2.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary1-2.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary1-2.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary1-2.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary1-2.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary1-2.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary1-2.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.54.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.54.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.54.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary1-2.54.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.54.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.55.1 { + db eval { + SELECT * FROM t1 WHERE rowid=281474976710656 + } +} {26 0001000000000000} +do_test boundary1-2.55.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary1-2.55.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary1-2.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary1-2.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary1-2.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY rowid + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary1-2.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary1-2.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary1-2.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary1-2.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary1-2.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary1-2.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary1-2.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.55.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.55.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.55.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary1-2.55.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.55.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.56.1 { + db eval { + SELECT * FROM t1 WHERE rowid=32767 + } +} {23 0000000000007fff} +do_test boundary1-2.56.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary1-2.56.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary1-2.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary1-2.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary1-2.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary1-2.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary1-2.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary1-2.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary1-2.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.56.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary1-2.56.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary1-2.56.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary1-2.56.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.56.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.57.1 { + db eval { + SELECT * FROM t1 WHERE rowid=127 + } +} {4 000000000000007f} +do_test boundary1-2.57.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary1-2.57.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary1-2.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary1-2.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary1-2.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary1-2.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary1-2.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary1-2.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.57.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.57.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary1-2.57.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary1-2.57.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.57.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.58.1 { + db eval { + SELECT * FROM t1 WHERE rowid=36028797018963967 + } +} {27 007fffffffffffff} +do_test boundary1-2.58.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary1-2.58.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary1-2.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary1-2.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary1-2.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY rowid + } +} {45 17 28 3} +do_test boundary1-2.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY rowid DESC + } +} {3 28 17 45} +do_test boundary1-2.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary1-2.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary1-2.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary1-2.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY rowid + } +} {27 45 17 28 3} +do_test boundary1-2.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY rowid DESC + } +} {3 28 17 45 27} +do_test boundary1-2.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary1-2.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary1-2.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.58.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.58.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.58.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary1-2.58.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.58.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.59.1 { + db eval { + SELECT * FROM t1 WHERE rowid=4398046511104 + } +} {56 0000040000000000} +do_test boundary1-2.59.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary1-2.59.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary1-2.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary1-2.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary1-2.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary1-2.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary1-2.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary1-2.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary1-2.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary1-2.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.59.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.59.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary1-2.59.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary1-2.59.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.59.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.60.1 { + db eval { + SELECT * FROM t1 WHERE rowid=1 + } +} {60 0000000000000001} +do_test boundary1-2.60.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary1-2.60.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary1-2.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary1-2.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary1-2.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary1-2.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary1-2.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary1-2.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.60.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.60.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.60.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary1-2.60.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.60.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.61.1 { + db eval { + SELECT * FROM t1 WHERE rowid=36028797018963968 + } +} {45 0080000000000000} +do_test boundary1-2.61.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary1-2.61.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary1-2.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary1-2.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary1-2.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY rowid + } +} {17 28 3} +do_test boundary1-2.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY rowid DESC + } +} {3 28 17} +do_test boundary1-2.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary1-2.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary1-2.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary1-2.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY rowid + } +} {45 17 28 3} +do_test boundary1-2.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY rowid DESC + } +} {3 28 17 45} +do_test boundary1-2.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary1-2.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary1-2.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.61.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.61.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary1-2.61.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary1-2.61.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.61.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-2147483649 + } +} {47 ffffffff7fffffff} +do_test boundary1-2.62.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary1-2.62.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary1-2.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary1-2.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary1-2.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary1-2.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary1-2.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary1-2.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY rowid + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary1-2.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary1-2.62.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary1-2.62.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary1-2.62.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.62.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary1-2.62.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary1-2.63.1 { + db eval { + SELECT * FROM t1 WHERE rowid=-36028797018963969 + } +} {2 ff7fffffffffffff} +do_test boundary1-2.63.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary1-2.63.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary1-2.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary1-2.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary1-2.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary1-2.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary1-2.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary1-2.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY rowid + } +} {55} +do_test boundary1-2.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY rowid DESC + } +} {55} +do_test boundary1-2.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary1-2.63.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary1-2.63.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary1-2.63.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY rowid + } +} {55 2} +do_test boundary1-2.63.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY rowid DESC + } +} {2 55} +do_test boundary1-2.63.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary1-2.64.1 { + db eval { + SELECT * FROM t1 WHERE rowid=3 + } +} {5 0000000000000003} +do_test boundary1-2.64.2 { + db eval { + SELECT rowid, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary1-2.64.3 { + db eval { + SELECT rowid, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary1-2.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary1-2.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary1-2.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary1-2.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary1-2.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary1-2.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary1-2.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary1-2.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.64.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary1-2.64.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary1-2.64.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary1-2.64.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.64.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.65.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.65.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.65.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.65.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.65.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE rowid > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary1-2.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary1-2.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary1-2.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary1-2.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE rowid >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary1-2.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE rowid < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary1-2.66.le.1 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary1-2.66.le.2 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary1-2.66.le.3 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY rowid + } +} {} +do_test boundary1-2.66.le.4 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY rowid DESC + } +} {} +do_test boundary1-2.66.le.5 { + db eval { + SELECT a FROM t1 WHERE rowid <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.tcl b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.tcl new file mode 100644 index 0000000000000000000000000000000000000000..b141166072d9174f9cc05232724ecc5253c1e64c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.tcl @@ -0,0 +1,445 @@ +puts {# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary2.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0 + 1 + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 1} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary2 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT);" +set a 0 +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1 VALUES($r,$a,'$x');" +} +puts " CREATE INDEX t1i1 ON t1(r);" +puts " CREATE INDEX t1i2 ON t1(a);" +puts " CREATE INDEX t1i3 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {64}" + +set nums3 $nums2 +lappend nums3 9.22337303685477580800e+18 +lappend nums3 -9.22337303685477580800e+18 + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-2.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE r=$r" + puts " \175" + puts "\175 {$r $a $x}" + puts "do_test $tname-2.$i.2 \173" + puts " db eval \173" + puts " SELECT r, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-2.$i.3 \173" + puts " db eval \173" + puts " SELECT r, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-2.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-2.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-2.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + } +} + +puts "do_test $tname-3.1 \173" +puts " db eval \173" +puts " DROP INDEX t1i1;" +puts " DROP INDEX t1i2;" +puts " DROP INDEX t1i3;" +puts " \175" +puts "\175 {}" + +set i 0 +foreach r $nums3 { + incr i + + if {abs($r)<9.22337203685477580800e+18} { + set x $t1rx($r) + set a $t1ra($r) + set r5 $r.5 + set r0 $r.0 + puts "do_test $tname-4.$i.1 \173" + puts " db eval \173" + puts " SELECT * FROM t1 WHERE r=$r" + puts " \175" + puts "\175 {$r $a $x}" + puts "do_test $tname-4.$i.2 \173" + puts " db eval \173" + puts " SELECT r, a FROM t1 WHERE x='$x'" + puts " \175" + puts "\175 {$r $a}" + puts "do_test $tname-4.$i.3 \173" + puts " db eval \173" + puts " SELECT r, x FROM t1 WHERE a=$a" + puts " \175" + puts "\175 {$r $x}" + } + + foreach op {> >= < <=} subno {gt ge lt le} { + + ################################################################ 2.x.y.1 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r" { + lappend rset $rx + lappend aset $t1ra($rx) + } + } + puts "do_test $tname-4.$i.$subno.1 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a" + puts " \175" + puts "\175 {[sort $aset]}" + + ################################################################ 2.x.y.2 + puts "do_test $tname-4.$i.$subno.2 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY a DESC" + puts " \175" + puts "\175 {[reverse [sort $aset]]}" + + ################################################################ 2.x.y.3 + set aset {} + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.3 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.4 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.4 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.5 + set aset {} + set xset {} + foreach rx $rset { + lappend xset $t1rx($rx) + } + foreach x [sort $xset] { + set rx $t1xr($x) + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.5 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r ORDER BY x" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.10 + if {abs($r)>9223372036854775808 || [string length $r5]>15} continue + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r0" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.10 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.11 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.11 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r0 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + + + ################################################################ 2.x.y.12 + set rset {} + set aset {} + foreach rx $nums2 { + if "\$rx $op \$r5" { + lappend rset $rx + } + } + foreach rx [sort $rset] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.12 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r" + puts " \175" + puts "\175 {$aset}" + + ################################################################ 2.x.y.13 + set aset {} + foreach rx [reverse [sort $rset]] { + lappend aset $t1ra($rx) + } + puts "do_test $tname-4.$i.$subno.13 \173" + puts " db eval \173" + puts " SELECT a FROM t1 WHERE r $op $r5 ORDER BY r DESC" + puts " \175" + puts "\175 {$aset}" + } +} + + +puts {finish_test} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.test new file mode 100644 index 0000000000000000000000000000000000000000..15a824dc5d60f868e5286bcb046bbfcdf5db906a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary2.test @@ -0,0 +1,15198 @@ +# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary2.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary2-1.1 { + db eval { + CREATE TABLE t1(r INTEGER, a INTEGER, x TEXT); + INSERT INTO t1 VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1 VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1 VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1 VALUES(127,4,'000000000000007f'); + INSERT INTO t1 VALUES(3,5,'0000000000000003'); + INSERT INTO t1 VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1 VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1 VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1 VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1 VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1 VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1 VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1 VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1 VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1 VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1 VALUES(16384,16,'0000000000004000'); + INSERT INTO t1 VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1 VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1 VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1 VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1 VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1 VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1 VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1 VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1 VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1 VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1 VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1 VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1 VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1 VALUES(255,30,'00000000000000ff'); + INSERT INTO t1 VALUES(4,31,'0000000000000004'); + INSERT INTO t1 VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1 VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1 VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1 VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1 VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1 VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1 VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1 VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1 VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1 VALUES(2,41,'0000000000000002'); + INSERT INTO t1 VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1 VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1 VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1 VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1 VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1 VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1 VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1 VALUES(128,49,'0000000000000080'); + INSERT INTO t1 VALUES(32768,50,'0000000000008000'); + INSERT INTO t1 VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1 VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1 VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1 VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1 VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1 VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1 VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1 VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1 VALUES(0,59,'0000000000000000'); + INSERT INTO t1 VALUES(1,60,'0000000000000001'); + INSERT INTO t1 VALUES(256,61,'0000000000000100'); + INSERT INTO t1 VALUES(65536,62,'0000000000010000'); + INSERT INTO t1 VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1 VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(r); + CREATE INDEX t1i2 ON t1(a); + CREATE INDEX t1i3 ON t1(x); + } +} {} +do_test boundary2-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary2-2.1.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927935 + } +} {72057594037927935 17 00ffffffffffffff} +do_test boundary2-2.1.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary2-2.1.3 { + db eval { + SELECT r, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary2-2.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary2-2.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary2-2.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r + } +} {28 3} +do_test boundary2-2.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r DESC + } +} {3 28} +do_test boundary2-2.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary2-2.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary2-2.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-2.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r + } +} {17 28 3} +do_test boundary2-2.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-2.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary2-2.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-2.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.1.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.1.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.1.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-2.1.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.1.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.2.1 { + db eval { + SELECT * FROM t1 WHERE r=16384 + } +} {16384 16 0000000000004000} +do_test boundary2-2.2.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary2-2.2.3 { + db eval { + SELECT r, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary2-2.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-2.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-2.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-2.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-2.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.2.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.2.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-2.2.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-2.2.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.2.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.3.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967296 + } +} {4294967296 36 0000000100000000} +do_test boundary2-2.3.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary2-2.3.3 { + db eval { + SELECT r, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary2-2.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-2.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-2.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-2.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-2.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.3.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.3.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.3.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-2.3.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.3.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.4.1 { + db eval { + SELECT * FROM t1 WHERE r=16777216 + } +} {16777216 6 0000000001000000} +do_test boundary2-2.4.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary2-2.4.3 { + db eval { + SELECT r, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary2-2.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-2.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-2.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-2.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-2.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-2.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-2.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.4.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.4.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-2.4.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-2.4.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.4.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.5.1 { + db eval { + SELECT * FROM t1 WHERE r=-32769 + } +} {-32769 29 ffffffffffff7fff} +do_test boundary2-2.5.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary2-2.5.3 { + db eval { + SELECT r, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary2-2.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-2.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-2.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-2.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-2.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-2.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-2.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.5.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-2.5.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-2.5.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.5.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.5.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.6.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355329 + } +} {-140737488355329 21 ffff7fffffffffff} +do_test boundary2-2.6.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary2-2.6.3 { + db eval { + SELECT r, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary2-2.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-2.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-2.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary2-2.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-2.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r + } +} {55 2 64} +do_test boundary2-2.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-2.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary2-2.6.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-2.6.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-2.6.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-2.6.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-2.6.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-2.7.1 { + db eval { + SELECT * FROM t1 WHERE r=2 + } +} {2 41 0000000000000002} +do_test boundary2-2.7.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary2-2.7.3 { + db eval { + SELECT r, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary2-2.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-2.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-2.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-2.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.7.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.7.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.7.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-2.7.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.7.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.8.1 { + db eval { + SELECT * FROM t1 WHERE r=4 + } +} {4 31 0000000000000004} +do_test boundary2-2.8.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary2-2.8.3 { + db eval { + SELECT r, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary2-2.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-2.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-2.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-2.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-2.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.8.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.8.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-2.8.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-2.8.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.8.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.9.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421311 + } +} {562949953421311 13 0001ffffffffffff} +do_test boundary2-2.9.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary2-2.9.3 { + db eval { + SELECT r, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary2-2.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-2.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-2.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-2.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-2.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-2.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-2.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-2.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-2.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-2.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.9.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.9.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.9.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-2.9.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.9.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.10.1 { + db eval { + SELECT * FROM t1 WHERE r=256 + } +} {256 61 0000000000000100} +do_test boundary2-2.10.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary2-2.10.3 { + db eval { + SELECT r, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary2-2.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-2.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-2.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-2.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.10.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.10.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.10.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-2.10.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.10.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.11.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738368 + } +} {34359738368 22 0000000800000000} +do_test boundary2-2.11.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary2-2.11.3 { + db eval { + SELECT r, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary2-2.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-2.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-2.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-2.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.11.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.11.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.11.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-2.11.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.11.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.12.1 { + db eval { + SELECT * FROM t1 WHERE r=65536 + } +} {65536 62 0000000000010000} +do_test boundary2-2.12.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary2-2.12.3 { + db eval { + SELECT r, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary2-2.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-2.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-2.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-2.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-2.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.12.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.12.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.12.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-2.12.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.12.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.13.1 { + db eval { + SELECT * FROM t1 WHERE r=268435456 + } +} {268435456 40 0000000010000000} +do_test boundary2-2.13.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary2-2.13.3 { + db eval { + SELECT r, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary2-2.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-2.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-2.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-2.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.13.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.13.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.13.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-2.13.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.13.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355328 + } +} {-140737488355328 44 ffff800000000000} +do_test boundary2-2.14.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary2-2.14.3 { + db eval { + SELECT r, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary2-2.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-2.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-2.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-2.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-2.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-2.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-2.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-2.14.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-2.14.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-2.14.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-2.14.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-2.14.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-2.15.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627776 + } +} {1099511627776 19 0000010000000000} +do_test boundary2-2.15.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary2-2.15.3 { + db eval { + SELECT r, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary2-2.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-2.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-2.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-2.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-2.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-2.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.15.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.15.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.15.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-2.15.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.15.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary2-2.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary2-2.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r + } +} {} +do_test boundary2-2.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r DESC + } +} {} +do_test boundary2-2.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary2-2.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary2-2.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary2-2.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r + } +} {3} +do_test boundary2-2.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r DESC + } +} {3} +do_test boundary2-2.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary2-2.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-2.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.16.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.16.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.16.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.16.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.16.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.17.1 { + db eval { + SELECT * FROM t1 WHERE r=32768 + } +} {32768 50 0000000000008000} +do_test boundary2-2.17.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary2-2.17.3 { + db eval { + SELECT r, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary2-2.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-2.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-2.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-2.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-2.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.17.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.17.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.17.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-2.17.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.17.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963968 + } +} {-36028797018963968 64 ff80000000000000} +do_test boundary2-2.18.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary2-2.18.3 { + db eval { + SELECT r, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary2-2.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-2.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-2.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary2-2.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary2-2.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r + } +} {55 2} +do_test boundary2-2.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r DESC + } +} {2 55} +do_test boundary2-2.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary2-2.18.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary2-2.18.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-2.18.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r + } +} {55 2 64} +do_test boundary2-2.18.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-2.18.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary2-2.19.1 { + db eval { + SELECT * FROM t1 WHERE r=65535 + } +} {65535 48 000000000000ffff} +do_test boundary2-2.19.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary2-2.19.3 { + db eval { + SELECT r, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary2-2.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-2.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-2.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-2.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-2.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-2.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.19.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.19.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.19.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-2.19.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.19.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.20.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967295 + } +} {4294967295 14 00000000ffffffff} +do_test boundary2-2.20.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary2-2.20.3 { + db eval { + SELECT r, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary2-2.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-2.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-2.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-2.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.20.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.20.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.20.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-2.20.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.20.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.21.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627775 + } +} {1099511627775 57 000000ffffffffff} +do_test boundary2-2.21.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary2-2.21.3 { + db eval { + SELECT r, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary2-2.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-2.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-2.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-2.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-2.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-2.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.21.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.21.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.21.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-2.21.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.21.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.22.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388608 + } +} {-8388608 37 ffffffffff800000} +do_test boundary2-2.22.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary2-2.22.3 { + db eval { + SELECT r, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary2-2.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-2.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-2.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-2.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-2.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-2.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-2.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.22.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-2.22.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-2.22.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.22.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.22.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-2.23.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813888 + } +} {549755813888 35 0000008000000000} +do_test boundary2-2.23.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary2-2.23.3 { + db eval { + SELECT r, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary2-2.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-2.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-2.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-2.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-2.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-2.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.23.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.23.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.23.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-2.23.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.23.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.24.1 { + db eval { + SELECT * FROM t1 WHERE r=8388607 + } +} {8388607 18 00000000007fffff} +do_test boundary2-2.24.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary2-2.24.3 { + db eval { + SELECT r, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary2-2.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-2.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-2.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-2.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.24.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.24.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.24.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-2.24.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.24.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.25.1 { + db eval { + SELECT * FROM t1 WHERE r=-3 + } +} {-3 52 fffffffffffffffd} +do_test boundary2-2.25.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary2-2.25.3 { + db eval { + SELECT r, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary2-2.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-2.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-2.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-2.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-2.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-2.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-2.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.25.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.25.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.25.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.25.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.25.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.26.1 { + db eval { + SELECT * FROM t1 WHERE r=0 + } +} {0 59 0000000000000000} +do_test boundary2-2.26.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary2-2.26.3 { + db eval { + SELECT r, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary2-2.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-2.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-2.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-2.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.26.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-2.26.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.26.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-2.26.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.26.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.27.1 { + db eval { + SELECT * FROM t1 WHERE r=-1 + } +} {-1 38 ffffffffffffffff} +do_test boundary2-2.27.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary2-2.27.3 { + db eval { + SELECT r, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary2-2.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-2.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-2.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-2.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-2.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.27.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.27.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.27.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.27.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.27.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.28.1 { + db eval { + SELECT * FROM t1 WHERE r=-2 + } +} {-2 33 fffffffffffffffe} +do_test boundary2-2.28.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary2-2.28.3 { + db eval { + SELECT r, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary2-2.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-2.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-2.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-2.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-2.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-2.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-2.28.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-2.28.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-2.28.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.28.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.28.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-2.29.1 { + db eval { + SELECT * FROM t1 WHERE r=2097152 + } +} {2097152 42 0000000000200000} +do_test boundary2-2.29.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary2-2.29.3 { + db eval { + SELECT r, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary2-2.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-2.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-2.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-2.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.29.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.29.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.29.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-2.29.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.29.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.30.1 { + db eval { + SELECT * FROM t1 WHERE r=128 + } +} {128 49 0000000000000080} +do_test boundary2-2.30.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary2-2.30.3 { + db eval { + SELECT r, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary2-2.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-2.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-2.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-2.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.30.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.30.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.30.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-2.30.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.30.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.31.1 { + db eval { + SELECT * FROM t1 WHERE r=255 + } +} {255 30 00000000000000ff} +do_test boundary2-2.31.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary2-2.31.3 { + db eval { + SELECT r, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary2-2.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-2.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-2.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-2.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-2.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.31.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.31.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.31.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-2.31.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.31.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483648 + } +} {-2147483648 11 ffffffff80000000} +do_test boundary2-2.32.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary2-2.32.3 { + db eval { + SELECT r, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary2-2.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-2.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-2.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-2.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-2.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-2.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.32.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-2.32.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-2.32.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.32.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-2.32.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.33.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738367 + } +} {34359738367 39 00000007ffffffff} +do_test boundary2-2.33.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary2-2.33.3 { + db eval { + SELECT r, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary2-2.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-2.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-2.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-2.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-2.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-2.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.33.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.33.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.33.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-2.33.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.33.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813889 + } +} {-549755813889 58 ffffff7fffffffff} +do_test boundary2-2.34.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary2-2.34.3 { + db eval { + SELECT r, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary2-2.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-2.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-2.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-2.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-2.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-2.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-2.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-2.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-2.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-2.34.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-2.34.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-2.34.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-2.34.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-2.34.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-2.35.1 { + db eval { + SELECT * FROM t1 WHERE r=-32768 + } +} {-32768 32 ffffffffffff8000} +do_test boundary2-2.35.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary2-2.35.3 { + db eval { + SELECT r, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary2-2.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-2.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-2.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-2.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-2.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-2.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-2.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-2.35.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-2.35.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.35.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.35.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.35.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.36.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483647 + } +} {2147483647 20 000000007fffffff} +do_test boundary2-2.36.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary2-2.36.3 { + db eval { + SELECT r, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary2-2.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-2.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-2.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-2.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.36.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.36.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.36.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-2.36.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.36.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.37.1 { + db eval { + SELECT * FROM t1 WHERE r=-129 + } +} {-129 54 ffffffffffffff7f} +do_test boundary2-2.37.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary2-2.37.3 { + db eval { + SELECT r, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary2-2.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-2.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-2.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-2.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-2.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-2.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-2.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-2.37.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-2.37.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.37.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.37.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.37.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.1 { + db eval { + SELECT * FROM t1 WHERE r=-128 + } +} {-128 53 ffffffffffffff80} +do_test boundary2-2.38.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary2-2.38.3 { + db eval { + SELECT r, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary2-2.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-2.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-2.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-2.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-2.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-2.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-2.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-2.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-2.38.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-2.38.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-2.38.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.38.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.38.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-2.39.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927936 + } +} {72057594037927936 28 0100000000000000} +do_test boundary2-2.39.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary2-2.39.3 { + db eval { + SELECT r, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary2-2.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary2-2.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary2-2.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r + } +} {3} +do_test boundary2-2.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r DESC + } +} {3} +do_test boundary2-2.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary2-2.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary2-2.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary2-2.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r + } +} {28 3} +do_test boundary2-2.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r DESC + } +} {3 28} +do_test boundary2-2.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary2-2.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-2.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.39.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.39.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.39.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-2.39.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.39.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.40.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483648 + } +} {2147483648 51 0000000080000000} +do_test boundary2-2.40.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary2-2.40.3 { + db eval { + SELECT r, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary2-2.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-2.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-2.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-2.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-2.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-2.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-2.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.40.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.40.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.40.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-2.40.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.40.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.41.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813887 + } +} {549755813887 46 0000007fffffffff} +do_test boundary2-2.41.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary2-2.41.3 { + db eval { + SELECT r, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary2-2.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-2.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-2.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-2.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-2.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-2.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-2.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.41.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.41.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.41.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-2.41.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.41.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813888 + } +} {-549755813888 63 ffffff8000000000} +do_test boundary2-2.42.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary2-2.42.3 { + db eval { + SELECT r, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary2-2.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-2.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-2.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-2.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-2.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-2.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-2.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-2.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-2.42.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-2.42.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-2.42.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.42.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-2.42.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.43.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710655 + } +} {281474976710655 10 0000ffffffffffff} +do_test boundary2-2.43.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary2-2.43.3 { + db eval { + SELECT r, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary2-2.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-2.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-2.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-2.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-2.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-2.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-2.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-2.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.43.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.43.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.43.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-2.43.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.43.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.44.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511103 + } +} {4398046511103 7 000003ffffffffff} +do_test boundary2-2.44.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary2-2.44.3 { + db eval { + SELECT r, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary2-2.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-2.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-2.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-2.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-2.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.44.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.44.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.44.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-2.44.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.44.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.45.1 { + db eval { + SELECT * FROM t1 WHERE r=268435455 + } +} {268435455 12 000000000fffffff} +do_test boundary2-2.45.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary2-2.45.3 { + db eval { + SELECT r, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary2-2.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-2.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-2.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-2.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-2.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-2.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-2.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.45.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.45.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-2.45.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-2.45.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.45.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.1 { + db eval { + SELECT * FROM t1 WHERE r=-9223372036854775808 + } +} {-9223372036854775808 55 8000000000000000} +do_test boundary2-2.46.2 { + db eval { + SELECT r, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary2-2.46.3 { + db eval { + SELECT r, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary2-2.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-2.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary2-2.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary2-2.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r + } +} {} +do_test boundary2-2.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r DESC + } +} {} +do_test boundary2-2.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary2-2.46.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary2-2.46.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary2-2.46.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r + } +} {55} +do_test boundary2-2.46.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r DESC + } +} {55} +do_test boundary2-2.46.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary2-2.47.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421312 + } +} {562949953421312 43 0002000000000000} +do_test boundary2-2.47.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary2-2.47.3 { + db eval { + SELECT r, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary2-2.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-2.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-2.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-2.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-2.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-2.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-2.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-2.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-2.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-2.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-2.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-2.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.47.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.47.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.47.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-2.47.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.47.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388609 + } +} {-8388609 1 ffffffffff7fffff} +do_test boundary2-2.48.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary2-2.48.3 { + db eval { + SELECT r, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary2-2.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-2.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-2.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-2.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-2.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-2.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-2.48.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-2.48.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-2.48.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.48.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.48.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-2.49.1 { + db eval { + SELECT * FROM t1 WHERE r=16777215 + } +} {16777215 9 0000000000ffffff} +do_test boundary2-2.49.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary2-2.49.3 { + db eval { + SELECT r, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary2-2.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-2.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-2.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-2.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-2.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.49.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.49.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-2.49.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-2.49.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.49.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.50.1 { + db eval { + SELECT * FROM t1 WHERE r=8388608 + } +} {8388608 24 0000000000800000} +do_test boundary2-2.50.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary2-2.50.3 { + db eval { + SELECT r, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary2-2.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-2.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-2.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-2.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-2.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.50.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.50.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-2.50.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-2.50.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.50.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.51.1 { + db eval { + SELECT * FROM t1 WHERE r=16383 + } +} {16383 8 0000000000003fff} +do_test boundary2-2.51.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary2-2.51.3 { + db eval { + SELECT r, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary2-2.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-2.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-2.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-2.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-2.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.51.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.51.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-2.51.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-2.51.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.51.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.52.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355328 + } +} {140737488355328 34 0000800000000000} +do_test boundary2-2.52.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary2-2.52.3 { + db eval { + SELECT r, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary2-2.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-2.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-2.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-2.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-2.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-2.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-2.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-2.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.52.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.52.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.52.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-2.52.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.52.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.53.1 { + db eval { + SELECT * FROM t1 WHERE r=2097151 + } +} {2097151 15 00000000001fffff} +do_test boundary2-2.53.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary2-2.53.3 { + db eval { + SELECT r, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary2-2.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-2.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-2.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-2.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-2.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-2.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.53.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-2.53.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-2.53.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-2.53.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.53.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.54.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355327 + } +} {140737488355327 25 00007fffffffffff} +do_test boundary2-2.54.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary2-2.54.3 { + db eval { + SELECT r, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary2-2.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-2.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-2.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-2.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-2.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-2.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-2.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.54.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.54.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.54.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-2.54.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.54.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.55.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710656 + } +} {281474976710656 26 0001000000000000} +do_test boundary2-2.55.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary2-2.55.3 { + db eval { + SELECT r, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary2-2.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-2.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-2.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-2.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-2.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-2.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-2.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-2.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-2.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-2.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.55.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.55.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.55.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-2.55.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.55.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.56.1 { + db eval { + SELECT * FROM t1 WHERE r=32767 + } +} {32767 23 0000000000007fff} +do_test boundary2-2.56.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary2-2.56.3 { + db eval { + SELECT r, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary2-2.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-2.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-2.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-2.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-2.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-2.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-2.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.56.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-2.56.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-2.56.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-2.56.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.56.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.57.1 { + db eval { + SELECT * FROM t1 WHERE r=127 + } +} {127 4 000000000000007f} +do_test boundary2-2.57.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary2-2.57.3 { + db eval { + SELECT r, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary2-2.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-2.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-2.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-2.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-2.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-2.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.57.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.57.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-2.57.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-2.57.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.57.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.58.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963967 + } +} {36028797018963967 27 007fffffffffffff} +do_test boundary2-2.58.2 { + db eval { + SELECT r, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary2-2.58.3 { + db eval { + SELECT r, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary2-2.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-2.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-2.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-2.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-2.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-2.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-2.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-2.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-2.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-2.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-2.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-2.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.58.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.58.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.58.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-2.58.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.58.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.59.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511104 + } +} {4398046511104 56 0000040000000000} +do_test boundary2-2.59.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary2-2.59.3 { + db eval { + SELECT r, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary2-2.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-2.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-2.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-2.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-2.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-2.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-2.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-2.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.59.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.59.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-2.59.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-2.59.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.59.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.60.1 { + db eval { + SELECT * FROM t1 WHERE r=1 + } +} {1 60 0000000000000001} +do_test boundary2-2.60.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary2-2.60.3 { + db eval { + SELECT r, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary2-2.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-2.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-2.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-2.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-2.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-2.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.60.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.60.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.60.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-2.60.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.60.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.61.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963968 + } +} {36028797018963968 45 0080000000000000} +do_test boundary2-2.61.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary2-2.61.3 { + db eval { + SELECT r, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary2-2.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary2-2.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-2.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r + } +} {17 28 3} +do_test boundary2-2.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-2.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary2-2.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-2.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-2.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-2.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-2.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-2.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-2.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.61.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.61.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-2.61.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-2.61.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.61.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483649 + } +} {-2147483649 47 ffffffff7fffffff} +do_test boundary2-2.62.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary2-2.62.3 { + db eval { + SELECT r, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary2-2.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-2.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-2.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-2.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-2.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-2.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-2.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-2.62.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-2.62.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-2.62.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.62.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-2.62.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-2.63.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963969 + } +} {-36028797018963969 2 ff7fffffffffffff} +do_test boundary2-2.63.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary2-2.63.3 { + db eval { + SELECT r, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary2-2.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-2.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-2.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-2.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary2-2.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary2-2.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r + } +} {55} +do_test boundary2-2.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r DESC + } +} {55} +do_test boundary2-2.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary2-2.63.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary2-2.63.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary2-2.63.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r + } +} {55 2} +do_test boundary2-2.63.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r DESC + } +} {2 55} +do_test boundary2-2.63.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary2-2.64.1 { + db eval { + SELECT * FROM t1 WHERE r=3 + } +} {3 5 0000000000000003} +do_test boundary2-2.64.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary2-2.64.3 { + db eval { + SELECT r, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary2-2.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-2.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-2.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-2.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-2.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-2.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-2.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-2.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.64.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-2.64.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-2.64.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-2.64.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.64.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.65.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.65.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.65.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.65.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.65.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-2.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-2.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-2.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-2.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-2.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-2.66.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-2.66.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-2.66.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-2.66.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-2.66.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-3.1 { + db eval { + DROP INDEX t1i1; + DROP INDEX t1i2; + DROP INDEX t1i3; + } +} {} +do_test boundary2-4.1.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927935 + } +} {72057594037927935 17 00ffffffffffffff} +do_test boundary2-4.1.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary2-4.1.3 { + db eval { + SELECT r, x FROM t1 WHERE a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary2-4.1.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a + } +} {3 28} +do_test boundary2-4.1.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY a DESC + } +} {28 3} +do_test boundary2-4.1.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r + } +} {28 3} +do_test boundary2-4.1.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY r DESC + } +} {3 28} +do_test boundary2-4.1.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927935 ORDER BY x + } +} {28 3} +do_test boundary2-4.1.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a + } +} {3 17 28} +do_test boundary2-4.1.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-4.1.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r + } +} {17 28 3} +do_test boundary2-4.1.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-4.1.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927935 ORDER BY x + } +} {17 28 3} +do_test boundary2-4.1.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.1.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.1.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-4.1.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.1.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.1.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.1.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.1.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-4.1.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.1.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927935 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.2.1 { + db eval { + SELECT * FROM t1 WHERE r=16384 + } +} {16384 16 0000000000004000} +do_test boundary2-4.2.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary2-4.2.3 { + db eval { + SELECT r, x FROM t1 WHERE a=16 + } +} {16384 0000000000004000} +do_test boundary2-4.2.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.2.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.2.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-4.2.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16384 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.2.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.2.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-4.2.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16384 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.2.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.2.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-4.2.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-4.2.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.2.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.2.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.2.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-4.2.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-4.2.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.2.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16384 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.3.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967296 + } +} {4294967296 36 0000000100000000} +do_test boundary2-4.3.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary2-4.3.3 { + db eval { + SELECT r, x FROM t1 WHERE a=36 + } +} {4294967296 0000000100000000} +do_test boundary2-4.3.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-4.3.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.3.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-4.3.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967296 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.3.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.3.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-4.3.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967296 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.3.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.3.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.3.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-4.3.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.3.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.3.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.3.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.3.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-4.3.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.3.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967296 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.4.1 { + db eval { + SELECT * FROM t1 WHERE r=16777216 + } +} {16777216 6 0000000001000000} +do_test boundary2-4.4.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary2-4.4.3 { + db eval { + SELECT r, x FROM t1 WHERE a=6 + } +} {16777216 0000000001000000} +do_test boundary2-4.4.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.4.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-4.4.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-4.4.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777216 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.4.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-4.4.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-4.4.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777216 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.4.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.4.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-4.4.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-4.4.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.4.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.4.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.4.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-4.4.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-4.4.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.4.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777216 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.5.1 { + db eval { + SELECT * FROM t1 WHERE r=-32769 + } +} {-32769 29 ffffffffffff7fff} +do_test boundary2-4.5.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary2-4.5.3 { + db eval { + SELECT r, x FROM t1 WHERE a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary2-4.5.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.5.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.5.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.5.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-4.5.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-4.5.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.5.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.5.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.5.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-4.5.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32769 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-4.5.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-4.5.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-4.5.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.5.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.5.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.5.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-4.5.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-4.5.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.5.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.5.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32769 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.6.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355329 + } +} {-140737488355329 21 ffff7fffffffffff} +do_test boundary2-4.6.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary2-4.6.3 { + db eval { + SELECT r, x FROM t1 WHERE a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary2-4.6.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.6.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.6.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.6.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-4.6.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.6.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.6.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.6.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.6.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-4.6.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355329 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.6.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a + } +} {2 55 64} +do_test boundary2-4.6.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-4.6.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r + } +} {55 2 64} +do_test boundary2-4.6.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-4.6.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355329 ORDER BY x + } +} {55 2 64} +do_test boundary2-4.6.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-4.6.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-4.6.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-4.6.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-4.6.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355329 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-4.7.1 { + db eval { + SELECT * FROM t1 WHERE r=2 + } +} {2 41 0000000000000002} +do_test boundary2-4.7.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000002' + } +} {2 41} +do_test boundary2-4.7.3 { + db eval { + SELECT r, x FROM t1 WHERE a=41 + } +} {2 0000000000000002} +do_test boundary2-4.7.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.7.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.7.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-4.7.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.7.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.7.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-4.7.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.7.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.7.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.7.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-4.7.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.7.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.7.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.7.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.7.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-4.7.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.7.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.8.1 { + db eval { + SELECT * FROM t1 WHERE r=4 + } +} {4 31 0000000000000004} +do_test boundary2-4.8.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000004' + } +} {4 31} +do_test boundary2-4.8.3 { + db eval { + SELECT r, x FROM t1 WHERE a=31 + } +} {4 0000000000000004} +do_test boundary2-4.8.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.8.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.8.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-4.8.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.8.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.8.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-4.8.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.8.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.8.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-4.8.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-4.8.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.8.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.8.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.8.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-4.8.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-4.8.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.8.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.9.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421311 + } +} {562949953421311 13 0001ffffffffffff} +do_test boundary2-4.9.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary2-4.9.3 { + db eval { + SELECT r, x FROM t1 WHERE a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary2-4.9.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-4.9.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-4.9.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-4.9.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-4.9.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421311 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-4.9.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-4.9.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-4.9.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.9.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-4.9.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421311 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.9.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.9.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.9.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-4.9.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.9.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.9.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.9.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.9.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-4.9.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.9.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421311 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.10.1 { + db eval { + SELECT * FROM t1 WHERE r=256 + } +} {256 61 0000000000000100} +do_test boundary2-4.10.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000100' + } +} {256 61} +do_test boundary2-4.10.3 { + db eval { + SELECT r, x FROM t1 WHERE a=61 + } +} {256 0000000000000100} +do_test boundary2-4.10.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.10.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.10.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-4.10.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 256 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.10.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.10.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-4.10.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 256 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.10.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.10.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.10.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-4.10.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.10.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.10.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.10.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.10.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-4.10.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.10.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 256 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.11.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738368 + } +} {34359738368 22 0000000800000000} +do_test boundary2-4.11.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary2-4.11.3 { + db eval { + SELECT r, x FROM t1 WHERE a=22 + } +} {34359738368 0000000800000000} +do_test boundary2-4.11.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.11.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.11.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-4.11.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738368 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.11.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.11.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-4.11.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738368 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.11.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.11.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.11.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-4.11.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.11.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.11.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.11.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.11.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-4.11.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.11.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738368 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.12.1 { + db eval { + SELECT * FROM t1 WHERE r=65536 + } +} {65536 62 0000000000010000} +do_test boundary2-4.12.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary2-4.12.3 { + db eval { + SELECT r, x FROM t1 WHERE a=62 + } +} {65536 0000000000010000} +do_test boundary2-4.12.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.12.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.12.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-4.12.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65536 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-4.12.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.12.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-4.12.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65536 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.12.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.12.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.12.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-4.12.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.12.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.12.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.12.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.12.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-4.12.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.12.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65536 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.13.1 { + db eval { + SELECT * FROM t1 WHERE r=268435456 + } +} {268435456 40 0000000010000000} +do_test boundary2-4.13.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary2-4.13.3 { + db eval { + SELECT r, x FROM t1 WHERE a=40 + } +} {268435456 0000000010000000} +do_test boundary2-4.13.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.13.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.13.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-4.13.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435456 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.13.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.13.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-4.13.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435456 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.13.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.13.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.13.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-4.13.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.13.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.13.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.13.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.13.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-4.13.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.13.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435456 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.1 { + db eval { + SELECT * FROM t1 WHERE r=-140737488355328 + } +} {-140737488355328 44 ffff800000000000} +do_test boundary2-4.14.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary2-4.14.3 { + db eval { + SELECT r, x FROM t1 WHERE a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary2-4.14.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.14.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.14.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.14.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-4.14.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.14.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.14.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.14.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary2-4.14.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.14.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a + } +} {2 21 55 64} +do_test boundary2-4.14.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY a DESC + } +} {64 55 21 2} +do_test boundary2-4.14.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r + } +} {55 2 64 21} +do_test boundary2-4.14.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY r DESC + } +} {21 64 2 55} +do_test boundary2-4.14.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -140737488355328 ORDER BY x + } +} {55 2 64 21} +do_test boundary2-4.14.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-4.14.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-4.14.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-4.14.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-4.14.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -140737488355328 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-4.15.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627776 + } +} {1099511627776 19 0000010000000000} +do_test boundary2-4.15.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary2-4.15.3 { + db eval { + SELECT r, x FROM t1 WHERE a=19 + } +} {1099511627776 0000010000000000} +do_test boundary2-4.15.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.15.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-4.15.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-4.15.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627776 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-4.15.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.15.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-4.15.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627776 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.15.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.15.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.15.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-4.15.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.15.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.15.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.15.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.15.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-4.15.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.15.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627776 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.16.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a + } +} {} +do_test boundary2-4.16.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY a DESC + } +} {} +do_test boundary2-4.16.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r + } +} {} +do_test boundary2-4.16.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY r DESC + } +} {} +do_test boundary2-4.16.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9223372036854775807 ORDER BY x + } +} {} +do_test boundary2-4.16.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a + } +} {3} +do_test boundary2-4.16.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY a DESC + } +} {3} +do_test boundary2-4.16.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r + } +} {3} +do_test boundary2-4.16.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY r DESC + } +} {3} +do_test boundary2-4.16.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9223372036854775807 ORDER BY x + } +} {3} +do_test boundary2-4.16.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.16.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.16.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-4.16.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.16.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.16.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.16.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.16.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.16.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.16.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9223372036854775807 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.17.1 { + db eval { + SELECT * FROM t1 WHERE r=32768 + } +} {32768 50 0000000000008000} +do_test boundary2-4.17.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary2-4.17.3 { + db eval { + SELECT r, x FROM t1 WHERE a=50 + } +} {32768 0000000000008000} +do_test boundary2-4.17.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-4.17.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.17.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-4.17.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32768 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.17.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.17.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-4.17.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32768 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.17.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.17.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.17.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-4.17.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.17.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.17.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.17.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.17.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-4.17.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.17.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963968 + } +} {-36028797018963968 64 ff80000000000000} +do_test boundary2-4.18.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary2-4.18.3 { + db eval { + SELECT r, x FROM t1 WHERE a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary2-4.18.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.18.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.18.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.18.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary2-4.18.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.18.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.18.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.18.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-4.18.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.18.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a + } +} {2 55} +do_test boundary2-4.18.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY a DESC + } +} {55 2} +do_test boundary2-4.18.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r + } +} {55 2} +do_test boundary2-4.18.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY r DESC + } +} {2 55} +do_test boundary2-4.18.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963968 ORDER BY x + } +} {55 2} +do_test boundary2-4.18.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a + } +} {2 55 64} +do_test boundary2-4.18.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY a DESC + } +} {64 55 2} +do_test boundary2-4.18.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r + } +} {55 2 64} +do_test boundary2-4.18.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY r DESC + } +} {64 2 55} +do_test boundary2-4.18.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963968 ORDER BY x + } +} {55 2 64} +do_test boundary2-4.19.1 { + db eval { + SELECT * FROM t1 WHERE r=65535 + } +} {65535 48 000000000000ffff} +do_test boundary2-4.19.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary2-4.19.3 { + db eval { + SELECT r, x FROM t1 WHERE a=48 + } +} {65535 000000000000ffff} +do_test boundary2-4.19.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary2-4.19.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.19.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary2-4.19.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 65535 ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary2-4.19.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.19.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary2-4.19.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 65535 ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.19.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.19.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.19.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary2-4.19.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY r DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.19.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.19.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.19.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.19.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary2-4.19.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY r DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.19.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 65535 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.20.1 { + db eval { + SELECT * FROM t1 WHERE r=4294967295 + } +} {4294967295 14 00000000ffffffff} +do_test boundary2-4.20.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary2-4.20.3 { + db eval { + SELECT r, x FROM t1 WHERE a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary2-4.20.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.20.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.20.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary2-4.20.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4294967295 ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.20.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.20.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-4.20.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4294967295 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.20.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.20.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.20.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-4.20.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.20.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.20.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.20.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.20.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary2-4.20.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY r DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.20.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4294967295 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.21.1 { + db eval { + SELECT * FROM t1 WHERE r=1099511627775 + } +} {1099511627775 57 000000ffffffffff} +do_test boundary2-4.21.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary2-4.21.3 { + db eval { + SELECT r, x FROM t1 WHERE a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary2-4.21.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary2-4.21.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.21.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary2-4.21.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1099511627775 ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-4.21.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.21.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-4.21.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1099511627775 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.21.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.21.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.21.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-4.21.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.21.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.21.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.21.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.21.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary2-4.21.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY r DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.21.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1099511627775 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.22.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388608 + } +} {-8388608 37 ffffffffff800000} +do_test boundary2-4.22.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary2-4.22.3 { + db eval { + SELECT r, x FROM t1 WHERE a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary2-4.22.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.22.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.22.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.22.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary2-4.22.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary2-4.22.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.22.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.22.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.22.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-4.22.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-4.22.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-4.22.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-4.22.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.22.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.22.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.22.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary2-4.22.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary2-4.22.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.22.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY r DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.22.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388608 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary2-4.23.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813888 + } +} {549755813888 35 0000008000000000} +do_test boundary2-4.23.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary2-4.23.3 { + db eval { + SELECT r, x FROM t1 WHERE a=35 + } +} {549755813888 0000008000000000} +do_test boundary2-4.23.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary2-4.23.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.23.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary2-4.23.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813888 ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-4.23.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.23.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-4.23.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813888 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.23.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.23.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.23.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-4.23.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.23.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.23.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.23.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.23.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary2-4.23.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY r DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.23.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.24.1 { + db eval { + SELECT * FROM t1 WHERE r=8388607 + } +} {8388607 18 00000000007fffff} +do_test boundary2-4.24.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary2-4.24.3 { + db eval { + SELECT r, x FROM t1 WHERE a=18 + } +} {8388607 00000000007fffff} +do_test boundary2-4.24.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.24.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.24.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-4.24.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388607 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.24.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.24.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-4.24.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388607 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.24.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.24.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.24.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-4.24.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.24.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.24.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.24.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.24.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-4.24.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.24.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388607 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.25.1 { + db eval { + SELECT * FROM t1 WHERE r=-3 + } +} {-3 52 fffffffffffffffd} +do_test boundary2-4.25.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary2-4.25.3 { + db eval { + SELECT r, x FROM t1 WHERE a=52 + } +} {-3 fffffffffffffffd} +do_test boundary2-4.25.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.25.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.25.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.25.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-4.25.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-4.25.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-4.25.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.25.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.25.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-4.25.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -3 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-4.25.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-4.25.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.25.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.25.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.25.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.25.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.25.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.25.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.25.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.25.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -3 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.26.1 { + db eval { + SELECT * FROM t1 WHERE r=0 + } +} {0 59 0000000000000000} +do_test boundary2-4.26.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000000' + } +} {0 59} +do_test boundary2-4.26.3 { + db eval { + SELECT r, x FROM t1 WHERE a=59 + } +} {0 0000000000000000} +do_test boundary2-4.26.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-4.26.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.26.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-4.26.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 0 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.26.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.26.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-4.26.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 0 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.26.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.26.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.26.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.26.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.26.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 0 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.26.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-4.26.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.26.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-4.26.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.26.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 0 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.27.1 { + db eval { + SELECT * FROM t1 WHERE r=-1 + } +} {-1 38 ffffffffffffffff} +do_test boundary2-4.27.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary2-4.27.3 { + db eval { + SELECT r, x FROM t1 WHERE a=38 + } +} {-1 ffffffffffffffff} +do_test boundary2-4.27.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.27.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.27.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary2-4.27.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.27.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.27.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.27.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-4.27.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -1 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-4.27.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.27.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-4.27.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.27.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.27.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.27.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.27.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.27.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.27.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY r DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.27.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -1 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.28.1 { + db eval { + SELECT * FROM t1 WHERE r=-2 + } +} {-2 33 fffffffffffffffe} +do_test boundary2-4.28.2 { + db eval { + SELECT r, a FROM t1 WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary2-4.28.3 { + db eval { + SELECT r, x FROM t1 WHERE a=33 + } +} {-2 fffffffffffffffe} +do_test boundary2-4.28.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.28.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.28.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.28.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary2-4.28.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary2-4.28.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary2-4.28.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.28.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.28.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary2-4.28.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary2-4.28.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.28.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.28.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.28.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY r DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.28.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary2-4.28.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary2-4.28.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary2-4.28.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.28.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY r DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.28.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary2-4.29.1 { + db eval { + SELECT * FROM t1 WHERE r=2097152 + } +} {2097152 42 0000000000200000} +do_test boundary2-4.29.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary2-4.29.3 { + db eval { + SELECT r, x FROM t1 WHERE a=42 + } +} {2097152 0000000000200000} +do_test boundary2-4.29.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.29.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.29.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary2-4.29.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097152 ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.29.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.29.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-4.29.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097152 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.29.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.29.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.29.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-4.29.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.29.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.29.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.29.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.29.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary2-4.29.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY r DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.29.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097152 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.30.1 { + db eval { + SELECT * FROM t1 WHERE r=128 + } +} {128 49 0000000000000080} +do_test boundary2-4.30.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000080' + } +} {128 49} +do_test boundary2-4.30.3 { + db eval { + SELECT r, x FROM t1 WHERE a=49 + } +} {128 0000000000000080} +do_test boundary2-4.30.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.30.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.30.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-4.30.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 128 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.30.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.30.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-4.30.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 128 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.30.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.30.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.30.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-4.30.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.30.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 128 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.30.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.30.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.30.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-4.30.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.30.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 128 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.31.1 { + db eval { + SELECT * FROM t1 WHERE r=255 + } +} {255 30 00000000000000ff} +do_test boundary2-4.31.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary2-4.31.3 { + db eval { + SELECT r, x FROM t1 WHERE a=30 + } +} {255 00000000000000ff} +do_test boundary2-4.31.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.31.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.31.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary2-4.31.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 255 ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary2-4.31.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.31.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary2-4.31.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 255 ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.31.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.31.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.31.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary2-4.31.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY r DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.31.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 255 ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.31.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.31.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.31.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary2-4.31.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY r DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.31.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 255 ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483648 + } +} {-2147483648 11 ffffffff80000000} +do_test boundary2-4.32.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary2-4.32.3 { + db eval { + SELECT r, x FROM t1 WHERE a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary2-4.32.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.32.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.32.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.32.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-4.32.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.32.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.32.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.32.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-4.32.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.32.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-4.32.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-4.32.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.32.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-4.32.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.32.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-4.32.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-4.32.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.32.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-4.32.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483648 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.33.1 { + db eval { + SELECT * FROM t1 WHERE r=34359738367 + } +} {34359738367 39 00000007ffffffff} +do_test boundary2-4.33.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary2-4.33.3 { + db eval { + SELECT r, x FROM t1 WHERE a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary2-4.33.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.33.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.33.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary2-4.33.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 34359738367 ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary2-4.33.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary2-4.33.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary2-4.33.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 34359738367 ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.33.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.33.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.33.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary2-4.33.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY r DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.33.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.33.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.33.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.33.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary2-4.33.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY r DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.33.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 34359738367 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813889 + } +} {-549755813889 58 ffffff7fffffffff} +do_test boundary2-4.34.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary2-4.34.3 { + db eval { + SELECT r, x FROM t1 WHERE a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary2-4.34.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-4.34.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.34.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.34.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-4.34.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary2-4.34.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.34.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.34.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary2-4.34.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813889 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.34.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a + } +} {2 21 44 55 64} +do_test boundary2-4.34.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY a DESC + } +} {64 55 44 21 2} +do_test boundary2-4.34.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r + } +} {55 2 64 21 44} +do_test boundary2-4.34.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY r DESC + } +} {44 21 64 2 55} +do_test boundary2-4.34.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813889 ORDER BY x + } +} {55 2 64 21 44} +do_test boundary2-4.34.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-4.34.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-4.34.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-4.34.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-4.34.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813889 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-4.35.1 { + db eval { + SELECT * FROM t1 WHERE r=-32768 + } +} {-32768 32 ffffffffffff8000} +do_test boundary2-4.35.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary2-4.35.3 { + db eval { + SELECT r, x FROM t1 WHERE a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary2-4.35.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.35.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.35.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.35.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-4.35.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-4.35.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.35.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.35.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.35.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary2-4.35.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -32768 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary2-4.35.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary2-4.35.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary2-4.35.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.35.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY r DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.35.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary2-4.35.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-4.35.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.35.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.35.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.35.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -32768 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.36.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483647 + } +} {2147483647 20 000000007fffffff} +do_test boundary2-4.36.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary2-4.36.3 { + db eval { + SELECT r, x FROM t1 WHERE a=20 + } +} {2147483647 000000007fffffff} +do_test boundary2-4.36.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.36.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.36.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-4.36.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483647 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.36.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.36.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary2-4.36.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483647 ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.36.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.36.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.36.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary2-4.36.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY r DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.36.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.36.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.36.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.36.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-4.36.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.36.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483647 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.37.1 { + db eval { + SELECT * FROM t1 WHERE r=-129 + } +} {-129 54 ffffffffffffff7f} +do_test boundary2-4.37.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary2-4.37.3 { + db eval { + SELECT r, x FROM t1 WHERE a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary2-4.37.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-4.37.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.37.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.37.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-4.37.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-4.37.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.37.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.37.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.37.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary2-4.37.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -129 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary2-4.37.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary2-4.37.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.37.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.37.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY r DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.37.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary2-4.37.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-4.37.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.37.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.37.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.37.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -129 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.1 { + db eval { + SELECT * FROM t1 WHERE r=-128 + } +} {-128 53 ffffffffffffff80} +do_test boundary2-4.38.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary2-4.38.3 { + db eval { + SELECT r, x FROM t1 WHERE a=53 + } +} {-128 ffffffffffffff80} +do_test boundary2-4.38.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary2-4.38.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.38.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.38.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary2-4.38.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary2-4.38.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary2-4.38.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.38.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.38.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary2-4.38.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -128 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary2-4.38.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary2-4.38.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.38.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY r DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.38.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary2-4.38.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary2-4.38.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary2-4.38.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.38.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY r DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.38.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -128 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary2-4.39.1 { + db eval { + SELECT * FROM t1 WHERE r=72057594037927936 + } +} {72057594037927936 28 0100000000000000} +do_test boundary2-4.39.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary2-4.39.3 { + db eval { + SELECT r, x FROM t1 WHERE a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary2-4.39.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a + } +} {3} +do_test boundary2-4.39.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY a DESC + } +} {3} +do_test boundary2-4.39.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r + } +} {3} +do_test boundary2-4.39.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY r DESC + } +} {3} +do_test boundary2-4.39.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 72057594037927936 ORDER BY x + } +} {3} +do_test boundary2-4.39.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a + } +} {3 28} +do_test boundary2-4.39.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY a DESC + } +} {28 3} +do_test boundary2-4.39.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r + } +} {28 3} +do_test boundary2-4.39.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY r DESC + } +} {3 28} +do_test boundary2-4.39.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 72057594037927936 ORDER BY x + } +} {28 3} +do_test boundary2-4.39.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.39.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.39.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary2-4.39.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY r DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.39.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.39.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.39.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.39.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary2-4.39.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY r DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.39.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 72057594037927936 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.40.1 { + db eval { + SELECT * FROM t1 WHERE r=2147483648 + } +} {2147483648 51 0000000080000000} +do_test boundary2-4.40.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary2-4.40.3 { + db eval { + SELECT r, x FROM t1 WHERE a=51 + } +} {2147483648 0000000080000000} +do_test boundary2-4.40.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary2-4.40.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.40.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary2-4.40.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2147483648 ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary2-4.40.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary2-4.40.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary2-4.40.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2147483648 ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.40.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.40.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.40.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary2-4.40.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY r DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.40.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.40.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.40.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.40.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary2-4.40.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY r DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.40.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2147483648 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.41.1 { + db eval { + SELECT * FROM t1 WHERE r=549755813887 + } +} {549755813887 46 0000007fffffffff} +do_test boundary2-4.41.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary2-4.41.3 { + db eval { + SELECT r, x FROM t1 WHERE a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary2-4.41.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary2-4.41.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.41.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary2-4.41.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 549755813887 ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary2-4.41.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary2-4.41.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary2-4.41.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 549755813887 ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.41.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.41.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.41.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary2-4.41.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY r DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.41.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.41.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.41.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.41.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary2-4.41.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY r DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.41.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 549755813887 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.1 { + db eval { + SELECT * FROM t1 WHERE r=-549755813888 + } +} {-549755813888 63 ffffff8000000000} +do_test boundary2-4.42.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary2-4.42.3 { + db eval { + SELECT r, x FROM t1 WHERE a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary2-4.42.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.42.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.42.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.42.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-4.42.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary2-4.42.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.42.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.42.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary2-4.42.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -549755813888 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.42.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a + } +} {2 21 44 55 58 64} +do_test boundary2-4.42.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY a DESC + } +} {64 58 55 44 21 2} +do_test boundary2-4.42.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r + } +} {55 2 64 21 44 58} +do_test boundary2-4.42.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY r DESC + } +} {58 44 21 64 2 55} +do_test boundary2-4.42.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -549755813888 ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary2-4.42.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-4.42.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-4.42.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.42.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-4.42.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -549755813888 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.43.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710655 + } +} {281474976710655 10 0000ffffffffffff} +do_test boundary2-4.43.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary2-4.43.3 { + db eval { + SELECT r, x FROM t1 WHERE a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary2-4.43.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-4.43.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-4.43.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.43.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-4.43.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710655 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.43.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-4.43.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-4.43.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.43.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-4.43.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710655 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.43.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.43.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.43.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-4.43.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.43.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.43.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.43.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.43.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-4.43.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.43.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710655 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.44.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511103 + } +} {4398046511103 7 000003ffffffffff} +do_test boundary2-4.44.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary2-4.44.3 { + db eval { + SELECT r, x FROM t1 WHERE a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary2-4.44.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.44.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.44.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-4.44.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511103 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.44.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary2-4.44.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary2-4.44.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511103 ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.44.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.44.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.44.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary2-4.44.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY r DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.44.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.44.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.44.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.44.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-4.44.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.44.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511103 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.45.1 { + db eval { + SELECT * FROM t1 WHERE r=268435455 + } +} {268435455 12 000000000fffffff} +do_test boundary2-4.45.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary2-4.45.3 { + db eval { + SELECT r, x FROM t1 WHERE a=12 + } +} {268435455 000000000fffffff} +do_test boundary2-4.45.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.45.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary2-4.45.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary2-4.45.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 268435455 ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.45.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary2-4.45.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary2-4.45.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 268435455 ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.45.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.45.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary2-4.45.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary2-4.45.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY r DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.45.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.45.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.45.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary2-4.45.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary2-4.45.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY r DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.45.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 268435455 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.1 { + db eval { + SELECT * FROM t1 WHERE r=-9223372036854775808 + } +} {-9223372036854775808 55 8000000000000000} +do_test boundary2-4.46.2 { + db eval { + SELECT r, a FROM t1 WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary2-4.46.3 { + db eval { + SELECT r, x FROM t1 WHERE a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary2-4.46.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.46.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.46.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.46.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-4.46.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.46.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.46.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.46.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.46.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9223372036854775808 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.46.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a + } +} {} +do_test boundary2-4.46.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY a DESC + } +} {} +do_test boundary2-4.46.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r + } +} {} +do_test boundary2-4.46.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY r DESC + } +} {} +do_test boundary2-4.46.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9223372036854775808 ORDER BY x + } +} {} +do_test boundary2-4.46.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a + } +} {55} +do_test boundary2-4.46.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY a DESC + } +} {55} +do_test boundary2-4.46.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r + } +} {55} +do_test boundary2-4.46.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY r DESC + } +} {55} +do_test boundary2-4.46.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9223372036854775808 ORDER BY x + } +} {55} +do_test boundary2-4.47.1 { + db eval { + SELECT * FROM t1 WHERE r=562949953421312 + } +} {562949953421312 43 0002000000000000} +do_test boundary2-4.47.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary2-4.47.3 { + db eval { + SELECT r, x FROM t1 WHERE a=43 + } +} {562949953421312 0002000000000000} +do_test boundary2-4.47.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-4.47.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-4.47.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-4.47.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-4.47.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 562949953421312 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-4.47.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a + } +} {3 17 27 28 43 45} +do_test boundary2-4.47.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY a DESC + } +} {45 43 28 27 17 3} +do_test boundary2-4.47.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r + } +} {43 27 45 17 28 3} +do_test boundary2-4.47.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY r DESC + } +} {3 28 17 45 27 43} +do_test boundary2-4.47.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 562949953421312 ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary2-4.47.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.47.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.47.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary2-4.47.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY r DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.47.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.47.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.47.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.47.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-4.47.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.47.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 562949953421312 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.1 { + db eval { + SELECT * FROM t1 WHERE r=-8388609 + } +} {-8388609 1 ffffffffff7fffff} +do_test boundary2-4.48.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary2-4.48.3 { + db eval { + SELECT r, x FROM t1 WHERE a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary2-4.48.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.48.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.48.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.48.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary2-4.48.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.48.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.48.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.48.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary2-4.48.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -8388609 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.48.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary2-4.48.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary2-4.48.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.48.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY r DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary2-4.48.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary2-4.48.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary2-4.48.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary2-4.48.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.48.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY r DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.48.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -8388609 ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary2-4.49.1 { + db eval { + SELECT * FROM t1 WHERE r=16777215 + } +} {16777215 9 0000000000ffffff} +do_test boundary2-4.49.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary2-4.49.3 { + db eval { + SELECT r, x FROM t1 WHERE a=9 + } +} {16777215 0000000000ffffff} +do_test boundary2-4.49.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.49.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary2-4.49.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary2-4.49.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16777215 ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.49.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.49.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-4.49.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16777215 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.49.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.49.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.49.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-4.49.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.49.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.49.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.49.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary2-4.49.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary2-4.49.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY r DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.49.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16777215 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.50.1 { + db eval { + SELECT * FROM t1 WHERE r=8388608 + } +} {8388608 24 0000000000800000} +do_test boundary2-4.50.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary2-4.50.3 { + db eval { + SELECT r, x FROM t1 WHERE a=24 + } +} {8388608 0000000000800000} +do_test boundary2-4.50.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.50.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.50.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary2-4.50.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 8388608 ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary2-4.50.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.50.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary2-4.50.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 8388608 ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.50.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.50.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.50.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary2-4.50.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY r DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.50.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.50.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.50.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary2-4.50.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary2-4.50.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY r DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.50.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 8388608 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.51.1 { + db eval { + SELECT * FROM t1 WHERE r=16383 + } +} {16383 8 0000000000003fff} +do_test boundary2-4.51.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary2-4.51.3 { + db eval { + SELECT r, x FROM t1 WHERE a=8 + } +} {16383 0000000000003fff} +do_test boundary2-4.51.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.51.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.51.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary2-4.51.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 16383 ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.51.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.51.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary2-4.51.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 16383 ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.51.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.51.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary2-4.51.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary2-4.51.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY r DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.51.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.51.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.51.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary2-4.51.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary2-4.51.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY r DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.51.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 16383 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.52.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355328 + } +} {140737488355328 34 0000800000000000} +do_test boundary2-4.52.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary2-4.52.3 { + db eval { + SELECT r, x FROM t1 WHERE a=34 + } +} {140737488355328 0000800000000000} +do_test boundary2-4.52.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary2-4.52.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary2-4.52.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary2-4.52.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355328 ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-4.52.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-4.52.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-4.52.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355328 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.52.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.52.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.52.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-4.52.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.52.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.52.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.52.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.52.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary2-4.52.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY r DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.52.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355328 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.53.1 { + db eval { + SELECT * FROM t1 WHERE r=2097151 + } +} {2097151 15 00000000001fffff} +do_test boundary2-4.53.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary2-4.53.3 { + db eval { + SELECT r, x FROM t1 WHERE a=15 + } +} {2097151 00000000001fffff} +do_test boundary2-4.53.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.53.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary2-4.53.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary2-4.53.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 2097151 ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary2-4.53.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.53.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary2-4.53.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 2097151 ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.53.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.53.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.53.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary2-4.53.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY r DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.53.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.53.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary2-4.53.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary2-4.53.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary2-4.53.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY r DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.53.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 2097151 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.54.1 { + db eval { + SELECT * FROM t1 WHERE r=140737488355327 + } +} {140737488355327 25 00007fffffffffff} +do_test boundary2-4.54.2 { + db eval { + SELECT r, a FROM t1 WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary2-4.54.3 { + db eval { + SELECT r, x FROM t1 WHERE a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary2-4.54.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary2-4.54.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary2-4.54.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary2-4.54.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 140737488355327 ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-4.54.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.54.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-4.54.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 140737488355327 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.54.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.54.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.54.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-4.54.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.54.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.54.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.54.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.54.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary2-4.54.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY r DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.54.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 140737488355327 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.55.1 { + db eval { + SELECT * FROM t1 WHERE r=281474976710656 + } +} {281474976710656 26 0001000000000000} +do_test boundary2-4.55.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary2-4.55.3 { + db eval { + SELECT r, x FROM t1 WHERE a=26 + } +} {281474976710656 0001000000000000} +do_test boundary2-4.55.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a + } +} {3 13 17 27 28 43 45} +do_test boundary2-4.55.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary2-4.55.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.55.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13} +do_test boundary2-4.55.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 281474976710656 ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary2-4.55.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a + } +} {3 13 17 26 27 28 43 45} +do_test boundary2-4.55.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary2-4.55.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.55.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary2-4.55.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 281474976710656 ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary2-4.55.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.55.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.55.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary2-4.55.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY r DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.55.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.55.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.55.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.55.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary2-4.55.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY r DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.55.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 281474976710656 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.56.1 { + db eval { + SELECT * FROM t1 WHERE r=32767 + } +} {32767 23 0000000000007fff} +do_test boundary2-4.56.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary2-4.56.3 { + db eval { + SELECT r, x FROM t1 WHERE a=23 + } +} {32767 0000000000007fff} +do_test boundary2-4.56.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.56.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.56.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary2-4.56.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 32767 ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary2-4.56.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary2-4.56.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary2-4.56.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 32767 ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.56.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.56.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary2-4.56.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary2-4.56.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY r DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.56.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.56.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary2-4.56.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary2-4.56.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary2-4.56.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY r DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.56.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 32767 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.57.1 { + db eval { + SELECT * FROM t1 WHERE r=127 + } +} {127 4 000000000000007f} +do_test boundary2-4.57.2 { + db eval { + SELECT r, a FROM t1 WHERE x='000000000000007f' + } +} {127 4} +do_test boundary2-4.57.3 { + db eval { + SELECT r, x FROM t1 WHERE a=4 + } +} {127 000000000000007f} +do_test boundary2-4.57.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.57.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary2-4.57.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary2-4.57.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 127 ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.57.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.57.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary2-4.57.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 127 ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.57.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.57.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary2-4.57.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary2-4.57.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY r DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.57.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 127 ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.57.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.57.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary2-4.57.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary2-4.57.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY r DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.57.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 127 ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.58.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963967 + } +} {36028797018963967 27 007fffffffffffff} +do_test boundary2-4.58.2 { + db eval { + SELECT r, a FROM t1 WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary2-4.58.3 { + db eval { + SELECT r, x FROM t1 WHERE a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary2-4.58.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-4.58.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-4.58.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-4.58.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-4.58.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963967 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-4.58.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a + } +} {3 17 27 28 45} +do_test boundary2-4.58.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY a DESC + } +} {45 28 27 17 3} +do_test boundary2-4.58.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r + } +} {27 45 17 28 3} +do_test boundary2-4.58.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY r DESC + } +} {3 28 17 45 27} +do_test boundary2-4.58.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963967 ORDER BY x + } +} {27 45 17 28 3} +do_test boundary2-4.58.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.58.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.58.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary2-4.58.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY r DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.58.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.58.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.58.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.58.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-4.58.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.58.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963967 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.59.1 { + db eval { + SELECT * FROM t1 WHERE r=4398046511104 + } +} {4398046511104 56 0000040000000000} +do_test boundary2-4.59.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary2-4.59.3 { + db eval { + SELECT r, x FROM t1 WHERE a=56 + } +} {4398046511104 0000040000000000} +do_test boundary2-4.59.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary2-4.59.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.59.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary2-4.59.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 4398046511104 ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary2-4.59.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary2-4.59.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary2-4.59.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 4398046511104 ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.59.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary2-4.59.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.59.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary2-4.59.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY r DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.59.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.59.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.59.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary2-4.59.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary2-4.59.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY r DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.59.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 4398046511104 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.60.1 { + db eval { + SELECT * FROM t1 WHERE r=1 + } +} {1 60 0000000000000001} +do_test boundary2-4.60.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000001' + } +} {1 60} +do_test boundary2-4.60.3 { + db eval { + SELECT r, x FROM t1 WHERE a=60 + } +} {1 0000000000000001} +do_test boundary2-4.60.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.60.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.60.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary2-4.60.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 1 ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary2-4.60.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.60.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary2-4.60.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 1 ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.60.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary2-4.60.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.60.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary2-4.60.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY r DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.60.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 1 ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.60.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.60.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.60.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary2-4.60.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY r DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.60.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 1 ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.61.1 { + db eval { + SELECT * FROM t1 WHERE r=36028797018963968 + } +} {36028797018963968 45 0080000000000000} +do_test boundary2-4.61.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary2-4.61.3 { + db eval { + SELECT r, x FROM t1 WHERE a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary2-4.61.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a + } +} {3 17 28} +do_test boundary2-4.61.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY a DESC + } +} {28 17 3} +do_test boundary2-4.61.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r + } +} {17 28 3} +do_test boundary2-4.61.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY r DESC + } +} {3 28 17} +do_test boundary2-4.61.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 36028797018963968 ORDER BY x + } +} {17 28 3} +do_test boundary2-4.61.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a + } +} {3 17 28 45} +do_test boundary2-4.61.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY a DESC + } +} {45 28 17 3} +do_test boundary2-4.61.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r + } +} {45 17 28 3} +do_test boundary2-4.61.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY r DESC + } +} {3 28 17 45} +do_test boundary2-4.61.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 36028797018963968 ORDER BY x + } +} {45 17 28 3} +do_test boundary2-4.61.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.61.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.61.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary2-4.61.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY r DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.61.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.61.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.61.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary2-4.61.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary2-4.61.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY r DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.61.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 36028797018963968 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.1 { + db eval { + SELECT * FROM t1 WHERE r=-2147483649 + } +} {-2147483649 47 ffffffff7fffffff} +do_test boundary2-4.62.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary2-4.62.3 { + db eval { + SELECT r, x FROM t1 WHERE a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary2-4.62.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.62.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.62.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.62.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary2-4.62.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary2-4.62.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.62.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.62.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary2-4.62.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -2147483649 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.62.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a + } +} {2 21 44 55 58 63 64} +do_test boundary2-4.62.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary2-4.62.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.62.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY r DESC + } +} {63 58 44 21 64 2 55} +do_test boundary2-4.62.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary2-4.62.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a + } +} {2 21 44 47 55 58 63 64} +do_test boundary2-4.62.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary2-4.62.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.62.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY r DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary2-4.62.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -2147483649 ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary2-4.63.1 { + db eval { + SELECT * FROM t1 WHERE r=-36028797018963969 + } +} {-36028797018963969 2 ff7fffffffffffff} +do_test boundary2-4.63.2 { + db eval { + SELECT r, a FROM t1 WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary2-4.63.3 { + db eval { + SELECT r, x FROM t1 WHERE a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary2-4.63.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.63.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary2-4.63.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.63.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary2-4.63.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.63.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.63.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.63.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.63.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary2-4.63.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -36028797018963969 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.63.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a + } +} {55} +do_test boundary2-4.63.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY a DESC + } +} {55} +do_test boundary2-4.63.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r + } +} {55} +do_test boundary2-4.63.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY r DESC + } +} {55} +do_test boundary2-4.63.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -36028797018963969 ORDER BY x + } +} {55} +do_test boundary2-4.63.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a + } +} {2 55} +do_test boundary2-4.63.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY a DESC + } +} {55 2} +do_test boundary2-4.63.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r + } +} {55 2} +do_test boundary2-4.63.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY r DESC + } +} {2 55} +do_test boundary2-4.63.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -36028797018963969 ORDER BY x + } +} {55 2} +do_test boundary2-4.64.1 { + db eval { + SELECT * FROM t1 WHERE r=3 + } +} {3 5 0000000000000003} +do_test boundary2-4.64.2 { + db eval { + SELECT r, a FROM t1 WHERE x='0000000000000003' + } +} {3 5} +do_test boundary2-4.64.3 { + db eval { + SELECT r, x FROM t1 WHERE a=5 + } +} {3 0000000000000003} +do_test boundary2-4.64.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.64.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary2-4.64.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary2-4.64.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 3 ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary2-4.64.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary2-4.64.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary2-4.64.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 3 ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.64.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.64.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary2-4.64.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary2-4.64.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY r DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.64.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 3 ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.64.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary2-4.64.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary2-4.64.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary2-4.64.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY r DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.64.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 3 ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.65.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.65.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.65.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.65.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.65.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.65.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.65.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.65.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.65.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.65.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= 9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.65.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.65.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.65.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.65.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.65.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.65.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.65.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.65.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.65.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.65.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= 9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.gt.1 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.66.gt.2 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.66.gt.3 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.66.gt.4 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.66.gt.5 { + db eval { + SELECT a FROM t1 WHERE r > -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.ge.1 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary2-4.66.ge.2 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary2-4.66.ge.3 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary2-4.66.ge.4 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary2-4.66.ge.5 { + db eval { + SELECT a FROM t1 WHERE r >= -9.22337303685477580800e+18 ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary2-4.66.lt.1 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.66.lt.2 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.66.lt.3 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.66.lt.4 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.66.lt.5 { + db eval { + SELECT a FROM t1 WHERE r < -9.22337303685477580800e+18 ORDER BY x + } +} {} +do_test boundary2-4.66.le.1 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a + } +} {} +do_test boundary2-4.66.le.2 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY a DESC + } +} {} +do_test boundary2-4.66.le.3 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r + } +} {} +do_test boundary2-4.66.le.4 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY r DESC + } +} {} +do_test boundary2-4.66.le.5 { + db eval { + SELECT a FROM t1 WHERE r <= -9.22337303685477580800e+18 ORDER BY x + } +} {} +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary3.test new file mode 100644 index 0000000000000000000000000000000000000000..dbe9abfa0a9fb7fc28987dae9b4ca9724c2860ec --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary3.test @@ -0,0 +1,12456 @@ +# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary3.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } + +do_test boundary3-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(-8388609,1,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,2,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,3,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(127,4,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(3,5,'0000000000000003'); + INSERT INTO t1(oid,a,x) VALUES(16777216,6,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511103,7,'000003ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(16383,8,'0000000000003fff'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,10,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,11,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(268435455,12,'000000000fffffff'); + INSERT INTO t1(oid,a,x) VALUES(562949953421311,13,'0001ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,14,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(2097151,15,'00000000001fffff'); + INSERT INTO t1(oid,a,x) VALUES(16384,16,'0000000000004000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,17,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,18,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,19,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,20,'000000007fffffff'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,21,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738368,22,'0000000800000000'); + INSERT INTO t1(oid,a,x) VALUES(32767,23,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(8388608,24,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,25,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,26,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,27,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,28,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,29,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(255,30,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(4,31,'0000000000000004'); + INSERT INTO t1(oid,a,x) VALUES(-32768,32,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-2,33,'fffffffffffffffe'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,36,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,37,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(-1,38,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(34359738367,39,'00000007ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(268435456,40,'0000000010000000'); + INSERT INTO t1(oid,a,x) VALUES(2,41,'0000000000000002'); + INSERT INTO t1(oid,a,x) VALUES(2097152,42,'0000000000200000'); + INSERT INTO t1(oid,a,x) VALUES(562949953421312,43,'0002000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,44,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,45,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813887,46,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,47,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(65535,48,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(128,49,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(32768,50,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,51,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(-3,52,'fffffffffffffffd'); + INSERT INTO t1(oid,a,x) VALUES(-128,53,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(-129,54,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,55,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(4398046511104,56,'0000040000000000'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,57,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,58,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(0,59,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(1,60,'0000000000000001'); + INSERT INTO t1(oid,a,x) VALUES(256,61,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(65536,62,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,63,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,64,'ff80000000000000'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary3-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {64} +do_test boundary3-1.3 { + db eval { + CREATE TABLE t2(r,a); + INSERT INTO t2 SELECT rowid, a FROM t1; + CREATE INDEX t2i1 ON t2(r); + CREATE INDEX t2i2 ON t2(a); + INSERT INTO t2 VALUES(9.22337303685477580800e+18,65); + INSERT INTO t2 VALUES(-9.22337303685477580800e+18,66); + SELECT count(*) FROM t2; + } +} {66} +do_test boundary3-2.1.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=72057594037927935 AND t2.a=t1.a + } +} {17 00ffffffffffffff} +do_test boundary3-2.1.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00ffffffffffffff' + } +} {72057594037927935 17} +do_test boundary3-2.1.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=17 + } +} {72057594037927935 00ffffffffffffff} +do_test boundary3-2.1.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 72057594037927935 ORDER BY t2.a + } +} {3 28} +do_test boundary3-2.1.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 72057594037927935 ORDER BY t1.a DESC + } +} {28 3} +do_test boundary3-2.1.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {28 3} +do_test boundary3-2.1.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {3 28} +do_test boundary3-2.1.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=17 + ORDER BY x + } +} {28 3} +do_test boundary3-2.1.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 72057594037927935 ORDER BY t2.a + } +} {3 17 28} +do_test boundary3-2.1.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 72057594037927935 ORDER BY t1.a DESC + } +} {28 17 3} +do_test boundary3-2.1.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {17 28 3} +do_test boundary3-2.1.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {3 28 17} +do_test boundary3-2.1.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=17 + ORDER BY x + } +} {17 28 3} +do_test boundary3-2.1.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 72057594037927935 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.1.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 72057594037927935 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.1.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary3-2.1.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.1.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=17 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.1.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 72057594037927935 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.1.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 72057594037927935 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.1.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary3-2.1.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY t1.rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.1.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=17 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16384 AND t2.a=t1.a + } +} {16 0000000000004000} +do_test boundary3-2.2.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000004000' + } +} {16384 16} +do_test boundary3-2.2.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=16 + } +} {16384 0000000000004000} +do_test boundary3-2.2.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16384 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.2.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16384 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.2.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.2.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=16 + ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.2.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16384 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.2.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16384 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.2.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.2.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=16 + ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.2.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.2.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16384 ORDER BY t2.a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.2.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16384 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary3-2.2.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.2.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=16 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.2.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16384 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.2.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16384 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary3-2.2.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.2.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.2.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=16 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.2.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.2.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=16 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4294967296 AND t2.a=t1.a + } +} {36 0000000100000000} +do_test boundary3-2.3.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000100000000' + } +} {4294967296 36} +do_test boundary3-2.3.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=36 + } +} {4294967296 0000000100000000} +do_test boundary3-2.3.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4294967296 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary3-2.3.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4294967296 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.3.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.3.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=36 + ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.3.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4294967296 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.3.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4294967296 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.3.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.3.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=36 + ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.3.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.3.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4294967296 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.3.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4294967296 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.3.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.3.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=36 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.3.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.3.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4294967296 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.3.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4294967296 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.3.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.3.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.3.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=36 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.3.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.3.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=36 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16777216 AND t2.a=t1.a + } +} {6 0000000001000000} +do_test boundary3-2.4.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000001000000' + } +} {16777216 6} +do_test boundary3-2.4.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=6 + } +} {16777216 0000000001000000} +do_test boundary3-2.4.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16777216 ORDER BY t2.a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.4.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16777216 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary3-2.4.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.4.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=6 + ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.4.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16777216 ORDER BY t2.a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.4.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16777216 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary3-2.4.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.4.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=6 + ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.4.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.4.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16777216 ORDER BY t2.a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.4.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16777216 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary3-2.4.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.4.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=6 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.4.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.4.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16777216 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.4.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16777216 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary3-2.4.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.4.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.4.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=6 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.4.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.4.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=6 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-32769 AND t2.a=t1.a + } +} {29 ffffffffffff7fff} +do_test boundary3-2.5.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffff7fff' + } +} {-32769 29} +do_test boundary3-2.5.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=29 + } +} {-32769 ffffffffffff7fff} +do_test boundary3-2.5.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -32769 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.5.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -32769 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.5.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.5.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=29 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary3-2.5.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.5.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -32769 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.5.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -32769 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.5.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.5.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=29 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary3-2.5.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.5.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.5.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -32769 ORDER BY t2.a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary3-2.5.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -32769 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary3-2.5.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=29 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.5.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -32769 ORDER BY t2.a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary3-2.5.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -32769 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary3-2.5.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.5.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=29 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.5.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=29 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.6.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-140737488355329 AND t2.a=t1.a + } +} {21 ffff7fffffffffff} +do_test boundary3-2.6.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffff7fffffffffff' + } +} {-140737488355329 21} +do_test boundary3-2.6.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=21 + } +} {-140737488355329 ffff7fffffffffff} +do_test boundary3-2.6.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -140737488355329 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.6.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -140737488355329 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.6.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.6.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary3-2.6.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=21 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.6.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -140737488355329 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.6.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -140737488355329 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.6.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.6.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary3-2.6.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=21 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.6.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -140737488355329 ORDER BY t2.a + } +} {2 55 64} +do_test boundary3-2.6.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -140737488355329 ORDER BY t1.a DESC + } +} {64 55 2} +do_test boundary3-2.6.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {55 2 64} +do_test boundary3-2.6.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {64 2 55} +do_test boundary3-2.6.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=21 + ORDER BY x + } +} {55 2 64} +do_test boundary3-2.6.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -140737488355329 ORDER BY t2.a + } +} {2 21 55 64} +do_test boundary3-2.6.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -140737488355329 ORDER BY t1.a DESC + } +} {64 55 21 2} +do_test boundary3-2.6.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid + } +} {55 2 64 21} +do_test boundary3-2.6.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY t1.rowid DESC + } +} {21 64 2 55} +do_test boundary3-2.6.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=21 + ORDER BY x + } +} {55 2 64 21} +do_test boundary3-2.7.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2 AND t2.a=t1.a + } +} {41 0000000000000002} +do_test boundary3-2.7.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000002' + } +} {2 41} +do_test boundary3-2.7.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=41 + } +} {2 0000000000000002} +do_test boundary3-2.7.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.7.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.7.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.7.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=41 + ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.7.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.7.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.7.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.7.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=41 + ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.7.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.7.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.7.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.7.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.7.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=41 + ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.7.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.7.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.7.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.7.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.7.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.7.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=41 + ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.7.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.7.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=41 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4 AND t2.a=t1.a + } +} {31 0000000000000004} +do_test boundary3-2.8.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000004' + } +} {4 31} +do_test boundary3-2.8.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=31 + } +} {4 0000000000000004} +do_test boundary3-2.8.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.8.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.8.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.8.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=31 + ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.8.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.8.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.8.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.8.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=31 + ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.8.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.8.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4 ORDER BY t2.a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.8.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary3-2.8.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.8.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=31 + ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.8.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.8.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4 ORDER BY t2.a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.8.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary3-2.8.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.8.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.8.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=31 + ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.8.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.8.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=31 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=562949953421311 AND t2.a=t1.a + } +} {13 0001ffffffffffff} +do_test boundary3-2.9.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0001ffffffffffff' + } +} {562949953421311 13} +do_test boundary3-2.9.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=13 + } +} {562949953421311 0001ffffffffffff} +do_test boundary3-2.9.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 562949953421311 ORDER BY t2.a + } +} {3 17 27 28 43 45} +do_test boundary3-2.9.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 562949953421311 ORDER BY t1.a DESC + } +} {45 43 28 27 17 3} +do_test boundary3-2.9.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {43 27 45 17 28 3} +do_test boundary3-2.9.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary3-2.9.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=13 + ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary3-2.9.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 562949953421311 ORDER BY t2.a + } +} {3 13 17 27 28 43 45} +do_test boundary3-2.9.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 562949953421311 ORDER BY t1.a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary3-2.9.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.9.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary3-2.9.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=13 + ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.9.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 562949953421311 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.9.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 562949953421311 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.9.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary3-2.9.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=13 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.9.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 562949953421311 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.9.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 562949953421311 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.9.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary3-2.9.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY t1.rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.9.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=13 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=256 AND t2.a=t1.a + } +} {61 0000000000000100} +do_test boundary3-2.10.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000100' + } +} {256 61} +do_test boundary3-2.10.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=61 + } +} {256 0000000000000100} +do_test boundary3-2.10.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 256 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.10.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 256 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.10.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.10.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=61 + ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.10.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 256 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.10.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 256 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.10.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.10.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=61 + ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.10.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.10.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 256 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.10.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 256 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.10.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.10.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=61 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.10.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 256 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.10.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 256 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.10.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.10.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.10.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=61 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.10.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.10.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=61 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=34359738368 AND t2.a=t1.a + } +} {22 0000000800000000} +do_test boundary3-2.11.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000800000000' + } +} {34359738368 22} +do_test boundary3-2.11.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=22 + } +} {34359738368 0000000800000000} +do_test boundary3-2.11.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 34359738368 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.11.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 34359738368 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.11.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.11.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=22 + ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.11.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 34359738368 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.11.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 34359738368 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.11.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.11.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=22 + ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.11.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.11.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 34359738368 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.11.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 34359738368 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.11.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.11.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=22 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.11.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.11.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 34359738368 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.11.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 34359738368 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.11.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.11.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.11.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=22 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.11.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.11.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=22 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=65536 AND t2.a=t1.a + } +} {62 0000000000010000} +do_test boundary3-2.12.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000010000' + } +} {65536 62} +do_test boundary3-2.12.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=62 + } +} {65536 0000000000010000} +do_test boundary3-2.12.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 65536 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.12.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 65536 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.12.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.12.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=62 + ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.12.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 65536 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary3-2.12.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 65536 ORDER BY t1.a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.12.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.12.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=62 + ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.12.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.12.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 65536 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.12.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 65536 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.12.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.12.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=62 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.12.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.12.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 65536 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.12.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 65536 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.12.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.12.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.12.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=62 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.12.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.12.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=62 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=268435456 AND t2.a=t1.a + } +} {40 0000000010000000} +do_test boundary3-2.13.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000010000000' + } +} {268435456 40} +do_test boundary3-2.13.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=40 + } +} {268435456 0000000010000000} +do_test boundary3-2.13.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 268435456 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.13.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 268435456 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.13.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.13.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=40 + ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.13.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 268435456 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.13.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 268435456 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.13.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.13.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=40 + ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.13.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.13.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 268435456 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.13.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 268435456 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.13.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.13.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=40 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.13.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.13.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 268435456 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.13.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 268435456 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.13.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.13.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.13.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=40 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.13.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.13.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=40 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.14.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-140737488355328 AND t2.a=t1.a + } +} {44 ffff800000000000} +do_test boundary3-2.14.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffff800000000000' + } +} {-140737488355328 44} +do_test boundary3-2.14.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=44 + } +} {-140737488355328 ffff800000000000} +do_test boundary3-2.14.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -140737488355328 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.14.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -140737488355328 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.14.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.14.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.14.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=44 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.14.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -140737488355328 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.14.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -140737488355328 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.14.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.14.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44} +do_test boundary3-2.14.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=44 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.14.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -140737488355328 ORDER BY t2.a + } +} {2 21 55 64} +do_test boundary3-2.14.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -140737488355328 ORDER BY t1.a DESC + } +} {64 55 21 2} +do_test boundary3-2.14.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {55 2 64 21} +do_test boundary3-2.14.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {21 64 2 55} +do_test boundary3-2.14.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=44 + ORDER BY x + } +} {55 2 64 21} +do_test boundary3-2.14.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -140737488355328 ORDER BY t2.a + } +} {2 21 44 55 64} +do_test boundary3-2.14.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -140737488355328 ORDER BY t1.a DESC + } +} {64 55 44 21 2} +do_test boundary3-2.14.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.14.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.14.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=44 + ORDER BY x + } +} {55 2 64 21 44} +do_test boundary3-2.15.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1099511627776 AND t2.a=t1.a + } +} {19 0000010000000000} +do_test boundary3-2.15.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000010000000000' + } +} {1099511627776 19} +do_test boundary3-2.15.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=19 + } +} {1099511627776 0000010000000000} +do_test boundary3-2.15.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1099511627776 ORDER BY t2.a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.15.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1099511627776 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary3-2.15.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.15.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=19 + ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.15.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1099511627776 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary3-2.15.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1099511627776 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.15.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.15.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=19 + ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.15.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.15.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1099511627776 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.15.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1099511627776 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.15.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.15.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=19 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.15.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.15.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1099511627776 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.15.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1099511627776 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.15.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.15.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.15.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=19 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.15.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.15.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=19 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 9223372036854775807 ORDER BY t2.a + } +} {} +do_test boundary3-2.16.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 9223372036854775807 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.16.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.16.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.16.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=3 + ORDER BY x + } +} {} +do_test boundary3-2.16.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 9223372036854775807 ORDER BY t2.a + } +} {3} +do_test boundary3-2.16.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 9223372036854775807 ORDER BY t1.a DESC + } +} {3} +do_test boundary3-2.16.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {3} +do_test boundary3-2.16.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {3} +do_test boundary3-2.16.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=3 + ORDER BY x + } +} {3} +do_test boundary3-2.16.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 9223372036854775807 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.16.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 9223372036854775807 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.16.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary3-2.16.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=3 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.16.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 9223372036854775807 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.16.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 9223372036854775807 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.16.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.16.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.16.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=3 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=32768 AND t2.a=t1.a + } +} {50 0000000000008000} +do_test boundary3-2.17.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000008000' + } +} {32768 50} +do_test boundary3-2.17.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=50 + } +} {32768 0000000000008000} +do_test boundary3-2.17.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 32768 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary3-2.17.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 32768 ORDER BY t1.a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.17.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.17.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=50 + ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.17.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 32768 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.17.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 32768 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.17.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.17.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=50 + ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.17.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.17.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 32768 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.17.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 32768 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.17.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.17.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=50 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.17.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 32768 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.17.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 32768 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.17.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.17.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.17.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=50 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.17.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.17.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=50 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.18.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-36028797018963968 AND t2.a=t1.a + } +} {64 ff80000000000000} +do_test boundary3-2.18.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ff80000000000000' + } +} {-36028797018963968 64} +do_test boundary3-2.18.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=64 + } +} {-36028797018963968 ff80000000000000} +do_test boundary3-2.18.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -36028797018963968 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.18.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -36028797018963968 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.18.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.18.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21} +do_test boundary3-2.18.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=64 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.18.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -36028797018963968 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.18.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.18.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.18.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary3-2.18.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=64 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.18.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -36028797018963968 ORDER BY t2.a + } +} {2 55} +do_test boundary3-2.18.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -36028797018963968 ORDER BY t1.a DESC + } +} {55 2} +do_test boundary3-2.18.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {55 2} +do_test boundary3-2.18.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {2 55} +do_test boundary3-2.18.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=64 + ORDER BY x + } +} {55 2} +do_test boundary3-2.18.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -36028797018963968 ORDER BY t2.a + } +} {2 55 64} +do_test boundary3-2.18.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -36028797018963968 ORDER BY t1.a DESC + } +} {64 55 2} +do_test boundary3-2.18.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid + } +} {55 2 64} +do_test boundary3-2.18.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY t1.rowid DESC + } +} {64 2 55} +do_test boundary3-2.18.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=64 + ORDER BY x + } +} {55 2 64} +do_test boundary3-2.19.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=65535 AND t2.a=t1.a + } +} {48 000000000000ffff} +do_test boundary3-2.19.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000000ffff' + } +} {65535 48} +do_test boundary3-2.19.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=48 + } +} {65535 000000000000ffff} +do_test boundary3-2.19.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 65535 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57 62} +do_test boundary3-2.19.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 65535 ORDER BY t1.a DESC + } +} {62 57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.19.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.19.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=48 + ORDER BY x + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62} +do_test boundary3-2.19.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 65535 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 51 56 57 62} +do_test boundary3-2.19.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 65535 ORDER BY t1.a DESC + } +} {62 57 56 51 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.19.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.19.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=48 + ORDER BY x + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.19.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48} +do_test boundary3-2.19.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 65535 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.19.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 65535 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.19.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.19.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=48 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.19.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50} +do_test boundary3-2.19.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 65535 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.19.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 65535 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.19.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.19.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.19.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=48 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.19.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48} +do_test boundary3-2.19.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=48 + ORDER BY t1.rowid DESC + } +} {48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4294967295 AND t2.a=t1.a + } +} {14 00000000ffffffff} +do_test boundary3-2.20.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000ffffffff' + } +} {4294967295 14} +do_test boundary3-2.20.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=14 + } +} {4294967295 00000000ffffffff} +do_test boundary3-2.20.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4294967295 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.20.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4294967295 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.20.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.20.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=14 + ORDER BY x + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36} +do_test boundary3-2.20.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4294967295 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.20.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4294967295 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.20.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.20.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=14 + ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.20.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.20.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4294967295 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.20.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4294967295 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.20.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.20.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=14 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.20.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.20.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4294967295 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.20.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4294967295 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.20.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.20.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.20.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=14 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.20.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14} +do_test boundary3-2.20.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=14 + ORDER BY t1.rowid DESC + } +} {14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1099511627775 AND t2.a=t1.a + } +} {57 000000ffffffffff} +do_test boundary3-2.21.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000ffffffffff' + } +} {1099511627775 57} +do_test boundary3-2.21.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=57 + } +} {1099511627775 000000ffffffffff} +do_test boundary3-2.21.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1099511627775 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56} +do_test boundary3-2.21.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1099511627775 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.21.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.21.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=57 + ORDER BY x + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19} +do_test boundary3-2.21.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1099511627775 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary3-2.21.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1099511627775 ORDER BY t1.a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.21.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.21.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=57 + ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.21.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.21.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1099511627775 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.21.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1099511627775 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.21.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.21.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=57 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.21.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.21.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1099511627775 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.21.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1099511627775 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.21.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.21.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.21.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=57 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.21.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57} +do_test boundary3-2.21.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=57 + ORDER BY t1.rowid DESC + } +} {57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-8388608 AND t2.a=t1.a + } +} {37 ffffffffff800000} +do_test boundary3-2.22.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffff800000' + } +} {-8388608 37} +do_test boundary3-2.22.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=37 + } +} {-8388608 ffffffffff800000} +do_test boundary3-2.22.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -8388608 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.22.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -8388608 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.22.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.22.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=37 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 29 32 54 53 52 33 38} +do_test boundary3-2.22.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29} +do_test boundary3-2.22.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -8388608 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.22.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -8388608 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.22.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.22.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=37 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary3-2.22.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.22.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.22.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -8388608 ORDER BY t2.a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary3-2.22.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -8388608 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary3-2.22.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=37 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.22.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -8388608 ORDER BY t2.a + } +} {1 2 11 21 37 44 47 55 58 63 64} +do_test boundary3-2.22.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -8388608 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 21 11 2 1} +do_test boundary3-2.22.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.22.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=37 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37} +do_test boundary3-2.22.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=37 + ORDER BY t1.rowid DESC + } +} {37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=549755813888 AND t2.a=t1.a + } +} {35 0000008000000000} +do_test boundary3-2.23.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000008000000000' + } +} {549755813888 35} +do_test boundary3-2.23.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=35 + } +} {549755813888 0000008000000000} +do_test boundary3-2.23.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 549755813888 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 43 45 56 57} +do_test boundary3-2.23.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 549755813888 ORDER BY t1.a DESC + } +} {57 56 45 43 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.23.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.23.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=35 + ORDER BY x + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57} +do_test boundary3-2.23.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 549755813888 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary3-2.23.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 549755813888 ORDER BY t1.a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.23.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.23.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=35 + ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.23.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.23.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 549755813888 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.23.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 549755813888 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.23.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.23.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=35 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.23.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.23.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 549755813888 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.23.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 549755813888 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.23.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.23.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.23.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=35 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.23.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35} +do_test boundary3-2.23.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=35 + ORDER BY t1.rowid DESC + } +} {35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=8388607 AND t2.a=t1.a + } +} {18 00000000007fffff} +do_test boundary3-2.24.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000007fffff' + } +} {8388607 18} +do_test boundary3-2.24.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=18 + } +} {8388607 00000000007fffff} +do_test boundary3-2.24.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 8388607 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.24.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 8388607 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.24.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.24.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=18 + ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.24.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 8388607 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.24.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 8388607 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.24.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.24.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=18 + ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.24.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.24.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 8388607 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.24.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 8388607 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.24.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.24.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=18 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.24.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.24.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 8388607 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.24.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 8388607 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.24.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.24.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.24.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=18 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.24.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.24.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=18 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-3 AND t2.a=t1.a + } +} {52 fffffffffffffffd} +do_test boundary3-2.25.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='fffffffffffffffd' + } +} {-3 52} +do_test boundary3-2.25.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=52 + } +} {-3 fffffffffffffffd} +do_test boundary3-2.25.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.25.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -3 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.25.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.25.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=52 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary3-2.25.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.25.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary3-2.25.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -3 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.25.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.25.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=52 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary3-2.25.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.25.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.25.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -3 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary3-2.25.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -3 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.25.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=52 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.25.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -3 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.25.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -3 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.25.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.25.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=52 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.25.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=52 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=0 AND t2.a=t1.a + } +} {59 0000000000000000} +do_test boundary3-2.26.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000000' + } +} {0 59} +do_test boundary3-2.26.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=59 + } +} {0 0000000000000000} +do_test boundary3-2.26.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 0 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary3-2.26.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 0 ORDER BY t1.a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.26.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.26.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=59 + ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.26.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 0 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.26.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 0 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.26.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.26.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=59 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.26.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.26.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 0 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.26.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 0 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.26.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=59 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 0 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary3-2.26.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 0 ORDER BY t1.a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.26.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.26.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.26.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=59 + ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.26.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.26.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=59 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-1 AND t2.a=t1.a + } +} {38 ffffffffffffffff} +do_test boundary3-2.27.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffffff' + } +} {-1 38} +do_test boundary3-2.27.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=38 + } +} {-1 ffffffffffffffff} +do_test boundary3-2.27.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.27.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -1 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.27.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.27.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=38 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59} +do_test boundary3-2.27.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.27.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -1 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.27.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.27.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=38 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary3-2.27.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.27.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.27.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.27.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -1 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary3-2.27.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=38 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.27.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.27.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -1 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.27.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.27.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=38 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.27.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=38 + ORDER BY t1.rowid DESC + } +} {38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2 AND t2.a=t1.a + } +} {33 fffffffffffffffe} +do_test boundary3-2.28.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='fffffffffffffffe' + } +} {-2 33} +do_test boundary3-2.28.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=33 + } +} {-2 fffffffffffffffe} +do_test boundary3-2.28.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.28.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.28.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.28.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=33 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 38} +do_test boundary3-2.28.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38} +do_test boundary3-2.28.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 56 57 59 60 61 62} +do_test boundary3-2.28.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.28.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.28.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=33 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 33 38} +do_test boundary3-2.28.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.28.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33} +do_test boundary3-2.28.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.28.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.28.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=33 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52} +do_test boundary3-2.28.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 44 47 52 53 54 55 58 63 64} +do_test boundary3-2.28.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 52 47 44 37 33 32 29 21 11 2 1} +do_test boundary3-2.28.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.28.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=33 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33} +do_test boundary3-2.28.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=33 + ORDER BY t1.rowid DESC + } +} {33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2097152 AND t2.a=t1.a + } +} {42 0000000000200000} +do_test boundary3-2.29.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000200000' + } +} {2097152 42} +do_test boundary3-2.29.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=42 + } +} {2097152 0000000000200000} +do_test boundary3-2.29.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2097152 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.29.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2097152 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.29.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.29.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=42 + ORDER BY x + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18} +do_test boundary3-2.29.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2097152 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.29.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2097152 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.29.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.29.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=42 + ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.29.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.29.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2097152 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.29.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2097152 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.29.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.29.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=42 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.29.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.29.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2097152 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.29.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2097152 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.29.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.29.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.29.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=42 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.29.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42} +do_test boundary3-2.29.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=42 + ORDER BY t1.rowid DESC + } +} {42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=128 AND t2.a=t1.a + } +} {49 0000000000000080} +do_test boundary3-2.30.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000080' + } +} {128 49} +do_test boundary3-2.30.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=49 + } +} {128 0000000000000080} +do_test boundary3-2.30.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 128 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.30.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 128 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.30.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.30.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=49 + ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.30.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 128 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.30.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 128 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.30.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.30.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=49 + ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.30.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.30.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 128 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.30.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 128 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.30.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.30.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=49 + ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.30.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.30.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 128 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.30.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 128 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.30.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.30.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.30.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=49 + ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.30.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.30.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=49 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=255 AND t2.a=t1.a + } +} {30 00000000000000ff} +do_test boundary3-2.31.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000000000ff' + } +} {255 30} +do_test boundary3-2.31.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=30 + } +} {255 00000000000000ff} +do_test boundary3-2.31.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 255 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.31.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 255 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.31.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.31.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=30 + ORDER BY x + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61} +do_test boundary3-2.31.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 255 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 50 51 56 57 61 62} +do_test boundary3-2.31.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 255 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.31.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.31.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=30 + ORDER BY x + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.31.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30} +do_test boundary3-2.31.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 255 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.31.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 255 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.31.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.31.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=30 + ORDER BY x + } +} {59 60 41 5 31 4 49 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.31.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49} +do_test boundary3-2.31.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 255 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.31.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 255 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.31.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.31.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.31.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=30 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.31.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30} +do_test boundary3-2.31.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=30 + ORDER BY t1.rowid DESC + } +} {30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.32.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2147483648 AND t2.a=t1.a + } +} {11 ffffffff80000000} +do_test boundary3-2.32.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffff80000000' + } +} {-2147483648 11} +do_test boundary3-2.32.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=11 + } +} {-2147483648 ffffffff80000000} +do_test boundary3-2.32.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2147483648 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.32.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2147483648 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.32.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.32.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=11 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.32.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.32.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2147483648 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.32.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2147483648 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.32.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.32.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=11 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.32.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.32.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.32.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2147483648 ORDER BY t2.a + } +} {2 21 44 47 55 58 63 64} +do_test boundary3-2.32.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2147483648 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary3-2.32.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.32.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=11 + ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.32.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.32.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2147483648 ORDER BY t2.a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary3-2.32.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2147483648 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary3-2.32.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.32.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=11 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.32.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=11 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=34359738367 AND t2.a=t1.a + } +} {39 00000007ffffffff} +do_test boundary3-2.33.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000007ffffffff' + } +} {34359738367 39} +do_test boundary3-2.33.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=39 + } +} {34359738367 00000007ffffffff} +do_test boundary3-2.33.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 34359738367 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.33.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 34359738367 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.33.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.33.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=39 + ORDER BY x + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22} +do_test boundary3-2.33.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 34359738367 ORDER BY t2.a + } +} {3 7 10 13 17 19 22 25 26 27 28 34 35 39 43 45 46 56 57} +do_test boundary3-2.33.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 34359738367 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 35 34 28 27 26 25 22 19 17 13 10 7 3} +do_test boundary3-2.33.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.33.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=39 + ORDER BY x + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.33.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39} +do_test boundary3-2.33.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 34359738367 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.33.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 34359738367 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.33.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.33.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=39 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.33.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36} +do_test boundary3-2.33.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 34359738367 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.33.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 34359738367 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.33.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.33.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.33.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=39 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.33.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39} +do_test boundary3-2.33.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=39 + ORDER BY t1.rowid DESC + } +} {39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.34.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-549755813889 AND t2.a=t1.a + } +} {58 ffffff7fffffffff} +do_test boundary3-2.34.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffff7fffffffff' + } +} {-549755813889 58} +do_test boundary3-2.34.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=58 + } +} {-549755813889 ffffff7fffffffff} +do_test boundary3-2.34.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -549755813889 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary3-2.34.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -549755813889 ORDER BY t1.a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.34.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.34.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=58 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.34.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.34.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -549755813889 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63} +do_test boundary3-2.34.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -549755813889 ORDER BY t1.a DESC + } +} {63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.34.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.34.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=58 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.34.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.34.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58} +do_test boundary3-2.34.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -549755813889 ORDER BY t2.a + } +} {2 21 44 55 64} +do_test boundary3-2.34.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -549755813889 ORDER BY t1.a DESC + } +} {64 55 44 21 2} +do_test boundary3-2.34.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.34.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=58 + ORDER BY x + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44} +do_test boundary3-2.34.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {44 21 64 2 55} +do_test boundary3-2.34.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -549755813889 ORDER BY t2.a + } +} {2 21 44 55 58 64} +do_test boundary3-2.34.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -549755813889 ORDER BY t1.a DESC + } +} {64 58 55 44 21 2} +do_test boundary3-2.34.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.34.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=58 + ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.34.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=58 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.35.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-32768 AND t2.a=t1.a + } +} {32 ffffffffffff8000} +do_test boundary3-2.35.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffff8000' + } +} {-32768 32} +do_test boundary3-2.35.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=32 + } +} {-32768 ffffffffffff8000} +do_test boundary3-2.35.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -32768 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.35.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -32768 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.35.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.35.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=32 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary3-2.35.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.35.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -32768 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 32 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.35.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -32768 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 32 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.35.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.35.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=32 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 32 54 53 52 33 38} +do_test boundary3-2.35.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.35.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32} +do_test boundary3-2.35.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -32768 ORDER BY t2.a + } +} {1 2 11 21 29 37 44 47 55 58 63 64} +do_test boundary3-2.35.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -32768 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 29 21 11 2 1} +do_test boundary3-2.35.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=32 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29} +do_test boundary3-2.35.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -32768 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary3-2.35.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -32768 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.35.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.35.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=32 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.35.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=32 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2147483647 AND t2.a=t1.a + } +} {20 000000007fffffff} +do_test boundary3-2.36.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000007fffffff' + } +} {2147483647 20} +do_test boundary3-2.36.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=20 + } +} {2147483647 000000007fffffff} +do_test boundary3-2.36.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2147483647 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.36.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2147483647 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.36.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.36.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=20 + ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.36.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2147483647 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.36.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2147483647 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.36.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.36.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=20 + ORDER BY x + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.36.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20} +do_test boundary3-2.36.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2147483647 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.36.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2147483647 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.36.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.36.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=20 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.36.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40} +do_test boundary3-2.36.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2147483647 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.36.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2147483647 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.36.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.36.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.36.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=20 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.36.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.36.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=20 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-129 AND t2.a=t1.a + } +} {54 ffffffffffffff7f} +do_test boundary3-2.37.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffff7f' + } +} {-129 54} +do_test boundary3-2.37.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=54 + } +} {-129 ffffffffffffff7f} +do_test boundary3-2.37.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -129 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary3-2.37.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -129 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.37.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.37.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=54 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary3-2.37.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.37.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -129 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.37.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -129 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.37.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.37.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=54 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 54 53 52 33 38} +do_test boundary3-2.37.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.37.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54} +do_test boundary3-2.37.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -129 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 55 58 63 64} +do_test boundary3-2.37.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -129 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.37.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=54 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32} +do_test boundary3-2.37.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -129 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary3-2.37.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -129 ORDER BY t1.a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.37.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.37.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=54 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.37.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=54 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-128 AND t2.a=t1.a + } +} {53 ffffffffffffff80} +do_test boundary3-2.38.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffffffff80' + } +} {-128 53} +do_test boundary3-2.38.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=53 + } +} {-128 ffffffffffffff80} +do_test boundary3-2.38.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -128 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 56 57 59 60 61 62} +do_test boundary3-2.38.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -128 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.38.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.38.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=53 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 52 33 38} +do_test boundary3-2.38.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52} +do_test boundary3-2.38.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -128 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 33 34 35 36 38 39 40 41 42 43 45 46 48 49 50 51 52 53 56 57 59 60 61 62} +do_test boundary3-2.38.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -128 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 53 52 51 50 49 48 46 45 43 42 41 40 39 38 36 35 34 33 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.38.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.38.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=53 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 53 52 33 38} +do_test boundary3-2.38.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.38.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53} +do_test boundary3-2.38.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -128 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 54 55 58 63 64} +do_test boundary3-2.38.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -128 ORDER BY t1.a DESC + } +} {64 63 58 55 54 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.38.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=53 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54} +do_test boundary3-2.38.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -128 ORDER BY t2.a + } +} {1 2 11 21 29 32 37 44 47 53 54 55 58 63 64} +do_test boundary3-2.38.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -128 ORDER BY t1.a DESC + } +} {64 63 58 55 54 53 47 44 37 32 29 21 11 2 1} +do_test boundary3-2.38.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.38.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=53 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53} +do_test boundary3-2.38.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=53 + ORDER BY t1.rowid DESC + } +} {53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=72057594037927936 AND t2.a=t1.a + } +} {28 0100000000000000} +do_test boundary3-2.39.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0100000000000000' + } +} {72057594037927936 28} +do_test boundary3-2.39.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=28 + } +} {72057594037927936 0100000000000000} +do_test boundary3-2.39.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 72057594037927936 ORDER BY t2.a + } +} {3} +do_test boundary3-2.39.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 72057594037927936 ORDER BY t1.a DESC + } +} {3} +do_test boundary3-2.39.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {3} +do_test boundary3-2.39.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {3} +do_test boundary3-2.39.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=28 + ORDER BY x + } +} {3} +do_test boundary3-2.39.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 72057594037927936 ORDER BY t2.a + } +} {3 28} +do_test boundary3-2.39.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 72057594037927936 ORDER BY t1.a DESC + } +} {28 3} +do_test boundary3-2.39.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {28 3} +do_test boundary3-2.39.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {3 28} +do_test boundary3-2.39.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=28 + ORDER BY x + } +} {28 3} +do_test boundary3-2.39.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 72057594037927936 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.39.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 72057594037927936 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.39.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17} +do_test boundary3-2.39.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=28 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.39.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 72057594037927936 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.39.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 72057594037927936 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.39.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28} +do_test boundary3-2.39.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY t1.rowid DESC + } +} {28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.39.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=28 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2147483648 AND t2.a=t1.a + } +} {51 0000000080000000} +do_test boundary3-2.40.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000080000000' + } +} {2147483648 51} +do_test boundary3-2.40.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=51 + } +} {2147483648 0000000080000000} +do_test boundary3-2.40.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2147483648 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 56 57} +do_test boundary3-2.40.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2147483648 ORDER BY t1.a DESC + } +} {57 56 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.40.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.40.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=51 + ORDER BY x + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14} +do_test boundary3-2.40.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2147483648 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 22 25 26 27 28 34 35 36 39 43 45 46 51 56 57} +do_test boundary3-2.40.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2147483648 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 39 36 35 34 28 27 26 25 22 19 17 14 13 10 7 3} +do_test boundary3-2.40.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.40.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=51 + ORDER BY x + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.40.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51} +do_test boundary3-2.40.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2147483648 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.40.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2147483648 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.40.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.40.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=51 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20} +do_test boundary3-2.40.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2147483648 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 20 21 23 24 29 30 31 32 33 37 38 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.40.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2147483648 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 38 37 33 32 31 30 29 24 23 21 20 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.40.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.40.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.40.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=51 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.40.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51} +do_test boundary3-2.40.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=51 + ORDER BY t1.rowid DESC + } +} {51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=549755813887 AND t2.a=t1.a + } +} {46 0000007fffffffff} +do_test boundary3-2.41.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000007fffffffff' + } +} {549755813887 46} +do_test boundary3-2.41.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=46 + } +} {549755813887 0000007fffffffff} +do_test boundary3-2.41.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 549755813887 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 56 57} +do_test boundary3-2.41.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 549755813887 ORDER BY t1.a DESC + } +} {57 56 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.41.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.41.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=46 + ORDER BY x + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35} +do_test boundary3-2.41.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 549755813887 ORDER BY t2.a + } +} {3 7 10 13 17 19 25 26 27 28 34 35 43 45 46 56 57} +do_test boundary3-2.41.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 549755813887 ORDER BY t1.a DESC + } +} {57 56 46 45 43 35 34 28 27 26 25 19 17 13 10 7 3} +do_test boundary3-2.41.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.41.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=46 + ORDER BY x + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.41.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46} +do_test boundary3-2.41.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 549755813887 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.41.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 549755813887 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.41.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.41.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=46 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.41.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22} +do_test boundary3-2.41.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 549755813887 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 20 21 22 23 24 29 30 31 32 33 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.41.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 549755813887 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 33 32 31 30 29 24 23 22 21 20 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.41.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.41.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.41.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=46 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.41.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46} +do_test boundary3-2.41.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=46 + ORDER BY t1.rowid DESC + } +} {46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.42.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-549755813888 AND t2.a=t1.a + } +} {63 ffffff8000000000} +do_test boundary3-2.42.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffff8000000000' + } +} {-549755813888 63} +do_test boundary3-2.42.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=63 + } +} {-549755813888 ffffff8000000000} +do_test boundary3-2.42.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -549755813888 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.42.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -549755813888 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.42.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.42.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=63 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.42.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.42.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -549755813888 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62 63} +do_test boundary3-2.42.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -549755813888 ORDER BY t1.a DESC + } +} {63 62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.42.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.42.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=63 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.42.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.42.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63} +do_test boundary3-2.42.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -549755813888 ORDER BY t2.a + } +} {2 21 44 55 58 64} +do_test boundary3-2.42.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -549755813888 ORDER BY t1.a DESC + } +} {64 58 55 44 21 2} +do_test boundary3-2.42.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.42.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=63 + ORDER BY x + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58} +do_test boundary3-2.42.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {58 44 21 64 2 55} +do_test boundary3-2.42.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -549755813888 ORDER BY t2.a + } +} {2 21 44 55 58 63 64} +do_test boundary3-2.42.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -549755813888 ORDER BY t1.a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary3-2.42.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.42.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=63 + ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.42.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=63 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.43.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=281474976710655 AND t2.a=t1.a + } +} {10 0000ffffffffffff} +do_test boundary3-2.43.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000ffffffffffff' + } +} {281474976710655 10} +do_test boundary3-2.43.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=10 + } +} {281474976710655 0000ffffffffffff} +do_test boundary3-2.43.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 281474976710655 ORDER BY t2.a + } +} {3 13 17 26 27 28 43 45} +do_test boundary3-2.43.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 281474976710655 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary3-2.43.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.43.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary3-2.43.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=10 + ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.43.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 281474976710655 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary3-2.43.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 281474976710655 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary3-2.43.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.43.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary3-2.43.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=10 + ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.43.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 281474976710655 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.43.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 281474976710655 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.43.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary3-2.43.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.43.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=10 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.43.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 281474976710655 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.43.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 281474976710655 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.43.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary3-2.43.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY t1.rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.43.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=10 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4398046511103 AND t2.a=t1.a + } +} {7 000003ffffffffff} +do_test boundary3-2.44.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000003ffffffffff' + } +} {4398046511103 7} +do_test boundary3-2.44.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=7 + } +} {4398046511103 000003ffffffffff} +do_test boundary3-2.44.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4398046511103 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.44.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4398046511103 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.44.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.44.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=7 + ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.44.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4398046511103 ORDER BY t2.a + } +} {3 7 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.44.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4398046511103 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 7 3} +do_test boundary3-2.44.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.44.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=7 + ORDER BY x + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.44.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7} +do_test boundary3-2.44.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4398046511103 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.44.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4398046511103 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.44.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.44.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=7 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19} +do_test boundary3-2.44.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4398046511103 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.44.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4398046511103 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.44.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.44.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.44.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=7 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.44.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.44.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=7 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=268435455 AND t2.a=t1.a + } +} {12 000000000fffffff} +do_test boundary3-2.45.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000fffffff' + } +} {268435455 12} +do_test boundary3-2.45.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=12 + } +} {268435455 000000000fffffff} +do_test boundary3-2.45.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 268435455 ORDER BY t2.a + } +} {3 7 10 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.45.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 268435455 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 10 7 3} +do_test boundary3-2.45.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.45.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=12 + ORDER BY x + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40} +do_test boundary3-2.45.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 268435455 ORDER BY t2.a + } +} {3 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.45.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 268435455 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 3} +do_test boundary3-2.45.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.45.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=12 + ORDER BY x + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.45.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12} +do_test boundary3-2.45.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 268435455 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.45.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 268435455 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 6 5 4 2 1} +do_test boundary3-2.45.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.45.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=12 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.45.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6} +do_test boundary3-2.45.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 268435455 ORDER BY t2.a + } +} {1 2 4 5 6 8 9 11 12 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.45.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 268435455 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 12 11 9 8 6 5 4 2 1} +do_test boundary3-2.45.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.45.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.45.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=12 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.45.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12} +do_test boundary3-2.45.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=12 + ORDER BY t1.rowid DESC + } +} {12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.46.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-9223372036854775808 AND t2.a=t1.a + } +} {55 8000000000000000} +do_test boundary3-2.46.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='8000000000000000' + } +} {-9223372036854775808 55} +do_test boundary3-2.46.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=55 + } +} {-9223372036854775808 8000000000000000} +do_test boundary3-2.46.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -9223372036854775808 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.46.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -9223372036854775808 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.46.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.46.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary3-2.46.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=55 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.46.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -9223372036854775808 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.46.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -9223372036854775808 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.46.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.46.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.46.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=55 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.46.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -9223372036854775808 ORDER BY t2.a + } +} {} +do_test boundary3-2.46.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -9223372036854775808 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.46.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.46.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.46.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=55 + ORDER BY x + } +} {} +do_test boundary3-2.46.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -9223372036854775808 ORDER BY t2.a + } +} {55} +do_test boundary3-2.46.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -9223372036854775808 ORDER BY t1.a DESC + } +} {55} +do_test boundary3-2.46.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid + } +} {55} +do_test boundary3-2.46.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY t1.rowid DESC + } +} {55} +do_test boundary3-2.46.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=55 + ORDER BY x + } +} {55} +do_test boundary3-2.47.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=562949953421312 AND t2.a=t1.a + } +} {43 0002000000000000} +do_test boundary3-2.47.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0002000000000000' + } +} {562949953421312 43} +do_test boundary3-2.47.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=43 + } +} {562949953421312 0002000000000000} +do_test boundary3-2.47.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 562949953421312 ORDER BY t2.a + } +} {3 17 27 28 45} +do_test boundary3-2.47.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 562949953421312 ORDER BY t1.a DESC + } +} {45 28 27 17 3} +do_test boundary3-2.47.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {27 45 17 28 3} +do_test boundary3-2.47.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27} +do_test boundary3-2.47.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=43 + ORDER BY x + } +} {27 45 17 28 3} +do_test boundary3-2.47.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 562949953421312 ORDER BY t2.a + } +} {3 17 27 28 43 45} +do_test boundary3-2.47.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 562949953421312 ORDER BY t1.a DESC + } +} {45 43 28 27 17 3} +do_test boundary3-2.47.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {43 27 45 17 28 3} +do_test boundary3-2.47.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43} +do_test boundary3-2.47.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=43 + ORDER BY x + } +} {43 27 45 17 28 3} +do_test boundary3-2.47.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 562949953421312 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.47.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 562949953421312 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.47.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13} +do_test boundary3-2.47.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.47.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=43 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.47.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 562949953421312 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.47.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 562949953421312 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.47.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary3-2.47.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY t1.rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.47.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=43 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-8388609 AND t2.a=t1.a + } +} {1 ffffffffff7fffff} +do_test boundary3-2.48.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffffff7fffff' + } +} {-8388609 1} +do_test boundary3-2.48.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=1 + } +} {-8388609 ffffffffff7fffff} +do_test boundary3-2.48.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -8388609 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.48.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -8388609 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.48.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.48.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=1 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37} +do_test boundary3-2.48.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -8388609 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.48.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -8388609 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.48.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.48.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=1 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.48.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.48.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1} +do_test boundary3-2.48.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -8388609 ORDER BY t2.a + } +} {2 11 21 44 47 55 58 63 64} +do_test boundary3-2.48.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -8388609 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2} +do_test boundary3-2.48.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=1 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11} +do_test boundary3-2.48.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -8388609 ORDER BY t2.a + } +} {1 2 11 21 44 47 55 58 63 64} +do_test boundary3-2.48.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -8388609 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 11 2 1} +do_test boundary3-2.48.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.48.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=1 + ORDER BY x + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1} +do_test boundary3-2.48.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=1 + ORDER BY t1.rowid DESC + } +} {1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16777215 AND t2.a=t1.a + } +} {9 0000000000ffffff} +do_test boundary3-2.49.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000ffffff' + } +} {16777215 9} +do_test boundary3-2.49.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=9 + } +} {16777215 0000000000ffffff} +do_test boundary3-2.49.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16777215 ORDER BY t2.a + } +} {3 6 7 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.49.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16777215 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 7 6 3} +do_test boundary3-2.49.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.49.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=9 + ORDER BY x + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6} +do_test boundary3-2.49.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16777215 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.49.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16777215 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.49.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.49.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=9 + ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.49.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.49.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16777215 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.49.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16777215 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.49.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.49.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=9 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.49.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.49.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16777215 ORDER BY t2.a + } +} {1 2 4 5 8 9 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.49.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16777215 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 9 8 5 4 2 1} +do_test boundary3-2.49.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.49.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.49.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=9 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.49.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9} +do_test boundary3-2.49.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=9 + ORDER BY t1.rowid DESC + } +} {9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=8388608 AND t2.a=t1.a + } +} {24 0000000000800000} +do_test boundary3-2.50.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000800000' + } +} {8388608 24} +do_test boundary3-2.50.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=24 + } +} {8388608 0000000000800000} +do_test boundary3-2.50.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 8388608 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.50.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 8388608 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.50.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.50.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=24 + ORDER BY x + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9} +do_test boundary3-2.50.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 8388608 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 19 20 22 24 25 26 27 28 34 35 36 39 40 43 45 46 51 56 57} +do_test boundary3-2.50.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 8388608 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 40 39 36 35 34 28 27 26 25 24 22 20 19 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.50.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.50.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=24 + ORDER BY x + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.50.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24} +do_test boundary3-2.50.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 8388608 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.50.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 8388608 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.50.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.50.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=24 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.50.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18} +do_test boundary3-2.50.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 8388608 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 18 21 23 24 29 30 31 32 33 37 38 41 42 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.50.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 8388608 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 42 41 38 37 33 32 31 30 29 24 23 21 18 16 15 11 8 5 4 2 1} +do_test boundary3-2.50.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.50.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.50.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=24 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.50.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24} +do_test boundary3-2.50.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=24 + ORDER BY t1.rowid DESC + } +} {24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=16383 AND t2.a=t1.a + } +} {8 0000000000003fff} +do_test boundary3-2.51.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000003fff' + } +} {16383 8} +do_test boundary3-2.51.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=8 + } +} {16383 0000000000003fff} +do_test boundary3-2.51.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 16383 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.51.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 16383 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.51.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.51.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=8 + ORDER BY x + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16} +do_test boundary3-2.51.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 16383 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.51.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 16383 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.51.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.51.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=8 + ORDER BY x + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.51.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8} +do_test boundary3-2.51.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 16383 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.51.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 16383 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 5 4 2 1} +do_test boundary3-2.51.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.51.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=8 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.51.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61} +do_test boundary3-2.51.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 16383 ORDER BY t2.a + } +} {1 2 4 5 8 11 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.51.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 16383 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 11 8 5 4 2 1} +do_test boundary3-2.51.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.51.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.51.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=8 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.51.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8} +do_test boundary3-2.51.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=8 + ORDER BY t1.rowid DESC + } +} {8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=140737488355328 AND t2.a=t1.a + } +} {34 0000800000000000} +do_test boundary3-2.52.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000800000000000' + } +} {140737488355328 34} +do_test boundary3-2.52.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=34 + } +} {140737488355328 0000800000000000} +do_test boundary3-2.52.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 140737488355328 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 43 45} +do_test boundary3-2.52.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 140737488355328 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 10 3} +do_test boundary3-2.52.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10} +do_test boundary3-2.52.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=34 + ORDER BY x + } +} {10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 140737488355328 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary3-2.52.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 140737488355328 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary3-2.52.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary3-2.52.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=34 + ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.52.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 140737488355328 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.52.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 140737488355328 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.52.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary3-2.52.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=34 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.52.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 140737488355328 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.52.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 140737488355328 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.52.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34} +do_test boundary3-2.52.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY t1.rowid DESC + } +} {34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.52.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=34 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=2097151 AND t2.a=t1.a + } +} {15 00000000001fffff} +do_test boundary3-2.53.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00000000001fffff' + } +} {2097151 15} +do_test boundary3-2.53.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=15 + } +} {2097151 00000000001fffff} +do_test boundary3-2.53.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 2097151 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.53.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 2097151 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 14 13 12 10 9 7 6 3} +do_test boundary3-2.53.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.53.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=15 + ORDER BY x + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42} +do_test boundary3-2.53.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 2097151 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 51 56 57} +do_test boundary3-2.53.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 2097151 ORDER BY t1.a DESC + } +} {57 56 51 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.53.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.53.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=15 + ORDER BY x + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.53.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15} +do_test boundary3-2.53.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 2097151 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.53.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 2097151 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.53.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.53.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=15 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62} +do_test boundary3-2.53.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 2097151 ORDER BY t2.a + } +} {1 2 4 5 8 11 15 16 21 23 29 30 31 32 33 37 38 41 44 47 48 49 50 52 53 54 55 58 59 60 61 62 63 64} +do_test boundary3-2.53.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 2097151 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 55 54 53 52 50 49 48 47 44 41 38 37 33 32 31 30 29 23 21 16 15 11 8 5 4 2 1} +do_test boundary3-2.53.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.53.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.53.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=15 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.53.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15} +do_test boundary3-2.53.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=15 + ORDER BY t1.rowid DESC + } +} {15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=140737488355327 AND t2.a=t1.a + } +} {25 00007fffffffffff} +do_test boundary3-2.54.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='00007fffffffffff' + } +} {140737488355327 25} +do_test boundary3-2.54.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=25 + } +} {140737488355327 00007fffffffffff} +do_test boundary3-2.54.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 140737488355327 ORDER BY t2.a + } +} {3 10 13 17 26 27 28 34 43 45} +do_test boundary3-2.54.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 140737488355327 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 17 13 10 3} +do_test boundary3-2.54.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34} +do_test boundary3-2.54.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=25 + ORDER BY x + } +} {34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 140737488355327 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary3-2.54.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 140737488355327 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.54.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.54.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=25 + ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.54.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 140737488355327 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.54.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 140737488355327 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.54.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.54.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=25 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.54.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 140737488355327 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.54.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 140737488355327 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.54.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25} +do_test boundary3-2.54.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY t1.rowid DESC + } +} {25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.54.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=25 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.55.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=281474976710656 AND t2.a=t1.a + } +} {26 0001000000000000} +do_test boundary3-2.55.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0001000000000000' + } +} {281474976710656 26} +do_test boundary3-2.55.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=26 + } +} {281474976710656 0001000000000000} +do_test boundary3-2.55.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 281474976710656 ORDER BY t2.a + } +} {3 13 17 27 28 43 45} +do_test boundary3-2.55.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 281474976710656 ORDER BY t1.a DESC + } +} {45 43 28 27 17 13 3} +do_test boundary3-2.55.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.55.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13} +do_test boundary3-2.55.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=26 + ORDER BY x + } +} {13 43 27 45 17 28 3} +do_test boundary3-2.55.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 281474976710656 ORDER BY t2.a + } +} {3 13 17 26 27 28 43 45} +do_test boundary3-2.55.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 281474976710656 ORDER BY t1.a DESC + } +} {45 43 28 27 26 17 13 3} +do_test boundary3-2.55.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.55.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26} +do_test boundary3-2.55.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=26 + ORDER BY x + } +} {26 13 43 27 45 17 28 3} +do_test boundary3-2.55.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 281474976710656 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.55.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 281474976710656 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.55.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10} +do_test boundary3-2.55.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.55.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=26 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.55.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 281474976710656 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.55.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 281474976710656 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.55.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26} +do_test boundary3-2.55.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY t1.rowid DESC + } +} {26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.55.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=26 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=32767 AND t2.a=t1.a + } +} {23 0000000000007fff} +do_test boundary3-2.56.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000007fff' + } +} {32767 23} +do_test boundary3-2.56.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=23 + } +} {32767 0000000000007fff} +do_test boundary3-2.56.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 32767 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.56.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 32767 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.56.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.56.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=23 + ORDER BY x + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50} +do_test boundary3-2.56.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 32767 ORDER BY t2.a + } +} {3 6 7 9 10 12 13 14 15 17 18 19 20 22 23 24 25 26 27 28 34 35 36 39 40 42 43 45 46 48 50 51 56 57 62} +do_test boundary3-2.56.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 32767 ORDER BY t1.a DESC + } +} {62 57 56 51 50 48 46 45 43 42 40 39 36 35 34 28 27 26 25 24 23 22 20 19 18 17 15 14 13 12 10 9 7 6 3} +do_test boundary3-2.56.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.56.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=23 + ORDER BY x + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.56.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23} +do_test boundary3-2.56.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 32767 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.56.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 32767 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 21 16 11 8 5 4 2 1} +do_test boundary3-2.56.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.56.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=23 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16} +do_test boundary3-2.56.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 32767 ORDER BY t2.a + } +} {1 2 4 5 8 11 16 21 23 29 30 31 32 33 37 38 41 44 47 49 52 53 54 55 58 59 60 61 63 64} +do_test boundary3-2.56.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 32767 ORDER BY t1.a DESC + } +} {64 63 61 60 59 58 55 54 53 52 49 47 44 41 38 37 33 32 31 30 29 23 21 16 11 8 5 4 2 1} +do_test boundary3-2.56.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.56.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.56.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=23 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.56.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23} +do_test boundary3-2.56.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=23 + ORDER BY t1.rowid DESC + } +} {23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=127 AND t2.a=t1.a + } +} {4 000000000000007f} +do_test boundary3-2.57.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='000000000000007f' + } +} {127 4} +do_test boundary3-2.57.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=4 + } +} {127 000000000000007f} +do_test boundary3-2.57.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 127 ORDER BY t2.a + } +} {3 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.57.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 127 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 3} +do_test boundary3-2.57.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.57.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=4 + ORDER BY x + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49} +do_test boundary3-2.57.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 127 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.57.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 127 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.57.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.57.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=4 + ORDER BY x + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.57.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4} +do_test boundary3-2.57.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 127 ORDER BY t2.a + } +} {1 2 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.57.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 127 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 2 1} +do_test boundary3-2.57.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.57.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=4 + ORDER BY x + } +} {59 60 41 5 31 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.57.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31} +do_test boundary3-2.57.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 127 ORDER BY t2.a + } +} {1 2 4 5 11 21 29 31 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.57.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 127 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 31 29 21 11 5 4 2 1} +do_test boundary3-2.57.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.57.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.57.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=4 + ORDER BY x + } +} {59 60 41 5 31 4 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.57.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4} +do_test boundary3-2.57.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=4 + ORDER BY t1.rowid DESC + } +} {4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=36028797018963967 AND t2.a=t1.a + } +} {27 007fffffffffffff} +do_test boundary3-2.58.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='007fffffffffffff' + } +} {36028797018963967 27} +do_test boundary3-2.58.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=27 + } +} {36028797018963967 007fffffffffffff} +do_test boundary3-2.58.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 36028797018963967 ORDER BY t2.a + } +} {3 17 28 45} +do_test boundary3-2.58.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 36028797018963967 ORDER BY t1.a DESC + } +} {45 28 17 3} +do_test boundary3-2.58.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {45 17 28 3} +do_test boundary3-2.58.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {3 28 17 45} +do_test boundary3-2.58.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=27 + ORDER BY x + } +} {45 17 28 3} +do_test boundary3-2.58.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 36028797018963967 ORDER BY t2.a + } +} {3 17 27 28 45} +do_test boundary3-2.58.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 36028797018963967 ORDER BY t1.a DESC + } +} {45 28 27 17 3} +do_test boundary3-2.58.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {27 45 17 28 3} +do_test boundary3-2.58.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27} +do_test boundary3-2.58.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=27 + ORDER BY x + } +} {27 45 17 28 3} +do_test boundary3-2.58.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 36028797018963967 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.58.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 36028797018963967 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.58.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43} +do_test boundary3-2.58.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=27 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.58.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 36028797018963967 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.58.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 36028797018963967 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.58.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary3-2.58.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY t1.rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.58.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=27 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=4398046511104 AND t2.a=t1.a + } +} {56 0000040000000000} +do_test boundary3-2.59.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000040000000000' + } +} {4398046511104 56} +do_test boundary3-2.59.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=56 + } +} {4398046511104 0000040000000000} +do_test boundary3-2.59.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 4398046511104 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45} +do_test boundary3-2.59.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 4398046511104 ORDER BY t1.a DESC + } +} {45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.59.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.59.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=56 + ORDER BY x + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25} +do_test boundary3-2.59.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 4398046511104 ORDER BY t2.a + } +} {3 10 13 17 25 26 27 28 34 43 45 56} +do_test boundary3-2.59.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 4398046511104 ORDER BY t1.a DESC + } +} {56 45 43 34 28 27 26 25 17 13 10 3} +do_test boundary3-2.59.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.59.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=56 + ORDER BY x + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.59.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56} +do_test boundary3-2.59.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 4398046511104 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 57 58 59 60 61 62 63 64} +do_test boundary3-2.59.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 4398046511104 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.59.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.59.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=56 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7} +do_test boundary3-2.59.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 4398046511104 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 11 12 14 15 16 18 19 20 21 22 23 24 29 30 31 32 33 35 36 37 38 39 40 41 42 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.59.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 4398046511104 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 42 41 40 39 38 37 36 35 33 32 31 30 29 24 23 22 21 20 19 18 16 15 14 12 11 9 8 7 6 5 4 2 1} +do_test boundary3-2.59.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.59.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.59.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=56 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.59.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56} +do_test boundary3-2.59.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=56 + ORDER BY t1.rowid DESC + } +} {56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=1 AND t2.a=t1.a + } +} {60 0000000000000001} +do_test boundary3-2.60.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000001' + } +} {1 60} +do_test boundary3-2.60.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=60 + } +} {1 0000000000000001} +do_test boundary3-2.60.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.60.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 1 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.60.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.60.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=60 + ORDER BY x + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41} +do_test boundary3-2.60.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 1 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 41 42 43 45 46 48 49 50 51 56 57 60 61 62} +do_test boundary3-2.60.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 1 ORDER BY t1.a DESC + } +} {62 61 60 57 56 51 50 49 48 46 45 43 42 41 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.60.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.60.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=60 + ORDER BY x + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.60.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60} +do_test boundary3-2.60.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 63 64} +do_test boundary3-2.60.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 1 ORDER BY t1.a DESC + } +} {64 63 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.60.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.60.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=60 + ORDER BY x + } +} {59 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.60.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59} +do_test boundary3-2.60.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 1 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.60.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 1 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.60.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.60.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.60.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=60 + ORDER BY x + } +} {59 60 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.60.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60} +do_test boundary3-2.60.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=60 + ORDER BY t1.rowid DESC + } +} {60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=36028797018963968 AND t2.a=t1.a + } +} {45 0080000000000000} +do_test boundary3-2.61.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0080000000000000' + } +} {36028797018963968 45} +do_test boundary3-2.61.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=45 + } +} {36028797018963968 0080000000000000} +do_test boundary3-2.61.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 36028797018963968 ORDER BY t2.a + } +} {3 17 28} +do_test boundary3-2.61.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 36028797018963968 ORDER BY t1.a DESC + } +} {28 17 3} +do_test boundary3-2.61.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {17 28 3} +do_test boundary3-2.61.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {3 28 17} +do_test boundary3-2.61.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=45 + ORDER BY x + } +} {17 28 3} +do_test boundary3-2.61.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 36028797018963968 ORDER BY t2.a + } +} {3 17 28 45} +do_test boundary3-2.61.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 36028797018963968 ORDER BY t1.a DESC + } +} {45 28 17 3} +do_test boundary3-2.61.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {45 17 28 3} +do_test boundary3-2.61.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {3 28 17 45} +do_test boundary3-2.61.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=45 + ORDER BY x + } +} {45 17 28 3} +do_test boundary3-2.61.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 36028797018963968 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.61.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.61.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27} +do_test boundary3-2.61.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=45 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.61.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 36028797018963968 ORDER BY t2.a + } +} {1 2 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.61.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 36028797018963968 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 27 26 25 24 23 22 21 20 19 18 16 15 14 13 12 11 10 9 8 7 6 5 4 2 1} +do_test boundary3-2.61.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45} +do_test boundary3-2.61.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY t1.rowid DESC + } +} {45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.61.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=45 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-2147483649 AND t2.a=t1.a + } +} {47 ffffffff7fffffff} +do_test boundary3-2.62.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ffffffff7fffffff' + } +} {-2147483649 47} +do_test boundary3-2.62.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=47 + } +} {-2147483649 ffffffff7fffffff} +do_test boundary3-2.62.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -2147483649 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.62.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -2147483649 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.62.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.62.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=47 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11} +do_test boundary3-2.62.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -2147483649 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 45 46 47 48 49 50 51 52 53 54 56 57 59 60 61 62} +do_test boundary3-2.62.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -2147483649 ORDER BY t1.a DESC + } +} {62 61 60 59 57 56 54 53 52 51 50 49 48 47 46 45 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.62.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.62.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=47 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.62.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.62.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47} +do_test boundary3-2.62.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -2147483649 ORDER BY t2.a + } +} {2 21 44 55 58 63 64} +do_test boundary3-2.62.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -2147483649 ORDER BY t1.a DESC + } +} {64 63 58 55 44 21 2} +do_test boundary3-2.62.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.62.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=47 + ORDER BY x + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63} +do_test boundary3-2.62.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {63 58 44 21 64 2 55} +do_test boundary3-2.62.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -2147483649 ORDER BY t2.a + } +} {2 21 44 47 55 58 63 64} +do_test boundary3-2.62.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -2147483649 ORDER BY t1.a DESC + } +} {64 63 58 55 47 44 21 2} +do_test boundary3-2.62.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.62.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=47 + ORDER BY x + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47} +do_test boundary3-2.62.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=47 + ORDER BY t1.rowid DESC + } +} {47 63 58 44 21 64 2 55} +do_test boundary3-2.63.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=-36028797018963969 AND t2.a=t1.a + } +} {2 ff7fffffffffffff} +do_test boundary3-2.63.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='ff7fffffffffffff' + } +} {-36028797018963969 2} +do_test boundary3-2.63.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=2 + } +} {-36028797018963969 ff7fffffffffffff} +do_test boundary3-2.63.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -36028797018963969 ORDER BY t2.a + } +} {1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.63.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -36028797018963969 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 1} +do_test boundary3-2.63.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.63.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64} +do_test boundary3-2.63.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=2 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.63.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -36028797018963969 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.63.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -36028797018963969 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.63.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.63.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2} +do_test boundary3-2.63.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=2 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.63.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -36028797018963969 ORDER BY t2.a + } +} {55} +do_test boundary3-2.63.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -36028797018963969 ORDER BY t1.a DESC + } +} {55} +do_test boundary3-2.63.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {55} +do_test boundary3-2.63.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {55} +do_test boundary3-2.63.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=2 + ORDER BY x + } +} {55} +do_test boundary3-2.63.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -36028797018963969 ORDER BY t2.a + } +} {2 55} +do_test boundary3-2.63.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -36028797018963969 ORDER BY t1.a DESC + } +} {55 2} +do_test boundary3-2.63.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid + } +} {55 2} +do_test boundary3-2.63.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY t1.rowid DESC + } +} {2 55} +do_test boundary3-2.63.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=2 + ORDER BY x + } +} {55 2} +do_test boundary3-2.64.1 { + db eval { + SELECT t1.* FROM t1, t2 WHERE t1.rowid=3 AND t2.a=t1.a + } +} {5 0000000000000003} +do_test boundary3-2.64.2 { + db eval { + SELECT t2.* FROM t1 JOIN t2 USING(a) WHERE x='0000000000000003' + } +} {3 5} +do_test boundary3-2.64.3 { + db eval { + SELECT t1.rowid, x FROM t1 JOIN t2 ON t2.r=t1.rowid WHERE t2.a=5 + } +} {3 0000000000000003} +do_test boundary3-2.64.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 3 ORDER BY t2.a + } +} {3 4 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.64.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 3 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 4 3} +do_test boundary3-2.64.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.64.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=5 + ORDER BY x + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.gt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31} +do_test boundary3-2.64.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 3 ORDER BY t2.a + } +} {3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 30 31 34 35 36 39 40 42 43 45 46 48 49 50 51 56 57 61 62} +do_test boundary3-2.64.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 3 ORDER BY t1.a DESC + } +} {62 61 57 56 51 50 49 48 46 45 43 42 40 39 36 35 34 31 30 28 27 26 25 24 23 22 20 19 18 17 16 15 14 13 12 10 9 8 7 6 5 4 3} +do_test boundary3-2.64.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.64.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=5 + ORDER BY x + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.64.ge.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5} +do_test boundary3-2.64.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 3 ORDER BY t2.a + } +} {1 2 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.64.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 3 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 2 1} +do_test boundary3-2.64.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.64.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=5 + ORDER BY x + } +} {59 60 41 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.64.lt.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41} +do_test boundary3-2.64.lt.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 3 ORDER BY t2.a + } +} {1 2 5 11 21 29 32 33 37 38 41 44 47 52 53 54 55 58 59 60 63 64} +do_test boundary3-2.64.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 3 ORDER BY t1.a DESC + } +} {64 63 60 59 58 55 54 53 52 47 44 41 38 37 33 32 29 21 11 5 2 1} +do_test boundary3-2.64.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.64.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.64.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=5 + ORDER BY x + } +} {59 60 41 5 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.64.le.10 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5} +do_test boundary3-2.64.le.11 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= CAST(t2.r AS real) + WHERE t2.a=5 + ORDER BY t1.rowid DESC + } +} {5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > 9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.65.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.65.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.65.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.65.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=65 + ORDER BY x + } +} {} +do_test boundary3-2.65.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= 9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.65.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.65.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.65.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.65.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=65 + ORDER BY x + } +} {} +do_test boundary3-2.65.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < 9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.65.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.65.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.65.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=65 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.65.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= 9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.65.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= 9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.65.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.65.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.65.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=65 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.gt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid > -9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.66.gt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid > -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.66.gt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.66.gt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.66.gt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid > t2.r + WHERE t2.a=66 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.ge.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid >= -9.22337303685477580800e+18 ORDER BY t2.a + } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64} +do_test boundary3-2.66.ge.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid >= -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1} +do_test boundary3-2.66.ge.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38 59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3} +do_test boundary3-2.66.ge.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {3 28 17 45 27 43 13 26 10 34 25 56 7 19 57 35 46 22 39 36 14 51 20 40 12 6 9 24 18 42 15 62 48 50 23 16 8 61 30 49 4 31 5 41 60 59 38 33 52 53 54 32 29 37 1 11 47 63 58 44 21 64 2 55} +do_test boundary3-2.66.ge.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid >= t2.r + WHERE t2.a=66 + ORDER BY x + } +} {59 60 41 5 31 4 49 30 61 8 16 23 50 48 62 15 42 18 24 9 6 12 40 20 51 14 36 39 22 46 35 57 19 7 56 25 34 10 26 13 43 27 45 17 28 3 55 2 64 21 44 58 63 47 11 1 37 29 32 54 53 52 33 38} +do_test boundary3-2.66.lt.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid < -9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.66.lt.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid < -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.66.lt.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.66.lt.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.66.lt.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid < t2.r + WHERE t2.a=66 + ORDER BY x + } +} {} +do_test boundary3-2.66.le.1 { + db eval { + SELECT t2.a FROM t1 JOIN t2 USING(a) + WHERE t1.rowid <= -9.22337303685477580800e+18 ORDER BY t2.a + } +} {} +do_test boundary3-2.66.le.2 { + db eval { + SELECT t2.a FROM t2 NATURAL JOIN t1 + WHERE t1.rowid <= -9.22337303685477580800e+18 ORDER BY t1.a DESC + } +} {} +do_test boundary3-2.66.le.3 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid + } +} {} +do_test boundary3-2.66.le.4 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY t1.rowid DESC + } +} {} +do_test boundary3-2.66.le.5 { + db eval { + SELECT t1.a FROM t1 JOIN t2 ON t1.rowid <= t2.r + WHERE t2.a=66 + ORDER BY x + } +} {} +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.tcl b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.tcl new file mode 100644 index 0000000000000000000000000000000000000000..20f5c9680fb8a7d781187a0ac874a86125c83644 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.tcl @@ -0,0 +1,340 @@ +puts {# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary4.tcl,v 1.3 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +ifcapable !altertable { finish_test; return } +} + +expr srand(0) + +# Generate interesting boundary numbers +# +foreach x { + 0x7f + 0x7fff + 0x7fffff + 0x7fffffff + 0x7fffffffff + 0x7fffffffffff + 0x7fffffffffffff + 0x7fffffffffffffff +} { + set x [expr {wide($x)}] + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set boundarynum([expr {-($x+1)}]) 1 + set boundarynum([expr {-($x+2)}]) 1 + set boundarynum([expr {$x+$x+1}]) 1 + set boundarynum([expr {$x+$x+2}]) 1 +} +set x [expr {wide(127)}] +for {set i 127} {$i<=9} {incr i} { + set boundarynum($x) 1 + set boundarynum([expr {$x+1}]) 1 + set x [expr {wide($x*128 + 127)}] +} + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# A simple selection sort. Not trying to be efficient. +# +proc sort {inlist} { + set outlist {} + set mn [lindex $inlist 0] + foreach x $inlist { + if {$x<$mn} {set mn $x} + } + set outlist $mn + set mx $mn + while {1} { + set valid 0 + foreach x $inlist { + if {$x>$mx && (!$valid || $mn>$x)} { + set mn $x + set valid 1 + } + } + if {!$valid} break + lappend outlist $mn + set mx $mn + } + return $outlist +} + +# Reverse the order of a list +# +proc reverse {inlist} { + set i [llength $inlist] + set outlist {} + for {incr i -1} {$i>=0} {incr i -1} { + lappend outlist [lindex $inlist $i] + } + return $outlist +} + +set nums1 [scramble [array names boundarynum]] +set nums2 [scramble [array names boundarynum]] + +set tname boundary4 +puts "do_test $tname-1.1 \173" +puts " db eval \173" +puts " CREATE TABLE t1(a,x);" +set a 0 +set all_rowid {} +set all_a {} +set all_x {} +foreach r $nums1 { + incr a + set t1ra($r) $a + set t1ar($a) $r + set x [format %08x%08x [expr {wide($r)>>32}] $r] + set t1rx($r) $x + set t1xr($x) $r + puts " INSERT INTO t1(oid,a,x) VALUES($r,$a,'$x');" + lappend all_rowid $r + lappend all_a $a + lappend all_x $x +} +puts " CREATE INDEX t1i1 ON t1(a);" +puts " CREATE INDEX t1i2 ON t1(x);" +puts " \175" +puts "\175 {}" + +puts "do_test $tname-1.2 \173" +puts " db eval \173" +puts " SELECT count(*) FROM t1" +puts " \175" +puts "\175 {[llength $nums1]}" + +proc maketest {tnum sql answer} { + puts "do_test $::tname-$tnum \173" + puts " db eval \173" + puts " $sql" + puts " \175" + puts "\175 {$answer}" +} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 1.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans +maketest 1.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 1.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 1.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 1.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans +maketest 1.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 1.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans +maketest 1.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 1.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans +maketest 1.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 1.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans +maketest 1.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans + +maketest 2.1 {UPDATE t1 SET rowid=a, a=rowid} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 2.3 {SELECT a, rowid, x FROM t1 ORDER BY +a} $ans +maketest 2.4 {SELECT a, rowid, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 2.5 {SELECT a, rowid, x FROM t1 ORDER BY +a DESC} $ans +maketest 2.6 {SELECT a, rowid, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 2.7 {SELECT a, rowid, x FROM t1 ORDER BY +rowid} $ans +maketest 2.8 {SELECT a, rowid, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 2.9 {SELECT a, rowid, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 2.10 {SELECT a, rowid, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 2.11 {SELECT a, rowid, x FROM t1 ORDER BY +x} $ans +maketest 2.12 {SELECT a, rowid, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 2.13 {SELECT a, rowid, x FROM t1 ORDER BY +x DESC} $ans +maketest 2.14 {SELECT a, rowid, x FROM t1 ORDER BY x DESC} $ans + +maketest 3.1 {UPDATE t1 SET rowid=a, a=rowid} {} +maketest 3.2 {ALTER TABLE t1 ADD COLUMN z; UPDATE t1 SET z=zeroblob(600)} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 3.3 {SELECT rowid, a, x FROM t1 ORDER BY +rowid} $ans +maketest 3.4 {SELECT rowid, a, x FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 3.5 {SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC} $ans +maketest 3.6 {SELECT rowid, a, x FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 3.7 {SELECT rowid, a, x FROM t1 ORDER BY +a} $ans +maketest 3.8 {SELECT rowid, a, x FROM t1 ORDER BY a} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 3.9 {SELECT rowid, a, x FROM t1 ORDER BY +a DESC} $ans +maketest 3.10 {SELECT rowid, a, x FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 3.11 {SELECT rowid, a, x FROM t1 ORDER BY +x} $ans +maketest 3.12 {SELECT rowid, a, x FROM t1 ORDER BY x} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 3.13 {SELECT rowid, a, x FROM t1 ORDER BY +x DESC} $ans +maketest 3.14 {SELECT rowid, a, x FROM t1 ORDER BY x DESC} $ans + + +maketest 4.1 {UPDATE t1 SET rowid=a, a=rowid, x=z, z=x} {} + +set ans {} +foreach r [sort $all_rowid] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 4.3 {SELECT a, rowid, z FROM t1 ORDER BY +a} $ans +maketest 4.4 {SELECT a, rowid, z FROM t1 ORDER BY a} $ans + +set ans {} +foreach r [reverse [sort $all_rowid]] { + lappend ans $r $t1ra($r) $t1rx($r) +} +maketest 4.5 {SELECT a, rowid, z FROM t1 ORDER BY +a DESC} $ans +maketest 4.6 {SELECT a, rowid, z FROM t1 ORDER BY a DESC} $ans + +set ans {} +foreach a [sort $all_a] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 4.7 {SELECT a, rowid, z FROM t1 ORDER BY +rowid} $ans +maketest 4.8 {SELECT a, rowid, z FROM t1 ORDER BY rowid} $ans + +set ans {} +foreach a [reverse [sort $all_a]] { + set r $t1ar($a) + lappend ans $r $a $t1rx($r) +} +maketest 4.9 {SELECT a, rowid, z FROM t1 ORDER BY +rowid DESC} $ans +maketest 4.10 {SELECT a, rowid, z FROM t1 ORDER BY rowid DESC} $ans + +set ans {} +foreach x [sort $all_x] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 4.11 {SELECT a, rowid, z FROM t1 ORDER BY +z} $ans +maketest 4.12 {SELECT a, rowid, z FROM t1 ORDER BY z} $ans + +set ans {} +foreach x [reverse [sort $all_x]] { + set r $t1xr($x) + lappend ans $r $t1ra($r) $x +} +maketest 4.13 {SELECT a, rowid, z FROM t1 ORDER BY +z DESC} $ans +maketest 4.14 {SELECT a, rowid, z FROM t1 ORDER BY z DESC} $ans + +puts {finish_test} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.test new file mode 100644 index 0000000000000000000000000000000000000000..b77ac3acf0bc91870acefdd1eb46fe327394f76d --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/boundary4.test @@ -0,0 +1,343 @@ +# 2008 December 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file is automatically generated from a separate TCL script. +# This file seeks to exercise integer boundary values. +# +# $Id: boundary4.test,v 1.2 2009/01/02 15:45:48 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Many of the boundary tests depend on a working 64-bit implementation. +if {![working_64bit_int]} { finish_test; return } +ifcapable !altertable { finish_test; return } + +do_test boundary4-1.1 { + db eval { + CREATE TABLE t1(a,x); + INSERT INTO t1(oid,a,x) VALUES(549755813887,1,'0000007fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-8388608,2,'ffffffffff800000'); + INSERT INTO t1(oid,a,x) VALUES(0,3,'0000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-129,4,'ffffffffffffff7f'); + INSERT INTO t1(oid,a,x) VALUES(8388608,5,'0000000000800000'); + INSERT INTO t1(oid,a,x) VALUES(65535,6,'000000000000ffff'); + INSERT INTO t1(oid,a,x) VALUES(8388607,7,'00000000007fffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627776,8,'0000010000000000'); + INSERT INTO t1(oid,a,x) VALUES(16777215,9,'0000000000ffffff'); + INSERT INTO t1(oid,a,x) VALUES(32767,10,'0000000000007fff'); + INSERT INTO t1(oid,a,x) VALUES(4294967296,11,'0000000100000000'); + INSERT INTO t1(oid,a,x) VALUES(-549755813888,12,'ffffff8000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355328,13,'ffff800000000000'); + INSERT INTO t1(oid,a,x) VALUES(256,14,'0000000000000100'); + INSERT INTO t1(oid,a,x) VALUES(16777216,15,'0000000001000000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927936,16,'0100000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-1,17,'ffffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(9223372036854775807,18,'7fffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(281474976710655,19,'0000ffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(1099511627775,20,'000000ffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-8388609,21,'ffffffffff7fffff'); + INSERT INTO t1(oid,a,x) VALUES(32768,22,'0000000000008000'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963968,23,'0080000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-32769,24,'ffffffffffff7fff'); + INSERT INTO t1(oid,a,x) VALUES(127,25,'000000000000007f'); + INSERT INTO t1(oid,a,x) VALUES(-9223372036854775808,26,'8000000000000000'); + INSERT INTO t1(oid,a,x) VALUES(72057594037927935,27,'00ffffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-549755813889,28,'ffffff7fffffffff'); + INSERT INTO t1(oid,a,x) VALUES(255,29,'00000000000000ff'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963969,30,'ff7fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483648,31,'ffffffff80000000'); + INSERT INTO t1(oid,a,x) VALUES(281474976710656,32,'0001000000000000'); + INSERT INTO t1(oid,a,x) VALUES(65536,33,'0000000000010000'); + INSERT INTO t1(oid,a,x) VALUES(140737488355328,34,'0000800000000000'); + INSERT INTO t1(oid,a,x) VALUES(549755813888,35,'0000008000000000'); + INSERT INTO t1(oid,a,x) VALUES(2147483648,36,'0000000080000000'); + INSERT INTO t1(oid,a,x) VALUES(4294967295,37,'00000000ffffffff'); + INSERT INTO t1(oid,a,x) VALUES(140737488355327,38,'00007fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-2147483649,39,'ffffffff7fffffff'); + INSERT INTO t1(oid,a,x) VALUES(36028797018963967,40,'007fffffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(128,41,'0000000000000080'); + INSERT INTO t1(oid,a,x) VALUES(-32768,42,'ffffffffffff8000'); + INSERT INTO t1(oid,a,x) VALUES(-36028797018963968,43,'ff80000000000000'); + INSERT INTO t1(oid,a,x) VALUES(-140737488355329,44,'ffff7fffffffffff'); + INSERT INTO t1(oid,a,x) VALUES(-128,45,'ffffffffffffff80'); + INSERT INTO t1(oid,a,x) VALUES(2147483647,46,'000000007fffffff'); + CREATE INDEX t1i1 ON t1(a); + CREATE INDEX t1i2 ON t1(x); + } +} {} +do_test boundary4-1.2 { + db eval { + SELECT count(*) FROM t1 + } +} {46} +do_test boundary4-1.3 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-1.4 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-1.5 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-1.6 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-1.7 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-1.8 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-1.9 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-1.10 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-1.11 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-1.12 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-1.13 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-1.14 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-2.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid + } +} {} +do_test boundary4-2.3 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-2.4 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-2.5 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-2.6 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-2.7 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-2.8 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-2.9 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-2.10 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-2.11 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-2.12 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-2.13 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-2.14 { + db eval { + SELECT a, rowid, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-3.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid + } +} {} +do_test boundary4-3.2 { + db eval { + ALTER TABLE t1 ADD COLUMN z; UPDATE t1 SET z=zeroblob(600) + } +} {} +do_test boundary4-3.3 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-3.4 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-3.5 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-3.6 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY rowid DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-3.7 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-3.8 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-3.9 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-3.10 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY a DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-3.11 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-3.12 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-3.13 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY +x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-3.14 { + db eval { + SELECT rowid, a, x FROM t1 ORDER BY x DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-4.1 { + db eval { + UPDATE t1 SET rowid=a, a=rowid, x=z, z=x + } +} {} +do_test boundary4-4.3 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-4.4 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY a + } +} {-9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff 0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff} +do_test boundary4-4.5 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-4.6 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY a DESC + } +} {9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000 -1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000} +do_test boundary4-4.7 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-4.8 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY rowid + } +} {549755813887 1 0000007fffffffff -8388608 2 ffffffffff800000 0 3 0000000000000000 -129 4 ffffffffffffff7f 8388608 5 0000000000800000 65535 6 000000000000ffff 8388607 7 00000000007fffff 1099511627776 8 0000010000000000 16777215 9 0000000000ffffff 32767 10 0000000000007fff 4294967296 11 0000000100000000 -549755813888 12 ffffff8000000000 -140737488355328 13 ffff800000000000 256 14 0000000000000100 16777216 15 0000000001000000 72057594037927936 16 0100000000000000 -1 17 ffffffffffffffff 9223372036854775807 18 7fffffffffffffff 281474976710655 19 0000ffffffffffff 1099511627775 20 000000ffffffffff -8388609 21 ffffffffff7fffff 32768 22 0000000000008000 36028797018963968 23 0080000000000000 -32769 24 ffffffffffff7fff 127 25 000000000000007f -9223372036854775808 26 8000000000000000 72057594037927935 27 00ffffffffffffff -549755813889 28 ffffff7fffffffff 255 29 00000000000000ff -36028797018963969 30 ff7fffffffffffff -2147483648 31 ffffffff80000000 281474976710656 32 0001000000000000 65536 33 0000000000010000 140737488355328 34 0000800000000000 549755813888 35 0000008000000000 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 140737488355327 38 00007fffffffffff -2147483649 39 ffffffff7fffffff 36028797018963967 40 007fffffffffffff 128 41 0000000000000080 -32768 42 ffffffffffff8000 -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -128 45 ffffffffffffff80 2147483647 46 000000007fffffff} +do_test boundary4-4.9 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-4.10 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY rowid DESC + } +} {2147483647 46 000000007fffffff -128 45 ffffffffffffff80 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -32768 42 ffffffffffff8000 128 41 0000000000000080 36028797018963967 40 007fffffffffffff -2147483649 39 ffffffff7fffffff 140737488355327 38 00007fffffffffff 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 549755813888 35 0000008000000000 140737488355328 34 0000800000000000 65536 33 0000000000010000 281474976710656 32 0001000000000000 -2147483648 31 ffffffff80000000 -36028797018963969 30 ff7fffffffffffff 255 29 00000000000000ff -549755813889 28 ffffff7fffffffff 72057594037927935 27 00ffffffffffffff -9223372036854775808 26 8000000000000000 127 25 000000000000007f -32769 24 ffffffffffff7fff 36028797018963968 23 0080000000000000 32768 22 0000000000008000 -8388609 21 ffffffffff7fffff 1099511627775 20 000000ffffffffff 281474976710655 19 0000ffffffffffff 9223372036854775807 18 7fffffffffffffff -1 17 ffffffffffffffff 72057594037927936 16 0100000000000000 16777216 15 0000000001000000 256 14 0000000000000100 -140737488355328 13 ffff800000000000 -549755813888 12 ffffff8000000000 4294967296 11 0000000100000000 32767 10 0000000000007fff 16777215 9 0000000000ffffff 1099511627776 8 0000010000000000 8388607 7 00000000007fffff 65535 6 000000000000ffff 8388608 5 0000000000800000 -129 4 ffffffffffffff7f 0 3 0000000000000000 -8388608 2 ffffffffff800000 549755813887 1 0000007fffffffff} +do_test boundary4-4.11 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +z + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-4.12 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY z + } +} {0 3 0000000000000000 127 25 000000000000007f 128 41 0000000000000080 255 29 00000000000000ff 256 14 0000000000000100 32767 10 0000000000007fff 32768 22 0000000000008000 65535 6 000000000000ffff 65536 33 0000000000010000 8388607 7 00000000007fffff 8388608 5 0000000000800000 16777215 9 0000000000ffffff 16777216 15 0000000001000000 2147483647 46 000000007fffffff 2147483648 36 0000000080000000 4294967295 37 00000000ffffffff 4294967296 11 0000000100000000 549755813887 1 0000007fffffffff 549755813888 35 0000008000000000 1099511627775 20 000000ffffffffff 1099511627776 8 0000010000000000 140737488355327 38 00007fffffffffff 140737488355328 34 0000800000000000 281474976710655 19 0000ffffffffffff 281474976710656 32 0001000000000000 36028797018963967 40 007fffffffffffff 36028797018963968 23 0080000000000000 72057594037927935 27 00ffffffffffffff 72057594037927936 16 0100000000000000 9223372036854775807 18 7fffffffffffffff -9223372036854775808 26 8000000000000000 -36028797018963969 30 ff7fffffffffffff -36028797018963968 43 ff80000000000000 -140737488355329 44 ffff7fffffffffff -140737488355328 13 ffff800000000000 -549755813889 28 ffffff7fffffffff -549755813888 12 ffffff8000000000 -2147483649 39 ffffffff7fffffff -2147483648 31 ffffffff80000000 -8388609 21 ffffffffff7fffff -8388608 2 ffffffffff800000 -32769 24 ffffffffffff7fff -32768 42 ffffffffffff8000 -129 4 ffffffffffffff7f -128 45 ffffffffffffff80 -1 17 ffffffffffffffff} +do_test boundary4-4.13 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY +z DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +do_test boundary4-4.14 { + db eval { + SELECT a, rowid, z FROM t1 ORDER BY z DESC + } +} {-1 17 ffffffffffffffff -128 45 ffffffffffffff80 -129 4 ffffffffffffff7f -32768 42 ffffffffffff8000 -32769 24 ffffffffffff7fff -8388608 2 ffffffffff800000 -8388609 21 ffffffffff7fffff -2147483648 31 ffffffff80000000 -2147483649 39 ffffffff7fffffff -549755813888 12 ffffff8000000000 -549755813889 28 ffffff7fffffffff -140737488355328 13 ffff800000000000 -140737488355329 44 ffff7fffffffffff -36028797018963968 43 ff80000000000000 -36028797018963969 30 ff7fffffffffffff -9223372036854775808 26 8000000000000000 9223372036854775807 18 7fffffffffffffff 72057594037927936 16 0100000000000000 72057594037927935 27 00ffffffffffffff 36028797018963968 23 0080000000000000 36028797018963967 40 007fffffffffffff 281474976710656 32 0001000000000000 281474976710655 19 0000ffffffffffff 140737488355328 34 0000800000000000 140737488355327 38 00007fffffffffff 1099511627776 8 0000010000000000 1099511627775 20 000000ffffffffff 549755813888 35 0000008000000000 549755813887 1 0000007fffffffff 4294967296 11 0000000100000000 4294967295 37 00000000ffffffff 2147483648 36 0000000080000000 2147483647 46 000000007fffffff 16777216 15 0000000001000000 16777215 9 0000000000ffffff 8388608 5 0000000000800000 8388607 7 00000000007fffff 65536 33 0000000000010000 65535 6 000000000000ffff 32768 22 0000000000008000 32767 10 0000000000007fff 256 14 0000000000000100 255 29 00000000000000ff 128 41 0000000000000080 127 25 000000000000007f 0 3 0000000000000000} +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/btree01.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/btree01.test new file mode 100644 index 0000000000000000000000000000000000000000..6e4717ae65853f9d951a523a9d1511480b574826 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/btree01.test @@ -0,0 +1,156 @@ +# 2014-11-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 contains test cases for b-tree logic. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix btree01 + +# The refactoring on the b-tree balance() routine in check-in +# http://www.sqlite.org/src/info/face33bea1ba3a (2014-10-27) +# caused the integrity_check on the following SQL to fail. +# +do_execsql_test btree01-1.1 { + PRAGMA page_size=65536; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b BLOB); + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(3000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=2; + PRAGMA integrity_check; +} {ok} + +# The previous test is sufficient to prevent a regression. But we +# add a number of additional tests to stress the balancer in similar +# ways, looking for related problems. +# +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.2.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(3000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.3.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(2000); + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.4.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==0; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==1; + UPDATE t1 SET b=zeroblob(6499) WHERE (a%3)==2; + UPDATE t1 SET b=zeroblob(64000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.5.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c; + UPDATE t1 SET b=zeroblob(2331); + UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.6.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6542) FROM c; + UPDATE t1 SET b=zeroblob(2332); + UPDATE t1 SET b=zeroblob(65496) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=30} {incr i} { + do_test btree01-1.7.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<30) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(1); + UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} +for {set i 1} {$i<=31} {incr i} { + do_test btree01-1.8.$i { + db eval { + DELETE FROM t1; + WITH RECURSIVE + c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<31) + INSERT INTO t1(a,b) SELECT i, zeroblob(6500) FROM c; + UPDATE t1 SET b=zeroblob(4000); + UPDATE t1 SET b=zeroblob(65000) WHERE a=$::i; + PRAGMA integrity_check; + } + } {ok} +} + +# 2022-03-06 OSSFuzz issue 45329 +# An assertion fault due to the failure to clear a flag in an optimization +# committed last night. +# +# When the stay-on-last page optimization of sqlite3BtreeIndexMoveto() is +# invoked, it needs to clear the BTCF_ValidOvfl flag. +# +db close +sqlite3 db :memory: +do_execsql_test btree01-2.1 { + PRAGMA page_size=1024; + CREATE TABLE t1(a INT PRIMARY KEY, b BLOB, c INT) WITHOUT ROWID; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c) SELECT x*2, zeroblob(100), x FROM c; + UPDATE t1 SET b=zeroblob(1000) WHERE a=198; + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INT); + INSERT INTO t2(y) VALUES(198),(187),(100); + SELECT y, c FROM t2 LEFT JOIN t1 ON y=a ORDER BY x; +} {198 99 187 {} 100 50} +do_execsql_test btree01-2.2 { + SELECT y, c FROM t1 RIGHT JOIN t2 ON y=a ORDER BY x; +} {198 99 187 {} 100 50} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/btreefault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/btreefault.test new file mode 100644 index 0000000000000000000000000000000000000000..d0ba05961c119c37462991acdf4302ba45cc51ce --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/btreefault.test @@ -0,0 +1,106 @@ +# 2013 April 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. +# +#*********************************************************************** +# +# This file contains fault injection tests designed to test the btree.c +# module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set testprefix btreefault + +# This test will not work with an in-memory journal, as the database will +# become corrupt if an error is injected into a transaction after it starts +# writing data out to the db file. +if {[permutation]=="inmemory_journal"} { + finish_test + return +} + +do_test 1-pre1 { + execsql { + PRAGMA auto_vacuum = incremental; + PRAGMA journal_mode = DELETE; + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(randomblob(1000), randomblob(100)); + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + INSERT INTO t1 SELECT randomblob(1000), randomblob(1000) FROM t1; + DELETE FROM t1 WHERE rowid%2; + } + faultsim_save_and_close +} {} + +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + set ::STMT [sqlite3_prepare db "SELECT * FROM t1 ORDER BY a" -1 DUMMY] + sqlite3_step $::STMT + sqlite3_step $::STMT +} -body { + execsql { PRAGMA incremental_vacuum = 10 } +} -test { + sqlite3_finalize $::STMT + faultsim_test_result {0 {}} + faultsim_integrity_check +} + +#------------------------------------------------------------------------- +# dbsqlfuzz crash-6ef3cd3b18ccc5de86120950a0498641acd90a33.txt +# +reset_db + +do_execsql_test 2.0 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b); + CREATE INDEX i1 ON t1(b); + CREATE TABLE t2(x, y); +} + +do_execsql_test 2.1 { + INSERT INTO t1 VALUES(25, 25, 25); + INSERT INTO t2 VALUES(25, 'a'), (25, 'b'), (25, 'c'); +} + +faultsim_save +do_test 2.2 { + set res [list] + db eval { + SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b + } { + lappend res $x $y + if {$y=="b"} { + db eval { DELETE FROM t1 WHERE i=25 } + } + } + set res +} {25 a 25 b} + +do_faultsim_test 2 -faults oom-t* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + set ::myres [list] + db eval { + SELECT x, y FROM t1 CROSS JOIN t2 WHERE t2.x=t1.i AND +t1.i=25 ORDER BY b + } { + lappend ::myres $x $y + if {$y=="b"} { + db eval { DELETE FROM t1 WHERE i=25 } + } + } + set ::myres +} -test { + faultsim_test_result {0 {25 a 25 b}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/busy.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/busy.test new file mode 100644 index 0000000000000000000000000000000000000000..896c7fa651e44eeb0c180d1afbc47c25c744f290 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/busy.test @@ -0,0 +1,139 @@ +# 2005 july 8 +# +# 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 test the busy handler +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix busy + +do_test busy-1.1 { + sqlite3 db2 test.db + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + SELECT * FROM t1 + } +} 1 +proc busy x { + lappend ::busyargs $x + if {$x>2} {return 1} + return 0 +} +set busyargs {} +do_test busy-1.2 { + db busy busy + db2 eval {BEGIN EXCLUSIVE} + catchsql {BEGIN IMMEDIATE} +} {1 {database is locked}} +do_test busy-1.3 { + set busyargs +} {0 1 2 3} +do_test busy-1.4 { + set busyargs {} + catchsql {BEGIN IMMEDIATE} + set busyargs +} {0 1 2 3} + +do_test busy-2.1 { + db2 eval {COMMIT} + db eval {BEGIN; INSERT INTO t1 VALUES(5)} + db2 eval {BEGIN; SELECT * FROM t1} + set busyargs {} + catchsql COMMIT +} {1 {database is locked}} +do_test busy-2.2 { + set busyargs +} {0 1 2 3} + +db2 close + +#------------------------------------------------------------------------- +# Test that the busy-handler is invoked correctly for "PRAGMA optimize" +# and ANALYZE commnds. +ifcapable pragma&&analyze&&!stat4 { + +reset_db + +do_execsql_test 3.1 { + CREATE TABLE t1(x); + CREATE TABLE t2(y); + CREATE TABLE t3(z); + + CREATE INDEX i1 ON t1(x); + CREATE INDEX i2 ON t2(y); + + INSERT INTO t1 VALUES(1); + INSERT INTO t2 VALUES(1); + ANALYZE; + + SELECT * FROM t1 WHERE x=1; + SELECT * FROM t2 WHERE y=1; +} {1 1} + +do_test 3.2 { + sqlite3 db2 test.db + execsql { BEGIN EXCLUSIVE } db2 + catchsql { PRAGMA optimize } +} {1 {database is locked}} + +proc busy_handler {n} { + if {$n>1000} { execsql { COMMIT } db2 } + return 0 +} +db busy busy_handler + +do_test 3.3 { + catchsql { PRAGMA optimize } +} {0 {}} + +do_test 3.4 { + execsql { + BEGIN; + SELECT count(*) FROM sqlite_master; + } db2 +} {6} + +proc busy_handler {n} { return 1 } +do_test 3.5 { + catchsql { PRAGMA optimize } +} {1 {database is locked}} + +do_test 3.6 { + execsql { COMMIT } db2 + execsql { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000 + ) + INSERT INTO t1 SELECT i FROM s; + } + execsql { + BEGIN; + SELECT count(*) FROM sqlite_master; + } db2 +} {6} + +do_test 3.7 { + catchsql { PRAGMA optimize } +} {1 {database is locked}} + +proc busy_handler {n} { + if {$n>1000} { execsql { COMMIT } db2 } + return 0 +} +do_test 3.8 { + catchsql { PRAGMA optimize } +} {0 {}} + +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cache.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cache.test new file mode 100644 index 0000000000000000000000000000000000000000..ffc25c460e73be51b91c24021df5d531cc8881fe --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cache.test @@ -0,0 +1,140 @@ +# 2007 March 24 +# +# 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. +# +#*********************************************************************** +# +# $Id: cache.test,v 1.4 2007/08/22 02:56:44 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !pager_pragmas||!compound { + finish_test + return +} +sqlite3_soft_heap_limit 0 + +proc pager_cache_size {db} { + set bt [btree_from_db $db] + db_enter $db + array set stats [btree_pager_stats $bt] + db_leave $db + return $stats(page) +} + +if {[permutation] == ""} { + do_test cache-1.1 { pager_cache_size db } {0} +} + +do_test cache-1.2 { + execsql { + PRAGMA auto_vacuum=OFF; + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + } + pager_cache_size db +} {2} + +# At one point, repeatedly locking and unlocking the cache was causing +# a resource leak of one page per repetition. The page wasn't actually +# leaked, but would not be reused until the pager-cache was full (i.e. +# 2000 pages by default). +# +# This tests that once the pager-cache is initialized, it can be locked +# and unlocked repeatedly without internally allocating any new pages. +# +set cache_size [pager_cache_size db] +for {set ii 0} {$ii < 10} {incr ii} { + do_test cache-1.3.$ii { + execsql {SELECT * FROM abc} + pager_cache_size db + } $::cache_size +} + +#------------------------------------------------------------------------- +# This block of tests checks that it is possible to set the cache_size of a +# database to a small (< 10) value. More specifically: +# +# cache-2.1.*: Test that "PRAGMA cache_size" appears to work with small +# values. +# cache-2.2.*: Test that "PRAGMA main.cache_size" appears to work with +# small values. +# cache-2.3.*: Test cache_size=1 correctly spills/flushes the cache. +# cache-2.4.*: Test cache_size=0 correctly spills/flushes the cache. +# +# +db_delete_and_reopen +do_execsql_test cache-2.0 { + PRAGMA auto_vacuum=OFF; + PRAGMA journal_mode=DELETE; + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + INSERT INTO t1 VALUES('x', 'y'); + INSERT INTO t2 VALUES('i', 'j'); +} {delete} + +for {set i 0} {$i < 20} {incr i} { + do_execsql_test cache-2.1.$i.1 "PRAGMA cache_size = $i" + do_execsql_test cache-2.1.$i.2 "PRAGMA cache_size" $i + do_execsql_test cache-2.1.$i.3 "SELECT * FROM t1" {x y} + do_execsql_test cache-2.1.$i.4 "PRAGMA cache_size" $i +} +for {set i 0} {$i < 20} {incr i} { + do_execsql_test cache-2.2.$i.1 "PRAGMA main.cache_size = $i" + do_execsql_test cache-2.2.$i.2 "PRAGMA main.cache_size" $i + do_execsql_test cache-2.2.$i.3 "SELECT * FROM t1" {x y} + do_execsql_test cache-2.2.$i.4 "PRAGMA main.cache_size" $i +} + +# Tests for cache_size = 1. +# +do_execsql_test cache-2.3.1 { + PRAGMA cache_size = 1; + BEGIN; + INSERT INTO t1 VALUES(1, 2); + PRAGMA lock_status; +} {main reserved temp closed} +do_test cache-2.3.2 { pager_cache_size db } 2 +do_execsql_test cache-2.3.3 { + INSERT INTO t2 VALUES(1, 2); + PRAGMA lock_status; +} {main exclusive temp closed} +do_test cache-2.3.4 { pager_cache_size db } 2 +do_execsql_test cache-2.3.5 COMMIT +do_test cache-2.3.6 { pager_cache_size db } 1 + +do_execsql_test cache-2.3.7 { + SELECT * FROM t1 UNION SELECT * FROM t2; +} {1 2 i j x y} +do_test cache-2.3.8 { pager_cache_size db } 1 + +# Tests for cache_size = 0. +# +do_execsql_test cache-2.4.1 { + PRAGMA cache_size = 0; + BEGIN; + INSERT INTO t1 VALUES(1, 2); + PRAGMA lock_status; +} {main reserved temp closed} +do_test cache-2.4.2 { pager_cache_size db } 2 +do_execsql_test cache-2.4.3 { + INSERT INTO t2 VALUES(1, 2); + PRAGMA lock_status; +} {main exclusive temp closed} +do_test cache-2.4.4 { pager_cache_size db } 2 +do_execsql_test cache-2.4.5 COMMIT + +do_test cache-2.4.6 { pager_cache_size db } 0 +do_execsql_test cache-2.4.7 { + SELECT * FROM t1 UNION SELECT * FROM t2; +} {1 2 i j x y} +do_test cache-2.4.8 { pager_cache_size db } 0 + +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cacheflush.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cacheflush.test new file mode 100644 index 0000000000000000000000000000000000000000..50461893ef1cebe98524e14b1dbfa6cfbc291945 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cacheflush.test @@ -0,0 +1,323 @@ +# 2011 November 16 +# +# 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 test cases for sqlite3_db_cacheflush API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cacheflush +test_set_config_pagecache 0 0 + +# Run the supplied SQL on a copy of the database currently stored on +# disk in file $dbfile. +proc diskquery {dbfile sql} { + forcecopy $dbfile dq.db + sqlite3 dq dq.db + set res [execsql $sql dq] + dq close + set res +} + +# Simplest possible test. +# +do_execsql_test 1.1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + BEGIN; + INSERT INTO t1 VALUES(3, 4); +} +do_test 1.1.1 { + diskquery test.db { SELECT * FROM t1 } +} {1 2} +do_test 1.1.2 { + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1 } +} {1 2 3 4} + +# Test that multiple pages may be flushed to disk. +# +do_execsql_test 1.2.0 { + COMMIT; + CREATE TABLE t2(a, b); + BEGIN; + INSERT INTO t1 VALUES(5, 6); + INSERT INTO t2 VALUES('a', 'b'); +} +do_test 1.2.1 { + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {1 2 3 4} +do_test 1.2.2 { + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {1 2 3 4 5 6 a b} + +# Test that pages with nRef!=0 are not flushed to disk. +# +do_execsql_test 1.3.0 { + COMMIT; + CREATE TABLE t3(a, b); + BEGIN; + INSERT INTO t1 VALUES(7, 8); + INSERT INTO t2 VALUES('c', 'd'); + INSERT INTO t3 VALUES('i', 'ii'); +} +do_test 1.3.1 { + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 a b} +do_test 1.3.2 { + db eval { SELECT a FROM t1 } { + if {$a==3} { + sqlite3_db_cacheflush db + } + } + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 a b c d i ii} +do_test 1.3.2 { + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + } +} {1 2 3 4 5 6 7 8 a b c d i ii} + +# Check that SQLITE_BUSY is returned if pages cannot be flushed due to +# conflicting read locks. +# +do_execsql_test 1.4.0 { + COMMIT; + BEGIN; + INSERT INTO t1 VALUES(9, 10); +} +do_test 1.4.1 { + sqlite3 db2 test.db + db2 eval { + BEGIN; + SELECT * FROM t1; + } + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8} +do_test 1.4.2 { + list [catch { sqlite3_db_cacheflush db } msg] $msg +} {1 {database is locked}} +do_test 1.4.3 { + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8} +do_test 1.4.4 { + db2 close + sqlite3_db_cacheflush db + diskquery test.db { + SELECT * FROM t1; + } +} {1 2 3 4 5 6 7 8 9 10} +do_execsql_test 1.4.5 { COMMIT } + +#------------------------------------------------------------------------- +# Test that ATTACHed database caches are also flushed. +# +forcedelete test.db2 +do_execsql_test 2.1.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t4(x, y); + INSERT INTO t4 VALUES('A', 'B'); + BEGIN; + INSERT INTO t1 VALUES(11, 12); + INSERT INTO t4 VALUES('C', 'D'); +} +do_test 2.1.1 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10} +do_test 2.1.2 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B} +do_test 2.1.3 { + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.1.4 { + sqlite3_db_cacheflush db + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D} +do_execsql_test 2.1.5 { COMMIT } + +# And that hitting an SQLITE_BUSY when flushing "main" does not stop +# SQLite from going on to flush "aux". +# +do_execsql_test 2.2.0 { + BEGIN; + INSERT INTO t1 VALUES(13, 14); + INSERT INTO t4 VALUES('E', 'F'); +} +do_test 2.2.1 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.2.2 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D} +do_test 2.2.3 { + sqlite3 db2 test.db + execsql { + BEGIN; + SELECT * FROM t1; + } db2 + list [catch { sqlite3_db_cacheflush db } msg] $msg +} {1 {database is locked}} +do_test 2.2.4 { + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_test 2.2.5 { + diskquery test.db2 { SELECT * FROM t4; } +} {A B C D E F} +do_test 2.2.6 { + db2 close + sqlite3_db_cacheflush db + diskquery test.db { SELECT * FROM t1; } +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14} +do_execsql_test 2.2.7 { COMMIT } + +#------------------------------------------------------------------------- +# Test that nothing terrible happens if sqlite3_db_cacheflush() is +# called on an in-memory database. +# +do_test 3.0 { + db close + sqlite3 db :memory: + db eval { + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t2(y PRIMARY KEY); + BEGIN; + INSERT INTO t1 VALUES(randomblob(100)); + INSERT INTO t2 VALUES(randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100)); + INSERT INTO t2 VALUES(randomblob(100)); + } + sqlite3_db_cacheflush db +} {} + +do_execsql_test 3.1 { PRAGMA integrity_check } ok +do_execsql_test 3.2 { COMMIT } +do_execsql_test 3.3 { PRAGMA integrity_check } ok +do_execsql_test 3.4 { + SELECT count(*) FROM t1; + SELECT count(*) FROM t2; +} {2 2} + +#------------------------------------------------------------------------- +# Test that calling sqlite3_db_cacheflush() does not interfere with +# savepoint transactions. +# +do_test 4.0 { + reset_db + execsql { + CREATE TABLE ta(a, aa); + CREATE TABLE tb(b, bb); + INSERT INTO ta VALUES('a', randomblob(500)); + INSERT INTO tb VALUES('b', randomblob(500)); + BEGIN; + UPDATE ta SET a = 'A'; + SAVEPOINT one; + UPDATE tb SET b = 'B'; + } + + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A B} + +do_test 4.1 { + execsql { + ROLLBACK TO one; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b} + +do_test 4.2 { + execsql { + INSERT INTO tb VALUES('c', randomblob(10)); + INSERT INTO tb VALUES('d', randomblob(10)); + INSERT INTO tb VALUES('e', randomblob(10)); + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b c d e} + +do_test 4.3 { + execsql { + SAVEPOINT two; + UPDATE tb SET b = upper(b); + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A B C D E} + +do_test 4.4 { + execsql { + ROLLBACK TO two; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b c d e} + +do_test 4.4 { + execsql { + ROLLBACK TO one; + } + sqlite3_db_cacheflush db + diskquery test.db { + SELECT a FROM ta; + SELECT b FROM tb; + } +} {A b} + +do_test 4.5 { + execsql { + ROLLBACK; + SELECT a FROM ta; + SELECT b FROM tb; + } +} {a b} + +test_restore_config_pagecache +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cachespill.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cachespill.test new file mode 100644 index 0000000000000000000000000000000000000000..069251354fc43f750893eb1d4a076de2a57f87f7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cachespill.test @@ -0,0 +1,77 @@ +# 2017 April 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 cachespill + +ifcapable !pager_pragmas { + finish_test + return +} + +#------------------------------------------------------------------------- +# Test that "PRAGMA cache_spill = 0" completely disables cache spilling. +# +do_execsql_test 1.1 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + PRAGMA cache_size = 100; + CREATE TABLE t1(a); +} + +do_test 1.2 { + file size test.db +} {2048} + +do_test 1.3 { + execsql { + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + expr {[file size test.db] > 50000} +} {1} + +do_test 1.4 { + execsql ROLLBACK + file size test.db +} {2048} + +do_test 1.5 { + execsql { + PRAGMA cache_spill = 0; + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + file size test.db +} {2048} + +do_test 1.5 { + execsql { + ROLLBACK; + PRAGMA cache_spill = 1; + BEGIN; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<200 + ) INSERT INTO t1 SELECT randomblob(900) FROM s; + } + expr {[file size test.db] > 50000} +} {1} + +do_execsql_test 1.6 { ROLLBACK } + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi2.test new file mode 100644 index 0000000000000000000000000000000000000000..de47ab3d4fd4b7ccf86436250c343f7edad0a710 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi2.test @@ -0,0 +1,803 @@ +# 2003 January 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi2.test,v 1.37 2008/12/30 17:55:00 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Return the text values from the current row pointed at by STMT as a list. +proc get_row_values {STMT} { + set VALUES [list] + for {set i 0} {$i < [sqlite3_data_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_text $STMT $i] + } + return $VALUES +} + +# Return the column names followed by declaration types for the result set +# of the SQL statement STMT. +# +# i.e. for: +# CREATE TABLE abc(a text, b integer); +# SELECT * FROM abc; +# +# The result is {a b text integer} +proc get_column_names {STMT} { + set VALUES [list] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_name $STMT $i] + } + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend VALUES [sqlite3_column_decltype $STMT $i] + } + return $VALUES +} + +# Check basic functionality +# +do_test capi2-1.1 { + set DB [sqlite3_connection_pointer db] + execsql {CREATE TABLE t1(a,b,c)} + set VM [sqlite3_prepare $DB {SELECT name, rowid FROM sqlite_master} -1 TAIL] + set TAIL +} {} +do_test capi2-1.2 { + sqlite3_step $VM +} {SQLITE_ROW} +do_test capi2-1.3 { + sqlite3_data_count $VM +} {2} +do_test capi2-1.4 { + get_row_values $VM +} {t1 1} +do_test capi2-1.5 { + get_column_names $VM +} {name rowid TEXT INTEGER} +do_test capi2-1.6 { + sqlite3_step $VM +} {SQLITE_DONE} +do_test capi2-1.7 { + list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM] +} {2 {} {name rowid TEXT INTEGER}} + +# This used to be SQLITE_MISUSE. But now we automatically reset prepared +# statements. +ifcapable autoreset { + do_test capi2-1.8 { + sqlite3_step $VM + } {SQLITE_ROW} +} else { + do_test capi2-1.8 { + sqlite3_step $VM + } {SQLITE_MISUSE} +} + +# Update: In v2, once SQLITE_MISUSE is returned the statement handle cannot +# be interrogated for more information. However in v3, since the column +# count, names and types are determined at compile time, these are still +# accessible after an SQLITE_MISUSE error. +do_test capi2-1.9 { + sqlite3_reset $VM + list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM] +} {2 {} {name rowid TEXT INTEGER}} +do_test capi2-1.10 { + sqlite3_data_count $VM +} {0} + +do_test capi2-1.11 { + sqlite3_finalize $VM +} {SQLITE_OK} + +# Check to make sure that the "tail" of a multi-statement SQL script +# is returned by sqlite3_prepare. +# +do_test capi2-2.1 { + set SQL { + SELECT name, rowid FROM sqlite_master; + SELECT name, rowid FROM sqlite_master WHERE 0; + -- A comment at the end + } + set VM [sqlite3_prepare $DB $SQL -1 SQL] + set SQL +} { + SELECT name, rowid FROM sqlite_master WHERE 0; + -- A comment at the end + } +do_test capi2-2.2 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ROW 2 {t1 1} {name rowid TEXT INTEGER}} +do_test capi2-2.3 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}} +do_test capi2-2.4 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-2.5 { + set VM [sqlite3_prepare $DB $SQL -1 SQL] + set SQL +} { + -- A comment at the end + } +do_test capi2-2.6 { + set r [sqlite3_step $VM] + lappend r [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 2 {} {name rowid TEXT INTEGER}} +do_test capi2-2.7 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-2.8 { + set VM [sqlite3_prepare $DB $SQL -1 SQL] + list $SQL $VM +} {{} {}} + +# Check the error handling. +# +do_test capi2-3.1 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {}} +do_test capi2-3.2 { + set rc [catch { + sqlite3_prepare $DB {select bogus from } -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) incomplete input} {}} +do_test capi2-3.3 { + set rc [catch { + sqlite3_prepare $DB {;;;;select bogus from sqlite_master} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {}} +do_test capi2-3.4 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master;x;} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {x;}} +do_test capi2-3.5 { + set rc [catch { + sqlite3_prepare $DB {select bogus from sqlite_master;;;x;} -1 TAIL + } msg] + lappend rc $msg $TAIL +} {1 {(1) no such column: bogus} {;;x;}} +do_test capi2-3.6 { + set rc [catch { + sqlite3_prepare $DB {select 5/0;} -1 TAIL + } VM] + lappend rc $TAIL +} {0 {}} +do_test capi2-3.7 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ROW 1 {{}} {5/0 {}}} +do_test capi2-3.8 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-3.9 { + execsql {CREATE UNIQUE INDEX i1 ON t1(a)} + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,2,3)} -1 TAIL] + set TAIL +} {} +do_test capi2-3.9b {db changes} {0} +do_test capi2-3.10 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 0 {} {}} + +# Update for v3 - the change has not actually happened until the query is +# finalized. Is this going to cause trouble for anyone? Lee Nelson maybe? +# (Later:) The change now happens just before SQLITE_DONE is returned. +do_test capi2-3.10b {db changes} {1} +do_test capi2-3.11 { + sqlite3_finalize $VM +} {SQLITE_OK} +do_test capi2-3.11b {db changes} {1} +#do_test capi2-3.12-misuse { +# sqlite3_finalize $VM +#} {SQLITE_MISUSE} +do_test capi2-3.13 { + set VM [sqlite3_prepare $DB {INSERT INTO t1 VALUES(1,3,4)} -1 TAIL] + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ERROR 0 {} {}} + +# Update for v3: Preparing a statement does not affect the change counter. +# (Test result changes from 0 to 1). (Later:) change counter updates occur +# when sqlite3_step returns, not at finalize time. +do_test capi2-3.13b {db changes} {0} + +do_test capi2-3.14 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \ + [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.a} SQLITE_CONSTRAINT_UNIQUE} +do_test capi2-3.15 { + set VM [sqlite3_prepare $DB {CREATE TABLE t2(a NOT NULL, b)} -1 TAIL] + set TAIL +} {} +do_test capi2-3.16 { + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_DONE 0 {} {}} +do_test capi2-3.17 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] +} {SQLITE_OK {not an error}} +do_test capi2-3.18 { + set VM [sqlite3_prepare $DB {INSERT INTO t2 VALUES(NULL,2)} -1 TAIL] + list [sqlite3_step $VM] \ + [sqlite3_column_count $VM] \ + [get_row_values $VM] \ + [get_column_names $VM] +} {SQLITE_ERROR 0 {} {}} +do_test capi2-3.19 { + list [sqlite3_finalize $VM] [sqlite3_errmsg $DB] \ + [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT {NOT NULL constraint failed: t2.a} SQLITE_CONSTRAINT_NOTNULL} + +do_test capi2-3.20 { + execsql { + CREATE TABLE a1(message_id, name , UNIQUE(message_id, name) ); + INSERT INTO a1 VALUES(1, 1); + } +} {} +do_test capi2-3.21 { + set VM [sqlite3_prepare $DB {INSERT INTO a1 VALUES(1, 1)} -1 TAIL] + sqlite3_step $VM +} {SQLITE_ERROR} +do_test capi2-3.22 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi2-3.23 { + sqlite3_finalize $VM +} {SQLITE_CONSTRAINT} +do_test capi2-3.24 { + list [sqlite3_errcode $DB] [sqlite3_extended_errcode $DB] +} {SQLITE_CONSTRAINT SQLITE_CONSTRAINT_UNIQUE} + +# Two or more virtual machines exists at the same time. +# +do_test capi2-4.1 { + set VM1 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(1,2)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.2 { + set VM2 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(2,3)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.3 { + set VM3 [sqlite3_prepare $DB {INSERT INTO t2 VALUES(3,4)} -1 TAIL] + set TAIL +} {} +do_test capi2-4.4 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.5 { + execsql {SELECT * FROM t2 ORDER BY a} +} {2 3} +do_test capi2-4.6 { + sqlite3_finalize $VM2 +} {SQLITE_OK} +do_test capi2-4.7 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.8 { + execsql {SELECT * FROM t2 ORDER BY a} +} {2 3 3 4} +do_test capi2-4.9 { + sqlite3_finalize $VM3 +} {SQLITE_OK} +do_test capi2-4.10 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_DONE 0 {} {}} +do_test capi2-4.11 { + execsql {SELECT * FROM t2 ORDER BY a} +} {1 2 2 3 3 4} +do_test capi2-4.12 { + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Interleaved SELECTs +# +do_test capi2-5.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + set VM2 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + set VM3 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.2 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.3 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.4 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {2 3} {a b {} {}}} +do_test capi2-5.5 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.6 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.7 { + list [sqlite3_step $VM3] \ + [sqlite3_column_count $VM3] \ + [get_row_values $VM3] \ + [get_column_names $VM3] +} {SQLITE_DONE 2 {} {a b {} {}}} +do_test capi2-5.8 { + sqlite3_finalize $VM3 +} {SQLITE_OK} +do_test capi2-5.9 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.10 { + sqlite3_finalize $VM1 +} {SQLITE_OK} +do_test capi2-5.11 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {3 4} {a b {} {}}} +do_test capi2-5.12 { + list [sqlite3_step $VM2] \ + [sqlite3_column_count $VM2] \ + [get_row_values $VM2] \ + [get_column_names $VM2] +} {SQLITE_ROW 2 {1 2} {a b {} {}}} +do_test capi2-5.11 { + sqlite3_finalize $VM2 +} {SQLITE_OK} + +# Check for proper SQLITE_BUSY returns. +# +do_test capi2-6.1 { + execsql { + BEGIN; + CREATE TABLE t3(x counter); + INSERT INTO t3 VALUES(1); + INSERT INTO t3 VALUES(2); + INSERT INTO t3 SELECT x+2 FROM t3; + INSERT INTO t3 SELECT x+4 FROM t3; + INSERT INTO t3 SELECT x+8 FROM t3; + COMMIT; + } + set VM1 [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL] + sqlite3 db2 test.db + execsql {BEGIN} db2 +} {} +# Update for v3: BEGIN doesn't write-lock the database. It is quite +# difficult to get v3 to write-lock the database, which causes a few +# problems for test scripts. +# +# do_test capi2-6.2 { +# list [sqlite3_step $VM1] \ +# [sqlite3_column_count $VM1] \ +# [get_row_values $VM1] \ +# [get_column_names $VM1] +# } {SQLITE_BUSY 0 {} {}} +do_test capi2-6.3 { + execsql {COMMIT} db2 +} {} +do_test capi2-6.4 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 1 {x counter}} +do_test capi2-6.5 { + catchsql {INSERT INTO t3 VALUES(10);} db2 +} {1 {database is locked}} +do_test capi2-6.6 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 2 {x counter}} +do_test capi2-6.7 { + execsql {SELECT * FROM t2} db2 +} {2 3 3 4 1 2} +do_test capi2-6.8 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 3 {x counter}} +do_test capi2-6.9 { + execsql {SELECT * FROM t2} +} {2 3 3 4 1 2} +do_test capi2-6.10 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 4 {x counter}} +do_test capi2-6.11 { + execsql {BEGIN} +} {} +do_test capi2-6.12 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 5 {x counter}} + +# A read no longer blocks a write in the same connection. +#do_test capi2-6.13 { +# catchsql {UPDATE t3 SET x=x+1} +#} {1 {database table is locked}} + +do_test capi2-6.14 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 6 {x counter}} +do_test capi2-6.15 { + execsql {SELECT * FROM t1} +} {1 2 3} +do_test capi2-6.16 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 7 {x counter}} +do_test capi2-6.17 { + catchsql {UPDATE t1 SET b=b+1} +} {0 {}} +do_test capi2-6.18 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 8 {x counter}} +do_test capi2-6.19 { + execsql {SELECT * FROM t1} +} {1 3 3} +do_test capi2-6.20 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 9 {x counter}} +#do_test capi2-6.21 { +# execsql {ROLLBACK; SELECT * FROM t1} +#} {1 2 3} +do_test capi2-6.22 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 10 {x counter}} +#do_test capi2-6.23 { +# execsql {BEGIN TRANSACTION;} +#} {} +do_test capi2-6.24 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 11 {x counter}} +do_test capi2-6.25 { + execsql { + INSERT INTO t1 VALUES(2,3,4); + SELECT * FROM t1; + } +} {1 3 3 2 3 4} +do_test capi2-6.26 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 12 {x counter}} +do_test capi2-6.27 { + catchsql { + INSERT INTO t1 VALUES(2,4,5); + SELECT * FROM t1; + } +} {1 {UNIQUE constraint failed: t1.a}} +do_test capi2-6.28 { + list [sqlite3_step $VM1] \ + [sqlite3_column_count $VM1] \ + [get_row_values $VM1] \ + [get_column_names $VM1] +} {SQLITE_ROW 1 13 {x counter}} +do_test capi2-6.99 { + sqlite3_finalize $VM1 +} {SQLITE_OK} +catchsql {ROLLBACK} + +do_test capi2-7.1 { + stepsql $DB { + SELECT * FROM t1 + } +} {0 1 2 3} +do_test capi2-7.2 { + stepsql $DB { + PRAGMA count_changes=on + } +} {0} +do_test capi2-7.3 { + stepsql $DB { + UPDATE t1 SET a=a+10; + } +} {0 1} +do_test capi2-7.4 { + stepsql $DB { + INSERT INTO t1 SELECT a+1,b+1,c+1 FROM t1; + } +} {0 1} +do_test capi2-7.4b {sqlite3_changes $DB} {1} +do_test capi2-7.5 { + stepsql $DB { + UPDATE t1 SET a=a+10; + } +} {0 2} +do_test capi2-7.5b {sqlite3_changes $DB} {2} +do_test capi2-7.6 { + stepsql $DB { + SELECT * FROM t1; + } +} {0 21 2 3 22 3 4} +do_test capi2-7.7 { + stepsql $DB { + INSERT INTO t1 SELECT a+2,b+2,c+2 FROM t1; + } +} {0 2} +do_test capi2-7.8 { + sqlite3_changes $DB +} {2} +do_test capi2-7.9 { + stepsql $DB { + SELECT * FROM t1; + } +} {0 21 2 3 22 3 4 23 4 5 24 5 6} +do_test capi2-7.10 { + stepsql $DB { + UPDATE t1 SET a=a-20; + SELECT * FROM t1; + } +} {0 4 1 2 3 2 3 4 3 4 5 4 5 6} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 4). +do_test capi2-7.11 { + sqlite3_changes $DB +} {4} +do_test capi2-7.11a { + execsql {SELECT count(*) FROM t1} +} {4} + +ifcapable {explain} { + do_test capi2-7.12 { + set x [stepsql $DB {EXPLAIN SELECT * FROM t1}] + lindex $x 0 + } {0} +} + +# Ticket #261 - make sure we can finalize before the end of a query. +# +do_test capi2-8.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Tickets #384 and #385 - make sure the TAIL argument to sqlite3_prepare +# and all of the return pointers in sqlite_step can be null. +# +do_test capi2-9.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t2} -1 DUMMY] + sqlite3_step $VM1 + sqlite3_finalize $VM1 +} {SQLITE_OK} + +# Test that passing a NULL pointer to sqlite3_finalize() or sqlite3_reset +# does not cause an error. +do_test capi2-10.1 { + sqlite3_finalize 0 +} {SQLITE_OK} +do_test capi2-10.2 { + sqlite3_reset 0 +} {SQLITE_OK} + +#--------------------------------------------------------------------------- +# The following tests - capi2-11.* - test the "column origin" APIs. +# +# sqlite3_column_origin_name() +# sqlite3_column_database_name() +# sqlite3_column_table_name() +# + +ifcapable columnmetadata { + +# This proc uses the database handle $::DB to compile the SQL statement passed +# as a parameter. The return value of this procedure is a list with one +# element for each column returned by the compiled statement. Each element of +# this list is itself a list of length three, consisting of the origin +# database, table and column for the corresponding returned column. +proc check_origins {sql} { + set ret [list] + set ::STMT [sqlite3_prepare $::DB $sql -1 dummy] + for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} { + lappend ret [list \ + [sqlite3_column_database_name $::STMT $i] \ + [sqlite3_column_table_name $::STMT $i] \ + [sqlite3_column_origin_name $::STMT $i] \ + ] + } + sqlite3_finalize $::STMT + return $ret +} +do_test capi2-11.1 { + execsql { + CREATE TABLE tab1(col1, col2); + } +} {} +do_test capi2-11.2 { + check_origins {SELECT col2, col1 FROM tab1} +} [list {main tab1 col2} {main tab1 col1}] +do_test capi2-11.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM tab1} +} [list {main tab1 col2} {main tab1 col1}] + +ifcapable subquery { + do_test capi2-11.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM tab1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.5 { + check_origins {SELECT (SELECT col2 FROM tab1), (SELECT col1 FROM tab1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM tab1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-11.7 { + check_origins {SELECT * FROM tab1} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-11.8 { + check_origins {SELECT * FROM (SELECT * FROM tab1)} + } [list {main tab1 col1} {main tab1 col2}] +} + +ifcapable view&&subquery { + do_test capi2-12.1 { + execsql { + CREATE VIEW view1 AS SELECT * FROM tab1; + } + } {} + do_test capi2-12.2 { + check_origins {SELECT col2, col1 FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.5 { + check_origins {SELECT (SELECT col2 FROM view1), (SELECT col1 FROM view1)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM view1} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-12.7 { + check_origins {SELECT * FROM view1} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.8 { + check_origins {select * from (select * from view1)} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.9 { + check_origins {select * from (select * from (select * from view1))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-12.10 { + db close + sqlite3 db test.db + set ::DB [sqlite3_connection_pointer db] + check_origins {select * from (select * from (select * from view1))} + } [list {main tab1 col1} {main tab1 col2}] + + # This view will thwart the flattening optimization. + do_test capi2-13.1 { + execsql { + CREATE VIEW view2 AS SELECT * FROM tab1 limit 10 offset 10; + } + } {} + do_test capi2-13.2 { + check_origins {SELECT col2, col1 FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.3 { + check_origins {SELECT col2 AS hello, col1 AS world FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.4 { + check_origins {SELECT b, a FROM (SELECT col1 AS a, col2 AS b FROM view2)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.5 { + check_origins {SELECT (SELECT col2 FROM view2), (SELECT col1 FROM view2)} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.6 { + check_origins {SELECT (SELECT col2), (SELECT col1) FROM view2} + } [list {main tab1 col2} {main tab1 col1}] + do_test capi2-13.7 { + check_origins {SELECT * FROM view2} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.8 { + check_origins {select * from (select * from view2)} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.9 { + check_origins {select * from (select * from (select * from view2))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.10 { + db close + sqlite3 db test.db + set ::DB [sqlite3_connection_pointer db] + check_origins {select * from (select * from (select * from view2))} + } [list {main tab1 col1} {main tab1 col2}] + do_test capi2-13.11 { + check_origins {select * from (select * from tab1 limit 10 offset 10)} + } [list {main tab1 col1} {main tab1 col2}] +} + + +} ;# ifcapable columnmetadata + +db2 close +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3.test new file mode 100644 index 0000000000000000000000000000000000000000..e65f90e3aade0c0332478a4e32dee32e54409ead --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3.test @@ -0,0 +1,1276 @@ +# 2003 January 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi3.test,v 1.70 2009/01/09 02:49:32 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix capi3 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3-1.*: Test sqlite3_prepare +# capi3-2.*: Test sqlite3_prepare16 +# capi3-3.*: Test sqlite3_open +# capi3-4.*: Test sqlite3_open16 +# capi3-5.*: Test the various sqlite3_result_* APIs +# capi3-6.*: Test that sqlite3_close fails if there are outstanding VMs. +# + +set DB [sqlite3_connection_pointer db] + +do_test capi3-1.0 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-1.1 { + set STMT [sqlite3_prepare $DB {SELECT name FROM sqlite_master} -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {} +do_test capi3-1.2.1 { + sqlite3_errcode $DB +} {SQLITE_OK} +do_test capi3-1.2.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-1.3 { + sqlite3_errmsg $DB +} {not an error} +do_test capi3-1.4 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3-1.5 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql [string length $sql] TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3-1.6 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare $DB $sql [expr [string length $sql]+1] TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} + +do_test capi3-1.7 { + set sql {SELECT namex FROM sqlite_master} + catch { + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + } +} {1} +do_test capi3-1.8.1 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi3-1.8.2 { + sqlite3_extended_errcode $DB +} {SQLITE_ERROR} +do_test capi3-1.9 { + sqlite3_errmsg $DB +} {no such column: namex} + +ifcapable {utf16} { + do_test capi3-2.1 { + set sql16 [utf16 {SELECT name FROM sqlite_master}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 ::TAIL] + sqlite3_finalize $STMT + utf8 $::TAIL + } {} + do_test capi3-2.2 { + set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] + set STMT [sqlite3_prepare16 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + utf8 $TAIL + } {SELECT 10} + do_test capi3-2.3 { + set sql [utf16 {SELECT namex FROM sqlite_master}] + catch { + set STMT [sqlite3_prepare16 $DB $sql -1] + } + } {1} + do_test capi3-2.4.1 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3-2.4.2 { + sqlite3_extended_errcode $DB + } {SQLITE_ERROR} + do_test capi3-2.5 { + sqlite3_errmsg $DB + } {no such column: namex} + + ifcapable schema_pragmas { + do_test capi3-2.6 { + execsql {CREATE TABLE tablename(x)} + set sql16 [utf16 {PRAGMA table_info("TableName"); --excess text}] + set STMT [sqlite3_prepare16 $DB $sql16 -1] + sqlite3_step $STMT + } SQLITE_ROW + do_test capi3-2.7 { + sqlite3_step $STMT + } SQLITE_DONE + do_test capi3-2.8 { + sqlite3_finalize $STMT + } SQLITE_OK + } + +} ;# endif utf16 + +# rename sqlite3_open sqlite3_open_old +# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options} + +do_test capi3-3.1 { + set db2 [sqlite3_open test.db {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3-3.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3-3.3 { + catch { + set db2 [sqlite3_open /bogus/path/test.db {}] + } + set ::capi3_errno [sqlite3_system_errno $db2] + list [sqlite3_extended_errcode $db2] [expr {$::capi3_errno!=0}] +} {SQLITE_CANTOPEN 1} +do_test capi3-3.4 { + sqlite3_errmsg $db2 +} {unable to open database file} +do_test capi3-3.5 { + list [sqlite3_system_errno $db2] [sqlite3_close $db2] +} [list $::capi3_errno SQLITE_OK] +if {[clang_sanitize_address]==0 && 0} { + do_test capi3-3.6.1-misuse { + sqlite3_close $db2 + } {SQLITE_MISUSE} + do_test capi3-3.6.2-misuse { + sqlite3_errmsg $db2 + } {bad parameter or other API misuse} + ifcapable {utf16} { + do_test capi3-3.6.3-misuse { + utf8 [sqlite3_errmsg16 $db2] + } {bad parameter or other API misuse} + } +} + +do_test capi3-3.7 { + set db2 [sqlite3_open] + sqlite3_errcode $db2 +} {SQLITE_OK} +do_test capi3-3.8 { + sqlite3_close $db2 +} {SQLITE_OK} + +# rename sqlite3_open "" +# rename sqlite3_open_old sqlite3_open + +ifcapable {utf16} { +do_test capi3-4.1 { + set db2 [sqlite3_open16 [utf16 test.db] {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3-4.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3-4.3 { + catch { + set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3-4.4 { + utf8 [sqlite3_errmsg16 $db2] +} {unable to open database file} +do_test capi3-4.5 { + sqlite3_close $db2 +} {SQLITE_OK} +} ;# utf16 + +# This proc is used to test the following API calls: +# +# sqlite3_column_count +# sqlite3_column_name +# sqlite3_column_name16 +# sqlite3_column_decltype +# sqlite3_column_decltype16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_header {STMT test names decltypes} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Column names in UTF-8 + do_test $test.1 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.2 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.3 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.4 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.5 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} + set cnamelist + } $decltypes + + # Column declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.6 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]] + } + set cnamelist + } $decltypes + } + + + # Test some out of range conditions: + ifcapable {utf16} { + do_test $test.7 { + list \ + [sqlite3_column_name $STMT -1] \ + [sqlite3_column_name16 $STMT -1] \ + [sqlite3_column_decltype $STMT -1] \ + [sqlite3_column_decltype16 $STMT -1] \ + [sqlite3_column_name $STMT $numcols] \ + [sqlite3_column_name16 $STMT $numcols] \ + [sqlite3_column_decltype $STMT $numcols] \ + [sqlite3_column_decltype16 $STMT $numcols] + } {{} {} {} {} {} {} {} {}} + } +} + +# This proc is used to test the following API calls: +# +# sqlite3_column_origin_name +# sqlite3_column_origin_name16 +# sqlite3_column_table_name +# sqlite3_column_table_name16 +# sqlite3_column_database_name +# sqlite3_column_database_name16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_origin_header {STMT test dbs tables cols} { + # If sqlite3_column_origin_name() and friends are not compiled into + # this build, this proc is a no-op. + ifcapable columnmetadata { + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Database names in UTF-8 + do_test $test.8 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_database_name $STMT $i] + } + set cnamelist + } $dbs + + # Database names in UTF-16 + ifcapable {utf16} { + do_test $test.9 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]] + } + set cnamelist + } $dbs + } + + # Table names in UTF-8 + do_test $test.10 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_table_name $STMT $i] + } + set cnamelist + } $tables + + # Table names in UTF-16 + ifcapable {utf16} { + do_test $test.11 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]] + } + set cnamelist + } $tables + } + + # Origin names in UTF-8 + do_test $test.12 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_origin_name $STMT $i] + } + set cnamelist + } $cols + + # Origin declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.13 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]] + } + set cnamelist + } $cols + } + } +} + +# This proc is used to test the following APIs: +# +# sqlite3_data_count +# sqlite3_column_type +# sqlite3_column_int +# sqlite3_column_text +# sqlite3_column_text16 +# sqlite3_column_double +# +# $STMT is a compiled SQL statement for which the previous call +# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use +# for test names within this proc. $types is a list of the +# manifest types for the current row. $ints, $doubles and $strings +# are lists of the integer, real and string representations of +# the values in the current row. +# +# Example: +# +# set STMT [sqlite3_prepare "SELECT 'hello', 1.1, NULL" -1 DUMMY] +# sqlite3_step $STMT +# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}} +# +proc check_data {STMT test types ints doubles strings} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set numcols [sqlite3_data_count $STMT] + for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i} + +# types +do_test $test.1 { + set types [list] + foreach i $idxlist { + set x [sqlite3_column_type $STMT $i] + # EVIDENCE-OF: R-12793-43283 Every value in SQLite has one of five + # fundamental datatypes: 64-bit signed integer 64-bit IEEE floating + # point number string BLOB NULL + if {[lsearch {INTEGER FLOAT TEXT BLOB NULL} $x]<0} { + set types ERROR + break + } else { + lappend types $x + } + } + set types +} $types + + +# Integers +do_test $test.2 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]} + set ints +} $ints + +# bytes +set lens [list] +foreach i $::idxlist { + lappend lens [string length [lindex $strings $i]] +} +do_test $test.3 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes $STMT $i] + } + set bytes +} $lens + +# bytes16 +ifcapable {utf16} { + set lens [list] + foreach i $::idxlist { + lappend lens [expr 2 * [string length [lindex $strings $i]]] + } + do_test $test.4 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes16 $STMT $i] + } + set bytes + } $lens +} + +# Blob +do_test $test.5 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]} + set utf8 +} $strings + +# UTF-8 +do_test $test.6 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Floats +do_test $test.7 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-16 +ifcapable {utf16} { + do_test $test.8 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]} + set utf8 + } $strings +} + +# Integers +do_test $test.9 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]} + set ints +} $ints + +# Floats +do_test $test.10 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-8 +do_test $test.11 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Types +do_test $test.12 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Test that an out of range request returns the equivalent of NULL +do_test $test.13 { + sqlite3_column_int $STMT -1 +} {0} +do_test $test.13 { + sqlite3_column_text $STMT -1 +} {} + +} + +ifcapable !floatingpoint { + finish_test + return +} + +do_test capi3-5.0 { + execsql { + CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16)); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES('one', 'two', NULL); + INSERT INTO t1 VALUES(1.2, 1.3, 1.4); + } + set sql "SELECT * FROM t1" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.1 {main main main} {t1 t1 t1} {a b c} +do_test capi3-5.2 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.3 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3} + +do_test capi3-5.5 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.6 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}} + +do_test capi3-5.8 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3-5.9 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} + +do_test capi3-5.11 { + sqlite3_step $STMT +} SQLITE_DONE + +do_test capi3-5.12 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3-5.20 { + set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.21 {a sum(b) max(c)} {VARINT {} {}} +check_origin_header $STMT capi3-5.22 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3-5.23 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3-5.30 { + set sql "SELECT a AS x, sum(b) AS y, max(c) AS z FROM t1 AS m GROUP BY x" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3-5.31 {x y z} {VARINT {} {}} +check_origin_header $STMT capi3-5.32 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3-5.33 { + sqlite3_finalize $STMT +} SQLITE_OK + +# 2018-01-09: If a column is the last token if a string, the column name +# was not being set correctly, due to changes in check-in +# https://sqlite.org/src/info/0fdf97efe5df7455 +# +# This problem was detected by the community during beta-testing. +# +do_test capi3-5.34 { + set STMT [sqlite3_prepare $DB {SELECT :a, :b} -1 TAIL] + sqlite3_column_count $STMT +} 2 +check_header $STMT capi-5.35 {:a :b} {{} {}} +sqlite3_finalize $STMT + +set ::ENC [execsql {pragma encoding}] +db close + +do_test capi3-6.0 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy } + set sql {SELECT a FROM t1 order by rowid} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + expr 0 +} {0} +do_test capi3-6.1 { + db cache flush + sqlite3_close $DB +} {SQLITE_BUSY} + +# 6.2 and 6.3 used to return SQLITE_ERROR and SQLITE_SCHEMA, respectively. +# But since attempting to close a connection no longer resets the internal +# schema and expires all statements, this is no longer the case. +do_test capi3-6.2 { + sqlite3_step $STMT +} {SQLITE_ROW} +#check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1} +do_test capi3-6.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +if {[clang_sanitize_address]==0} { + do_test capi3-6.4-misuse { + db cache flush + sqlite3_close $DB + } {SQLITE_OK} +} +db close + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +if {![sqlite3 -has-codec]} { + # Test what happens when the library encounters a newer file format. + do_test capi3-7.1 { + set_file_format 5 + } {} + do_test capi3-7.2 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {unsupported file format}} + db close +} + +if {![sqlite3 -has-codec]} { + # Now test that the library correctly handles bogus entries in the + # sqlite_master table (schema corruption). + do_test capi3-8.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + CREATE TABLE t1(a); + } + db close + } {} + do_test capi3-8.2 { + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); + } + db close + } {} + do_test capi3-8.3 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + do_test capi3-8.4 { + # Build a 5-field row record. The first field is a string 'table', and + # subsequent fields are all NULL. + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a); + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); + } + db close + } {}; + do_test capi3-8.5 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + db close +} +forcedelete test.db +forcedelete test.db-journal + + +# Test the english language string equivalents for sqlite error codes +set code2english [list \ +SQLITE_OK {not an error} \ +SQLITE_ERROR {SQL logic error} \ +SQLITE_PERM {access permission denied} \ +SQLITE_ABORT {query aborted} \ +SQLITE_BUSY {database is locked} \ +SQLITE_LOCKED {database table is locked} \ +SQLITE_NOMEM {out of memory} \ +SQLITE_READONLY {attempt to write a readonly database} \ +SQLITE_INTERRUPT {interrupted} \ +SQLITE_IOERR {disk I/O error} \ +SQLITE_CORRUPT {database disk image is malformed} \ +SQLITE_FULL {database or disk is full} \ +SQLITE_CANTOPEN {unable to open database file} \ +SQLITE_SCHEMA {database schema has changed} \ +SQLITE_CONSTRAINT {constraint failed} \ +SQLITE_MISMATCH {datatype mismatch} \ +SQLITE_MISUSE {bad parameter or other API misuse} \ +SQLITE_AUTH {authorization denied} \ +SQLITE_RANGE {column index out of range} \ +SQLITE_NOTADB {file is not a database} \ +unknownerror {unknown error} \ +] + +set test_number 1 +foreach {code english} $code2english { + do_test capi3-9.$test_number "sqlite3_test_errstr $code" $english + incr test_number +} + +# Test the error message when a "real" out of memory occurs. +if { [permutation] != "nofaultsim" } { + do_test capi3-10-1 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 1 + catchsql { + select * from sqlite_master; + } + } {1 {out of memory}} + do_test capi3-10-2 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3-10-3 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 + do_test capi3-10-4 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 1 + catchsql { + select * from sqlite_master where rowid>5; + } + } {1 {out of memory}} + do_test capi3-10-5 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3-10-6 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 +} + +# The following tests - capi3-11.* - test that a COMMIT or ROLLBACK +# statement issued while there are still outstanding VMs that are part of +# the transaction fails. +sqlite3 db test.db +set DB [sqlite3_connection_pointer db] +sqlite_register_test_function $DB func +do_test capi3-11.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'int'); + INSERT INTO t1 VALUES(2, 'notatype'); + } +} {} +do_test capi3-11.1.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.2 { + set STMT [sqlite3_prepare $DB "SELECT func(b, a) FROM t1" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} + +# As of 3.6.5 a COMMIT is OK during while a query is still running - +# as long as it is a read-only query and not an incremental BLOB write. +# +do_test capi3-11.3.1 { + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.3.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-11.3.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.3.4 { + db eval {PRAGMA lock_status} +} {main shared temp closed} + +do_test capi3-11.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-11.5 { + sqlite3_finalize $STMT +} {SQLITE_ERROR} +do_test capi3-11.6 { + catchsql { + SELECT * FROM t1; + } +} {0 {1 int 2 notatype}} +do_test capi3-11.7 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.8 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t2 VALUES(3); + } +} {} +do_test capi3-11.8.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.9 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.9.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3-11.9.2 { + catchsql { + ROLLBACK; + } +} {0 {}} +do_test capi3-11.9.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.10 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.11 { + sqlite3_step $STMT +} {SQLITE_DONE} +ifcapable !autoreset { + do_test capi3-11.12armor { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_MISUSE} +} else { + do_test capi3-11.12 { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_ROW} +} +do_test capi3-11.13 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-11.14 { + execsql { + SELECT a FROM t2; + } +} {1 2} +do_test capi3-11.14.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.15 { + catchsql { + ROLLBACK; + } +} {1 {cannot rollback - no transaction is active}} +do_test capi3-11.15.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.16 { + execsql { + SELECT a FROM t2; + } +} {1 2} + +# Sanity check on the definition of 'outstanding VM'. This means any VM +# that has had sqlite3_step() called more recently than sqlite3_finalize() or +# sqlite3_reset(). So a VM that has just been prepared or reset does not +# count as an active VM. +do_test capi3-11.17 { + execsql { + BEGIN; + } +} {} +do_test capi3-11.18 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t1" -1 TAIL] + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.19 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-11.20 { + catchsql { + BEGIN; + COMMIT; + } +} {0 {}} +do_test capi3-11.20 { + sqlite3_reset $STMT + catchsql { + COMMIT; + } +} {1 {cannot commit - no transaction is active}} +do_test capi3-11.21 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# The following tests - capi3-12.* - check that its Ok to start a +# transaction while other VMs are active, and that its Ok to execute +# atomic updates in the same situation +# +do_test capi3-12.1 { + set STMT [sqlite3_prepare $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.2 { + catchsql { + INSERT INTO t1 VALUES(3, NULL); + } +} {0 {}} +do_test capi3-12.3 { + catchsql { + INSERT INTO t2 VALUES(4); + } +} {0 {}} +do_test capi3-12.4 { + catchsql { + BEGIN; + INSERT INTO t1 VALUES(4, NULL); + } +} {0 {}} +do_test capi3-12.5 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.5.1 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3-12.6 { + sqlite3_step $STMT +} {SQLITE_DONE} +do_test capi3-12.7 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-12.8 { + execsql { + COMMIT; + SELECT a FROM t1; + } +} {1 2 3 4} + +# Test cases capi3-13.* test the sqlite3_clear_bindings() and +# sqlite3_sleep APIs. +# +if {[llength [info commands sqlite3_clear_bindings]]>0} { + do_test capi3-13.1 { + execsql { + DELETE FROM t1; + } + set STMT [sqlite3_prepare $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL] + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13.2 { + sqlite3_reset $STMT + sqlite3_bind_text $STMT 1 hello 5 + sqlite3_bind_text $STMT 2 world 5 + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13.3 { + sqlite3_reset $STMT + sqlite3_clear_bindings $STMT + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3-13-4 { + sqlite3_finalize $STMT + execsql { + SELECT * FROM t1; + } + } {{} {} hello world {} {}} +} +if {[llength [info commands sqlite3_sleep]]>0} { + do_test capi3-13-5 { + set ms [sqlite3_sleep 80] + expr {$ms==80 || $ms==1000} + } {1} +} + +# Ticket #1219: Make sure binding APIs can handle a NULL pointer. +# +if {[clang_sanitize_address]==0} { + do_test capi3-14.1-misuse { + set rc [catch {sqlite3_bind_text 0 1 hello 5} msg] + lappend rc $msg + } {1 SQLITE_MISUSE} +} + +# Ticket #1650: Honor the nBytes parameter to sqlite3_prepare. +# +do_test capi3-15.1 { + set sql {SELECT * FROM t2} + set nbytes [string length $sql] + append sql { WHERE a==1} + set STMT [sqlite3_prepare $DB $sql $nbytes TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3-15.2 { + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {2} +do_test capi3-15.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3-15.4 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 8 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {1} +do_test capi3-15.5 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 9 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12} +do_test capi3-15.6 { + # 123456789 1234567 + set sql {SELECT 1234567890} + set STMT [sqlite3_prepare $DB $sql 12 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_int $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12345} +do_test capi3-15.7 { + # 123456789 1234567 + set sql {SELECT 12.34567890} + set STMT [sqlite3_prepare $DB $sql 12 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_double $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12.34} +do_test capi3-15.8 { + # 123456789 1234567 + set sql {SELECT 12.34567890} + set STMT [sqlite3_prepare $DB $sql 14 TAIL] + sqlite3_step $STMT + set v1 [sqlite3_column_double $STMT 0] + sqlite3_finalize $STMT + set v1 +} {12.3456} + +# Make sure code is always generated even if an IF EXISTS or +# IF NOT EXISTS clause is present that the table does not or +# does exists. That way we will always have a prepared statement +# to expire when the schema changes. +# +do_test capi3-16.1 { + set sql {DROP TABLE IF EXISTS t3} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} +do_test capi3-16.2 { + set sql {CREATE TABLE IF NOT EXISTS t1(x,y)} + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} + +# But still we do not generate code if there is no SQL +# +do_test capi3-16.3 { + set STMT [sqlite3_prepare $DB {} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} +do_test capi3-16.4 { + set STMT [sqlite3_prepare $DB {;} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} + +# Ticket #2426: Misuse of sqlite3_column_* by calling it after +# a sqlite3_reset should be harmless. +# +do_test capi3-17.1 { + set STMT [sqlite3_prepare $DB {SELECT * FROM t2} -1 TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3-17.2 { + sqlite3_reset $STMT + sqlite3_column_int $STMT 0 +} {0} +do_test capi3-17.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# Verify that sqlite3_step() fails with an SQLITE_SCHEMA error +# when the statement is prepared with sqlite3_prepare() (not +# sqlite3_prepare_v2()) and the schema has changed. +# +do_test capi3-18.1 { + set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL] + sqlite3 db2 test.db + db2 eval {CREATE TABLE t3(x)} + db2 close + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-18.2 { + sqlite3_reset $STMT + sqlite3_errcode db +} {SQLITE_SCHEMA} +do_test capi3-18.3 { + sqlite3_errmsg db +} {database schema has changed} +# The error persist on retry when sqlite3_prepare() has been used. +do_test capi3-18.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3-18.5 { + sqlite3_reset $STMT + sqlite3_errcode db +} {SQLITE_SCHEMA} +do_test capi3-18.6 { + sqlite3_errmsg db +} {database schema has changed} +sqlite3_finalize $STMT + +# Ticket #3134. Prepare a statement with an nBytes parameter of 0. +# Make sure this works correctly and does not reference memory out of +# range. +# +do_test capi3-19.1 { + sqlite3_prepare_tkt3134 db +} {} + +# Test that calling sqlite3_column_blob() on a TEXT value does not change +# the return type of subsequent calls to sqlite3_column_type(). +# +do_execsql_test 20.1 { + CREATE TABLE t4(x); + INSERT INTO t4 VALUES('abcdefghij'); +} +do_test 20.2 { + set stmt [sqlite3_prepare db "SELECT * FROM t4" -1 dummy] + sqlite3_step $stmt +} {SQLITE_ROW} +do_test 20.3 { sqlite3_column_type $stmt 0 } {TEXT} +do_test 20.4 { sqlite3_column_blob $stmt 0 } {abcdefghij} +do_test 20.5 { sqlite3_column_type $stmt 0 } {TEXT} +do_test 20.6 { sqlite3_finalize $stmt } SQLITE_OK + + +# Tests of the interface when no VFS is registered. +# +if {![info exists tester_do_binarylog]} { + db close + vfs_unregister_all + do_test capi3-20.1 { + sqlite3_sleep 100 + } {0} + vfs_reregister_all +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3b.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3b.test new file mode 100644 index 0000000000000000000000000000000000000000..72bbbaf65678938bcfb9fe072c55f675f00db2b8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3b.test @@ -0,0 +1,145 @@ +# 2004 September 2 +# +# 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. The +# focus of this script testing the callback-free C/C++ API and in +# particular the behavior of sqlite3_step() when trying to commit +# with lock contention. +# +# $Id: capi3b.test,v 1.4 2007/08/10 19:46:14 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# These tests depend on the pager holding changes in cache +# until it is time to commit. But that won't happen if the +# soft-heap-limit is set too low. So disable the soft heap limit +# for the duration of this test. +# +sqlite3_soft_heap_limit 0 + + +set DB [sqlite3_connection_pointer db] +sqlite3 db2 test.db +set DB2 [sqlite3_connection_pointer db2] + +# Create some data in the database +# +do_test capi3b-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + SELECT * FROM t1 + } +} {1 2} + +# Make sure the second database connection can see the data +# +do_test capi3b-1.2 { + execsql { + SELECT * FROM t1 + } db2 +} {1 2} + +# First database connection acquires a shared lock +# +do_test capi3b-1.3 { + execsql { + BEGIN; + SELECT * FROM t1; + } +} {1 2} + +# Second database connection tries to write. The sqlite3_step() +# function returns SQLITE_BUSY because it cannot commit. +# +do_test capi3b-1.4 { + set VM [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(3)} -1 TAIL] + sqlite3_step $VM +} SQLITE_BUSY + +# The sqlite3_step call can be repeated multiple times. +# +do_test capi3b-1.5.1 { + sqlite3_step $VM +} SQLITE_BUSY +do_test capi3b-1.5.2 { + sqlite3_step $VM +} SQLITE_BUSY + +# The first connection closes its transaction. This allows the second +# connections sqlite3_step to succeed. +# +do_test capi3b-1.6 { + execsql COMMIT + sqlite3_step $VM +} SQLITE_DONE +do_test capi3b-1.7 { + sqlite3_finalize $VM +} SQLITE_OK +do_test capi3b-1.8 { + execsql {SELECT * FROM t1} db2 +} {1 2 3} +do_test capi3b-1.9 { + execsql {SELECT * FROM t1} +} {1 2 3} + +# Start doing a SELECT with one connection. This gets a SHARED lock. +# Then do an INSERT with the other connection. The INSERT should +# not be able to complete until the SELECT finishes. +# +do_test capi3b-2.1 { + set VM1 [sqlite3_prepare $DB {SELECT * FROM t1} -1 TAIL] + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.2 { + sqlite3_column_text $VM1 0 +} 1 +do_test capi3b-2.3 { + set VM2 [sqlite3_prepare $DB2 {INSERT INTO t1 VALUES(4)} -1 TAIL] + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.4 { + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.5 { + sqlite3_column_text $VM1 0 +} 2 +do_test capi3b-2.6 { + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.7 { + sqlite3_step $VM1 +} SQLITE_ROW +do_test capi3b-2.8 { + sqlite3_column_text $VM1 0 +} 3 +do_test capi3b-2.9 { + sqlite3_step $VM2 +} SQLITE_BUSY +do_test capi3b-2.10 { + sqlite3_step $VM1 +} SQLITE_DONE +do_test capi3b-2.11 { + sqlite3_step $VM2 +} SQLITE_DONE +do_test capi3b-2.12 { + sqlite3_finalize $VM1 + sqlite3_finalize $VM2 + execsql {SELECT * FROM t1} +} {1 2 3 4} + +catch {db2 close} + +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3c.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3c.test new file mode 100644 index 0000000000000000000000000000000000000000..247dbf35e520a48891a82849756ecfc12d366c55 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3c.test @@ -0,0 +1,1401 @@ +# 2006 November 08 +# +# 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. +# +# This is a copy of the capi3.test file that has been adapted to +# test the new sqlite3_prepare_v2 interface. +# +# $Id: capi3c.test,v 1.23 2009/07/22 07:27:57 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix capi3c + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3c-1.*: Test sqlite3_prepare_v2 +# capi3c-2.*: Test sqlite3_prepare16_v2 +# capi3c-3.*: Test sqlite3_open +# capi3c-4.*: Test sqlite3_open16 +# capi3c-5.*: Test the various sqlite3_result_* APIs +# capi3c-6.*: Test that sqlite3_close fails if there are outstanding VMs. +# + +set DB [sqlite3_connection_pointer db] + +do_test capi3c-1.0 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-1.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT name FROM sqlite_master} -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {} +do_test capi3c-1.2.1 { + sqlite3_errcode $DB +} {SQLITE_OK} +do_test capi3c-1.2.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3c-1.3 { + sqlite3_errmsg $DB +} {not an error} +do_test capi3c-1.4 { + set sql {SELECT name FROM sqlite_master;SELECT 10} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + set TAIL +} {SELECT 10} +do_test capi3c-1.5 { + set sql {SELECT namex FROM sqlite_master} + catch { + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + } +} {1} +do_test capi3c-1.6.1 { + sqlite3_errcode $DB +} {SQLITE_ERROR} +do_test capi3c-1.6.2 { + sqlite3_extended_errcode $DB +} {SQLITE_ERROR} +do_test capi3c-1.7 { + sqlite3_errmsg $DB +} {no such column: namex} + + +ifcapable {utf16} { + do_test capi3c-2.1 { + set sql16 [utf16 {SELECT name FROM sqlite_master}] + set STMT [sqlite3_prepare16_v2 $DB $sql16 -1 ::TAIL] + sqlite3_finalize $STMT + utf8 $::TAIL + } {} + do_test capi3c-2.2 { + set sql [utf16 {SELECT name FROM sqlite_master;SELECT 10}] + set STMT [sqlite3_prepare16_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + utf8 $TAIL + } {SELECT 10} + do_test capi3c-2.3 { + set sql [utf16 {SELECT namex FROM sqlite_master}] + catch { + set STMT [sqlite3_prepare16_v2 $DB $sql -1 TAIL] + } + } {1} + do_test capi3c-2.4.1 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-2.4.2 { + sqlite3_extended_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-2.5 { + sqlite3_errmsg $DB + } {no such column: namex} + + ifcapable schema_pragmas { + do_test capi3c-2.6 { + execsql {CREATE TABLE tablename(x)} + set sql16 [utf16 {PRAGMA table_info("TableName")}] + set STMT [sqlite3_prepare16_v2 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + } SQLITE_ROW + do_test capi3c-2.7 { + sqlite3_step $STMT + } SQLITE_DONE + do_test capi3c-2.8 { + sqlite3_finalize $STMT + } SQLITE_OK + } + +} ;# endif utf16 + +# rename sqlite3_open sqlite3_open_old +# proc sqlite3_open {fname options} {sqlite3_open_new $fname $options} + +do_test capi3c-3.1 { + set db2 [sqlite3_open test.db {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3c-3.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3c-3.3 { + catch { + set db2 [sqlite3_open /bogus/path/test.db {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3c-3.4 { + sqlite3_errmsg $db2 +} {unable to open database file} +do_test capi3c-3.5 { + sqlite3_close $db2 +} {SQLITE_OK} +if {[clang_sanitize_address]==0} { + do_test capi3c-3.6.1-misuse { + sqlite3_close $db2 + } {SQLITE_MISUSE} + do_test capi3c-3.6.2-misuse { + sqlite3_errmsg $db2 + } {bad parameter or other API misuse} + ifcapable {utf16} { + do_test capi3c-3.6.3-misuse { + utf8 [sqlite3_errmsg16 $db2] + } {bad parameter or other API misuse} + } +} + +# rename sqlite3_open "" +# rename sqlite3_open_old sqlite3_open + +ifcapable {utf16} { +do_test capi3c-4.1 { + set db2 [sqlite3_open16 [utf16 test.db] {}] + sqlite3_errcode $db2 +} {SQLITE_OK} +# FIX ME: Should test the db handle works. +do_test capi3c-4.2 { + sqlite3_close $db2 +} {SQLITE_OK} +do_test capi3c-4.3 { + catch { + set db2 [sqlite3_open16 [utf16 /bogus/path/test.db] {}] + } + sqlite3_errcode $db2 +} {SQLITE_CANTOPEN} +do_test capi3c-4.4 { + utf8 [sqlite3_errmsg16 $db2] +} {unable to open database file} +do_test capi3c-4.5 { + sqlite3_close $db2 +} {SQLITE_OK} +} ;# utf16 + +# This proc is used to test the following API calls: +# +# sqlite3_column_count +# sqlite3_column_name +# sqlite3_column_name16 +# sqlite3_column_decltype +# sqlite3_column_decltype16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_header {STMT test names decltypes} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Column names in UTF-8 + do_test $test.1 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.2 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.3 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} + set cnamelist + } $names + + # Column names in UTF-16 + ifcapable {utf16} { + do_test $test.4 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]] + } + set cnamelist + } $names + } + + # Column names in UTF-8 + do_test $test.5 { + set cnamelist [list] + foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} + set cnamelist + } $decltypes + + # Column declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.6 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]] + } + set cnamelist + } $decltypes + } + + + # Test some out of range conditions: + ifcapable {utf16} { + do_test $test.7 { + list \ + [sqlite3_column_name $STMT -1] \ + [sqlite3_column_name16 $STMT -1] \ + [sqlite3_column_decltype $STMT -1] \ + [sqlite3_column_decltype16 $STMT -1] \ + [sqlite3_column_name $STMT $numcols] \ + [sqlite3_column_name16 $STMT $numcols] \ + [sqlite3_column_decltype $STMT $numcols] \ + [sqlite3_column_decltype16 $STMT $numcols] + } {{} {} {} {} {} {} {} {}} + } +} + +# This proc is used to test the following API calls: +# +# sqlite3_column_origin_name +# sqlite3_column_origin_name16 +# sqlite3_column_table_name +# sqlite3_column_table_name16 +# sqlite3_column_database_name +# sqlite3_column_database_name16 +# +# $STMT is a compiled SQL statement. $test is a prefix +# to use for test names within this proc. $names is a list +# of the column names that should be returned by $STMT. +# $decltypes is a list of column declaration types for $STMT. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 1, 2, 2;" -1 DUMMY] +# check_header test1.1 {1 2 3} {"" "" ""} +# +proc check_origin_header {STMT test dbs tables cols} { + # If sqlite3_column_origin_name() and friends are not compiled into + # this build, this proc is a no-op. +ifcapable columnmetadata { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set ::numcols [sqlite3_column_count $STMT] + for {set i 0} {$i < $::numcols} {incr i} {lappend ::idxlist $i} + + # Database names in UTF-8 + do_test $test.8 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_database_name $STMT $i] + } + set cnamelist + } $dbs + + # Database names in UTF-16 + ifcapable {utf16} { + do_test $test.9 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_database_name16 $STMT $i]] + } + set cnamelist + } $dbs + } + + # Table names in UTF-8 + do_test $test.10 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_table_name $STMT $i] + } + set cnamelist + } $tables + + # Table names in UTF-16 + ifcapable {utf16} { + do_test $test.11 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_table_name16 $STMT $i]] + } + set cnamelist + } $tables + } + + # Origin names in UTF-8 + do_test $test.12 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [sqlite3_column_origin_name $STMT $i] + } + set cnamelist + } $cols + + # Origin declaration types in UTF-16 + ifcapable {utf16} { + do_test $test.13 { + set cnamelist [list] + foreach i $idxlist { + lappend cnamelist [utf8 [sqlite3_column_origin_name16 $STMT $i]] + } + set cnamelist + } $cols + } + } +} + +# This proc is used to test the following APIs: +# +# sqlite3_data_count +# sqlite3_column_type +# sqlite3_column_int +# sqlite3_column_text +# sqlite3_column_text16 +# sqlite3_column_double +# +# $STMT is a compiled SQL statement for which the previous call +# to sqlite3_step returned SQLITE_ROW. $test is a prefix to use +# for test names within this proc. $types is a list of the +# manifest types for the current row. $ints, $doubles and $strings +# are lists of the integer, real and string representations of +# the values in the current row. +# +# Example: +# +# set STMT [sqlite3_prepare_v2 "SELECT 'hello', 1.1, NULL" -1 DUMMY] +# sqlite3_step $STMT +# check_data test1.2 {TEXT REAL NULL} {0 1 0} {0 1.1 0} {hello 1.1 {}} +# +proc check_data {STMT test types ints doubles strings} { + + # Use the return value of sqlite3_column_count() to build + # a list of column indexes. i.e. If sqlite3_column_count + # is 3, build the list {0 1 2}. + set ::idxlist [list] + set numcols [sqlite3_data_count $STMT] + for {set i 0} {$i < $numcols} {incr i} {lappend ::idxlist $i} + +# types +do_test $test.1 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Integers +do_test $test.2 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int64 $STMT $i]} + set ints +} $ints + +# bytes +set lens [list] +foreach i $::idxlist { + lappend lens [string length [lindex $strings $i]] +} +do_test $test.3 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes $STMT $i] + } + set bytes +} $lens + +# bytes16 +ifcapable {utf16} { + set lens [list] + foreach i $::idxlist { + lappend lens [expr 2 * [string length [lindex $strings $i]]] + } + do_test $test.4 { + set bytes [list] + set lens [list] + foreach i $idxlist { + lappend bytes [sqlite3_column_bytes16 $STMT $i] + } + set bytes + } $lens +} + +# Blob +do_test $test.5 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_blob $STMT $i]} + set utf8 +} $strings + +# UTF-8 +do_test $test.6 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Floats +do_test $test.7 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-16 +ifcapable {utf16} { + do_test $test.8 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [utf8 [sqlite3_column_text16 $STMT $i]]} + set utf8 + } $strings +} + +# Integers +do_test $test.9 { + set ints [list] + foreach i $idxlist {lappend ints [sqlite3_column_int $STMT $i]} + set ints +} $ints + +# Floats +do_test $test.10 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_double $STMT $i]} + set utf8 +} $doubles + +# UTF-8 +do_test $test.11 { + set utf8 [list] + foreach i $idxlist {lappend utf8 [sqlite3_column_text $STMT $i]} + set utf8 +} $strings + +# Types +do_test $test.12 { + set types [list] + foreach i $idxlist {lappend types [sqlite3_column_type $STMT $i]} + set types +} $types + +# Test that an out of range request returns the equivalent of NULL +do_test $test.13 { + sqlite3_column_int $STMT -1 +} {0} +do_test $test.13 { + sqlite3_column_text $STMT -1 +} {} + +} + +ifcapable !floatingpoint { + finish_test + return +} + +do_test capi3c-5.0 { + execsql { + CREATE TABLE t1(a VARINT, b BLOB, c VARCHAR(16)); + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES('one', 'two', NULL); + INSERT INTO t1 VALUES(1.2, 1.3, 1.4); + } + set sql "SELECT * FROM t1" + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3c-5.1 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.1 {main main main} {t1 t1 t1} {a b c} +do_test capi3c-5.2 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.3 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.3 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3} + +do_test capi3c-5.5 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.6 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.6 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}} + +do_test capi3c-5.8 { + sqlite3_step $STMT +} SQLITE_ROW + +check_header $STMT capi3c-5.9 {a b c} {VARINT BLOB VARCHAR(16)} +check_origin_header $STMT capi3c-5.9 {main main main} {t1 t1 t1} {a b c} +check_data $STMT capi3c-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4} + +do_test capi3c-5.11 { + sqlite3_step $STMT +} SQLITE_DONE + +do_test capi3c-5.12 { + sqlite3_finalize $STMT +} SQLITE_OK + +do_test capi3c-5.20 { + set sql "SELECT a, sum(b), max(c) FROM t1 GROUP BY a" + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_column_count $STMT +} 3 + +check_header $STMT capi3c-5.21 {a sum(b) max(c)} {VARINT {} {}} +check_origin_header $STMT capi3c-5.22 {main {} {}} {t1 {} {}} {a {} {}} +do_test capi3c-5.23 { + sqlite3_finalize $STMT +} SQLITE_OK + + +set ::ENC [execsql {pragma encoding}] +db close + +do_test capi3c-6.0 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + if {[sqlite3 -has-codec]==0} { sqlite3_key $DB xyzzy } + set sql {SELECT a FROM t1 order by rowid} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + expr 0 +} {0} +do_test capi3c-6.1 { + db cache flush + sqlite3_close $DB +} {SQLITE_BUSY} +do_test capi3c-6.2 { + sqlite3_step $STMT +} {SQLITE_ROW} +check_data $STMT capi3c-6.3 {INTEGER} {1} {1.0} {1} +do_test capi3c-6.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} +if {[clang_sanitize_address]==0} { + do_test capi3c-6.4 { + db cache flush + sqlite3_close $DB + } {SQLITE_OK} + do_test capi3c-6.99-misuse { + db close + } {} +} else { + db close +} + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +if {![sqlite3 -has-codec]} { + # Test what happens when the library encounters a newer file format. + do_test capi3c-7.1 { + set_file_format 5 + } {} + do_test capi3c-7.2 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {unsupported file format}} + db close +} + +if {![sqlite3 -has-codec]} { + # Now test that the library correctly handles bogus entries in the + # sqlite_master table (schema corruption). + do_test capi3c-8.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + CREATE TABLE t1(a); + } + db close + } {} + do_test capi3c-8.2 { + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES(NULL,NULL,NULL,NULL,NULL); + } + db close + } {} + do_test capi3c-8.3 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + do_test capi3c-8.4 { + # Build a 5-field row record. The first field is a string 'table', and + # subsequent fields are all NULL. + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a); + PRAGMA writable_schema=ON; + INSERT INTO sqlite_master VALUES('table',NULL,NULL,NULL,NULL); + } + db close + } {}; + do_test capi3c-8.5 { + catch { sqlite3 db test.db } + catchsql { + SELECT * FROM sqlite_master; + } + } {1 {malformed database schema (?)}} + db close +} +forcedelete test.db +forcedelete test.db-journal + + +# Test the english language string equivalents for sqlite error codes +set code2english [list \ +SQLITE_OK {not an error} \ +SQLITE_ERROR {SQL logic error} \ +SQLITE_PERM {access permission denied} \ +SQLITE_ABORT {query aborted} \ +SQLITE_BUSY {database is locked} \ +SQLITE_LOCKED {database table is locked} \ +SQLITE_NOMEM {out of memory} \ +SQLITE_READONLY {attempt to write a readonly database} \ +SQLITE_INTERRUPT {interrupted} \ +SQLITE_IOERR {disk I/O error} \ +SQLITE_CORRUPT {database disk image is malformed} \ +SQLITE_FULL {database or disk is full} \ +SQLITE_CANTOPEN {unable to open database file} \ +SQLITE_EMPTY {unknown error} \ +SQLITE_SCHEMA {database schema has changed} \ +SQLITE_CONSTRAINT {constraint failed} \ +SQLITE_MISMATCH {datatype mismatch} \ +SQLITE_MISUSE {bad parameter or other API misuse} \ +SQLITE_AUTH {authorization denied} \ +SQLITE_RANGE {column index out of range} \ +SQLITE_NOTADB {file is not a database} \ +unknownerror {unknown error} \ +] + +set test_number 1 +foreach {code english} $code2english { + do_test capi3c-9.$test_number "sqlite3_test_errstr $code" $english + incr test_number +} + +# Test the error message when a "real" out of memory occurs. +if { [permutation] != "nofaultsim" } { + do_test capi3c-10-1 { + sqlite3 db test.db + set DB [sqlite3_connection_pointer db] + sqlite3_memdebug_fail 0 + catchsql { + select * from sqlite_master; + } + } {1 {out of memory}} + do_test capi3c-10-2 { + sqlite3_errmsg $::DB + } {out of memory} + ifcapable {utf16} { + do_test capi3c-10-3 { + utf8 [sqlite3_errmsg16 $::DB] + } {out of memory} + } + db close + sqlite3_memdebug_fail -1 +} + +# The following tests - capi3c-11.* - test that a COMMIT or ROLLBACK +# statement issued while there are still outstanding VMs that are part of +# the transaction fails. +sqlite3 db test.db +set DB [sqlite3_connection_pointer db] +sqlite_register_test_function $DB func +do_test capi3c-11.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 'int'); + INSERT INTO t1 VALUES(2, 'notatype'); + } +} {} +do_test capi3c-11.1.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.2 { + set STMT [sqlite3_prepare_v2 $DB "SELECT func(b, a) FROM t1" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} + +# As of 3.6.5 a COMMIT is OK during while a query is still running - +# as long as it is a read-only query and not an incremental BLOB write. +# +do_test capi3-11.3.1 { + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3-11.3.2 { + sqlite3_extended_errcode $DB +} {SQLITE_OK} +do_test capi3-11.3.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3-11.3.4 { + db eval {PRAGMA lock_status} +} {main shared temp closed} + +do_test capi3c-11.4 { + sqlite3_step $STMT +} {SQLITE_ERROR} +do_test capi3c-11.5 { + sqlite3_finalize $STMT +} {SQLITE_ERROR} +do_test capi3c-11.6 { + catchsql { + SELECT * FROM t1; + } +} {0 {1 int 2 notatype}} +do_test capi3c-11.7 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.8 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); + INSERT INTO t2 VALUES(2); + BEGIN; + INSERT INTO t2 VALUES(3); + } +} {} +do_test capi3c-11.8.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.9 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.9.1 { + sqlite3_get_autocommit $DB +} 0 +do_test capi3c-11.9.2 { + catchsql { + ROLLBACK; + } +} {0 {}} +do_test capi3c-11.9.3 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.10 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.11 { + sqlite3_step $STMT +} {SQLITE_DONE} +ifcapable !autoreset { + do_test capi3c-11.12armor { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_MISUSE} +} else { + do_test capi3c-11.12 { + sqlite3_step $STMT + sqlite3_step $STMT + } {SQLITE_ROW} +} +do_test capi3c-11.13 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3c-11.14 { + execsql { + SELECT a FROM t2; + } +} {1 2} +do_test capi3c-11.14.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.15 { + catchsql { + ROLLBACK; + } +} {1 {cannot rollback - no transaction is active}} +do_test capi3c-11.15.1 { + sqlite3_get_autocommit $DB +} 1 +do_test capi3c-11.16 { + execsql { + SELECT a FROM t2; + } +} {1 2} + +# Sanity check on the definition of 'outstanding VM'. This means any VM +# that has had sqlite3_step() called more recently than sqlite3_finalize() or +# sqlite3_reset(). So a VM that has just been prepared or reset does not +# count as an active VM. +do_test capi3c-11.17 { + execsql { + BEGIN; + } +} {} +do_test capi3c-11.18 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t1" -1 TAIL] + catchsql { + COMMIT; + } +} {0 {}} +do_test capi3c-11.19 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-11.20 { + catchsql { + BEGIN; + COMMIT; + } +} {0 {}} +do_test capi3c-11.20 { + sqlite3_reset $STMT + catchsql { + COMMIT; + } +} {1 {cannot commit - no transaction is active}} +do_test capi3c-11.21 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# The following tests - capi3c-12.* - check that its Ok to start a +# transaction while other VMs are active, and that its Ok to execute +# atomic updates in the same situation +# +do_test capi3c-12.1 { + set STMT [sqlite3_prepare_v2 $DB "SELECT a FROM t2" -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.2 { + catchsql { + INSERT INTO t1 VALUES(3, NULL); + } +} {0 {}} +do_test capi3c-12.3 { + catchsql { + INSERT INTO t2 VALUES(4); + } +} {0 {}} +do_test capi3c-12.4 { + catchsql { + BEGIN; + INSERT INTO t1 VALUES(4, NULL); + } +} {0 {}} +do_test capi3c-12.5 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.5.1 { + sqlite3_step $STMT +} {SQLITE_ROW} +do_test capi3c-12.6 { + sqlite3_step $STMT +} {SQLITE_DONE} +do_test capi3c-12.7 { + sqlite3_finalize $STMT +} {SQLITE_OK} +do_test capi3c-12.8 { + execsql { + COMMIT; + SELECT a FROM t1; + } +} {1 2 3 4} + +# Test cases capi3c-13.* test the sqlite3_clear_bindings() and +# sqlite3_sleep APIs. +# +if {[llength [info commands sqlite3_clear_bindings]]>0} { + do_test capi3c-13.1 { + execsql { + DELETE FROM t1; + } + set STMT [sqlite3_prepare_v2 $DB "INSERT INTO t1 VALUES(?, ?)" -1 TAIL] + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13.2 { + sqlite3_reset $STMT + sqlite3_bind_text $STMT 1 hello 5 + sqlite3_bind_text $STMT 2 world 5 + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13.3 { + sqlite3_reset $STMT + sqlite3_clear_bindings $STMT + sqlite3_step $STMT + } {SQLITE_DONE} + do_test capi3c-13-4 { + sqlite3_finalize $STMT + execsql { + SELECT * FROM t1; + } + } {{} {} hello world {} {}} +} +if {[llength [info commands sqlite3_sleep]]>0} { + do_test capi3c-13-5 { + set ms [sqlite3_sleep 80] + expr {$ms==80 || $ms==1000} + } {1} +} + +# Ticket #1219: Make sure binding APIs can handle a NULL pointer. +# +do_test capi3c-14.1 { + set rc [catch {sqlite3_bind_text 0 1 hello 5} msg] + lappend rc $msg +} {1 SQLITE_MISUSE} + +# Ticket #1650: Honor the nBytes parameter to sqlite3_prepare. +# +do_test capi3c-15.1 { + set sql {SELECT * FROM t2} + set nbytes [string length $sql] + append sql { WHERE a==1} + set STMT [sqlite3_prepare_v2 $DB $sql $nbytes TAIL] + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {1} +do_test capi3c-15.2 { + sqlite3_step $STMT + sqlite3_column_int $STMT 0 +} {2} +do_test capi3c-15.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +# Make sure code is always generated even if an IF EXISTS or +# IF NOT EXISTS clause is present that the table does not or +# does exists. That way we will always have a prepared statement +# to expire when the schema changes. +# +do_test capi3c-16.1 { + set sql {DROP TABLE IF EXISTS t3} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} +do_test capi3c-16.2 { + set sql {CREATE TABLE IF NOT EXISTS t1(x,y)} + set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT!=""} +} {1} + +# But still we do not generate code if there is no SQL +# +do_test capi3c-16.3 { + set STMT [sqlite3_prepare_v2 $DB {} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} +do_test capi3c-16.4 { + set STMT [sqlite3_prepare_v2 $DB {;} -1 TAIL] + sqlite3_finalize $STMT + expr {$STMT==""} +} {1} + +# Ticket #2154. +# +do_test capi3c-17.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT max(a) FROM t2} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.2 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.4 { + sqlite3_reset $STMT + db eval {CREATE INDEX i2 ON t2(a)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.5 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.6 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.7 { + sqlite3_reset $STMT + db eval {DROP INDEX i2} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.8 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-17.9 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.10 { + sqlite3_finalize $STMT + set STMT [sqlite3_prepare_v2 $DB {SELECT b FROM t1 WHERE a=?} -1 TAIL] + sqlite3_bind_int $STMT 1 2 + db eval { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,'one'); + INSERT INTO t1 VALUES(2,'two'); + INSERT INTO t1 VALUES(3,'three'); + INSERT INTO t1 VALUES(4,'four'); + } + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.11 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.12 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.13 { + sqlite3_reset $STMT + db eval {CREATE INDEX i1 ON t1(a)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.14 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.15 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.16 { + sqlite3_reset $STMT + db eval {DROP INDEX i1} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-17.17 { + sqlite3_column_text $STMT 0 +} two +do_test capi3c-17.18 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-17.99 { + sqlite3_finalize $STMT +} SQLITE_OK + +# On the mailing list it has been reported that finalizing after +# an SQLITE_BUSY return leads to a segfault. Here we test that case. +# +do_test capi3c-18.1 { + sqlite3 db2 test.db + set STMT [sqlite3_prepare_v2 $DB {SELECT max(a) FROM t1} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-18.2 { + sqlite3_column_int $STMT 0 +} 4 +do_test capi3c-18.3 { + sqlite3_reset $STMT + db2 eval {BEGIN EXCLUSIVE} + sqlite3_step $STMT +} SQLITE_BUSY +do_test capi3c-18.4 { + sqlite3_finalize $STMT +} SQLITE_BUSY +do_test capi3c-18.5 { + db2 eval {COMMIT} + db2 close +} {} + +# Ticket #2158. The sqlite3_step() will still return SQLITE_SCHEMA +# if the database schema changes in a way that makes the statement +# no longer valid. +# +do_test capi3c-19.1 { + db eval { + CREATE TABLE t3(x,y); + INSERT INTO t3 VALUES(1,2); + } + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-19.2 { + sqlite3_column_int $STMT 0 +} 1 +do_test capi3c-19.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-19.4 { + sqlite3_reset $STMT + db eval {DROP TABLE t3} + sqlite3_step $STMT +} SQLITE_ERROR +do_test capi3c-19.4.1 { + sqlite3_errmsg $DB +} {no such table: t3} +ifcapable deprecated { + do_test capi3c-19.4.2 { + sqlite3_expired $STMT + } 1 +} +do_test capi3c-19.4.3 { + sqlite3_errmsg $DB +} {no such table: t3} +ifcapable deprecated { + do_test capi3c-19.4.4 { + sqlite3_expired 0 + } 1 +} +do_test capi3c-19.5 { + sqlite3_reset $STMT + db eval { + CREATE TABLE t3(x,y); + INSERT INTO t3 VALUES(1,2); + } + sqlite3_step $STMT +} SQLITE_ROW +ifcapable deprecated { + do_test capi3c-19.5.2 { + sqlite3_expired $STMT + } 0 +} +do_test capi3c-19.6 { + sqlite3_column_int $STMT 1 +} 2 +do_test capi3c-19.99 { + sqlite3_finalize $STMT +} SQLITE_OK + +# Make sure a change in a separate database connection does not +# cause an SQLITE_SCHEMA return. +# +do_test capi3c-20.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + sqlite3 db2 test.db + db2 eval {CREATE TABLE t4(x)} + sqlite3_step $STMT +} SQLITE_ROW +do_test capi3c-20.2 { + sqlite3_column_int $STMT 1 +} 2 +do_test capi3c-20.3 { + sqlite3_step $STMT +} SQLITE_DONE +do_test capi3c-20.4 { + db2 close + sqlite3_finalize $STMT +} SQLITE_OK + +# Test that sqlite3_step() sets the database error code correctly. +# See ticket #2497. +# +ifcapable progress { + do_test capi3c-21.1 { + set STMT [sqlite3_prepare_v2 $DB {SELECT * FROM t3} -1 TAIL] + db progress 5 "expr 1" + sqlite3_step $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.2 { + sqlite3_extended_errcode $DB + } {SQLITE_INTERRUPT} + do_test capi3c-21.3 { + sqlite3_finalize $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.4 { + db progress + set STMT [sqlite3_prepare $DB {SELECT * FROM t3} -1 TAIL] + db progress 5 "expr 1" + sqlite3_step $STMT + } {SQLITE_ERROR} + do_test capi3c-21.5 { + sqlite3_errcode $DB + } {SQLITE_ERROR} + do_test capi3c-21.6 { + sqlite3_finalize $STMT + } {SQLITE_INTERRUPT} + do_test capi3c-21.7 { + sqlite3_errcode $DB + } {SQLITE_INTERRUPT} + do_test capi3c-21.8 { + sqlite3_extended_errcode $DB + } {SQLITE_INTERRUPT} +} + +# Make sure sqlite3_result_error_code() returns the correct error code. +# See ticket #2940 +# +do_test capi3c-22.1 { + db progress 0 {} + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',3)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_PERM} +sqlite3_finalize $STMT +do_test capi3c-22.2 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',4)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_ABORT} +sqlite3_finalize $STMT +do_test capi3c-22.3 { + set STMT [sqlite3_prepare_v2 db {SELECT test_error('the message',16)} -1 TAIL] + sqlite3_step $STMT +} {SQLITE_EMPTY} +sqlite3_finalize $STMT + +# For a multi-column result set where the same table column is repeated +# in multiple columns of the output, verify that doing a UTF-8 to UTF-16 +# conversion (or vice versa) on one column does not change the value of +# the second. +# +ifcapable utf16 { + do_test capi3c-23.1 { + set STMT [sqlite3_prepare_v2 db {SELECT b,b,b,b FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test capi3c-23.2 { + sqlite3_column_text16 $STMT 0 + sqlite3_column_text $STMT 1 + } {one} + do_test capi3c-23.3 { + sqlite3_column_text16 $STMT 2 + sqlite3_column_text $STMT 3 + } {one} + sqlite3_finalize $STMT + do_test capi3c-23.4 { + set STMT [sqlite3_prepare_v2 db {SELECT b||'x',b,b,b FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test capi3c-23.5 { + sqlite3_column_text16 $STMT 0 + sqlite3_column_text $STMT 1 + } {one} + do_test capi3c-23.6 { + sqlite3_column_text16 $STMT 2 + sqlite3_column_text $STMT 3 + } {one} + sqlite3_finalize $STMT +} + +# Test decltype on some SELECT statements that contain sub-selects. +# +proc decltype {zSql} { + set ret [list] + set STMT [sqlite3_prepare_v2 db $zSql -1 TAIL] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend ret [sqlite3_column_decltype $STMT $i] + } + sqlite3_finalize $STMT + return $ret +} +do_test capi3c-24.1 { + execsql { CREATE TABLE t5(a INTEGER, b STRING, c DATETIME) } + decltype {SELECT * FROM t5} +} {INTEGER STRING DATETIME} +do_test capi3c-24.2 { + decltype {SELECT (SELECT c) FROM t5} +} {DATETIME} +do_test capi3c-24.3 { + decltype {SELECT (SELECT * FROM (SELECT c)) FROM t5} +} {DATETIME} +do_test capi3c-24.4 { + decltype {SELECT * FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b} +} {INTEGER STRING DATETIME} +do_test capi3c-24.5 { + decltype { + SELECT (SELECT x FROM (SELECT c AS x)) + FROM (SELECT * FROM t5 ORDER BY c LIMIT 1) ORDER BY b + } +} {DATETIME} +do_test capi3c-24.3 { + decltype {SELECT (SELECT x FROM (SELECT t5.a AS x)) FROM t5} +} {INTEGER} + + +# Further tests of sqlite3_column_decltype(): +# +do_execsql_test 25.0 { + CREATE TABLE t11(a VARCHAR(10), b INTEGER); + CREATE TABLE t12(a VARCHAR(15), b FLOAT); +} + +foreach {tn sql} { + 1 "SELECT * FROM t11 UNION ALL SELECT * FROM t12" + 2 "SELECT * FROM t11 UNION SELECT * FROM t12" + 3 "SELECT * FROM t11 EXCEPT SELECT * FROM t12" + 4 "SELECT * FROM t11 INTERSECT SELECT * FROM t12" + + 5 "SELECT * FROM t11 UNION ALL SELECT * FROM t12 ORDER BY 1" + 6 "SELECT * FROM t11 UNION SELECT * FROM t12 ORDER BY 1" + 7 "SELECT * FROM t11 EXCEPT SELECT * FROM t12 ORDER BY 1" + 8 "SELECT * FROM t11 INTERSECT SELECT * FROM t12 ORDER BY 1" +} { + do_test 25.$tn { decltype $sql } {VARCHAR(10) INTEGER} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3d.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3d.test new file mode 100644 index 0000000000000000000000000000000000000000..7cad2870cd598add9b3b716a4f28f5cb22ba237f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3d.test @@ -0,0 +1,289 @@ +# 2008 June 18 +# +# 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. +# +# This file is devoted to testing the sqlite3_next_stmt and +# sqlite3_stmt_readonly and sqlite3_stmt_busy interfaces. +# +# $Id: capi3d.test,v 1.2 2008/07/14 15:11:20 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create N prepared statements against database connection db +# and return a list of all the generated prepared statements. +# +proc make_prepared_statements {N} { + set plist {} + for {set i 0} {$i<$N} {incr i} { + set sql "SELECT $i FROM sqlite_master WHERE name LIKE '%$i%'" + if {rand()<0.33} { + set s [sqlite3_prepare_v2 db $sql -1 notused] + } else { + ifcapable utf16 { + if {rand()<0.5} { + set sql [encoding convertto unicode $sql]\x00\x00 + set s [sqlite3_prepare16 db $sql -1 notused] + } else { + set s [sqlite3_prepare db $sql -1 notused] + } + } + ifcapable !utf16 { + set s [sqlite3_prepare db $sql -1 notused] + } + } + lappend plist $s + } + return $plist +} + + +# Scramble the $inlist into a random order. +# +proc scramble {inlist} { + set y {} + foreach x $inlist { + lappend y [list [expr {rand()}] $x] + } + set y [lsort $y] + set outlist {} + foreach x $y { + lappend outlist [lindex $x 1] + } + return $outlist +} + +# Database initially has no prepared statements. +# +do_test capi3d-1.1 { + db cache flush + sqlite3_next_stmt db 0 +} {} + +# Run the following tests for between 1 and 100 prepared statements. +# +for {set i 1} {$i<=100} {incr i} { + set stmtlist [make_prepared_statements $i] + do_test capi3d-1.2.$i.1 { + set p [sqlite3_next_stmt db 0] + set x {} + while {$p!=""} { + lappend x $p + set p [sqlite3_next_stmt db $p] + } + lsort $x + } [lsort $stmtlist] + do_test capi3-1.2.$i.2 { + foreach p [scramble $::stmtlist] { + sqlite3_finalize $p + } + sqlite3_next_stmt db 0 + } {} +} + +# Tests for the is-read-only interface. +# +proc test_is_readonly {testname sql truth} { + do_test $testname [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {%s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth + + # EVIDENCE-OF: R-61212-30018 If prepared statement X is an EXPLAIN or + # EXPLAIN QUERY PLAN statement, then sqlite3_stmt_readonly(X) returns + # the same value as if the EXPLAIN or EXPLAIN QUERY PLAN prefix were + # omitted. + # + do_test $testname.explain [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {EXPLAIN %s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth + do_test $testname.eqp [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {EXPLAIN QUERY PLAN %s} -1 TAIL] + set rc [sqlite3_stmt_readonly $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth +} + +# EVIDENCE-OF: R-23332-64992 The sqlite3_stmt_readonly(X) interface +# returns true (non-zero) if and only if the prepared statement X makes +# no direct changes to the content of the database file. +# +test_is_readonly capi3d-2.1 {SELECT * FROM sqlite_master} 1 +test_is_readonly capi3d-2.2 {CREATE TABLE t1(x)} 0 +db eval {CREATE TABLE t1(x)} +test_is_readonly capi3d-2.3 {INSERT INTO t1 VALUES(5)} 0 +test_is_readonly capi3d-2.4 {UPDATE t1 SET x=x+1 WHERE x<0} 0 +test_is_readonly capi3d-2.5 {SELECT * FROM t1} 1 +ifcapable wal { + test_is_readonly capi3d-2.6 {PRAGMA journal_mode=WAL} 0 + test_is_readonly capi3d-2.7 {PRAGMA wal_checkpoint} 0 +} +test_is_readonly capi3d-2.8 {PRAGMA application_id=1234} 0 +test_is_readonly capi3d-2.9 {VACUUM} 0 +test_is_readonly capi3d-2.10 {PRAGMA integrity_check} 1 +do_test capi3-2.49 { + sqlite3_stmt_readonly 0 +} 1 + + +# EVIDENCE-OF: R-04929-09147 This routine returns false if there is any +# possibility that the statement might change the database file. +# +# EVIDENCE-OF: R-13288-53765 A false return does not guarantee that the +# statement will change the database file. +# +# EVIDENCE-OF: R-22182-18548 For example, an UPDATE statement might have +# a WHERE clause that makes it a no-op, but the sqlite3_stmt_readonly() +# result would still be false. +# +# EVIDENCE-OF: R-50998-48593 Similarly, a CREATE TABLE IF NOT EXISTS +# statement is a read-only no-op if the table already exists, but +# sqlite3_stmt_readonly() still returns false for such a statement. +# +db eval { + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,3); +} +test_is_readonly capi3d-2.11 {UPDATE t2 SET a=a+1 WHERE false} 0 +test_is_readonly capi3d-2.12 {CREATE TABLE IF NOT EXISTS t2(x,y)} 0 + + +# EVIDENCE-OF: R-37014-01401 The ATTACH and DETACH statements also cause +# sqlite3_stmt_readonly() to return true since, while those statements +# change the configuration of a database connection, they do not make +# changes to the content of the database files on disk. +# +test_is_readonly capi3d-2.13 {ATTACH ':memory:' AS mem1} 1 +db eval {ATTACH ':memory:' AS mem1} +test_is_readonly capi3d-2.14 {DETACH mem1} 1 +db eval {DETACH mem1} + +# EVIDENCE-OF: R-07474-04783 Transaction control statements such as +# BEGIN, COMMIT, ROLLBACK, SAVEPOINT, and RELEASE cause +# sqlite3_stmt_readonly() to return true, since the statements +# themselves do not actually modify the database but rather they control +# the timing of when other statements modify the database. +# +test_is_readonly capi3d-2.15 {BEGIN} 1 +test_is_readonly capi3d-2.16 {COMMIT} 1 +test_is_readonly capi3d-2.17 {SAVEPOINT one} 1 +test_is_readonly capi3d-2.18 {RELEASE one} 1 + +# EVIDENCE-OF: R-36961-63052 The sqlite3_stmt_readonly() interface +# returns true for BEGIN since BEGIN merely sets internal flags, but the +# BEGIN IMMEDIATE and BEGIN EXCLUSIVE commands do touch the database and +# so sqlite3_stmt_readonly() returns false for those commands. +# +test_is_readonly capi3d-2.19 {BEGIN IMMEDIATE} 0 +test_is_readonly capi3d-2.20 {BEGIN EXCLUSIVE} 0 + +# EVIDENCE-OF: R-21769-42523 For example, if an application defines a +# function "eval()" that calls sqlite3_exec(), then the following SQL +# statement would change the database file through side-effects: SELECT +# eval('DELETE FROM t1') FROM t2; But because the SELECT statement does +# not change the database file directly, sqlite3_stmt_readonly() would +# still return true. +# +proc evalsql {sql} {db eval $sql} +db func eval evalsql +test_is_readonly capi3d-2.21 {SELECT eval('DELETE FROM t1') FROM t2} 1 + +# Tests for the is-explain interface. +# +proc test_is_explain {testname sql truth} { + do_test $testname [format { + set DB [sqlite3_connection_pointer db] + set STMT [sqlite3_prepare $DB {%s} -1 TAIL] + set rc [sqlite3_stmt_isexplain $STMT] + sqlite3_finalize $STMT + set rc + } $sql] $truth +} + +test_is_explain capi3d-2.51 {SELECT * FROM sqlite_master} 0 +test_is_explain capi3d-2.52 { explain SELECT * FROM sqlite_master} 1 +test_is_explain capi3d-2.53 { Explain Query Plan select * FROM sqlite_master} 2 +do_test capi3-2.99 { + sqlite3_stmt_isexplain 0 +} 0 + +# Tests for sqlite3_stmt_busy +# +do_test capi3d-3.1 { + db eval {INSERT INTO t1 VALUES(6); INSERT INTO t1 VALUES(7);} + set STMT [sqlite3_prepare db {SELECT * FROM t1} -1 TAIL] + sqlite3_stmt_busy $STMT +} {0} +do_test capi3d-3.2 { + sqlite3_step $STMT + sqlite3_stmt_busy $STMT +} {1} +do_test capi3d-3.3 { + sqlite3_step $STMT + sqlite3_stmt_busy $STMT +} {1} +do_test capi3d-3.4 { + sqlite3_reset $STMT + sqlite3_stmt_busy $STMT +} {0} + +do_test capi3d-3.99 { + sqlite3_finalize $STMT + sqlite3_stmt_busy 0 +} {0} + +#-------------------------------------------------------------------------- +# Test the sqlite3_stmt_busy() function with ROLLBACK statements. +# +reset_db + +do_execsql_test capi3d-4.1 { + CREATE TABLE t4(x,y); + BEGIN; +} + +do_test capi3d-4.2.1 { + set ::s1 [sqlite3_prepare_v2 db "ROLLBACK" -1 notused] + sqlite3_step $::s1 +} {SQLITE_DONE} + +do_test capi3d-4.2.2 { + sqlite3_stmt_busy $::s1 +} {0} + +do_catchsql_test capi3d-4.2.3 { + VACUUM +} {0 {}} + +do_test capi3d-4.2.4 { + sqlite3_reset $::s1 +} {SQLITE_OK} + +do_catchsql_test capi3d-4.2.5 { + VACUUM +} {0 {}} + +do_test capi3d-4.2.6 { + sqlite3_finalize $::s1 +} {SQLITE_OK} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3e.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3e.test new file mode 100644 index 0000000000000000000000000000000000000000..3e478e79040eff9d9df47dbd9a65d87a458cc914 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/capi3e.test @@ -0,0 +1,126 @@ +# 2010 Novemeber 18 +# +# 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. The +# focus of this script testing the callback-free C/C++ API. +# +# $Id: capi3e.test,v 1.70 2009/01/09 02:49:32 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Make sure the system encoding is utf-8. Otherwise, if the system encoding +# is other than utf-8, [file isfile $x] may not refer to the same file +# as [sqlite3 db $x]. +# +# This is no longer needed here because it should be done within the test +# fixture executable itself, via Tcl_SetSystemEncoding. +# +# encoding system utf-8 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +# Return the UTF-8 representation of the supplied UTF-16 string $str. +proc utf8 {str} { + # If $str ends in two 0x00 0x00 bytes, knock these off before + # converting to UTF-8 using TCL. + binary scan $str \c* vals + if {[lindex $vals end]==0 && [lindex $vals end-1]==0} { + set str [binary format \c* [lrange $vals 0 end-2]] + } + + set r [encoding convertfrom unicode $str] + return $r +} + +# These tests complement those in capi2.test. They are organized +# as follows: +# +# capi3e-1.*: Test sqlite3_open with various UTF8 filenames +# capi3e-2.*: Test sqlite3_open16 with various UTF8 filenames +# capi3e-3.*: Test ATTACH with various UTF8 filenames + +db close + +# here's the list of file names we're testing +set names {t 1 t. 1. t.d 1.d t-1 1-1 t.db ä.db ë.db ö.db ü.db ÿ.db} + +set i 0 +foreach name $names { + incr i + do_test capi3e-1.1.$i { + set db2 [sqlite3_open $name {}] + sqlite3_errcode $db2 + } {SQLITE_OK} + do_test capi3e-1.2.$i { + sqlite3_close $db2 + } {SQLITE_OK} + do_test capi3e-1.3.$i { + file isfile $name + } {1} +} + +ifcapable {utf16} { + set i 0 + foreach name $names { + incr i + do_test capi3e-2.1.$i { + set db2 [sqlite3_open16 [utf16 $name] {}] + sqlite3_errcode $db2 + } {SQLITE_OK} + do_test capi3e-2.2.$i { + sqlite3_close $db2 + } {SQLITE_OK} + do_test capi3e-2.3.$i { + file isfile $name + } {1} + } +} + +ifcapable attach { + do_test capi3e-3.1 { + sqlite3 db2 base.db + } {} + set i 0 + foreach name $names { + incr i + do_test capi3e-3.2.$i { + db2 eval "ATTACH DATABASE '$name' AS db$i;" + } {} + do_test capi3e-3.3.$i { + db2 eval "DETACH DATABASE db$i;" + } {} + } + do_test capi3e-3.4 { + db2 close + } {} +} + +# clean up +forcedelete base.db +foreach name $names { + forcedelete $name +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/carray01.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/carray01.test new file mode 100644 index 0000000000000000000000000000000000000000..1af9cb66e33457ab20cf523041c91b02d24065b2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/carray01.test @@ -0,0 +1,159 @@ +# 2020-11-17 +# +# 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 CARRAY extension +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix carray01 + +ifcapable !vtab { + finish_test + return +} +load_static_extension db carray + +# Parameter $stmt must be a prepared statement created using +# the sqlite3_prepare_v2 command and with parameters fully bound. +# This routine simply runs the statement, gathers the result, and +# returns a list containing the result. +# +# If the optional second argument is true, then the stmt is finalized +# after it is run. +# +proc run_stmt {stmt} { + set r {} + while {[sqlite3_step $stmt]=="SQLITE_ROW"} { + for {set i 0} {$i<[sqlite3_data_count $stmt]} {incr i} { + lappend r [sqlite3_column_text $stmt $i] + } + } + sqlite3_reset $stmt + return $r +} + +do_test 100 { + set STMT [sqlite3_prepare_v2 db {SELECT 5 IN carray(?3)} -1] + sqlite3_carray_bind $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 101 { + sqlite3_carray_bind -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 102 { + set STMT2 [sqlite3_prepare_v2 db { + SELECT DISTINCT typeof(value) FROM carray(?3)} -1] + sqlite3_carray_bind $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {integer} +do_test 110 { + sqlite3_carray_bind $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 120 { + sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 120b { + sqlite3_carray_bind -int64 $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {integer} +do_test 121 { + sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 122 { + sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 123 { + sqlite3_carray_bind -int32 -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 124 { + sqlite3_carray_bind -int32 -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 125 { + sqlite3_carray_bind -int32 $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 130 { + sqlite3_carray_bind -int64 $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 131 { + sqlite3_carray_bind -int64 -transient $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 131 { + sqlite3_carray_bind -int64 -static $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 140 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 141 { + sqlite3_carray_bind -double -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 142 { + sqlite3_carray_bind -double -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 143 { + sqlite3_carray_bind -double $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {real} +do_test 150 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 160 { + sqlite3_carray_bind -double $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {1} +do_test 170 { + sqlite3_carray_bind -text -static $STMT 3 1 2 3 4 6 7 + run_stmt $STMT +} {0} +do_test 171 { + sqlite3_carray_bind -text -static $STMT2 3 1 2 3 4 6 7 + run_stmt $STMT2 +} {text} +do_test 180 { + sqlite3_carray_bind -text -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 190 { + sqlite3_carray_bind -blob -static $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 191 { + sqlite3_carray_bind -blob -static $STMT2 3 1 2 3 4 5 6 7 + run_stmt $STMT2 +} {blob} +do_test 200 { + sqlite3_carray_bind -blob -transient $STMT 3 1 2 3 4 5 6 7 + run_stmt $STMT +} {0} +do_test 300 { + sqlite3_carray_bind $STMT 3 + run_stmt $STMT +} {0} + +sqlite3_finalize $STMT +sqlite3_finalize $STMT2 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cast.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cast.test new file mode 100644 index 0000000000000000000000000000000000000000..1c9071d775a6a7092edec65d7c2dda690094b3a2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cast.test @@ -0,0 +1,555 @@ +# 2005 June 25 +# +# 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. The +# focus of this file is testing the CAST operator. +# +# $Id: cast.test,v 1.10 2008/11/06 15:33:04 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Only run these tests if the build includes the CAST operator +ifcapable !cast { + finish_test + return +} + +# Tests for the CAST( AS blob), CAST( AS text) and CAST( AS numeric) built-ins +# +ifcapable bloblit { + do_test cast-1.1 { + execsql {SELECT x'616263'} + } abc + do_test cast-1.2 { + execsql {SELECT typeof(x'616263')} + } blob + do_test cast-1.3 { + execsql {SELECT CAST(x'616263' AS text)} + } abc + do_test cast-1.4 { + execsql {SELECT typeof(CAST(x'616263' AS text))} + } text + do_test cast-1.5 { + execsql {SELECT CAST(x'616263' AS numeric)} + } 0 + do_test cast-1.6 { + execsql {SELECT typeof(CAST(x'616263' AS numeric))} + } integer + do_test cast-1.7 { + execsql {SELECT CAST(x'616263' AS blob)} + } abc + do_test cast-1.8 { + execsql {SELECT typeof(CAST(x'616263' AS blob))} + } blob + do_test cast-1.9 { + execsql {SELECT CAST(x'616263' AS integer)} + } 0 + do_test cast-1.10 { + execsql {SELECT typeof(CAST(x'616263' AS integer))} + } integer +} +do_test cast-1.11 { + execsql {SELECT null} +} {{}} +do_test cast-1.12 { + execsql {SELECT typeof(NULL)} +} null +do_test cast-1.13 { + execsql {SELECT CAST(NULL AS text)} +} {{}} +do_test cast-1.14 { + execsql {SELECT typeof(CAST(NULL AS text))} +} null +do_test cast-1.15 { + execsql {SELECT CAST(NULL AS numeric)} +} {{}} +do_test cast-1.16 { + execsql {SELECT typeof(CAST(NULL AS numeric))} +} null +do_test cast-1.17 { + execsql {SELECT CAST(NULL AS blob)} +} {{}} +do_test cast-1.18 { + execsql {SELECT typeof(CAST(NULL AS blob))} +} null +do_test cast-1.19 { + execsql {SELECT CAST(NULL AS integer)} +} {{}} +do_test cast-1.20 { + execsql {SELECT typeof(CAST(NULL AS integer))} +} null +do_test cast-1.21 { + execsql {SELECT 123} +} {123} +do_test cast-1.22 { + execsql {SELECT typeof(123)} +} integer +do_test cast-1.23 { + execsql {SELECT CAST(123 AS text)} +} {123} +do_test cast-1.24 { + execsql {SELECT typeof(CAST(123 AS text))} +} text +do_test cast-1.25 { + execsql {SELECT CAST(123 AS numeric)} +} 123 +do_test cast-1.26 { + execsql {SELECT typeof(CAST(123 AS numeric))} +} integer +do_test cast-1.27 { + execsql {SELECT CAST(123 AS blob)} +} {123} +do_test cast-1.28 { + execsql {SELECT typeof(CAST(123 AS blob))} +} blob +do_test cast-1.29 { + execsql {SELECT CAST(123 AS integer)} +} {123} +do_test cast-1.30 { + execsql {SELECT typeof(CAST(123 AS integer))} +} integer +do_test cast-1.31 { + execsql {SELECT 123.456} +} {123.456} +do_test cast-1.32 { + execsql {SELECT typeof(123.456)} +} real +do_test cast-1.33 { + execsql {SELECT CAST(123.456 AS text)} +} {123.456} +do_test cast-1.34 { + execsql {SELECT typeof(CAST(123.456 AS text))} +} text +do_test cast-1.35 { + execsql {SELECT CAST(123.456 AS numeric)} +} 123.456 +do_test cast-1.36 { + execsql {SELECT typeof(CAST(123.456 AS numeric))} +} real +do_test cast-1.37 { + execsql {SELECT CAST(123.456 AS blob)} +} {123.456} +do_test cast-1.38 { + execsql {SELECT typeof(CAST(123.456 AS blob))} +} blob +do_test cast-1.39 { + execsql {SELECT CAST(123.456 AS integer)} +} {123} +do_test cast-1.38 { + execsql {SELECT typeof(CAST(123.456 AS integer))} +} integer +do_test cast-1.41 { + execsql {SELECT '123abc'} +} {123abc} +do_test cast-1.42 { + execsql {SELECT typeof('123abc')} +} text +do_test cast-1.43 { + execsql {SELECT CAST('123abc' AS text)} +} {123abc} +do_test cast-1.44 { + execsql {SELECT typeof(CAST('123abc' AS text))} +} text +do_test cast-1.45 { + execsql {SELECT CAST('123abc' AS numeric)} +} 123 +do_test cast-1.46 { + execsql {SELECT typeof(CAST('123abc' AS numeric))} +} integer +do_test cast-1.47 { + execsql {SELECT CAST('123abc' AS blob)} +} {123abc} +do_test cast-1.48 { + execsql {SELECT typeof(CAST('123abc' AS blob))} +} blob +do_test cast-1.49 { + execsql {SELECT CAST('123abc' AS integer)} +} 123 +do_test cast-1.50 { + execsql {SELECT typeof(CAST('123abc' AS integer))} +} integer +do_test cast-1.51 { + execsql {SELECT CAST('123.5abc' AS numeric)} +} 123.5 +do_test cast-1.53 { + execsql {SELECT CAST('123.5abc' AS integer)} +} 123 + +do_test cast-1.60 { + execsql {SELECT CAST(null AS REAL)} +} {{}} +do_test cast-1.61 { + execsql {SELECT typeof(CAST(null AS REAL))} +} {null} +do_test cast-1.62 { + execsql {SELECT CAST(1 AS REAL)} +} {1.0} +do_test cast-1.63 { + execsql {SELECT typeof(CAST(1 AS REAL))} +} {real} +do_test cast-1.64 { + execsql {SELECT CAST('1' AS REAL)} +} {1.0} +do_test cast-1.65 { + execsql {SELECT typeof(CAST('1' AS REAL))} +} {real} +do_test cast-1.66 { + execsql {SELECT CAST('abc' AS REAL)} +} {0.0} +do_test cast-1.67 { + execsql {SELECT typeof(CAST('abc' AS REAL))} +} {real} +do_test cast-1.68 { + execsql {SELECT CAST(x'31' AS REAL)} +} {1.0} +do_test cast-1.69 { + execsql {SELECT typeof(CAST(x'31' AS REAL))} +} {real} + + +# Ticket #1662. Ignore leading spaces in numbers when casting. +# +do_test cast-2.1 { + execsql {SELECT CAST(' 123' AS integer)} +} 123 +do_test cast-2.2 { + execsql {SELECT CAST(' -123.456' AS real)} +} -123.456 + +# ticket #2364. Use full percision integers if possible when casting +# to numeric. Do not fallback to real (and the corresponding 48-bit +# mantissa) unless absolutely necessary. +# +do_test cast-3.1 { + execsql {SELECT CAST(9223372036854774800 AS integer)} +} 9223372036854774800 +do_test cast-3.2 { + execsql {SELECT CAST(9223372036854774800 AS numeric)} +} 9223372036854774800 +breakpoint +do_realnum_test cast-3.3 { + execsql {SELECT CAST(9223372036854774800 AS real)} +} 9.22337203685477e+18 +do_test cast-3.4 { + execsql {SELECT CAST(CAST(9223372036854774800 AS real) AS integer)} +} 9223372036854774784 +do_test cast-3.5 { + execsql {SELECT CAST(-9223372036854774800 AS integer)} +} -9223372036854774800 +do_test cast-3.6 { + execsql {SELECT CAST(-9223372036854774800 AS numeric)} +} -9223372036854774800 +do_realnum_test cast-3.7 { + execsql {SELECT CAST(-9223372036854774800 AS real)} +} -9.22337203685477e+18 +do_test cast-3.8 { + execsql {SELECT CAST(CAST(-9223372036854774800 AS real) AS integer)} +} -9223372036854774784 +do_test cast-3.11 { + execsql {SELECT CAST('9223372036854774800' AS integer)} +} 9223372036854774800 +do_test cast-3.12 { + execsql {SELECT CAST('9223372036854774800' AS numeric)} +} 9223372036854774800 +do_realnum_test cast-3.13 { + execsql {SELECT CAST('9223372036854774800' AS real)} +} 9.22337203685477e+18 +do_test cast-3.14 { + execsql {SELECT CAST(CAST('9223372036854774800' AS real) AS integer)} +} 9223372036854774784 +do_test cast-3.15 { + execsql {SELECT CAST('-9223372036854774800' AS integer)} +} -9223372036854774800 +do_test cast-3.16 { + execsql {SELECT CAST('-9223372036854774800' AS numeric)} +} -9223372036854774800 +do_realnum_test cast-3.17 { + execsql {SELECT CAST('-9223372036854774800' AS real)} +} -9.22337203685477e+18 +do_test cast-3.18 { + execsql {SELECT CAST(CAST('-9223372036854774800' AS real) AS integer)} +} -9223372036854774784 +if {[db eval {PRAGMA encoding}]=="UTF-8"} { + do_test cast-3.21 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS integer)} + } 9223372036854774800 + do_test cast-3.22 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS numeric)} + } 9223372036854774800 + do_realnum_test cast-3.23 { + execsql {SELECT CAST(x'39323233333732303336383534373734383030' AS real)} + } 9.22337203685477e+18 + do_test cast-3.24 { + execsql { + SELECT CAST(CAST(x'39323233333732303336383534373734383030' AS real) + AS integer) + } + } 9223372036854774784 +} +do_test cast-3.31 { + execsql {SELECT CAST(NULL AS numeric)} +} {{}} + +# Test to see if it is possible to trick SQLite into reading past +# the end of a blob when converting it to a number. +do_test cast-3.32.1 { + set blob "1234567890" + set DB [sqlite3_connection_pointer db] + set ::STMT [sqlite3_prepare $DB {SELECT CAST(? AS real)} -1 TAIL] + sqlite3_bind_blob -static $::STMT 1 $blob 5 + sqlite3_step $::STMT +} {SQLITE_ROW} +do_test cast-3.32.2 { + sqlite3_column_int $::STMT 0 +} {12345} +do_test cast-3.32.3 { + sqlite3_finalize $::STMT +} {SQLITE_OK} + + +do_test cast-4.1 { + db eval { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES('abc'); + SELECT a, CAST(a AS integer) FROM t1; + } +} {abc 0} +do_test cast-4.2 { + db eval { + SELECT CAST(a AS integer), a FROM t1; + } +} {0 abc} +do_test cast-4.3 { + db eval { + SELECT a, CAST(a AS integer), a FROM t1; + } +} {abc 0 abc} +do_test cast-4.4 { + db eval { + SELECT CAST(a AS integer), a, CAST(a AS real), a FROM t1; + } +} {0 abc 0.0 abc} + +# Added 2018-01-26 +# +# EVIDENCE-OF: R-48741-32454 If the prefix integer is greater than +# +9223372036854775807 then the result of the cast is exactly +# +9223372036854775807. +do_execsql_test cast-5.1 { + SELECT CAST('9223372036854775808' AS integer); + SELECT CAST(' +000009223372036854775808' AS integer); + SELECT CAST('12345678901234567890123' AS INTEGER); +} {9223372036854775807 9223372036854775807 9223372036854775807} + +# EVIDENCE-OF: R-06028-16857 Similarly, if the prefix integer is less +# than -9223372036854775808 then the result of the cast is exactly +# -9223372036854775808. +do_execsql_test cast-5.2 { + SELECT CAST('-9223372036854775808' AS integer); + SELECT CAST('-9223372036854775809' AS integer); + SELECT CAST('-12345678901234567890123' AS INTEGER); +} {-9223372036854775808 -9223372036854775808 -9223372036854775808} + +# EVIDENCE-OF: R-33990-33527 When casting to INTEGER, if the text looks +# like a floating point value with an exponent, the exponent will be +# ignored because it is no part of the integer prefix. +# EVIDENCE-OF: R-24225-46995 For example, "(CAST '123e+5' AS INTEGER)" +# results in 123, not in 12300000. +do_execsql_test cast-5.3 { + SELECT CAST('123e+5' AS INTEGER); + SELECT CAST('123e+5' AS NUMERIC); + SELECT CAST('123e+5' AS REAL); +} {123 12300000 12300000.0} + + +# The following does not have anything to do with the CAST operator, +# but it does deal with affinity transformations. +# +do_execsql_test cast-6.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a NUMERIC); + INSERT INTO t1 VALUES + ('9000000000000000001'), + ('9000000000000000001 '), + (' 9000000000000000001'), + (' 9000000000000000001 '); + SELECT * FROM t1; +} {9000000000000000001 9000000000000000001 9000000000000000001 9000000000000000001} + +# 2019-06-07 +# https://www.sqlite.org/src/info/4c2d7639f076aa7c +do_execsql_test cast-7.1 { + SELECT CAST('-' AS NUMERIC); +} {0} +do_execsql_test cast-7.2 { + SELECT CAST('-0' AS NUMERIC); +} {0} +do_execsql_test cast-7.3 { + SELECT CAST('+' AS NUMERIC); +} {0} +do_execsql_test cast-7.4 { + SELECT CAST('/' AS NUMERIC); +} {0} + +# 2019-06-07 +# https://www.sqlite.org/src/info/e8bedb2a184001bb +do_execsql_test cast-7.10 { + SELECT '' - 2851427734582196970; +} {-2851427734582196970} +do_execsql_test cast-7.11 { + SELECT 0 - 2851427734582196970; +} {-2851427734582196970} +do_execsql_test cast-7.12 { + SELECT '' - 1; +} {-1} + +# 2019-06-10 +# https://www.sqlite.org/src/info/dd6bffbfb6e61db9 +# +# EVIDENCE-OF: R-55084-10555 Casting a TEXT or BLOB value into NUMERIC +# yields either an INTEGER or a REAL result. +# +do_execsql_test cast-7.20 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0 (c0 TEXT); + INSERT INTO t0(c0) VALUES ('1.0'); + SELECT CAST(c0 AS NUMERIC) FROM t0; +} {1} + +# 2019-06-10 +# https://sqlite.org/src/info/27de823723a41df45af3 +# +do_execsql_test cast-7.30 { + SELECT -'.'; +} 0 +do_execsql_test cast-7.31 { + SELECT '.'+0; +} 0 +do_execsql_test cast-7.32 { + SELECT CAST('.' AS numeric); +} 0 +do_execsql_test cast-7.33 { + SELECT -CAST('.' AS numeric); +} 0 + +# 2019-06-12 +# https://www.sqlite.org/src/info/674385aeba91c774 +# +do_execsql_test cast-7.40 { + SELECT CAST('-0.0' AS numeric); +} 0 +do_execsql_test cast-7.41 { + SELECT CAST('0.0' AS numeric); +} 0 +do_execsql_test cast-7.42 { + SELECT CAST('+0.0' AS numeric); +} 0 +do_execsql_test cast-7.43 { + SELECT CAST('-1.0' AS numeric); +} -1 + +ifcapable utf16 { + reset_db + execsql { PRAGMA encoding='utf16' } + + do_execsql_test cast-8.1 { + SELECT quote(X'310032003300')==quote(substr(X'310032003300', 1)) + } 1 + do_execsql_test cast-8.2 { + SELECT CAST(X'310032003300' AS TEXT) + ==CAST(substr(X'310032003300', 1) AS TEXT) + } 1 +} + +reset_db +do_execsql_test cast-9.0 { + CREATE TABLE t0(c0); + INSERT INTO t0(c0) VALUES (0); + CREATE VIEW v1(c0, c1) AS + SELECT CAST(0.0 AS NUMERIC), COUNT(*) OVER () FROM t0; + SELECT v1.c0 FROM v1, t0 WHERE v1.c0=0; +} {0.0} + +# Set the 2022-12-10 "reopen" of ticket [https://sqlite.org/src/tktview/57c47526c3] +# +do_execsql_test cast-9.1 { + CREATE TABLE dual(dummy TEXT); + INSERT INTO dual VALUES('X'); + SELECT CAST(4 AS NUMERIC); +} {4} +do_execsql_test cast-9.2 { + SELECT CAST(4.0 AS NUMERIC); +} {4.0} +do_execsql_test cast-9.3 { + SELECT CAST(4.5 AS NUMERIC); +} {4.5} +do_execsql_test cast-9.4 { + SELECT x, typeof(x) FROM (SELECT CAST(4 AS NUMERIC) AS x) JOIN dual; +} {4 integer} +do_execsql_test cast-9.5 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4 AS NUMERIC) AS x); +} {4 integer} +do_execsql_test cast-9.10 { + SELECT x, typeof(x) FROM (SELECT CAST(4.0 AS NUMERIC) AS x) JOIN dual; +} {4.0 real} +do_execsql_test cast-9.11 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4.0 AS NUMERIC) AS x); +} {4.0 real} +do_execsql_test cast-9.12 { + SELECT x, typeof(x) FROM (SELECT CAST(4.5 AS NUMERIC) AS x) JOIN dual; +} {4.5 real} +do_execsql_test cast-9.13 { + SELECT x, typeof(x) FROM dual CROSS JOIN (SELECT CAST(4.5 AS NUMERIC) AS x); +} {4.5 real} + +# 2022-12-15 dbsqlfuzz c9ee6f9a0a8b8fefb02cf69de2a8b67ca39525c8 +# +# Added a new SQLITE_AFF_FLEXNUM that does not try to convert int to real or +# real to int. +# +do_execsql_test cast-10.1 { + VALUES(CAST(44 AS REAL)),(55); +} {44.0 55} +do_execsql_test cast-10.2 { + SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55; +} {44.0 55} +do_execsql_test cast-10.3 { + SELECT * FROM (VALUES(CAST(44 AS REAL)),(55)); +} {44.0 55} +do_execsql_test cast-10.4 { + SELECT * FROM (SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55); +} {44.0 55} +do_execsql_test cast-10.5 { + SELECT * FROM dual CROSS JOIN (VALUES(CAST(44 AS REAL)),(55)); +} {X 44.0 X 55} +do_execsql_test cast-10.6 { + SELECT * FROM dual CROSS JOIN (SELECT CAST(44 AS REAL) AS 'm' + UNION ALL SELECT 55); +} {X 44.0 X 55} +ifcapable vtab { + do_execsql_test cast-10.7 { + DROP VIEW v1; + CREATE VIEW v1 AS SELECT CAST(44 AS REAL) AS 'm' UNION ALL SELECT 55; + SELECT name, type FROM pragma_table_info('v1'); + } {m NUM} + do_execsql_test cast-10.8 { + CREATE VIEW v2 AS VALUES(CAST(44 AS REAL)),(55); + SELECT type FROM pragma_table_info('v2'); + } {NUM} + do_execsql_test cast-10.9 { + SELECT * FROM v1; + } {44.0 55} + do_execsql_test cast-10.10 { + SELECT * FROM v2; + } {44.0 55} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cffault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cffault.test new file mode 100644 index 0000000000000000000000000000000000000000..0d029ece37d8f70e116e27bb2808bf719223f707 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cffault.test @@ -0,0 +1,158 @@ +# 2011 November 16 +# +# 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 fault-injection test cases for the +# sqlite3_db_cacheflush API. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cffault +source $testdir/malloc_common.tcl + +# Run the supplied SQL on a copy of the database currently stored on +# disk in file $dbfile. +proc diskquery {dbfile sql} { + forcecopy $dbfile dq.db + sqlite3 dq dq.db + set res [execsql $sql dq] + dq close + set res +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE INDEX i1 ON t1(b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + INSERT INTO t1 VALUES(7, 8); +} +faultsim_save_and_close + +do_faultsim_test 1.1 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 1.2 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + set result [list] + db eval { SELECT * FROM t1 } { + if {$a==5} { catch { sqlite3_db_cacheflush db } } + lappend result $a $b + } + set result +} -test { + faultsim_test_result {0 {1 3 3 5 5 7 7 9}} {1 {disk I/O error}} + catch { db eval COMMIT } + faultsim_integrity_check +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE TABLE t1(a PRIMARY KEY, b, c); + CREATE INDEX i1 ON t1(b); + CREATE INDEX i2 ON t1(c, b); + INSERT INTO t1 VALUES(1, 2, randomblob(600)); + INSERT INTO t1 VALUES(3, 4, randomblob(600)); + INSERT INTO t1 VALUES(5, 6, randomblob(600)); + INSERT INTO t1 VALUES(7, 8, randomblob(600)); + INSERT INTO t1 VALUES(9, 10, randomblob(600)); +} +faultsim_save_and_close + +do_faultsim_test 2.1 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + set result [list] + db eval { SELECT * FROM t1 } { + if {$a==5} { catch { sqlite3_db_cacheflush db } } + lappend result $a $b + } + set result +} -test { + faultsim_test_result {0 {1 3 3 5 5 7 7 9 9 11}} {1 {disk I/O error}} + catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.2 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b+1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval { SELECT * FROM t1 } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.3 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b-1; + } +} -body { + sqlite3_db_cacheflush db +} -test { + if {[sqlite3_get_autocommit db]} { error "Transaction rolled back!" } + faultsim_test_result {0 {}} {1 {disk I/O error}} + catch { db eval { INSERT INTO t1 VALUES(11, 12, randomblob(600)) } } + catch { db eval COMMIT } + faultsim_integrity_check +} + +do_faultsim_test 2.4 -prep { + faultsim_restore_and_reopen + db eval { + BEGIN; + UPDATE t1 SET b=b-1; + } +} -body { + catch { sqlite3_db_cacheflush db } + catch { sqlite3_db_release_memory db } + catch { sqlite3_db_cacheflush db } + execsql { SELECT a, b FROM t1 } +} -test { + faultsim_test_result {0 {1 1 3 3 5 5 7 7 9 9}} {1 {disk I/O error}} + catchsql ROLLBACK + faultsim_integrity_check +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/changes.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/changes.test new file mode 100644 index 0000000000000000000000000000000000000000..b3a2ae1eefcf0fb881d971fa527d36c2c4b3bd25 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/changes.test @@ -0,0 +1,88 @@ +# 2021 June 22 +# +# 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 sqlite3_changes() and sqlite3_total_changes() APIs. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix changes + +# To test that the change-counters do not suffer from 32-bit signed integer +# rollover, add the following line to the array of test cases below. The +# test will take will over an hour to run. +# +# 7 (1<<31)+10 "" +# + +foreach {tn nRow wor} { + 1 50 "" + 2 50 "WITHOUT ROWID" + + 3 5000 "" + 4 5000 "WITHOUT ROWID" + + 5 50000 "" + 6 50000 "WITHOUT ROWID" +} { + reset_db + set nBig [expr $nRow] + + do_execsql_test 1.$tn.0 " + PRAGMA journal_mode = off; + CREATE TABLE t1(x INTEGER PRIMARY KEY) $wor; + " {off} + + do_execsql_test 1.$tn.1 { + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i < $nBig + ) + INSERT INTO t1 SELECT i FROM s; + } + + do_test 1.$tn.2 { + db changes + } [expr $nBig] + + do_test 1.$tn.3 { + db total_changes + } [expr $nBig] + + do_execsql_test 1.$tn.4 { + INSERT INTO t1 VALUES(-1) + } + + do_test 1.$tn.5 { + db changes + } [expr 1] + + do_test 1.$tn.6 { + db total_changes + } [expr {$nBig+1}] + + do_execsql_test 1.$tn.7a { + SELECT count(*) FROM t1 + } [expr {$nBig+1}] + + do_execsql_test 1.$tn.7 { + DELETE FROM t1 + } + + do_test 1.$tn.8 { + db changes + } [expr {$nBig+1}] + + do_test 1.$tn.9 { + db total_changes + } [expr {2*($nBig+1)}] +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/check.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/check.test new file mode 100644 index 0000000000000000000000000000000000000000..10d1cf4be67bf84bfb707ae10686801f096e7f1c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/check.test @@ -0,0 +1,615 @@ +# 2005 November 2 +# +# 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. The +# focus of this file is testing CHECK constraints +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix check + +# Only run these tests if the build includes support for CHECK constraints +ifcapable !check { + finish_test + return +} +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 + +do_test check-1.1 { + execsql { + CREATE TABLE t1( + x INTEGER CHECK( x<5 ), + y REAL CHECK( y>x ) + ); + } +} {} +do_test check-1.2 { + execsql { + INSERT INTO t1 VALUES(3,4); + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.3 { + catchsql { + INSERT INTO t1 VALUES(6,7); + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.4 { + execsql { + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.5 { + catchsql { + INSERT INTO t1 VALUES(4,3); + } +} {1 {CHECK constraint failed: y>x}} +do_test check-1.6 { + execsql { + SELECT * FROM t1; + } +} {3 4.0} +do_test check-1.7 { + catchsql { + INSERT INTO t1 VALUES(NULL,6); + } +} {0 {}} +do_test check-1.8 { + execsql { + SELECT * FROM t1; + } +} {3 4.0 {} 6.0} +do_test check-1.9 { + catchsql { + INSERT INTO t1 VALUES(2,NULL); + } +} {0 {}} +do_test check-1.10 { + execsql { + SELECT * FROM t1; + } +} {3 4.0 {} 6.0 2 {}} +do_test check-1.11 { + execsql { + DELETE FROM t1 WHERE x IS NULL OR x!=3; + UPDATE t1 SET x=2 WHERE x==3; + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.12 { + catchsql { + UPDATE t1 SET x=7 WHERE x==2 + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.13 { + execsql { + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.14 { + catchsql { + UPDATE t1 SET x=5 WHERE x==2 + } +} {1 {CHECK constraint failed: x<5}} +do_test check-1.15 { + execsql { + SELECT * FROM t1; + } +} {2 4.0} +do_test check-1.16 { + catchsql { + UPDATE t1 SET x=4, y=11 WHERE x==2 + } +} {0 {}} +do_test check-1.17 { + execsql { + SELECT * FROM t1; + } +} {4 11.0} + +do_test check-2.1 { + execsql { + PRAGMA writable_schema = 1; + CREATE TABLE t2( + x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ), + y REAL CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ), + z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' ) + ); + CREATE TABLE t2n( + x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ), + y NUMERIC CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ), + z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' ) + ); + PRAGMA writable_schema = 0; + } +} {} +do_test check-2.2 { + execsql { + INSERT INTO t2 VALUES(1,2.2,'three'); + SELECT * FROM t2; + } +} {1 2.2 three} +db close +sqlite3 db test.db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test check-2.3 { + execsql { + INSERT INTO t2 VALUES(NULL, NULL, NULL); + SELECT * FROM t2; + } +} {1 2.2 three {} {} {}} +do_test check-2.4 { + catchsql { + INSERT INTO t2 VALUES(1.1, NULL, NULL); + } +} {1 {CHECK constraint failed: one}} +do_test check-2.5 { + # The 5 gets automatically promoted to 5.0 because the column type is REAL + catchsql { + INSERT INTO t2 VALUES(NULL, 5, NULL); + } +} {0 {}} +do_test check-2.5b { + # This time the column type is NUMERIC, so not automatic promption to REAL + # occurs and the constraint fails. + catchsql { + INSERT INTO t2n VALUES(NULL, 5, NULL); + } +} {1 {CHECK constraint failed: two}} +do_test check-2.6 { + catchsql { + INSERT INTO t2 VALUES(NULL, NULL, 3.14159); + } +} {0 {}} + +# Undocumented behavior: The CONSTRAINT name clause can follow a constraint. +# Such a clause is ignored. But the parser must accept it for backwards +# compatibility. +# +do_test check-2.10 { + execsql { + CREATE TABLE t2b( + x INTEGER CHECK( typeof(coalesce(x,0))=='integer' ) CONSTRAINT one, + y TEXT PRIMARY KEY constraint two, + z INTEGER, + UNIQUE(x,z) constraint three + ); + } +} {} +do_test check-2.11 { + catchsql { + INSERT INTO t2b VALUES('xyzzy','hi',5); + } +} {1 {CHECK constraint failed: typeof(coalesce(x,0))=='integer'}} +do_test check-2.12 { + execsql { + CREATE TABLE t2c( + x INTEGER CONSTRAINT x_one CONSTRAINT x_two + CHECK( typeof(coalesce(x,0))=='integer' ) + CONSTRAINT x_two CONSTRAINT x_three, + y INTEGER, z INTEGER, + CONSTRAINT u_one UNIQUE(x,y,z) CONSTRAINT u_two + ); + } +} {} +do_test check-2.13 { + catchsql { + INSERT INTO t2c VALUES('xyzzy',7,8); + } +} {1 {CHECK constraint failed: x_two}} +do_test check-2.cleanup { + execsql { + DROP TABLE IF EXISTS t2b; + DROP TABLE IF EXISTS t2c; + DROP TABLE IF EXISTS t2n; + } +} {} + +ifcapable subquery { + do_test check-3.1 { + catchsql { + CREATE TABLE t3( + x, y, z, + CHECK( x<(SELECT min(x) FROM t1) ) + ); + } + } {1 {subqueries prohibited in CHECK constraints}} +} + +do_test check-3.2 { + execsql { + SELECT name FROM sqlite_master ORDER BY name + } +} {t1 t2} +do_test check-3.3 { + catchsql { + CREATE TABLE t3( + x, y, z, + CHECK( q0 )); + CREATE TABLE t811(b, CHECK( xyzzy.t811.b BETWEEN 5 AND 10 )); +} {} + +# Make sure check constraints involving the ROWID are not ignored +# +do_execsql_test 9.1 { + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b INTEGER NOT NULL CONSTRAINT 'b-check' CHECK( b>a ), + c INTEGER NOT NULL CONSTRAINT 'c-check' CHECK( c>rowid*2 ), + d INTEGER NOT NULL CONSTRAINT 'd-check' CHECK( d BETWEEN b AND c ) + ); + INSERT INTO t1(a,b,c,d) VALUES(1,2,4,3),(2,4,6,5),(3,10,30,20); +} {} +do_catchsql_test 9.2 { + UPDATE t1 SET b=0 WHERE a=1; +} {1 {CHECK constraint failed: b-check}} +do_catchsql_test 9.3 { + UPDATE t1 SET c=a*2 WHERE a=1; +} {1 {CHECK constraint failed: c-check}} + +# Integrity check on a VIEW with columns. +# +db close +db2 close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 10.1 { + CREATE TABLE t1(x); + CREATE VIEW v1(y) AS SELECT x FROM t1; + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.0 { + CREATE TABLE t1 (Col0 CHECK(1 COLLATE BINARY BETWEEN 1 AND 1) ) ; +} +do_execsql_test 11.1 { + INSERT INTO t1 VALUES (NULL); +} +do_execsql_test 11.2 { + INSERT INTO t1 VALUES (NULL); +} + +do_execsql_test 11.3 { + CREATE TABLE t2(b, a CHECK( + CASE 'abc' COLLATE nocase WHEN a THEN 1 ELSE 0 END) + ); +} +do_execsql_test 11.4 { + INSERT INTO t2(a) VALUES('abc'); +} +do_execsql_test 11.5 { + INSERT INTO t2(b, a) VALUES(1, 'abc'||''); +} +do_execsql_test 11.6 { + INSERT INTO t2(b, a) VALUES(2, 'abc'); +} + +# 2019-12-24 ticket b383b90278186263 +# +reset_db +do_execsql_test 12.10 { + CREATE TABLE t1(a TEXT, CHECK(a=+a)); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.20 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a<>+a)); + INSERT INTO t1(a) VALUES(NULL); +} {} +do_catchsql_test 12.21 { + INSERT INTO t1(a) VALUES('xyz'); +} {1 {CHECK constraint failed: a<>+a}} +do_catchsql_test 12.22 { + INSERT INTO t1(a) VALUES(123); +} {1 {CHECK constraint failed: a<>+a}} +do_execsql_test 12.30 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(NOT(a=+a))); + INSERT INTO t1(a) VALUES(NULL); +} {} +do_catchsql_test 12.31 { + INSERT INTO t1(a) VALUES('xyz'); +} {1 {CHECK constraint failed: NOT(a=+a)}} +do_catchsql_test 12.32 { + INSERT INTO t1(a) VALUES(123); +} {1 {CHECK constraint failed: NOT(a=+a)}} +do_execsql_test 12.40 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(NOT(a<>+a))); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.50 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a BETWEEN 0 AND +a)); + INSERT INTO t1(a) VALUES(NULL),('xyz'),(5),(x'303132'),(4.75); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL 'xyz' '5' X'303132' '4.75'} +do_execsql_test 12.60 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a NOT BETWEEN 0 AND +a)); + INSERT INTO t1(a) VALUES(NULL); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL} +do_catchsql_test 12.61 { + INSERT INTO t1(a) VALUES(456); +} {1 {CHECK constraint failed: a NOT BETWEEN 0 AND +a}} +do_execsql_test 12.70 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a BETWEEN +a AND 999999)); + INSERT INTO t1(a) VALUES(NULL),(5); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL '5'} +do_execsql_test 12.80 { + DROP TABLE t1; + CREATE TABLE t1(a TEXT, CHECK(a NOT BETWEEN +a AND 999999)); + INSERT INTO t1(a) VALUES(NULL); + SELECT quote(a) FROM t1 ORDER BY rowid; +} {NULL} +do_catchsql_test 12.81 { + INSERT INTO t1(a) VALUES(456); +} {1 {CHECK constraint failed: a NOT BETWEEN +a AND 999999}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/chunksize.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/chunksize.test new file mode 100644 index 0000000000000000000000000000000000000000..47d118d841db286103a5e4fa5a35186161dac9a3 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/chunksize.test @@ -0,0 +1,41 @@ +# 2019 June 5 +# +# 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 chunksize + +if {$::tcl_platform(platform)!="unix"} { + finish_test + return +} + +foreach {tn jrnlmode} { + 1 delete + 2 wal +} { + reset_db + file_control_chunksize_test db main 32768 + do_execsql_test $tn.0 " PRAGMA journal_mode = $jrnlmode " $jrnlmode + do_execsql_test $tn.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + + execsql { PRAGMA wal_checkpoint } + + do_test $tn.2 { + file size test.db + } 32768 +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cksumvfs.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cksumvfs.test new file mode 100644 index 0000000000000000000000000000000000000000..8c7bcf5511ac399ed616a6856dd75a9e4795efa0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/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/local-test-sqlite3-delta-01/afc-sqlite3/test/close.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/close.test new file mode 100644 index 0000000000000000000000000000000000000000..107c7a782e7b82566557bb40648d47334167a5ee --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/close.test @@ -0,0 +1,89 @@ +# 2013 May 14 +# +# 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. +# +#*********************************************************************** +# +# Test some specific circumstances to do with shared cache mode. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix close + +# This module bypasses the "-key" logic in tester.tcl, so it cannot run +# with the codec enabled. +do_not_use_codec + +do_execsql_test 1.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('two'); + INSERT INTO t1 VALUES('three'); +} +db close + +do_test 1.1 { + set DB [sqlite3_open test.db] + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.2.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_close_v2 $DB +} {SQLITE_OK} +do_test 1.2.2 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.3.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_step $STMT + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.3.2 { + sqlite3_column_text $STMT 0 +} {one} + +do_test 1.3.3 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.4.1 { + set DB [sqlite3_open test.db] + set STMT [sqlite3_prepare $DB "SELECT * FROM t1" -1 dummy] + sqlite3_step $STMT + sqlite3_close_v2 $DB +} {SQLITE_OK} + +do_test 1.4.2 { + list [sqlite3_step $STMT] [sqlite3_column_text $STMT 0] +} {SQLITE_ROW two} + +do_test 1.4.3 { + list [catch { + sqlite3_prepare $DB "SELECT * FROM sqlite_master" -1 dummy + } msg] $msg +} {1 {(21) bad parameter or other API misuse}} + +do_test 1.4.4 { + sqlite3_finalize $STMT +} {SQLITE_OK} + +do_test 1.5 { + set DB [sqlite3_open test.db] + sqlite3_blob_open $DB main t1 x 2 0 BLOB + sqlite3_close_v2 $DB + sqlite3_blob_close $BLOB +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/closure01.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/closure01.test new file mode 100644 index 0000000000000000000000000000000000000000..ee3f2dd1d02b3a33642456c143897030847ae05c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/closure01.test @@ -0,0 +1,295 @@ +# 2013-04-25 +# +# 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. +# +#*********************************************************************** +# +# Test cases for transitive_closure virtual table. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix closure01 + +ifcapable !vtab||!cte { finish_test ; return } + +load_static_extension db closure + +do_execsql_test 1.0 { + BEGIN; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y INTEGER); + WITH RECURSIVE + cnt(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM cnt LIMIT 131072) + INSERT INTO t1(x, y) SELECT i, nullif(i,1)/2 FROM cnt; + CREATE INDEX t1y ON t1(y); + COMMIT; + CREATE VIRTUAL TABLE cx + USING transitive_closure(tablename=t1, idcolumn=x, parentcolumn=y); +} {} + +# The entire table +do_timed_execsql_test 1.1 { + SELECT count(*), depth FROM cx WHERE root=1 GROUP BY depth ORDER BY 1; +} {/1 0 1 17 2 1 4 2 8 3 16 4 .* 65536 16/} +do_timed_execsql_test 1.1-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + ) + SELECT count(*), depth FROM below GROUP BY depth ORDER BY 1; +} {/1 0 1 17 2 1 4 2 8 3 16 4 .* 65536 16/} + +# descendents of 32768 +do_timed_execsql_test 1.2 { + SELECT * FROM cx WHERE root=32768 ORDER BY id; +} {32768 0 65536 1 65537 1 131072 2} +do_timed_execsql_test 1.2-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(32768,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + WHERE below.depth<2 + ) + SELECT id, depth FROM below ORDER BY id; +} {32768 0 65536 1 65537 1 131072 2} + +# descendents of 16384 +do_timed_execsql_test 1.3 { + SELECT * FROM cx WHERE root=16384 AND depth<=2 ORDER BY id; +} {16384 0 32768 1 32769 1 65536 2 65537 2 65538 2 65539 2} +do_timed_execsql_test 1.3-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(16384,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below on t1.y=below.id + WHERE below.depth<2 + ) + SELECT id, depth FROM below ORDER BY id; +} {16384 0 32768 1 32769 1 65536 2 65537 2 65538 2 65539 2} + +# children of 16384 +do_execsql_test 1.4 { + SELECT id, depth, root, tablename, idcolumn, parentcolumn FROM cx + WHERE root=16384 + AND depth=1 + ORDER BY id; +} {32768 1 {} t1 x y 32769 1 {} t1 x y} + +# great-grandparent of 16384 +do_timed_execsql_test 1.5 { + SELECT id, depth, root, tablename, idcolumn, parentcolumn FROM cx + WHERE root=16384 + AND depth=3 + AND idcolumn='Y' + AND parentcolumn='X'; +} {2048 3 {} t1 Y X} +do_timed_execsql_test 1.5-cte { + WITH RECURSIVE + above(id,depth) AS ( + VALUES(16384,0) + UNION ALL + SELECT t1.y, above.depth+1 + FROM t1 JOIN above ON t1.x=above.id + WHERE above.depth<3 + ) + SELECT id FROM above WHERE depth=3; +} {2048} + +# depth<5 +do_timed_execsql_test 1.6 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth<5 + GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4} +do_timed_execsql_test 1.6-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below ON t1.y=below.id + WHERE below.depth<4 + ) + SELECT count(*), depth FROM below GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4} + +# depth<=5 +do_execsql_test 1.7 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth<=5 + GROUP BY depth ORDER BY 1; +} {1 0 2 1 4 2 8 3 16 4 32 5} + +# depth==5 +do_execsql_test 1.8 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth=5 + GROUP BY depth ORDER BY 1; +} {32 5} + +# depth BETWEEN 3 AND 5 +do_execsql_test 1.9 { + SELECT count(*), depth FROM cx WHERE root=1 AND depth BETWEEN 3 AND 5 + GROUP BY depth ORDER BY 1; +} {8 3 16 4 32 5} + +# depth==5 with min() and max() +do_timed_execsql_test 1.10 { + SELECT count(*), min(id), max(id) FROM cx WHERE root=1 AND depth=5; +} {32 32 63} +do_timed_execsql_test 1.10-cte { + WITH RECURSIVE + below(id,depth) AS ( + VALUES(1,0) + UNION ALL + SELECT t1.x, below.depth+1 + FROM t1 JOIN below ON t1.y=below.id + WHERE below.depth<5 + ) + SELECT count(*), min(id), max(id) FROM below WHERE depth=5; +} {32 32 63} + +# Create a much smaller table t2 with only 32 elements +db eval { + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + INSERT INTO t2 SELECT x, y FROM t1 WHERE x<32; + CREATE INDEX t2y ON t2(y); + CREATE VIRTUAL TABLE c2 + USING transitive_closure(tablename=t2, idcolumn=x, parentcolumn=y); +} + +# t2 full-table +do_execsql_test 2.1 { + SELECT count(*), min(id), max(id) FROM c2 WHERE root=1; +} {31 1 31} +# t2 root=10 +do_execsql_test 2.2 { + SELECT id FROM c2 WHERE root=10; +} {10 20 21} +# t2 root=11 +do_execsql_test 2.3 { + SELECT id FROM c2 WHERE root=12; +} {12 24 25} +# t2 root IN [10,12] +do_execsql_test 2.4 { + SELECT id FROM c2 WHERE root IN (10,12) ORDER BY id; +} {10 12 20 21 24 25} +# t2 root IN [10,12] (sorted) +do_execsql_test 2.5 { + SELECT id FROM c2 WHERE root IN (10,12) ORDER BY +id; +} {10 12 20 21 24 25} + +# t2 c2up from 20 +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE c2up USING transitive_closure( + tablename = t2, + idcolumn = y, + parentcolumn = x + ); + SELECT id FROM c2up WHERE root=20; +} {1 2 5 10 20} + +# cx as c2up +do_execsql_test 3.1 { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='y' + AND parentcolumn='x'; +} {1 2 5 10 20} + +# t2 first cousins of 20 +do_execsql_test 3.2 { + SELECT DISTINCT id FROM c2 + WHERE root IN (SELECT id FROM c2up + WHERE root=20 AND depth<=2) + ORDER BY id; +} {5 10 11 20 21 22 23} + +# t2 first cousins of 20 +do_execsql_test 3.3 { + SELECT id FROM c2 + WHERE root=(SELECT id FROM c2up + WHERE root=20 AND depth=2) + AND depth=2 + EXCEPT + SELECT id FROM c2 + WHERE root=(SELECT id FROM c2up + WHERE root=20 AND depth=1) + AND depth<=1 + ORDER BY id; +} {22 23} + +# missing tablename. +do_test 4.1 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t3' + AND idcolumn='y' + AND parentcolumn='x'; + } +} {1 {no such table: t3}} + +# missing idcolumn +do_test 4.2 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='xyz' + AND parentcolumn='x'; + } +} {1 {no such column: t2.xyz}} + +# missing parentcolumn +do_test 4.3 { + catchsql { + SELECT id FROM cx + WHERE root=20 + AND tablename='t2' + AND idcolumn='x' + AND parentcolumn='pqr'; + } +} {1 {no such column: t2.pqr}} + +# generic closure +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE temp.closure USING transitive_closure; + SELECT id FROM closure + WHERE root=1 + AND depth=3 + AND tablename='t1' + AND idcolumn='x' + AND parentcolumn='y' + ORDER BY id; +} {8 9 10 11 12 13 14 15} + +#------------------------------------------------------------------------- +# At one point the following join query was causing a malfunction in +# xBestIndex. +# +do_execsql_test 6.0 { + CREATE TABLE t4 ( + id INTEGER PRIMARY KEY, + name TEXT NOT NULL, + parent_id INTEGER + ); + CREATE VIRTUAL TABLE vt4 USING transitive_closure ( + idcolumn=id, parentcolumn=parent_id, tablename=t4 + ); +} + +do_execsql_test 6.1 { + SELECT * FROM t4, vt4 WHERE t4.id = vt4.root AND vt4.id=4 AND vt4.depth=2; +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/coalesce.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/coalesce.test new file mode 100644 index 0000000000000000000000000000000000000000..af4ea8dfa9b8f78af133743ee0505b58081fa52b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/coalesce.test @@ -0,0 +1,84 @@ +# 2009 November 10 +# +# 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. +# +#*********************************************************************** +# Additional test cases for the COALESCE() and IFNULL() functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +do_test coalesce-1.0 { + db eval { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d); + INSERT INTO t1 VALUES(1, null, null, null); + INSERT INTO t1 VALUES(2, 2, 99, 99); + INSERT INTO t1 VALUES(3, null, 3, 99); + INSERT INTO t1 VALUES(4, null, null, 4); + INSERT INTO t1 VALUES(5, null, null, null); + INSERT INTO t1 VALUES(6, 22, 99, 99); + INSERT INTO t1 VALUES(7, null, 33, 99); + INSERT INTO t1 VALUES(8, null, null, 44); + + SELECT coalesce(b,c,d) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.1 { + db eval { + SELECT coalesce(d+c+b,d+c,d) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.2 { + db eval { + SELECT ifnull(d+c+b,ifnull(d+c,d)) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.3 { + db eval { + SELECT ifnull(ifnull(d+c+b,d+c),d) FROM t1 ORDER BY a; + } +} {{} 200 102 4 {} 220 132 44} +do_test coalesce-1.4 { + db eval { + SELECT ifnull(ifnull(b,c),d) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.5 { + db eval { + SELECT ifnull(b,ifnull(c,d)) FROM t1 ORDER BY a; + } +} {{} 2 3 4 {} 22 33 44} +do_test coalesce-1.6 { + db eval { + SELECT coalesce(b,NOT b,-b,abs(b),lower(b),length(b),min(b,5),b*123,c) + FROM t1 ORDER BY a; + } +} {{} 2 3 {} {} 22 33 {}} +do_test coalesce-1.7 { + db eval { + SELECT ifnull(nullif(a,4),99) + FROM t1 ORDER BY a; + } +} {1 2 3 99 5 6 7 8} +do_test coalesce-1.8 { + db eval { +pragma vdbe_listing=on; + SELECT coalesce( + CASE WHEN b=2 THEN 123 END, + CASE WHEN b=3 THEN 234 END, + CASE WHEN c=3 THEN 345 WHEN c=33 THEN 456 END, + d + ) + FROM t1 ORDER BY a; + } +} {{} 123 345 4 {} 99 456 44} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate1.test new file mode 100644 index 0000000000000000000000000000000000000000..b65b8504748ade5f630a5192335427a48937d4e7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate1.test @@ -0,0 +1,452 @@ +# +# 2001 September 15 +# +# 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. The +# focus of this script is testing collation sequences. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix collate1 + +# +# Tests are roughly organised as follows: +# +# collate1-1.* - Single-field ORDER BY with an explicit COLLATE clause. +# collate1-2.* - Multi-field ORDER BY with an explicit COLLATE clause. +# collate1-3.* - ORDER BY using a default collation type. Also that an +# explict collate type overrides a default collate type. +# collate1-4.* - ORDER BY using a data type. +# + +# +# Collation type 'HEX'. If an argument can be interpreted as a hexadecimal +# number, then it is converted to one before the comparison is performed. +# Numbers are less than other strings. If neither argument is a number, +# [string compare] is used. +# +db collate HEX hex_collate +proc hex_collate {lhs rhs} { + set lhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $lhs] + set rhs_ishex [regexp {^(0x|)[1234567890abcdefABCDEF]+$} $rhs] + if {$lhs_ishex && $rhs_ishex} { + set lhsx [scan $lhs %x] + set rhsx [scan $rhs %x] + if {$lhs < $rhs} {return -1} + if {$lhs == $rhs} {return 0} + if {$lhs > $rhs} {return 1} + } + if {$lhs_ishex} { + return -1; + } + if {$rhs_ishex} { + return 1; + } + return [string compare $lhs $rhs] +} +db function hex {format 0x%X} + +# Mimic the SQLite 2 collation type NUMERIC. +db collate numeric numeric_collate +proc numeric_collate {lhs rhs} { + if {$lhs == $rhs} {return 0} + return [expr ($lhs>$rhs)?1:-1] +} + +do_test collate1-1.0 { + execsql { + CREATE TABLE collate1t1(c1, c2); + INSERT INTO collate1t1 VALUES(45, hex(45)); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES(281, hex(281)); + } +} {} +do_test collate1-1.1 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1; + } +} {{} 0x119 0x2D} +do_test collate1-1.2 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex; + } +} {{} 0x2D 0x119} +do_test collate1-1.3 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex DESC; + } +} {0x119 0x2D {}} +do_test collate1-1.4 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1 COLLATE hex ASC; + } +} {{} 0x2D 0x119} +do_test collate1-1.5 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 + } +} {{} 0x2D 0x119} +do_test collate1-1.6 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 ASC + } +} {{} 0x2D 0x119} +do_test collate1-1.7 { + execsql { + SELECT c2 COLLATE hex FROM collate1t1 ORDER BY 1 DESC + } +} {0x119 0x2D {}} +do_test collate1-1.99 { + execsql { + DROP TABLE collate1t1; + } +} {} + +do_test collate1-2.0 { + execsql { + CREATE TABLE collate1t1(c1, c2); + INSERT INTO collate1t1 VALUES('5', '0x11'); + INSERT INTO collate1t1 VALUES('5', '0xA'); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES('7', '0xA'); + INSERT INTO collate1t1 VALUES('11', '0x11'); + INSERT INTO collate1t1 VALUES('11', '0x101'); + } +} {} +do_test collate1-2.2 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE numeric, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.3 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary, 2 COLLATE hex; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.4 { + execsql { + SELECT c1, c2 FROM collate1t1 ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex; + } +} {7 0xA 5 0xA 5 0x11 11 0x11 11 0x101 {} {}} +do_test collate1-2.5 { + execsql { + SELECT c1, c2 FROM collate1t1 + ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex DESC; + } +} {7 0xA 5 0x11 5 0xA 11 0x101 11 0x11 {} {}} +do_test collate1-2.6 { + execsql { + SELECT c1, c2 FROM collate1t1 + ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.12.1 { + execsql { + SELECT c1 COLLATE numeric, c2 FROM collate1t1 + ORDER BY 1, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.2 { + execsql { + SELECT c1 COLLATE hex, c2 FROM collate1t1 + ORDER BY 1 COLLATE numeric, 2 COLLATE hex; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.3 { + execsql { + SELECT c1, c2 COLLATE hex FROM collate1t1 + ORDER BY 1 COLLATE numeric, 2; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.12.4 { + execsql { + SELECT c1 COLLATE numeric, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1, 2; + } +} {{} {} 5 0xA 5 0x11 7 0xA 11 0x11 11 0x101} +do_test collate1-2.13 { + execsql { + SELECT c1 COLLATE binary, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1, 2; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.14 { + execsql { + SELECT c1, c2 + FROM collate1t1 ORDER BY 1 COLLATE binary DESC, 2 COLLATE hex; + } +} {7 0xA 5 0xA 5 0x11 11 0x11 11 0x101 {} {}} +do_test collate1-2.15 { + execsql { + SELECT c1 COLLATE binary, c2 COLLATE hex + FROM collate1t1 + ORDER BY 1 DESC, 2 DESC; + } +} {7 0xA 5 0x11 5 0xA 11 0x101 11 0x11 {} {}} +do_test collate1-2.16 { + execsql { + SELECT c1 COLLATE hex, c2 COLLATE binary + FROM collate1t1 + ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC; + } +} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA} +do_test collate1-2.99 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# +# These tests ensure that the default collation type for a column is used +# by an ORDER BY clause correctly. The focus is all the different ways +# the column can be referenced. i.e. a, collate2t1.a, main.collate2t1.a etc. +# +do_test collate1-3.0 { + execsql { + CREATE TABLE collate1t1(a COLLATE hex, b); + INSERT INTO collate1t1 VALUES( '0x5', 5 ); + INSERT INTO collate1t1 VALUES( '1', 1 ); + INSERT INTO collate1t1 VALUES( '0x45', 69 ); + INSERT INTO collate1t1 VALUES( NULL, NULL ); + SELECT * FROM collate1t1 ORDER BY a; + } +} {{} {} 1 1 0x5 5 0x45 69} + +do_test collate1-3.1 { + execsql { + SELECT * FROM collate1t1 ORDER BY 1; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.2 { + execsql { + SELECT * FROM collate1t1 ORDER BY collate1t1.a; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.3 { + execsql { + SELECT * FROM collate1t1 ORDER BY main.collate1t1.a; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.4 { + execsql { + SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1; + } +} {{} {} 1 1 0x5 5 0x45 69} +do_test collate1-3.5 { + execsql { + SELECT a as c1, b as c2 FROM collate1t1 ORDER BY c1 COLLATE binary; + } +} {{} {} 0x45 69 0x5 5 1 1} +do_test collate1-3.5.1 { + execsql { + SELECT a COLLATE binary as c1, b as c2 + FROM collate1t1 ORDER BY c1; + } +} {{} {} 0x45 69 0x5 5 1 1} +do_test collate1-3.6 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# Update for SQLite version 3. The collate1-4.* test cases were written +# before manifest types were introduced. The following test cases still +# work, due to the 'affinity' mechanism, but they don't prove anything +# about collation sequences. +# +do_test collate1-4.0 { + execsql { + CREATE TABLE collate1t1(c1 numeric, c2 text); + INSERT INTO collate1t1 VALUES(1, 1); + INSERT INTO collate1t1 VALUES(12, 12); + INSERT INTO collate1t1 VALUES(NULL, NULL); + INSERT INTO collate1t1 VALUES(101, 101); + } +} {} +do_test collate1-4.1 { + execsql { + SELECT c1 FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.2 { + execsql { + SELECT c2 FROM collate1t1 ORDER BY 1; + } +} {{} 1 101 12} +do_test collate1-4.3 { + execsql { + SELECT c2+0 FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.4 { + execsql { + SELECT c1||'' FROM collate1t1 ORDER BY 1; + } +} {{} 1 101 12} +do_test collate1-4.4.1 { + execsql { + SELECT (c1||'') COLLATE numeric FROM collate1t1 ORDER BY 1; + } +} {{} 1 12 101} +do_test collate1-4.5 { + execsql { + DROP TABLE collate1t1; + } +} {} + +# A problem reported on the mailing list: A CREATE TABLE statement +# is allowed to have two or more COLLATE clauses on the same column. +# That probably ought to be an error, but we allow it for backwards +# compatibility. Just make sure it works and doesn't leak memory. +# +do_test collate1-5.1 { + execsql { + CREATE TABLE c5( + id INTEGER PRIMARY KEY, + a TEXT COLLATE binary COLLATE nocase COLLATE rtrim, + b TEXT COLLATE nocase COLLATE binary, + c TEXT COLLATE rtrim COLLATE binary COLLATE rtrim COLLATE nocase + ); + INSERT INTO c5 VALUES(1, 'abc','abc','abc'); + INSERT INTO c5 VALUES(2, 'abc ','ABC','ABC'); + SELECT id FROM c5 WHERE a='abc' ORDER BY id; + } +} {1 2} +do_test collate1-5.2 { + execsql { + SELECT id FROM c5 WHERE b='abc' ORDER BY id; + } +} {1} +do_test collate1-5.3 { + execsql { + SELECT id FROM c5 WHERE c='abc' ORDER BY id; + } +} {1 2} + + + +#------------------------------------------------------------------------- +# Fix problems with handling collation sequences named '"""'. +# +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test 6.1 { + SELECT """"""""; +} {\"\"\"} + +do_catchsql_test 6.2 { + CREATE TABLE x1(a); + SELECT a FROM x1 ORDER BY a COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.3 { + SELECT a FROM x1 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +do_catchsql_test 6.4 { + SELECT 0 UNION SELECT 0 ORDER BY 1 COLLATE """"""""; +} {1 {no such collation sequence: """}} + +db collate {"""} [list string compare -nocase] + +do_execsql_test 6.5 { + PRAGMA foreign_keys = ON; + CREATE TABLE p1(a PRIMARY KEY COLLATE '"""'); + CREATE TABLE c1(x, y REFERENCES p1); +} {} + +do_execsql_test 6.6 { + INSERT INTO p1 VALUES('abc'); + INSERT INTO c1 VALUES(1, 'ABC'); +} + +ifcapable foreignkey { + do_catchsql_test 6.7 { + DELETE FROM p1 WHERE rowid = 1 + } {1 {FOREIGN KEY constraint failed}} +} + +do_execsql_test 6.8 { + INSERT INTO p1 VALUES('abb'); + INSERT INTO p1 VALUES('wxz'); + INSERT INTO p1 VALUES('wxy'); + + INSERT INTO c1 VALUES(2, 'abb'); + INSERT INTO c1 VALUES(3, 'wxz'); + INSERT INTO c1 VALUES(4, 'WXY'); + SELECT x, y FROM c1 ORDER BY y COLLATE """"""""; +} {2 abb 1 ABC 4 WXY 3 wxz} + +# 2015-04-15: Nested COLLATE operators +# +do_execsql_test 7.0 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE nocase; +} {abc DEF} +do_execsql_test 7.1 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE nocase COLLATE nocase COLLATE nocase COLLATE binary; +} {DEF abc} +do_execsql_test 7.2 { + SELECT 'abc' UNION ALL SELECT 'DEF' + ORDER BY 1 COLLATE binary COLLATE binary COLLATE binary COLLATE nocase; +} {abc DEF} + +# 2019-06-14 +# https://sqlite.org/src/info/f1580ba1b574e9e9 +# +do_execsql_test 8.0 { + SELECT ' ' > char(20) COLLATE rtrim; +} 0 +do_execsql_test 8.1 { + SELECT '' < char(20) COLLATE rtrim; +} 1 +do_execsql_test 8.2 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 COLLATE RTRIM, c1 BLOB UNIQUE, + PRIMARY KEY (c0, c1)) WITHOUT ROWID; + INSERT INTO t0 VALUES (123, 3), (' ', 1), (' ', 2), ('', 4); + SELECT * FROM t0 WHERE c1 = 1; +} {{ } 1} + +# 2019-10-09 +# ALWAYS() macro fails following OOM +# Problem detected by dbsqlfuzz. +# +do_execsql_test 9.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); +} + +do_faultsim_test 9.1 -faults oom* -body { + execsql { + SELECT * FROM ( + SELECT b COLLATE nocase IN (SELECT c FROM t2) FROM t1 + ); + } +} -test { + faultsim_test_result {0 {}} +} + +# 2020-01-03 dbsqlfuzz find +# +reset_db +do_catchsql_test 10.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY,b); + INSERT INTO t1 VALUES(0,NULL); + CREATE TABLE t2(x UNIQUE); + CREATE VIEW v1a(z,y) AS SELECT x COLLATE x FROM t2; + SELECT a,b,z,y,'' FROM t1 JOIN v1a ON b IS NOT FALSE; +} {1 {no such collation sequence: x}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate2.test new file mode 100644 index 0000000000000000000000000000000000000000..281aa35709c8fef99f84a76603a5959fd82209cb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate2.test @@ -0,0 +1,742 @@ +# +# 2001 September 15 +# +# 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. The +# focus of this script is page cache subsystem. +# +# $Id: collate2.test,v 1.6 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix collate2 + +# +# Tests are organised as follows: +# +# collate2-1.* WHERE expressions (sqliteExprIfTrue). +# collate2-2.* WHERE NOT expressions (sqliteExprIfFalse). +# collate2-3.* SELECT expressions (sqliteExprCode). +# collate2-4.* Precedence of collation/data types in binary comparisons +# collate2-5.* JOIN syntax. +# + +# Create a collation type BACKWARDS for use in testing. This collation type +# is similar to the built-in TEXT collation type except the order of +# characters in each string is reversed before the comparison is performed. +db collate BACKWARDS backwards_collate +proc backwards_collate {a b} { + set ra {}; + set rb {} + foreach c [split $a {}] { set ra $c$ra } + foreach c [split $b {}] { set rb $c$rb } + return [string compare $ra $rb] +} + +# The following values are used in these tests: +# NULL aa ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB +# +# The collation orders for each of the tested collation types are: +# +# BINARY: NULL AA AB Aa Ab BA BB Ba Bb aA aB aa ab bA bB ba bb +# NOCASE: NULL aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB +# BACKWARDS: NULL AA BA aA bA AB BB aB bB Aa Ba aa ba Ab Bb ab bb +# +# These tests verify that the default collation type for a column is used +# for comparison operators (<, >, <=, >=, =) involving that column and +# an expression that is not a column with a default collation type. +# +# The collation sequences BINARY and NOCASE are built-in, the BACKWARDS +# collation sequence is implemented by the TCL proc backwards_collate +# above. +# +do_test collate2-1.0 { + execsql { + CREATE TABLE collate2t1( + a COLLATE BINARY, + b COLLATE NOCASE, + c COLLATE BACKWARDS + ); + INSERT INTO collate2t1 VALUES( NULL, NULL, NULL ); + + INSERT INTO collate2t1 VALUES( 'aa', 'aa', 'aa' ); + INSERT INTO collate2t1 VALUES( 'ab', 'ab', 'ab' ); + INSERT INTO collate2t1 VALUES( 'ba', 'ba', 'ba' ); + INSERT INTO collate2t1 VALUES( 'bb', 'bb', 'bb' ); + + INSERT INTO collate2t1 VALUES( 'aA', 'aA', 'aA' ); + INSERT INTO collate2t1 VALUES( 'aB', 'aB', 'aB' ); + INSERT INTO collate2t1 VALUES( 'bA', 'bA', 'bA' ); + INSERT INTO collate2t1 VALUES( 'bB', 'bB', 'bB' ); + + INSERT INTO collate2t1 VALUES( 'Aa', 'Aa', 'Aa' ); + INSERT INTO collate2t1 VALUES( 'Ab', 'Ab', 'Ab' ); + INSERT INTO collate2t1 VALUES( 'Ba', 'Ba', 'Ba' ); + INSERT INTO collate2t1 VALUES( 'Bb', 'Bb', 'Bb' ); + + INSERT INTO collate2t1 VALUES( 'AA', 'AA', 'AA' ); + INSERT INTO collate2t1 VALUES( 'AB', 'AB', 'AB' ); + INSERT INTO collate2t1 VALUES( 'BA', 'BA', 'BA' ); + INSERT INTO collate2t1 VALUES( 'BB', 'BB', 'BB' ); + } + if {[info exists collate_test_use_index]} { + execsql { + CREATE INDEX collate2t1_i1 ON collate2t1(a); + CREATE INDEX collate2t1_i2 ON collate2t1(b); + CREATE INDEX collate2t1_i3 ON collate2t1(c); + } + } +} {} +do_test collate2-1.1 { + execsql { + SELECT a FROM collate2t1 WHERE a > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.1 { + execsql { + SELECT a FROM collate2t1 WHERE a COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.2 { + execsql { + SELECT a FROM collate2t1 WHERE b COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.1.3 { + execsql { + SELECT a FROM collate2t1 WHERE c COLLATE binary > 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-1.2 { + execsql { + SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.1 { + execsql { + SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.2 { + execsql { + SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.3 { + execsql { + SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa' + ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.4 { + execsql { + SELECT b FROM collate2t1 WHERE b > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.5 { + execsql { + SELECT b FROM collate2t1 WHERE a COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.6 { + execsql { + SELECT b FROM collate2t1 WHERE b COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.2.7 { + execsql { + SELECT b FROM collate2t1 WHERE c COLLATE nocase > 'aa' ORDER BY +b; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.3 { + execsql { + SELECT c FROM collate2t1 WHERE c > 'aa' ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.1 { + execsql { + SELECT c FROM collate2t1 WHERE a COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.2 { + execsql { + SELECT c FROM collate2t1 WHERE b COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.3.3 { + execsql { + SELECT c FROM collate2t1 WHERE c COLLATE backwards > 'aa' + ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-1.4 { + execsql { + SELECT a FROM collate2t1 WHERE a < 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB} +do_test collate2-1.5 { + execsql { + SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY 1, oid; + } +} {} +do_test collate2-1.5.1 { + execsql { + SELECT b FROM collate2t1 WHERE b < 'aa' ORDER BY +b; + } +} {} +do_test collate2-1.6 { + execsql { + SELECT c FROM collate2t1 WHERE c < 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba} +do_test collate2-1.7 { + execsql { + SELECT a FROM collate2t1 WHERE a = 'aa'; + } +} {aa} +do_test collate2-1.8 { + execsql { + SELECT b FROM collate2t1 WHERE b = 'aa' ORDER BY oid; + } +} {aa aA Aa AA} +do_test collate2-1.9 { + execsql { + SELECT c FROM collate2t1 WHERE c = 'aa'; + } +} {aa} +do_test collate2-1.10 { + execsql { + SELECT a FROM collate2t1 WHERE a >= 'aa' ORDER BY 1; + } +} {aa ab bA bB ba bb} +do_test collate2-1.11 { + execsql { + SELECT b FROM collate2t1 WHERE b >= 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.12 { + execsql { + SELECT c FROM collate2t1 WHERE c >= 'aa' ORDER BY 1; + } +} {aa ba Ab Bb ab bb} +do_test collate2-1.13 { + execsql { + SELECT a FROM collate2t1 WHERE a <= 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB aa} +do_test collate2-1.14 { + execsql { + SELECT b FROM collate2t1 WHERE b <= 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-1.15 { + execsql { + SELECT c FROM collate2t1 WHERE c <= 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba aa} +do_test collate2-1.16 { + execsql { + SELECT a FROM collate2t1 WHERE a BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {Aa Ab BA BB Ba Bb} +do_test collate2-1.17 { + execsql { + SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.17.1 { + execsql { + SELECT b FROM collate2t1 WHERE b BETWEEN 'Aa' AND 'Bb' ORDER BY +b; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-1.18 { + execsql { + SELECT c FROM collate2t1 WHERE c BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {Aa Ba aa ba Ab Bb} +do_test collate2-1.19 { + execsql { + SELECT a FROM collate2t1 WHERE + CASE a WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa} +do_test collate2-1.20 { + execsql { + SELECT b FROM collate2t1 WHERE + CASE b WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-1.21 { + execsql { + SELECT c FROM collate2t1 WHERE + CASE c WHEN 'aa' THEN 1 ELSE 0 END + ORDER BY 1, oid; + } +} {aa} + +ifcapable subquery { + do_test collate2-1.22 { + execsql { + SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa bb} + do_test collate2-1.23 { + execsql { + SELECT b FROM collate2t1 WHERE b IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa aA Aa AA bb bB Bb BB} + do_test collate2-1.24 { + execsql { + SELECT c FROM collate2t1 WHERE c IN ('aa', 'bb') ORDER BY 1, oid; + } + } {aa bb} + do_test collate2-1.25 { + execsql { + SELECT a FROM collate2t1 + WHERE a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb} + do_test collate2-1.26 { + execsql { + SELECT b FROM collate2t1 + WHERE b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb aA bB Aa Bb AA BB} + do_test collate2-1.27 { + execsql { + SELECT c FROM collate2t1 + WHERE c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {aa bb} +} ;# ifcapable subquery + +do_test collate2-2.1 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a > 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB aa} +do_test collate2-2.2 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b > 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA} +do_test collate2-2.3 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c > 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba aa} +do_test collate2-2.4 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a < 'aa' ORDER BY 1; + } +} {aa ab bA bB ba bb} +do_test collate2-2.5 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b < 'aa' ORDER BY 1, oid; + } +} {aa aA Aa AA ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-2.6 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c < 'aa' ORDER BY 1; + } +} {aa ba Ab Bb ab bb} +do_test collate2-2.7 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a = 'aa'; + } +} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.8 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b = 'aa'; + } +} {ab ba bb aB bA bB Ab Ba Bb AB BA BB} +do_test collate2-2.9 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c = 'aa'; + } +} {ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.10 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a >= 'aa' ORDER BY 1; + } +} {AA AB Aa Ab BA BB Ba Bb aA aB} +do_test collate2-2.11 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b >= 'aa' ORDER BY 1, oid; + } +} {} +do_test collate2-2.12 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c >= 'aa' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB Aa Ba} +do_test collate2-2.13 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a <= 'aa' ORDER BY 1; + } +} {ab bA bB ba bb} +do_test collate2-2.14 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b <= 'aa' ORDER BY 1, oid; + } +} {ab aB Ab AB ba bA Ba BA bb bB Bb BB} +do_test collate2-2.15 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c <= 'aa' ORDER BY 1; + } +} {ba Ab Bb ab bb} +do_test collate2-2.16 { + execsql { + SELECT a FROM collate2t1 WHERE a NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {AA AB aA aB aa ab bA bB ba bb} +do_test collate2-2.17 { + execsql { + SELECT b FROM collate2t1 WHERE b NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1, oid; + } +} {} +do_test collate2-2.18 { + execsql { + SELECT c FROM collate2t1 WHERE c NOT BETWEEN 'Aa' AND 'Bb' ORDER BY 1; + } +} {AA BA aA bA AB BB aB bB ab bb} +do_test collate2-2.19 { + execsql { + SELECT a FROM collate2t1 WHERE NOT CASE a WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +do_test collate2-2.20 { + execsql { + SELECT b FROM collate2t1 WHERE NOT CASE b WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aB bA bB Ab Ba Bb AB BA BB} +do_test collate2-2.21 { + execsql { + SELECT c FROM collate2t1 WHERE NOT CASE c WHEN 'aa' THEN 1 ELSE 0 END; + } +} {{} ab ba bb aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + +ifcapable subquery { + do_test collate2-2.22 { + execsql { + SELECT a FROM collate2t1 WHERE NOT a IN ('aa', 'bb'); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.23 { + execsql { + SELECT b FROM collate2t1 WHERE NOT b IN ('aa', 'bb'); + } + } {ab ba aB bA Ab Ba AB BA} + do_test collate2-2.24 { + execsql { + SELECT c FROM collate2t1 WHERE NOT c IN ('aa', 'bb'); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.25 { + execsql { + SELECT a FROM collate2t1 + WHERE NOT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} + do_test collate2-2.26 { + execsql { + SELECT b FROM collate2t1 + WHERE NOT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aB bA Ab Ba AB BA} + do_test collate2-2.27 { + execsql { + SELECT c FROM collate2t1 + WHERE NOT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')); + } + } {ab ba aA aB bA bB Aa Ab Ba Bb AA AB BA BB} +} + +do_test collate2-3.1 { + execsql { + SELECT a > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0} +do_test collate2-3.2 { + execsql { + SELECT b > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1} +do_test collate2-3.3 { + execsql { + SELECT c > 'aa' FROM collate2t1; + } +} {{} 0 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0} +do_test collate2-3.4 { + execsql { + SELECT a < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1} +do_test collate2-3.5 { + execsql { + SELECT b < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.6 { + execsql { + SELECT c < 'aa' FROM collate2t1; + } +} {{} 0 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1} +do_test collate2-3.7 { + execsql { + SELECT a = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.8 { + execsql { + SELECT b = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.9 { + execsql { + SELECT c = 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.10 { + execsql { + SELECT a <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1} +do_test collate2-3.11 { + execsql { + SELECT b <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.12 { + execsql { + SELECT c <= 'aa' FROM collate2t1; + } +} {{} 1 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1} +do_test collate2-3.13 { + execsql { + SELECT a >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 0 0 1 1 0 0 0 0 0 0 0 0} +do_test collate2-3.14 { + execsql { + SELECT b >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} +do_test collate2-3.15 { + execsql { + SELECT c >= 'aa' FROM collate2t1; + } +} {{} 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0} +do_test collate2-3.16 { + execsql { + SELECT a BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 0 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1} +do_test collate2-3.17 { + execsql { + SELECT b BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1} +do_test collate2-3.18 { + execsql { + SELECT c BETWEEN 'Aa' AND 'Bb' FROM collate2t1; + } +} {{} 1 0 1 0 0 0 0 0 1 1 1 1 0 0 0 0} +do_test collate2-3.19 { + execsql { + SELECT CASE a WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} +do_test collate2-3.20 { + execsql { + SELECT CASE b WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0} +do_test collate2-3.21 { + execsql { + SELECT CASE c WHEN 'aa' THEN 1 ELSE 0 END FROM collate2t1; + } +} {0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0} + +ifcapable subquery { + do_test collate2-3.22 { + execsql { + SELECT a IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.23 { + execsql { + SELECT b IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1} + do_test collate2-3.24 { + execsql { + SELECT c IN ('aa', 'bb') FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.25 { + execsql { + SELECT a IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} + do_test collate2-3.26 { + execsql { + SELECT b IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1} + do_test collate2-3.27 { + execsql { + SELECT c IN (SELECT a FROM collate2t1 WHERE a IN ('aa', 'bb')) + FROM collate2t1; + } + } {{} 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0} +} + +do_test collate2-4.0 { + execsql { + CREATE TABLE collate2t2(b COLLATE binary); + CREATE TABLE collate2t3(b text); + INSERT INTO collate2t2 VALUES('aa'); + INSERT INTO collate2t3 VALUES('aa'); + } +} {} + +# Test that when both sides of a binary comparison operator have +# default collation types, the collate type for the leftmost term +# is used. +do_test collate2-4.1 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t2 + WHERE collate2t1.b = collate2t2.b; + } +} {aa aA Aa AA} +do_test collate2-4.2 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t2 + WHERE collate2t2.b = collate2t1.b; + } +} {aa} + +# Test that when one side has a default collation type and the other +# does not, the collation type is used. +do_test collate2-4.3 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t3 + WHERE collate2t1.b = collate2t3.b||'' + ORDER BY +collate2t1.a DESC; + } +} {aa aA Aa AA} +do_test collate2-4.4 { + execsql { + SELECT collate2t1.a FROM collate2t1, collate2t3 + WHERE collate2t3.b||'' = collate2t1.b + ORDER BY +collate2t1.a DESC; + } +} {aa aA Aa AA} + +do_test collate2-4.5 { + execsql { + DROP TABLE collate2t3; + } +} {} + +# +# Test that the default collation types are used when the JOIN syntax +# is used in place of a WHERE clause. +# +# SQLite transforms the JOIN syntax into a WHERE clause internally, so +# the focus of these tests is to ensure that the table on the left-hand-side +# of the join determines the collation type used. +# +do_test collate2-5.0 { + execsql { + SELECT collate2t1.b FROM collate2t1 JOIN collate2t2 USING (b); + } +} {aa aA Aa AA} +do_test collate2-5.1 { + execsql { + SELECT collate2t1.b FROM collate2t2 JOIN collate2t1 USING (b); + } +} {aa} +do_test collate2-5.2 { + execsql { + SELECT collate2t1.b FROM collate2t1 NATURAL JOIN collate2t2; + } +} {aa aA Aa AA} +do_test collate2-5.3 { + execsql { + SELECT collate2t1.b FROM collate2t2 NATURAL JOIN collate2t1; + } +} {aa} +do_test collate2-5.4.1 { + execsql { + SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 USING (b) order by collate2t1.oid; + } +} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}} +do_test collate2-5.4.2 { + execsql { + SELECT collate2t2.b FROM collate2t2 RIGHT JOIN collate2t1 ON collate2t1.b=collate2t2.b + ORDER BY collate2t1.oid; + } +} {{} aa {} {} {} aa {} {} {} aa {} {} {} aa {} {} {}} +do_test collate2-5.4.3 { + execsql { + SELECT collate2t2.b FROM collate2t1 LEFT JOIN collate2t2 ON collate2t2.b=collate2t1.b + ORDER BY collate2t1.oid; + } +} {{} aa {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}} +do_test collate2-5.5.1 { + execsql { + SELECT collate2t1.b, collate2t2.b FROM collate2t2 LEFT OUTER JOIN collate2t1 USING (b); + } +} {aa aa} +do_test collate2-5.5.2 { + execsql { + SELECT collate2t1.b, collate2t2.b + FROM collate2t1 RIGHT JOIN collate2t2 ON collate2t2.b=collate2t1.b + } +} {aa aa} + +do_execsql_test 6.1 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES('b'); + INSERT INTO t1 VALUES('B'); +} +do_execsql_test 6.2 { + SELECT * FROM t1 WHERE x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.3 { + SELECT * FROM t1 WHERE x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.4 { + SELECT * FROM t1 + WHERE x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.5 { + SELECT * FROM t1 WHERE +x COLLATE nocase BETWEEN 'a' AND 'c'; +} {b B} +do_execsql_test 6.6 { + SELECT * FROM t1 WHERE +x BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} +do_execsql_test 6.7 { + SELECT * FROM t1 + WHERE +x COLLATE nocase BETWEEN 'a' COLLATE nocase AND 'c' COLLATE nocase; +} {b B} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate3.test new file mode 100644 index 0000000000000000000000000000000000000000..99640d05b89bee6539e7fb8754639a28fcbcc880 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate3.test @@ -0,0 +1,531 @@ +# 2001 September 15 +# +# 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. The +# focus of this script is page cache subsystem. +# +# $Id: collate3.test,v 1.13 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# +# Tests are organised as follows: +# +# collate3.1.* - Errors related to unknown collation sequences. +# collate3.2.* - Errors related to undefined collation sequences. +# collate3.3.* - Writing to a table that has an index with an undefined c.s. +# collate3.4.* - Misc errors. +# collate3.5.* - Collation factory. +# + +# +# These tests ensure that when a user executes a statement with an +# unknown collation sequence an error is returned. +# +do_test collate3-1.0 { + execsql { + CREATE TABLE collate3t1(c1 UNIQUE); + } +} {} +do_test collate3-1.1 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 collate garbage; + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.1.2 { + catchsql { + SELECT DISTINCT c1 COLLATE garbage FROM collate3t1; + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.2 { + catchsql { + CREATE TABLE collate3t2(c1 collate garbage); + } +} {1 {no such collation sequence: garbage}} +do_test collate3-1.3 { + catchsql { + CREATE INDEX collate3i1 ON collate3t1(c1 COLLATE garbage); + } +} {1 {no such collation sequence: garbage}} + +execsql { + DROP TABLE collate3t1; +} + +proc caseless {a b} { string compare -nocase $a $b } +do_test collate3-1.4 { + db collate caseless caseless + execsql { + CREATE TABLE t1(a COLLATE caseless); + INSERT INTO t1 VALUES('Abc2'); + INSERT INTO t1 VALUES('abc1'); + INSERT INTO t1 VALUES('aBc3'); + } + execsql { SELECT * FROM t1 ORDER BY a } +} {abc1 Abc2 aBc3} + +do_test collate3-1.5 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.1 { + db collate caseless caseless + execsql { CREATE INDEX i1 ON t1(a) } + execsql { SELECT * FROM t1 ORDER BY a } +} {abc1 Abc2 aBc3} + +do_test collate3-1.6.2 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.3 { + db close + sqlite3 db test.db + catchsql { PRAGMA integrity_check } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.6.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.1 { + db collate caseless caseless + execsql { + DROP TABLE t1; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a COLLATE caseless); + INSERT INTO t1 VALUES('Abc2'); + INSERT INTO t1 VALUES('abc1'); + INSERT INTO t1 VALUES('aBc3'); + SELECT * FROM t1 ORDER BY a COLLATE caseless; + } +} {abc1 Abc2 aBc3} + +do_test collate3-1.7.2 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 ORDER BY a COLLATE caseless} +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.3 { + db close + sqlite3 db test.db + catchsql { PRAGMA integrity_check } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.4 { + db close + sqlite3 db test.db + catchsql { REINDEX } +} {1 {no such collation sequence: caseless}} + +do_test collate3-1.7.5 { + db close + sqlite3 db test.db + db collate caseless caseless + catchsql { PRAGMA integrity_check } +} {0 ok} + +proc needed {nm} { db collate caseless caseless } +do_test collate3-1.7.6 { + db close + sqlite3 db test.db + db collation_needed needed + catchsql { PRAGMA integrity_check } +} {0 ok} + +do_test collate3-1.8 { + execsql { DROP TABLE t1 } +} {} + +# +# Create a table with a default collation sequence, then close +# and re-open the database without re-registering the collation +# sequence. Then make sure the library stops us from using +# the collation sequence in: +# * an explicitly collated ORDER BY +# * an ORDER BY that uses the default collation sequence +# * an expression (=) +# * a CREATE TABLE statement +# * a CREATE INDEX statement that uses a default collation sequence +# * a GROUP BY that uses the default collation sequence +# * a SELECT DISTINCT that uses the default collation sequence +# * Compound SELECTs that uses the default collation sequence +# * An ORDER BY on a compound SELECT with an explicit ORDER BY. +# +do_test collate3-2.0 { + db collate string_compare {string compare} + execsql { + CREATE TABLE collate3t1(c1 COLLATE string_compare, c2); + } + db close + sqlite3 db test.db + expr 0 +} 0 +do_test collate3-2.1 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.2 { + catchsql { + SELECT * FROM collate3t1 ORDER BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.3 { + catchsql { + SELECT * FROM collate3t1 WHERE c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.4 { + catchsql { + CREATE TABLE collate3t2(c1 COLLATE string_compare); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.5 { + catchsql { + CREATE INDEX collate3t1_i1 ON collate3t1(c1); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.6 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {}} +do_test collate3-2.7.1 { + catchsql { + SELECT count(*) FROM collate3t1 GROUP BY c1; + } +} {1 {no such collation sequence: string_compare}} +# do_test collate3-2.7.2 { +# catchsql { +# SELECT * FROM collate3t1 GROUP BY c1; +# } +# } {1 {GROUP BY may only be used on aggregate queries}} +do_test collate3-2.7.2 { + catchsql { + SELECT * FROM collate3t1 GROUP BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-2.8 { + catchsql { + SELECT DISTINCT c1 FROM collate3t1; + } +} {1 {no such collation sequence: string_compare}} + +ifcapable compound { + do_test collate3-2.9 { + catchsql { + SELECT c1 FROM collate3t1 UNION SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.10 { + catchsql { + SELECT c1 FROM collate3t1 EXCEPT SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.11 { + catchsql { + SELECT c1 FROM collate3t1 INTERSECT SELECT c1 FROM collate3t1; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.12 { + catchsql { + SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1; + } + } {0 {}} + do_test collate3-2.13 { + catchsql { + SELECT 10 UNION ALL SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.14 { + catchsql { + SELECT 10 INTERSECT SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.15 { + catchsql { + SELECT 10 EXCEPT SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.16 { + catchsql { + SELECT 10 UNION SELECT 20 ORDER BY 1 COLLATE string_compare; + } + } {1 {no such collation sequence: string_compare}} + do_test collate3-2.17 { + catchsql { + SELECT c1 FROM collate3t1 UNION ALL SELECT c1 FROM collate3t1 ORDER BY 1; + } + } {1 {no such collation sequence: string_compare}} +} ;# ifcapable compound + +# +# Create an index that uses a collation sequence then close and +# re-open the database without re-registering the collation +# sequence. Then check that for the table with the index +# * An INSERT fails, +# * An UPDATE on the column with the index fails, +# * An UPDATE on a different column succeeds. +# * A DELETE with a WHERE clause fails +# * A DELETE without a WHERE clause succeeds +# +# Also, ensure that the restrictions tested by collate3-2.* still +# apply after the index has been created. +# +do_test collate3-3.0 { + db collate string_compare {string compare} + execsql { + CREATE INDEX collate3t1_i1 ON collate3t1(c1); + INSERT INTO collate3t1 VALUES('xxx', 'yyy'); + } + db close + sqlite3 db test.db + expr 0 +} 0 +db eval {select * from collate3t1} +do_test collate3-3.1 { + catchsql { + INSERT INTO collate3t1 VALUES('xxx', 0); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.2 { + catchsql { + UPDATE collate3t1 SET c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.3 { + catchsql { + UPDATE collate3t1 SET c2 = 'xxx'; + } +} {0 {}} +do_test collate3-3.4 { + catchsql { + DELETE FROM collate3t1 WHERE 1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.5 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {xxx xxx}} +do_test collate3-3.6 { + catchsql { + DELETE FROM collate3t1; + } +} {0 {}} +ifcapable {integrityck} { + do_test collate3-3.8 { + catchsql { + PRAGMA integrity_check + } + } {1 {no such collation sequence: string_compare}} +} +do_test collate3-3.9 { + catchsql { + SELECT * FROM collate3t1; + } +} {0 {}} +do_test collate3-3.10 { + catchsql { + SELECT * FROM collate3t1 ORDER BY 1 COLLATE string_compare; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.11 { + catchsql { + SELECT * FROM collate3t1 ORDER BY c1; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.12 { + catchsql { + SELECT * FROM collate3t1 WHERE c1 = 'xxx'; + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.13 { + catchsql { + CREATE TABLE collate3t2(c1 COLLATE string_compare); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.14 { + catchsql { + CREATE INDEX collate3t1_i2 ON collate3t1(c1); + } +} {1 {no such collation sequence: string_compare}} +do_test collate3-3.15 { + execsql { + DROP TABLE collate3t1; + } +} {} + +# Check we can create an index that uses an explicit collation +# sequence and then close and re-open the database. +do_test collate3-4.6 { + db collate user_defined "string compare" + execsql { + CREATE TABLE collate3t1(a, b); + INSERT INTO collate3t1 VALUES('hello', NULL); + CREATE INDEX collate3i1 ON collate3t1(a COLLATE user_defined); + } +} {} +do_test collate3-4.7 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined; + } +} {1 {no such collation sequence: user_defined}} +do_test collate3-4.8.1 { + db collate user_defined "string compare" + catchsql { + SELECT * FROM collate3t1 ORDER BY a COLLATE user_defined; + } +} {0 {hello {}}} +do_test collate3-4.8.2 { + db close + lindex [catch { + sqlite3 db test.db + }] 0 +} {0} +do_test collate3-4.8.3 { + execsql { + DROP TABLE collate3t1; + } +} {} + +# Compare strings as numbers. +proc numeric_compare {lhs rhs} { + if {$rhs > $lhs} { + set res -1 + } else { + set res [expr ($lhs > $rhs)?1:0] + } + return $res +} + +# Check we can create a view that uses an explicit collation +# sequence and then close and re-open the database. +ifcapable view { +do_test collate3-4.9 { + db collate user_defined numeric_compare + execsql { + CREATE TABLE collate3t1(a, b); + INSERT INTO collate3t1 VALUES('2', NULL); + INSERT INTO collate3t1 VALUES('101', NULL); + INSERT INTO collate3t1 VALUES('12', NULL); + CREATE VIEW collate3v1 AS SELECT * FROM collate3t1 + ORDER BY 1 COLLATE user_defined; + SELECT * FROM collate3v1; + } +} {2 {} 12 {} 101 {}} +do_test collate3-4.10 { + db close + sqlite3 db test.db + catchsql { + SELECT * FROM collate3v1; + } +} {1 {no such collation sequence: user_defined}} +do_test collate3-4.11 { + db collate user_defined numeric_compare + catchsql { + SELECT * FROM collate3v1; + } +} {0 {2 {} 12 {} 101 {}}} +do_test collate3-4.12 { + execsql { + DROP TABLE collate3t1; + } +} {} +} ;# ifcapable view + +# +# Test the collation factory. In the code, the "no such collation sequence" +# message is only generated in two places. So these tests just test that +# the collation factory can be called once from each of those points. +# +do_test collate3-5.0 { + catchsql { + CREATE TABLE collate3t1(a); + INSERT INTO collate3t1 VALUES(10); + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {1 {no such collation sequence: unk}} +do_test collate3-5.1 { + set ::cfact_cnt 0 + proc cfact {nm} { + db collate $nm {string compare} + incr ::cfact_cnt + } + db collation_needed cfact +} {} +do_test collate3-5.2 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.3 { + set ::cfact_cnt +} {1} +do_test collate3-5.4 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.5 { + set ::cfact_cnt +} {1} +do_test collate3-5.6 { + catchsql { + SELECT a FROM collate3t1 ORDER BY 1 COLLATE unk; + } +} {0 10} +do_test collate3-5.7 { + execsql { + DROP TABLE collate3t1; + CREATE TABLE collate3t1(a COLLATE unk); + } + db close + sqlite3 db test.db + catchsql { + SELECT a FROM collate3t1 ORDER BY 1; + } +} {1 {no such collation sequence: unk}} +do_test collate3-5.8 { + set ::cfact_cnt 0 + proc cfact {nm} { + db collate $nm {string compare} + incr ::cfact_cnt + } + db collation_needed cfact + catchsql { + SELECT a FROM collate3t1 ORDER BY 1; + } +} {0 {}} + +do_test collate3-5.9 { + execsql { + DROP TABLE collate3t1; + } +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate4.test new file mode 100644 index 0000000000000000000000000000000000000000..b8c1c573c3bc5b39e9c1dff402d15b9ac5f7a1c5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate4.test @@ -0,0 +1,704 @@ +# +# 2001 September 15 +# +# 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. The +# focus of this script is page cache subsystem. +# +# $Id: collate4.test,v 1.9 2008/01/05 17:39:30 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +db collate TEXT text_collate +proc text_collate {a b} { + return [string compare $a $b] +} + +# Do an SQL statement. Append the search count to the end of the result. +# +proc count sql { + set ::sqlite_search_count 0 + return [concat [execsql $sql] $::sqlite_search_count] +} + +# This procedure executes the SQL. Then it checks the generated program +# for the SQL and appends a "nosort" to the result if the program contains the +# SortCallback opcode. If the program does not contain the SortCallback +# opcode it appends "sort" +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# +# Test cases are organized roughly as follows: +# +# collate4-1.* ORDER BY. +# collate4-2.* WHERE clauses. +# collate4-3.* constraints (primary key, unique). +# collate4-4.* simple min() or max() queries. +# collate4-5.* REINDEX command +# collate4-6.* INTEGER PRIMARY KEY indices. +# + +# +# These tests - collate4-1.* - check that indices are correctly +# selected or not selected to implement ORDER BY clauses when +# user defined collation sequences are involved. +# +# Because these tests also exercise all the different ways indices +# can be created, they also serve to verify that indices are correctly +# initialized with user-defined collation sequences when they are +# created. +# +# Tests named collate4-1.1.* use indices with a single column. Tests +# collate4-1.2.* use indices with two columns. +# +do_test collate4-1.1.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t1 VALUES( 'a', 'a' ); + INSERT INTO collate4t1 VALUES( 'b', 'b' ); + INSERT INTO collate4t1 VALUES( NULL, NULL ); + INSERT INTO collate4t1 VALUES( 'B', 'B' ); + INSERT INTO collate4t1 VALUES( 'A', 'A' ); + CREATE INDEX collate4i1 ON collate4t1(a); + CREATE INDEX collate4i2 ON collate4t1(b); + } +} {} +do_test collate4-1.1.1 { + cksort {SELECT a FROM collate4t1 ORDER BY a} +} {{} a A b B nosort} +do_test collate4-1.1.2 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE NOCASE} +} {{} a A b B nosort} +do_test collate4-1.1.3 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE TEXT} +} {{} A B a b sort} +do_test collate4-1.1.4 { + cksort {SELECT b FROM collate4t1 ORDER BY b} +} {{} A B a b nosort} +do_test collate4-1.1.5 { + cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE TEXT} +} {{} A B a b nosort} +do_test collate4-1.1.6 { + cksort {SELECT b FROM collate4t1 ORDER BY b COLLATE NOCASE, rowid} +} {{} a A b B sort} + +do_test collate4-1.1.7 { + execsql { + CREATE TABLE collate4t2( + a PRIMARY KEY COLLATE NOCASE, + b UNIQUE COLLATE TEXT + ); + INSERT INTO collate4t2 VALUES( 'a', 'a' ); + INSERT INTO collate4t2 VALUES( NULL, NULL ); + INSERT INTO collate4t2 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.1.8 { + cksort {SELECT a FROM collate4t2 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.1.9 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE NOCASE} +} {{} a B nosort} +do_test collate4-1.1.10 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE TEXT} +} {{} B a sort} +do_test collate4-1.1.11 { + cksort {SELECT b FROM collate4t2 ORDER BY b} +} {{} B a nosort} +do_test collate4-1.1.12 { + cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE TEXT} +} {{} B a nosort} +do_test collate4-1.1.13 { + cksort {SELECT b FROM collate4t2 ORDER BY b COLLATE NOCASE} +} {{} a B sort} + +do_test collate4-1.1.14 { + execsql { + CREATE TABLE collate4t3( + b COLLATE TEXT, + a COLLATE NOCASE, + UNIQUE(a), PRIMARY KEY(b) + ); + INSERT INTO collate4t3 VALUES( 'a', 'a' ); + INSERT INTO collate4t3 VALUES( NULL, NULL ); + INSERT INTO collate4t3 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.1.15 { + cksort {SELECT a FROM collate4t3 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.1.16 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE NOCASE} +} {{} a B nosort} +do_test collate4-1.1.17 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE TEXT} +} {{} B a sort} +do_test collate4-1.1.18 { + cksort {SELECT b FROM collate4t3 ORDER BY b} +} {{} B a nosort} +do_test collate4-1.1.19 { + cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE TEXT} +} {{} B a nosort} +do_test collate4-1.1.20 { + cksort {SELECT b FROM collate4t3 ORDER BY b COLLATE NOCASE} +} {{} a B sort} + +do_test collate4-1.1.21 { + execsql { + CREATE TABLE collate4t4(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t4 VALUES( 'a', 'a' ); + INSERT INTO collate4t4 VALUES( 'b', 'b' ); + INSERT INTO collate4t4 VALUES( NULL, NULL ); + INSERT INTO collate4t4 VALUES( 'B', 'B' ); + INSERT INTO collate4t4 VALUES( 'A', 'A' ); + CREATE INDEX collate4i3 ON collate4t4(a COLLATE TEXT); + CREATE INDEX collate4i4 ON collate4t4(b COLLATE NOCASE); + } +} {} +do_test collate4-1.1.22 { + cksort {SELECT a FROM collate4t4 ORDER BY a, rowid} +} {{} a A b B sort} +do_test collate4-1.1.23 { + cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE NOCASE, rowid} +} {{} a A b B sort} +do_test collate4-1.1.24 { + cksort {SELECT a FROM collate4t4 ORDER BY a COLLATE TEXT, rowid} +} {{} A B a b nosort} +do_test collate4-1.1.25 { + cksort {SELECT b FROM collate4t4 ORDER BY b} +} {{} A B a b sort} +do_test collate4-1.1.26 { + cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE TEXT} +} {{} A B a b sort} +do_test collate4-1.1.27 { + cksort {SELECT b FROM collate4t4 ORDER BY b COLLATE NOCASE} +} {{} a A b B nosort} + +do_test collate4-1.1.30 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + DROP TABLE collate4t3; + DROP TABLE collate4t4; + } +} {} + +do_test collate4-1.2.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t1 VALUES( 'a', 'a' ); + INSERT INTO collate4t1 VALUES( 'b', 'b' ); + INSERT INTO collate4t1 VALUES( NULL, NULL ); + INSERT INTO collate4t1 VALUES( 'B', 'B' ); + INSERT INTO collate4t1 VALUES( 'A', 'A' ); + CREATE INDEX collate4i1 ON collate4t1(a, b); + } +} {} +do_test collate4-1.2.1 { + cksort {SELECT a FROM collate4t1 ORDER BY a} +} {{} A a B b nosort} +do_test collate4-1.2.2 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE nocase} +} {{} A a B b nosort} +do_test collate4-1.2.3 { + cksort {SELECT a FROM collate4t1 ORDER BY a COLLATE text} +} {{} A B a b sort} +do_test collate4-1.2.4 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b} +} {{} A a B b nosort} +do_test collate4-1.2.5 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE nocase, rowid} +} {{} a A b B sort} +do_test collate4-1.2.6 { + cksort {SELECT a FROM collate4t1 ORDER BY a, b COLLATE text} +} {{} A a B b nosort} + +do_test collate4-1.2.7 { + execsql { + CREATE TABLE collate4t2( + a COLLATE NOCASE, + b COLLATE TEXT, + PRIMARY KEY(a, b) + ); + INSERT INTO collate4t2 VALUES( 'a', 'a' ); + INSERT INTO collate4t2 VALUES( NULL, NULL ); + INSERT INTO collate4t2 VALUES( 'B', 'B' ); + } +} {} +do_test collate4-1.2.8 { + cksort {SELECT a FROM collate4t2 ORDER BY a} +} {{} a B nosort} +do_test collate4-1.2.9 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE nocase} +} {{} a B nosort} +do_test collate4-1.2.10 { + cksort {SELECT a FROM collate4t2 ORDER BY a COLLATE text} +} {{} B a sort} +do_test collate4-1.2.11 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b} +} {{} a B nosort} +do_test collate4-1.2.12 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE nocase} +} {{} a B sort} +do_test collate4-1.2.13 { + cksort {SELECT a FROM collate4t2 ORDER BY a, b COLLATE text} +} {{} a B nosort} + +do_test collate4-1.2.14 { + execsql { + CREATE TABLE collate4t3(a COLLATE NOCASE, b COLLATE TEXT); + INSERT INTO collate4t3 VALUES( 'a', 'a' ); + INSERT INTO collate4t3 VALUES( 'b', 'b' ); + INSERT INTO collate4t3 VALUES( NULL, NULL ); + INSERT INTO collate4t3 VALUES( 'B', 'B' ); + INSERT INTO collate4t3 VALUES( 'A', 'A' ); + CREATE INDEX collate4i2 ON collate4t3(a COLLATE TEXT, b COLLATE NOCASE); + } +} {} +do_test collate4-1.2.15 { + cksort {SELECT a FROM collate4t3 ORDER BY a, rowid} +} {{} a A b B sort} +do_test collate4-1.2.16 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE nocase, rowid} +} {{} a A b B sort} +do_test collate4-1.2.17 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text} +} {{} A B a b nosort} +do_test collate4-1.2.18 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b} +} {{} A B a b sort} +do_test collate4-1.2.19 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE nocase} +} {{} A B a b nosort} +do_test collate4-1.2.20 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text, b COLLATE text} +} {{} A B a b sort} +do_test collate4-1.2.21 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC} +} {b a B A {} nosort} +do_test collate4-1.2.22 { + cksort {SELECT a FROM collate4t3 ORDER BY a COLLATE text DESC, b} +} {b a B A {} sort} +do_test collate4-1.2.23 { + cksort {SELECT a FROM collate4t3 + ORDER BY a COLLATE text DESC, b COLLATE nocase} +} {b a B A {} sort} +do_test collate4-1.2.24 { + cksort {SELECT a FROM collate4t3 + ORDER BY a COLLATE text DESC, b COLLATE nocase DESC} +} {b a B A {} nosort} + +do_test collate4-1.2.25 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + DROP TABLE collate4t3; + } +} {} + +# +# These tests - collate4-2.* - check that indices are correctly +# selected or not selected to implement WHERE clauses when user +# defined collation sequences are involved. +# +# Indices may optimise WHERE clauses using <, >, <=, >=, = or IN +# operators. +# +do_test collate4-2.1.0 { + execsql { + PRAGMA automatic_index=OFF; + CREATE TABLE collate4t1(a COLLATE NOCASE); + CREATE TABLE collate4t2(b COLLATE TEXT); + + INSERT INTO collate4t1 VALUES('a'); + INSERT INTO collate4t1 VALUES('A'); + INSERT INTO collate4t1 VALUES('b'); + INSERT INTO collate4t1 VALUES('B'); + INSERT INTO collate4t1 VALUES('c'); + INSERT INTO collate4t1 VALUES('C'); + INSERT INTO collate4t1 VALUES('d'); + INSERT INTO collate4t1 VALUES('D'); + INSERT INTO collate4t1 VALUES('e'); + INSERT INTO collate4t1 VALUES('D'); + + INSERT INTO collate4t2 VALUES('A'); + INSERT INTO collate4t2 VALUES('Z'); + } +} {} +do_test collate4-2.1.1 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b; + } +} {A a A A 19} +do_test collate4-2.1.2 { + execsql { + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b; + } +} {A a A A 4} +do_test collate4-2.1.3 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE b = a; + } +} {A A 19} +do_test collate4-2.1.4 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT); + } + count { + SELECT * FROM collate4t2, collate4t1 WHERE a = b + ORDER BY collate4t2.rowid, collate4t1.rowid + } +} {A a A A 19} +do_test collate4-2.1.5 { + count { + SELECT * FROM collate4t2, collate4t1 WHERE b = a; + } +} {A A 3} +ifcapable subquery { + do_test collate4-2.1.6 { + count { + SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2) + ORDER BY rowid + } + } {a A 10} + do_test collate4-2.1.7 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT a FROM collate4t1 WHERE a IN (SELECT * FROM collate4t2) + ORDER BY rowid + } + } {a A 5} + do_test collate4-2.1.8 { + count { + SELECT a FROM collate4t1 WHERE a IN ('z', 'a'); + } + } {a A 4} + do_test collate4-2.1.9 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE TEXT); + } + count { + SELECT a FROM collate4t1 WHERE a IN ('z', 'a') ORDER BY rowid; + } + } {a A 9} +} +do_test collate4-2.1.10 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + } +} {} + +do_test collate4-2.2.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE nocase, b COLLATE text, c); + CREATE TABLE collate4t2(a COLLATE nocase, b COLLATE text, c COLLATE TEXT); + + INSERT INTO collate4t1 VALUES('0', '0', '0'); + INSERT INTO collate4t1 VALUES('0', '0', '1'); + INSERT INTO collate4t1 VALUES('0', '1', '0'); + INSERT INTO collate4t1 VALUES('0', '1', '1'); + INSERT INTO collate4t1 VALUES('1', '0', '0'); + INSERT INTO collate4t1 VALUES('1', '0', '1'); + INSERT INTO collate4t1 VALUES('1', '1', '0'); + INSERT INTO collate4t1 VALUES('1', '1', '1'); + insert into collate4t2 SELECT * FROM collate4t1; + } +} {} +do_test collate4-2.2.1 { + count { + SELECT * FROM collate4t2 NOT INDEXED NATURAL JOIN collate4t1 NOT INDEXED; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 63} +do_test collate4-2.2.1b { + execsql { + CREATE INDEX collate4i1 ON collate4t1(a, b, c); + } + count { + SELECT * FROM collate4t2 NATURAL JOIN collate4t1; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 29} +do_test collate4-2.2.2 { + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a, b, c COLLATE text); + } + count { + SELECT * FROM collate4t2 NATURAL JOIN collate4t1; + } +} {0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 22} + +do_test collate4-2.2.10 { + execsql { + DROP TABLE collate4t1; + DROP TABLE collate4t2; + } +} {} + +# +# These tests - collate4-3.* verify that indices that implement +# UNIQUE and PRIMARY KEY constraints operate correctly with user +# defined collation sequences. +# +do_test collate4-3.0 { + execsql { + CREATE TABLE collate4t1(a PRIMARY KEY COLLATE NOCASE); + } +} {} +do_test collate4-3.1 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.2 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.3 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.4 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.5 { + execsql { + DROP TABLE collate4t1; + CREATE TABLE collate4t1(a COLLATE NOCASE UNIQUE); + } +} {} +do_test collate4-3.6 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.7 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.8 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.9 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.10 { + execsql { + DROP TABLE collate4t1; + CREATE TABLE collate4t1(a); + CREATE UNIQUE INDEX collate4i1 ON collate4t1(a COLLATE NOCASE); + } +} {} +do_test collate4-3.11 { + catchsql { + INSERT INTO collate4t1 VALUES('abc'); + INSERT INTO collate4t1 VALUES('ABC'); + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.12 { + execsql { + SELECT * FROM collate4t1; + } +} {abc} +do_test collate4-3.13 { + catchsql { + INSERT INTO collate4t1 SELECT upper(a) FROM collate4t1; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} +do_test collate4-3.14 { + catchsql { + INSERT INTO collate4t1 VALUES(1); + UPDATE collate4t1 SET a = 'abc'; + } +} {1 {UNIQUE constraint failed: collate4t1.a}} + +do_test collate4-3.15 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# Mimic the SQLite 2 collation type NUMERIC. +db collate numeric numeric_collate +proc numeric_collate {lhs rhs} { + if {$lhs == $rhs} {return 0} + return [expr ($lhs>$rhs)?1:-1] +} + +# +# These tests - collate4-4.* check that min() and max() only ever +# use indices constructed with built-in collation type numeric. +# +# CHANGED: min() and max() now use the collation type. If there +# is an indice that can be used, it is used. +# +do_test collate4-4.0 { + execsql { + CREATE TABLE collate4t1(a COLLATE TEXT); + INSERT INTO collate4t1 VALUES('2'); + INSERT INTO collate4t1 VALUES('10'); + INSERT INTO collate4t1 VALUES('20'); + INSERT INTO collate4t1 VALUES('104'); + } +} {} +do_test collate4-4.1 { + count { + SELECT max(a) FROM collate4t1 + } +} {20 3} +do_test collate4-4.2 { + count { + SELECT min(a) FROM collate4t1 + } +} {10 3} +do_test collate4-4.3 { + # Test that the index with collation type TEXT is used. + execsql { + CREATE INDEX collate4i1 ON collate4t1(a); + } + count { + SELECT min(a) FROM collate4t1; + } +} {10 1} +do_test collate4-4.4 { + count { + SELECT max(a) FROM collate4t1; + } +} {20 0} +do_test collate4-4.5 { + # Test that the index with collation type NUMERIC is not used. + execsql { + DROP INDEX collate4i1; + CREATE INDEX collate4i1 ON collate4t1(a COLLATE NUMERIC); + } + count { + SELECT min(a) FROM collate4t1; + } +} {10 3} +do_test collate4-4.6 { + count { + SELECT max(a) FROM collate4t1; + } +} {20 3} +do_test collate4-4.7 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# Also test the scalar min() and max() functions. +# +do_test collate4-4.8 { + execsql { + CREATE TABLE collate4t1(a COLLATE TEXT, b COLLATE NUMERIC); + INSERT INTO collate4t1 VALUES('11', '101'); + INSERT INTO collate4t1 VALUES('101', '11') + } +} {} +do_test collate4-4.9 { + execsql { + SELECT max(a, b) FROM collate4t1; + } +} {11 11} +do_test collate4-4.10 { + execsql { + SELECT max(b, a) FROM collate4t1; + } +} {101 101} +do_test collate4-4.11 { + execsql { + SELECT max(a, '101') FROM collate4t1; + } +} {11 101} +do_test collate4-4.12 { + execsql { + SELECT max('101', a) FROM collate4t1; + } +} {11 101} +do_test collate4-4.13 { + execsql { + SELECT max(b, '101') FROM collate4t1; + } +} {101 101} +do_test collate4-4.14 { + execsql { + SELECT max('101', b) FROM collate4t1; + } +} {101 101} + +do_test collate4-4.15 { + execsql { + DROP TABLE collate4t1; + } +} {} + +# +# These tests - collate4.6.* - ensure that implict INTEGER PRIMARY KEY +# indices do not confuse collation sequences. +# +# These indices are never used for sorting in SQLite. And you can't +# create another index on an INTEGER PRIMARY KEY column, so we don't have +# to test that. +# (Revised 2004-Nov-22): The ROWID can be used for sorting now. +# +do_test collate4-6.0 { + execsql { + CREATE TABLE collate4t1(a INTEGER PRIMARY KEY); + INSERT INTO collate4t1 VALUES(101); + INSERT INTO collate4t1 VALUES(10); + INSERT INTO collate4t1 VALUES(15); + } +} {} +do_test collate4-6.1 { + cksort { + SELECT * FROM collate4t1 ORDER BY 1; + } +} {10 15 101 nosort} +do_test collate4-6.2 { + cksort { + SELECT * FROM collate4t1 ORDER BY oid; + } +} {10 15 101 nosort} +do_test collate4-6.3 { + cksort { + SELECT * FROM collate4t1 ORDER BY oid||'' COLLATE TEXT; + } +} {10 101 15 sort} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate6.test new file mode 100644 index 0000000000000000000000000000000000000000..d238639a5d3771f9fc607018becaefdefcbb34f5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate6.test @@ -0,0 +1,153 @@ +# +# 2001 September 15 +# +# 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. The +# focus of this script is collation sequences in concert with triggers. +# +# $Id: collate6.test,v 1.4 2007/07/30 14:40:48 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# There are no tests in this file that will work without +# trigger support. +# +ifcapable {!trigger} { + finish_test + return +} + +# Create a case-insensitive collation type NOCASE for use in testing. +# Normally, capital letters are less than their lower-case counterparts. +db collate NOCASE nocase_collate +proc nocase_collate {a b} { + return [string compare -nocase $a $b] +} + +# +# Tests are organized as follows: +# collate6-1.* - triggers. +# + +do_test collate6-1.0 { + execsql { + CREATE TABLE collate6log(a, b); + CREATE TABLE collate6tab(a COLLATE NOCASE, b COLLATE BINARY); + } +} {} + +# Test that the default collation sequence applies to new.* references +# in WHEN clauses. +do_test collate6-1.1 { + execsql { + CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab + WHEN new.a = 'a' BEGIN + INSERT INTO collate6log VALUES(new.a, new.b); + END; + } +} {} +do_test collate6-1.2 { + execsql { + INSERT INTO collate6tab VALUES('a', 'b'); + SELECT * FROM collate6log; + } +} {a b} +do_test collate6-1.3 { + execsql { + INSERT INTO collate6tab VALUES('A', 'B'); + SELECT * FROM collate6log; + } +} {a b A B} +do_test collate6-1.4 { + execsql { + DROP TRIGGER collate6trig; + DELETE FROM collate6log; + } +} {} + +# Test that the default collation sequence applies to new.* references +# in the body of triggers. +do_test collate6-1.5 { + execsql { + CREATE TRIGGER collate6trig BEFORE INSERT ON collate6tab BEGIN + INSERT INTO collate6log VALUES(new.a='a', new.b='b'); + END; + } +} {} +do_test collate6-1.6 { + execsql { + INSERT INTO collate6tab VALUES('a', 'b'); + SELECT * FROM collate6log; + } +} {1 1} +do_test collate6-1.7 { + execsql { + INSERT INTO collate6tab VALUES('A', 'B'); + SELECT * FROM collate6log; + } +} {1 1 1 0} +do_test collate6-1.8 { + execsql { + DROP TRIGGER collate6trig; + DELETE FROM collate6log; + } +} {} + +do_test collate6-1.9 { + execsql { + DROP TABLE collate6tab; + } +} {} + +# Test that an explicit collation sequence overrides an implicit +# one attached to a 'new' reference. +# +do_test collate6-2.1 { + execsql { + CREATE TABLE abc(a COLLATE binary, b, c); + CREATE TABLE def(a, b, c); + CREATE TRIGGER abc_t1 AFTER INSERT ON abc BEGIN + INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase; + END + } +} {} +do_test collate6-2.2 { + execsql { + INSERT INTO abc VALUES('One', 'Two', 'Three'); + INSERT INTO abc VALUES('one', 'two', 'three'); + SELECT * FROM def; + } +} {} +do_test collate6-2.3 { + execsql { + UPDATE abc SET a = 'four' WHERE a = 'one'; + CREATE TRIGGER abc_t2 AFTER UPDATE ON abc BEGIN + INSERT INTO def SELECT * FROM abc WHERE a < new.a COLLATE nocase; + END; + SELECT * FROM def; + } +} {} + +# At one point the 6-3.2 (but not 6-3.1) was causing an assert() to fail. +# +do_test collate6-3.1 { + execsql { + SELECT 1 FROM sqlite_master WHERE name COLLATE nocase = 'hello'; + } +} {} +do_test collate6-3.2 { + execsql { + SELECT 1 FROM sqlite_master WHERE 'hello' = name COLLATE nocase; + } +} {} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate7.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate7.test new file mode 100644 index 0000000000000000000000000000000000000000..da97491ece19d099f11cab4be31ea1de7e952912 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate7.test @@ -0,0 +1,72 @@ +# +# 2007 May 7 +# +# 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. The +# focus of this script is the experimental sqlite3_create_collation_v2() +# API. +# +# $Id: collate7.test,v 1.2 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::caseless_del 0 +proc caseless_cmp {zLeft zRight} { + string compare -nocase $zLeft $zRight +} + +do_test collate7-1.1 { + set cmd [list incr ::caseless_del] + sqlite3_create_collation_v2 db CASELESS caseless_cmp $cmd + set ::caseless_del +} {0} +do_test collate7-1.2 { + sqlite_delete_collation db CASELESS + set ::caseless_del +} {1} +do_test collate7-1.3 { + catchsql { + CREATE TABLE abc(a COLLATE CASELESS, b, c); + } +} {1 {no such collation sequence: CASELESS}} +do_test collate7-1.4 { + sqlite3_create_collation_v2 db CASELESS caseless_cmp {incr ::caseless_del} + db close + set ::caseless_del +} {2} + +do_test collate7-2.1 { + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_create_collation_v2 db CASELESS caseless_cmp {incr ::caseless_del} + execsql { + PRAGMA encoding='utf-16'; + CREATE TABLE abc16(a COLLATE CASELESS, b, c); + } db + set ::caseless_del +} {2} +do_test collate7-2.2 { + execsql { + SELECT * FROM abc16 WHERE a < 'abc'; + } + set ::caseless_del +} {2} +do_test collate7-2.3 { + sqlite_delete_collation db CASELESS + set ::caseless_del +} {3} +do_test collate7-2.4 { + catchsql { + SELECT * FROM abc16 WHERE a < 'abc'; + } +} {1 {no such collation sequence: CASELESS}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collate9.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate9.test new file mode 100644 index 0000000000000000000000000000000000000000..5a07773a1ce2fbf999c29b290ac52badb43bed87 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collate9.test @@ -0,0 +1,178 @@ +# +# 2007 November 12 +# +# 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. The +# focus of this script is making sure that the names of collation +# sequences may be quoted using double quotes in SQL statements. +# +# $Id: collate9.test,v 1.2 2008/07/10 00:32:42 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc reverse_sort {lhs rhs} { + return [string compare $rhs $lhs] +} +db collate "reverse sort" reverse_sort + +# This procedure executes the SQL. Then it checks to see if the OP_Sort +# opcode was executed. If an OP_Sort did occur, then "sort" is appended +# to the result. If no OP_Sort happened, then "nosort" is appended. +# +# This procedure is used to check to make sure sorting is or is not +# occurring as expected. +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# Test plan: +# +# collate9-1.* - Test collation sequences attached to table columns +# collate9-2.* - Test collation sequences attached to expressions +# collate9-3.* - Test collation sequences attached to an index +# collate9-4.* - Test collation sequences as an argument to REINDEX +# + +do_test collate9-1.1 { + execsql { + CREATE TABLE xy(x COLLATE "reverse sort", y COLLATE binary); + INSERT INTO xy VALUES('one', 'one'); + INSERT INTO xy VALUES('two', 'two'); + INSERT INTO xy VALUES('three', 'three'); + } +} {} +do_test collate9-1.2 { + execsql { + SELECT x FROM xy ORDER BY x + } +} {two three one} +do_test collate9-1.3 { + execsql { + SELECT y FROM xy ORDER BY y + } +} {one three two} +do_test collate9-1.4 { + cksort { + SELECT x FROM xy ORDER BY x + } +} {two three one sort} +do_test collate9-1.5 { + execsql { + CREATE INDEX xy_i ON xy(x) + } +} {} +do_test collate9-1.6 { + cksort { + SELECT x FROM xy ORDER BY x + } +} {two three one nosort} + +do_test collate9-2.1 { + execsql { + SELECT x, x < 'seven' FROM xy ORDER BY x + } +} {two 1 three 1 one 0} +do_test collate9-2.2 { + execsql { + SELECT y, y < 'seven' FROM xy ORDER BY x + } +} {two 0 three 0 one 1} +do_test collate9-2.3 { + execsql { + SELECT y, y COLLATE "reverse sort" < 'seven' FROM xy ORDER BY x + } +} {two 1 three 1 one 0} +do_test collate9-2.4 { + execsql { + SELECT y FROM xy ORDER BY y + } +} {one three two} +do_test collate9-2.5 { + execsql { + SELECT y FROM xy ORDER BY y COLLATE "reverse sort" + } +} {two three one} +do_test collate9-2.6 { + execsql { + SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa + } +} {two three one} + +do_test collate9-3.1 { + execsql { + CREATE INDEX xy_i2 ON xy(y COLLATE "reverse sort"); + } +} {} +do_test collate9-3.2 { + cksort { + SELECT y FROM xy ORDER BY y + } +} {one three two sort} +do_test collate9-3.3 { + cksort { + SELECT y FROM xy ORDER BY y COLLATE "reverse sort" + } +} {two three one nosort} +do_test collate9-3.4 { + cksort { + SELECT y AS aaa FROM xy ORDER BY aaa + } +} {one three two sort} +do_test collate9-3.5 { + cksort { + SELECT y COLLATE "reverse sort" AS aaa FROM xy ORDER BY aaa + } +} {two three one nosort} + +ifcapable reindex { + do_test collate9-4.1 { + execsql { + REINDEX "reverse sort" + } + } {} + + # Modify the "reverse sort" collation so that it now sorts in the same + # order as binary. + proc reverse_sort {lhs rhs} { + return [string compare $lhs $rhs] + } + + # The integrity check should now fail because the indexes created using + # "reverse sort" are no longer in sync with the collation sequence + # implementation. + do_test collate9-4.2 { + expr {"ok" eq [execsql { PRAGMA integrity_check }]} + } {0} + + do_test collate9-4.3 { + execsql { + REINDEX "reverse sort" + } + } {} + + # Integrity check should now pass. + do_test collate9-4.4 { + expr {"ok" eq [execsql { PRAGMA integrity_check }]} + } {1} + + do_test collate9-4.5 { + cksort { + SELECT x FROM xy ORDER BY x COLLATE "reverse sort" + } + } {one three two nosort} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collateA.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collateA.test new file mode 100644 index 0000000000000000000000000000000000000000..3f7ebd9242fa7bfcc1270af3d5cb31051bcf464d --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collateA.test @@ -0,0 +1,217 @@ +# +# 2008 January 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the built-in RTRIM collating +# API. +# +# $Id: collateA.test,v 1.3 2008/04/15 04:02:41 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_test collateA-1.1 { + execsql { + CREATE TABLE t1( + a INTEGER PRIMARY KEY, + b TEXT COLLATE BINARY, + c TEXT COLLATE RTRIM + ); + INSERT INTO t1 VALUES(1, 'abcde','abcde'); + INSERT INTO t1 VALUES(2, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(3, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(4, 'xyzzy ','xyzzy '); + INSERT INTO t1 VALUES(5, ' ', ' '); + INSERT INTO t1 VALUES(6, '', ''); + SELECT count(*) FROM t1; + } +} {6} +do_test collateA-1.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-1.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-1.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-1.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-1.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-1.11 { + execsql {SELECT 'abc123'='abc123 ' COLLATE RTRIM;} +} {1} +do_test collateA-1.12 { + execsql {SELECT 'abc123 '='abc123' COLLATE RTRIM;} +} {1} +do_test collateA-1.13 { + execsql {SELECT ' '='' COLLATE RTRIM, ' '='' COLLATE BINARY, ' '=''} +} {1 0 0} +do_test collateA-1.14 { + execsql {SELECT ''=' ' COLLATE RTRIM, ''=' ' COLLATE BINARY, ''=' '} +} {1 0 0} +do_test collateA-1.15 { + execsql {SELECT ' '=' ' COLLATE RTRIM, ' '=' '} +} {1 0} +do_test collateA-1.16 { + execsql {SELECT ''<>' ' COLLATE RTRIM, ''<>' ' COLLATE BINARY, ''<>' '} +} {0 1 1} +do_test collateA-1.17 { + execsql {SELECT a FROM t1 WHERE c='xyzz'} +} {} +do_test collateA-1.18 { + execsql {SELECT a FROM t1 WHERE c='xyzzyy '} +} {} +do_test collateA-1.19 { + execsql {SELECT a FROM t1 WHERE c='xyzz '} +} {} +do_test collateA-1.20 { + execsql {SELECT a FROM t1 WHERE c='abcd '} +} {} +do_test collateA-1.21 { + execsql {SELECT a FROM t1 WHERE c='abcd'} +} {} +do_test collateA-1.22 { + execsql {SELECT a FROM t1 WHERE c='abc'} +} {} +do_test collateA-1.23 { + execsql {SELECT a FROM t1 WHERE c='abcdef '} +} {} +do_test collateA-1.24 { + execsql {SELECT a FROM t1 WHERE c=''} +} {5 6} +do_test collateA-1.25 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} +do_test collateA-1.26 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} + + +do_test collateA-2.1 { + execsql { + CREATE INDEX i1b ON t1(b); + CREATE INDEX i1c ON t1(c); + PRAGMA integrity_check; + } +} {ok} +do_test collateA-2.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-2.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-2.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-2.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-2.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-2.17 { + execsql {SELECT a FROM t1 WHERE c='xyzz'} +} {} +do_test collateA-2.18 { + execsql {SELECT a FROM t1 WHERE c='xyzzyy '} +} {} +do_test collateA-2.19 { + execsql {SELECT a FROM t1 WHERE c='xyzz '} +} {} +do_test collateA-2.20 { + execsql {SELECT a FROM t1 WHERE c='abcd '} +} {} +do_test collateA-2.21 { + execsql {SELECT a FROM t1 WHERE c='abcd'} +} {} +do_test collateA-2.22 { + execsql {SELECT a FROM t1 WHERE c='abc'} +} {} +do_test collateA-2.23 { + execsql {SELECT a FROM t1 WHERE c='abcdef '} +} {} +do_test collateA-2.24 { + execsql {SELECT a FROM t1 WHERE c=''} +} {5 6} +do_test collateA-2.25 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} +do_test collateA-2.26 { + execsql {SELECT a FROM t1 WHERE c=' '} +} {5 6} + + +do_test collateA-3.1 { + db close + sqlite3 db test.db + execsql { + REINDEX; + PRAGMA integrity_check; + } +} {ok} +do_test collateA-3.2 { + execsql {SELECT a FROM t1 WHERE b='abcde '} +} {} +do_test collateA-3.3 { + execsql {SELECT a FROM t1 WHERE c='abcde '} +} {1} +do_test collateA-3.4 { + execsql {SELECT a FROM t1 WHERE b='xyzzy'} +} {} +do_test collateA-3.5 { + execsql {SELECT a FROM t1 WHERE c='xyzzy'} +} {2 3 4} +do_test collateA-3.6 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.7 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.8 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.9 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} +do_test collateA-3.10 { + execsql {SELECT a FROM t1 WHERE c='xyzzy '} +} {2 3 4} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/collateB.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/collateB.test new file mode 100644 index 0000000000000000000000000000000000000000..3c8d50d8e6dac18f3f3894c9fa10f60ac5d862a5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/collateB.test @@ -0,0 +1,77 @@ +# 2016-07-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. +# +#*********************************************************************** +# Test cases for a crash bug. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix collateB + +do_execsql_test collateB-1.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY); + CREATE TABLE t2(b INTEGER PRIMARY KEY, x1 INT COLLATE NOCASE); + CREATE TABLE t3(x2 INT); + SELECT * FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1; +} {} +do_execsql_test collateB-1.2 { + INSERT INTO t1(a) VALUES(1),(2),(3); + INSERT INTO t2(b,x1) VALUES(11,1),(22,2),(33,3); + INSERT INTO t3(x2) VALUES(11),(22),(33); + SELECT *,'|' FROM t3, t2, t1 WHERE x2=b AND x1=a AND a=1; +} {11 11 1 1 |} +do_execsql_test collateB-1.3 { + SELECT *,'|' FROM t3, t1, t2 WHERE x2=b AND x1=a AND a=1; +} {11 1 11 1 |} +do_execsql_test collateB-1.4 { + SELECT *,'|' FROM t2, t3, t1 WHERE x2=b AND x1=a AND a=1; +} {11 1 11 1 |} +do_execsql_test collateB-1.5 { + SELECT *,'|' FROM t2, t1, t3 WHERE x2=b AND x1=a AND a=1; +} {11 1 1 11 |} +do_execsql_test collateB-1.6 { + SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1; +} {1 11 1 11 |} +do_execsql_test collateB-1.7 { + SELECT *,'|' FROM t1, t2, t3 WHERE x2=b AND x1=a AND a=1; +} {1 11 1 11 |} +do_execsql_test collateB-1.12 { + SELECT *,'|' FROM t3, t2, t1 WHERE b=x2 AND a=x1 AND 1=a; +} {11 11 1 1 |} +do_execsql_test collateB-1.13 { + SELECT *,'|' FROM t3, t1, t2 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 11 1 |} +do_execsql_test collateB-1.14 { + SELECT *,'|' FROM t2, t3, t1 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 11 1 |} +do_execsql_test collateB-1.15 { + SELECT *,'|' FROM t2, t1, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {11 1 1 11 |} +do_execsql_test collateB-1.16 { + SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {1 11 1 11 |} +do_execsql_test collateB-1.17 { + SELECT *,'|' FROM t1, t2, t3 WHERE b=x2 AND a=x1 AND 1=a; +} {1 11 1 11 |} + +#------------------------------------------------------------------------- +# Test an assert() failure that was occuring if an index were created +# on a column explicitly declared "COLLATE binary". +reset_db +do_execsql_test 2.1 { + CREATE TABLE t4(a COLLATE binary); + CREATE INDEX i4 ON t4(a); + INSERT INTO t4 VALUES('one'), ('two'), ('three'); + VACUUM; +} + +integrity_check 2.2 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/colmeta.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/colmeta.test new file mode 100644 index 0000000000000000000000000000000000000000..21b0e0f38a59ef6de9f3f8f3f184dbd17652c647 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/colmeta.test @@ -0,0 +1,110 @@ +# +# 2006 February 9 +# +# 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. The +# focus of this script is the sqlite3_table_column_metadata() API. +# +# $Id: colmeta.test,v 1.4 2008/01/23 12:52:41 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Set up a schema in the main and temp test databases. +do_test colmeta-0 { + execsql { + CREATE TABLE abc(a, b, c); + CREATE TABLE abc2(a PRIMARY KEY COLLATE NOCASE, b VARCHAR(32), c); + CREATE TABLE abc3(a NOT NULL, b INTEGER PRIMARY KEY, c); + CREATE TABLE abc5(w,x,y,z,PRIMARY KEY(x,z)) WITHOUT ROWID; + CREATE TABLE abc6(rowid TEXT COLLATE rtrim, oid REAL, _rowid_ BLOB); + } + ifcapable autoinc { + execsql { + CREATE TABLE abc4(a, b INTEGER PRIMARY KEY AUTOINCREMENT, c); + } + } + ifcapable view { + execsql { + CREATE VIEW v1 AS SELECT * FROM abc2; + } + } +} {} + + +# Return values are of the form: +# +# { } +# +set tests { + 1 {main abc a} {0 {{} BINARY 0 0 0}} + 2 {{} abc a} {0 {{} BINARY 0 0 0}} + 3 {{} abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}} + 4 {main abc2 b} {0 {VARCHAR(32) BINARY 0 0 0}} + 5 {{} abc2 a} {0 {{} NOCASE 0 1 0}} + 6 {{} abc3 a} {0 {{} BINARY 1 0 0}} + 7 {{} abc3 b} {0 {INTEGER BINARY 0 1 0}} + 13 {main abc rowid} {0 {INTEGER BINARY 0 1 0}} + 14 {main abc3 rowid} {0 {INTEGER BINARY 0 1 0}} + 16 {main abc d} {1 {no such table column: abc.d}} + 20 {main abc5 w} {0 {{} BINARY 0 0 0}} + 21 {main abc5 x} {0 {{} BINARY 1 1 0}} + 22 {main abc5 y} {0 {{} BINARY 0 0 0}} + 23 {main abc5 z} {0 {{} BINARY 1 1 0}} + 24 {main abc5 rowid} {1 {no such table column: abc5.rowid}} + 30 {main abc6 rowid} {0 {TEXT rtrim 0 0 0}} + 31 {main abc6 oid} {0 {REAL BINARY 0 0 0}} + 32 {main abc6 _rowid_} {0 {BLOB BINARY 0 0 0}} +} +ifcapable autoinc { + set tests [concat $tests { + 100 {{} abc4 b} {0 {INTEGER BINARY 0 1 1}} + 101 {main abc4 rowid} {0 {INTEGER BINARY 0 1 1}} + }] +} +ifcapable view { + set tests [concat $tests { + 200 {{} v1 a} {1 {no such table column: v1.a}} + 201 {main v1 b} {1 {no such table column: v1.b}} + 202 {main v1 badname} {1 {no such table column: v1.badname}} + 203 {main v1 rowid} {1 {no such table column: v1.rowid}} + }] +} + +foreach {tn params results} $tests { + set ::DB [sqlite3_connection_pointer db] + + set tstbody [concat sqlite3_table_column_metadata $::DB $params] + do_test colmeta-$tn.1 { + list [catch $tstbody msg] [set msg] + } $results + + db close + sqlite3 db test.db + + set ::DB [sqlite3_connection_pointer db] + set tstbody [concat sqlite3_table_column_metadata $::DB $params] + do_test colmeta-$tn.2 { + list [catch $tstbody msg] [set msg] + } $results +} + +# Calling sqlite3_table_column_metadata with a NULL column name merely +# checks for the existance of the table. +# +do_test colmeta-300 { + catch {sqlite3_table_column_metadata $::DB main xyzzy} res +} {1} +do_test colmeta-301 { + catch {sqlite3_table_column_metadata $::DB main abc} res +} {0} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict.test new file mode 100644 index 0000000000000000000000000000000000000000..ba3ad9b0dd9ca1673b34f1419f99bc280f9d7ab9 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict.test @@ -0,0 +1,891 @@ +# 2002 January 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests for the conflict resolution extension +# to SQLite. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !conflict { + finish_test + return +} + +# Create tables for the first group of tests. +# +do_test conflict-1.0 { + execsql { + CREATE TABLE t1(a, b, c, UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# t3 Number of temporary files created by this test +# +foreach {i cmd t0 t1 t2 t3} { + 1 INSERT 1 {} 1 0 + 2 {INSERT OR IGNORE} 0 3 1 0 + 3 {INSERT OR REPLACE} 0 4 1 0 + 4 REPLACE 0 4 1 0 + 5 {INSERT OR FAIL} 1 {} 1 0 + 6 {INSERT OR ABORT} 1 {} 1 0 + 7 {INSERT OR ROLLBACK} 1 {} {} 0 +} { + do_test conflict-1.$i { + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + set r3 $::sqlite_opentemp_count + list $r0 $r1 $r2 $r3 + } [list $t0 $t1 $t2 $t3] +} + +# Create tables for the first group of tests. +# +do_test conflict-2.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict-2.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +# Create tables for the first group of tests. +# +do_test conflict-3.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)); + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict-3.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-4.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 4 1 + 3 IGNORE INSERT 0 3 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 3 1 + 8 IGNORE {INSERT OR REPLACE} 0 4 1 + 9 FAIL {INSERT OR IGNORE} 0 3 1 + 10 ABORT {INSERT OR REPLACE} 0 4 1 + 11 ROLLBACK {INSERT OR IGNORE } 0 3 1 +} { + do_test conflict-4.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1); + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-5.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the NOT NULL constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 5 1 + 3 IGNORE INSERT 0 {} 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 {} 1 + 8 IGNORE {INSERT OR REPLACE} 0 5 1 + 9 FAIL {INSERT OR IGNORE} 0 {} 1 + 10 ABORT {INSERT OR REPLACE} 0 5 1 + 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1 + 12 {} {INSERT OR IGNORE} 0 {} 1 + 13 {} {INSERT OR REPLACE} 0 5 1 + 14 {} {INSERT OR FAIL} 1 {} 1 + 15 {} {INSERT OR ABORT} 1 {} 1 + 16 {} {INSERT OR ROLLBACK} 1 {} {} +} { + if {$t0} {set t1 {NOT NULL constraint failed: t1.c}} + do_test conflict-5.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); + DELETE FROM t2; + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,NULL); + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict-6.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,1); + INSERT INTO t2 VALUES(2,3,2); + INSERT INTO t2 VALUES(3,4,1); + INSERT INTO t2 VALUES(4,5,4); + SELECT c FROM t2 ORDER BY b; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + } +} {1 2 1 4} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An UPDATE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "b" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t3 +# t3 Number of temporary files for tables +# t4 Number of temporary files for statement journals +# +# Update (2007-08-21): Since temporary table files are now opened lazily, +# and none of the following tests use large quantities of data, t3 is always 0. +# +# Update (2016-03-04): Subjournals now also open lazily, so t4 is also always 0. +# +foreach {i conf1 cmd t0 t1 t2 t3 t4} { + 1 {} UPDATE 1 {6 7 8 9} 1 0 0 + 2 REPLACE UPDATE 0 {7 6 9} 1 0 0 + 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0 + 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0 + 5 ABORT UPDATE 1 {1 2 3 4} 1 0 0 + 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0 + 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0 + 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 0 + 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0 +} { + if {$t0} {set t1 {UNIQUE constraint failed: t1.a}} + if {[info exists TEMP_STORE] && $TEMP_STORE==3} { + set t3 0 + } else { + set t3 [expr {$t3+$t4}] + } + do_test conflict-6.$i { + db close + sqlite3 db test.db + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + execsql {pragma temp_store=file} + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1); + INSERT INTO t1 SELECT * FROM t2; + UPDATE t3 SET x=0; + BEGIN; + $cmd t3 SET x=1; + $cmd t1 SET b=b*2; + $cmd t1 SET a=c+5; + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} + set r2 [execsql {SELECT x FROM t3}] + list $r0 $r1 $r2 $::sqlite_opentemp_count + } [list $t0 $t1 $t2 $t3] +} + +# Test to make sure a lot of IGNOREs don't cause a stack overflow +# +do_test conflict-7.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a unique, b); + } + for {set i 1} {$i<=50} {incr i} { + execsql "INSERT into t1 values($i,[expr {$i+1}]);" + } + execsql { + SELECT count(*), min(a), max(b) FROM t1; + } +} {50 1 51} +do_test conflict-7.2 { + execsql { + PRAGMA count_changes=on; + UPDATE OR IGNORE t1 SET a=1000; + } +} {1} +do_test conflict-7.2.1 { + db changes +} {1} +do_test conflict-7.3 { + execsql { + SELECT b FROM t1 WHERE a=1000; + } +} {2} +do_test conflict-7.4 { + execsql { + SELECT count(*) FROM t1; + } +} {50} +do_test conflict-7.5 { + execsql { + PRAGMA count_changes=on; + UPDATE OR REPLACE t1 SET a=1001; + } +} {50} +do_test conflict-7.5.1 { + db changes +} {50} +do_test conflict-7.6 { + execsql { + SELECT b FROM t1 WHERE a=1001; + } +} {51} +do_test conflict-7.7 { + execsql { + SELECT count(*) FROM t1; + } +} {1} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 50). +do_test conflict-7.7.1 { + db changes +} {50} + +# Make sure the row count is right for rows that are ignored on +# an insert. +# +do_test conflict-8.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,2); + } + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,3); + } +} {1} +do_test conflict-8.1.1 { + db changes +} {1} +do_test conflict-8.2 { + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,4); + } +} {0} +do_test conflict-8.2.1 { + db changes +} {0} +do_test conflict-8.3 { + execsql { + INSERT OR REPLACE INTO t1 VALUES(2,4); + } +} {1} +do_test conflict-8.3.1 { + db changes +} {1} +do_test conflict-8.4 { + execsql { + INSERT OR IGNORE INTO t1 SELECT * FROM t1; + } +} {0} +do_test conflict-8.4.1 { + db changes +} {0} +do_test conflict-8.5 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; + } +} {2} +do_test conflict-8.5.1 { + db changes +} {2} +do_test conflict-8.6 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; + } +} {3} +do_test conflict-8.6.1 { + db changes +} {3} + +integrity_check conflict-8.99 + +do_test conflict-9.1 { + execsql { + PRAGMA count_changes=0; + CREATE TABLE t2( + a INTEGER UNIQUE ON CONFLICT IGNORE, + b INTEGER UNIQUE ON CONFLICT FAIL, + c INTEGER UNIQUE ON CONFLICT REPLACE, + d INTEGER UNIQUE ON CONFLICT ABORT, + e INTEGER UNIQUE ON CONFLICT ROLLBACK + ); + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + SELECT * FROM t3; + } +} {1} +do_test conflict-9.2 { + catchsql { + INSERT INTO t2 VALUES(1,1,1,1,1); + INSERT INTO t2 VALUES(2,2,2,2,2); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.3 { + catchsql { + INSERT INTO t2 VALUES(1,3,3,3,3); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.4 { + catchsql { + UPDATE t2 SET a=a+1 WHERE a=1; + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict-9.5 { + catchsql { + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.6 { + catchsql { + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.7 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.8 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {2} +do_test conflict-9.9 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict-9.10 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {3} +do_test conflict-9.11 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.12 { + catchsql { + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.13 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.14 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {4} +do_test conflict-9.15 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict-9.16 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.17 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict-9.18 { + catchsql { + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict-9.19 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict-9.20 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.21 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict-9.22 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict-9.23 { + catchsql { + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {2 2 2 2 2 3 3 1 3 3}} +do_test conflict-9.24 { + catchsql { + UPDATE t2 SET c=c-1 WHERE c=2; + SELECT * FROM t2; + } +} {0 {2 2 1 2 2}} +do_test conflict-9.25 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {3 3 1 3 3}} +do_test conflict-9.26 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {6} + +do_test conflict-10.1 { + catchsql { + DELETE FROM t1; + BEGIN; + INSERT OR ROLLBACK INTO t1 VALUES(1,2); + INSERT OR ROLLBACK INTO t1 VALUES(1,3); + COMMIT; + } + execsql {SELECT * FROM t1} +} {} +do_test conflict-10.2 { + catchsql { + CREATE TABLE t4(x); + CREATE UNIQUE INDEX t4x ON t4(x); + BEGIN; + INSERT OR ROLLBACK INTO t4 VALUES(1); + INSERT OR ROLLBACK INTO t4 VALUES(1); + COMMIT; + } + execsql {SELECT * FROM t4} +} {} + +# Ticket #1171. Make sure statement rollbacks do not +# damage the database. +# +do_test conflict-11.1 { + execsql { + -- Create a database object (pages 2, 3 of the file) + BEGIN; + CREATE TABLE abc(a UNIQUE, b, c); + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + COMMIT; + } + + + # Set a small cache size so that changes will spill into + # the database file. + execsql { + PRAGMA cache_size = 10; + } + + # Make lots of changes. Because of the small cache, some + # (most?) of these changes will spill into the disk file. + # In other words, some of the changes will not be held in + # cache. + # + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + + # Execute a statement that does a statement rollback due to + # a constraint failure. + # + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + + # Rollback the database. Verify that the state of the ABC table + # is unchanged from the beginning of the transaction. In other words, + # make sure the DELETE on table ABC that occurred within the transaction + # had no effect. + # + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +integrity_check conflict-11.2 + +# Repeat test conflict-11.1 but this time commit. +# +do_test conflict-11.3 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + UPDATE abc SET a=a+1; + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +# Repeat test conflict-11.1 but this time commit. +# +do_test conflict-11.5 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + COMMIT; + SELECT * FROM abc; + } +} {1 2 3 7 8 9} +integrity_check conflict-11.6 + +# Make sure UPDATE OR REPLACE works on tables that have only +# an INTEGER PRIMARY KEY. +# +do_test conflict-12.1 { + execsql { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b text); + INSERT INTO t5 VALUES(1,'one'); + INSERT INTO t5 VALUES(2,'two'); + SELECT * FROM t5 + } +} {1 one 2 two} +do_test conflict-12.2 { + execsql { + UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {1 one 2 two} +do_test conflict-12.3 { + catchsql { + UPDATE t5 SET a=a+1 WHERE a=1; + } +} {1 {UNIQUE constraint failed: t5.a}} +verify_ex_errcode conflict-12.3b SQLITE_CONSTRAINT_PRIMARYKEY +do_test conflict-12.4 { + execsql { + UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {2 one} +do_test conflict-12.5 { + catchsql { + CREATE TABLE t5b(x); + INSERT INTO t5b(rowid, x) VALUES(1,10),(2,11); + UPDATE t5b SET rowid=rowid+1 WHERE x=10; + } +} {1 {UNIQUE constraint failed: t5b.rowid}} +verify_ex_errcode conflict-12.5b SQLITE_CONSTRAINT_ROWID + + +# Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437] +# REPLACE works like ABORT on a CHECK constraint. +# +do_test conflict-13.1 { + execsql { + CREATE TABLE t13(a CHECK(a!=2)); + BEGIN; + REPLACE INTO t13 VALUES(1); + } + catchsql { + REPLACE INTO t13 VALUES(2); + } +} {1 {CHECK constraint failed: a!=2}} +verify_ex_errcode conflict-13.1b SQLITE_CONSTRAINT_CHECK +do_test conflict-13.2 { + execsql { + REPLACE INTO t13 VALUES(3); + COMMIT; + SELECT * FROM t13; + } +} {1 3} + + +# Ticket https://www.sqlite.org/src/tktview/e6f1f2e34dceeb1ed61531c7e9 +# Verify that it is not possible to sneak a NULL value into a NOT NULL +# column using REPLACE. +# +do_catchsql_test conflict-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x NOT NULL DEFAULT NULL); + REPLACE INTO t1 DEFAULT VALUES; +} {1 {NOT NULL constraint failed: t1.x}} + +# 2019-12-15 gramfuzz1 find +# Three UNIQUE constraints, where the third would is a duplicate except +# that it adds ON CONFLICT REPLACE. Verify that the indexes end up +# sorted in the correct order (REPLACE last) so that constraint processing +# works correctly. +# +reset_db +do_execsql_test conflict-15.10 { + CREATE TABLE t1( + x PRIMARY KEY, + UNIQUE(x,x), + UNIQUE(x,x) ON CONFLICT REPLACE + ); + INSERT INTO t1(x) VALUES(1); + SELECT * FROM t1; +} {1} +do_catchsql_test conflict-15.20 { + INSERT INTO t1(x) VALUES(1); +} {1 {UNIQUE constraint failed: t1.x}} +do_execsql_test conflict-15.30 { + SELECT * FROM t1; +} {1} + +# 2023-01-16 https://sqlite.org/forum/forumpost/aa580a5af38a58e3 +# The parser accepts an ON CONFLICT clause on table CHECK constraints +# but not on column CHECK constraints. But the CHECK constraint is +# ignored. It has been like this since version 3.0.0. +# +# There might be applications and/or databases in the wild that have +# table CHECK constraints with ON CONFLICT clauses. In as much as this +# is a harmless quirk, we continue to support it in order to avoid +# breaking those legacy applications and databases. +# +reset_db +do_catchsql_test conflict-16.1 { + -- ON CONFLICT clauses are not allowed on column CHECK constraints + CREATE TABLE t1(a INT CHECK( a!=5 ) ON CONFLICT ignore); +} {1 {near "ON": syntax error}} +do_execsql_test conflict-16.2 { + -- ON CONFLICT is allowed on table CHECK constraints + CREATE TABLE t1(a INT, CHECK( a!=5 ) ON CONFLICT ignore); +} {} +do_catchsql_test conflict-16.3 { + -- The ON CONFLICT clause is in-op + INSERT INTO t1(a) VALUES(4),(5),(6); +} {1 {CHECK constraint failed: a!=5}} +do_execsql_test conflict-16.4 { + SELECT a FROM t1 ORDER BY a; +} {} +do_execsql_test conflict-16.5 { + INSERT OR IGNORE INTO t1(a) VALUES(4),(5),(6); + SELECT a FROM t1 ORDER BY a; +} {4 6} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict2.test new file mode 100644 index 0000000000000000000000000000000000000000..96289d38cad3a4a834111fe3da1733dc7d089e06 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict2.test @@ -0,0 +1,858 @@ +# 2013-11-04 +# +# 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. +# +# This file implements tests for the conflict resolution extension +# in WITHOUT ROWID tables +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !conflict { + finish_test + return +} + +# Create tables for the first group of tests. +# +do_test conflict2-1.0 { + execsql { + CREATE TABLE t1(a, b, c, PRIMARY KEY(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# t3 Number of temporary files created by this test +# +foreach {i cmd t0 t1 t2 t3} { + 1 INSERT 1 {} 1 0 + 2 {INSERT OR IGNORE} 0 3 1 0 + 3 {INSERT OR REPLACE} 0 4 1 0 + 4 REPLACE 0 4 1 0 + 5 {INSERT OR FAIL} 1 {} 1 0 + 6 {INSERT OR ABORT} 1 {} 1 0 + 7 {INSERT OR ROLLBACK} 1 {} {} 0 +} { + do_test conflict2-1.$i { + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + set r3 $::sqlite_opentemp_count + list $r0 $r1 $r2 $r3 + } [list $t0 $t1 $t2 $t3] +} + +# Create tables for the first group of tests. +# +do_test conflict2-2.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict2-2.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +# Create tables for the first group of tests. +# +do_test conflict2-3.0 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)) WITHOUT rowid; + CREATE TABLE t2(x); + SELECT c FROM t1 ORDER BY c; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i cmd t0 t1 t2} { + 1 INSERT 1 {} 1 + 2 {INSERT OR IGNORE} 0 3 1 + 3 {INSERT OR REPLACE} 0 4 1 + 4 REPLACE 0 4 1 + 5 {INSERT OR FAIL} 1 {} 1 + 6 {INSERT OR ABORT} 1 {} 1 + 7 {INSERT OR ROLLBACK} 1 {} {} +} { + do_test conflict2-3.$i { + set r0 [catch {execsql [subst { + DELETE FROM t1; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-4.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 4 1 + 3 IGNORE INSERT 0 3 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 3 1 + 8 IGNORE {INSERT OR REPLACE} 0 4 1 + 9 FAIL {INSERT OR IGNORE} 0 3 1 + 10 ABORT {INSERT OR REPLACE} 0 4 1 + 11 ROLLBACK {INSERT OR IGNORE } 0 3 1 +} { + do_test conflict2-4.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c,PRIMARY KEY(a,b) $conf1) WITHOUT rowid; + DELETE FROM t2; + INSERT INTO t1 VALUES(1,2,3); + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,4); + }]} r1] + catch {execsql {COMMIT}} + if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-5.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(x); + SELECT x FROM t2; + } +} {} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the NOT NULL constraint +# cmd An INSERT or REPLACE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "c" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t2 +# +foreach {i conf1 cmd t0 t1 t2} { + 1 {} INSERT 1 {} 1 + 2 REPLACE INSERT 0 5 1 + 3 IGNORE INSERT 0 {} 1 + 4 FAIL INSERT 1 {} 1 + 5 ABORT INSERT 1 {} 1 + 6 ROLLBACK INSERT 1 {} {} + 7 REPLACE {INSERT OR IGNORE} 0 {} 1 + 8 IGNORE {INSERT OR REPLACE} 0 5 1 + 9 FAIL {INSERT OR IGNORE} 0 {} 1 + 10 ABORT {INSERT OR REPLACE} 0 5 1 + 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1 + 12 {} {INSERT OR IGNORE} 0 {} 1 + 13 {} {INSERT OR REPLACE} 0 5 1 + 14 {} {INSERT OR FAIL} 1 {} 1 + 15 {} {INSERT OR ABORT} 1 {} 1 + 16 {} {INSERT OR ROLLBACK} 1 {} {} +} { + if {$t0} {set t1 {NOT NULL constraint failed: t1.c}} + do_test conflict2-5.$i { + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); + DELETE FROM t2; + BEGIN; + INSERT INTO t2 VALUES(1); + $cmd INTO t1 VALUES(1,2,NULL); + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} + set r2 [execsql {SELECT x FROM t2}] + list $r0 $r1 $r2 + } [list $t0 $t1 $t2] +} + +do_test conflict2-6.0 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(a,b,c); + INSERT INTO t2 VALUES(1,2,1); + INSERT INTO t2 VALUES(2,3,2); + INSERT INTO t2 VALUES(3,4,1); + INSERT INTO t2 VALUES(4,5,4); + SELECT c FROM t2 ORDER BY b; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + } +} {1 2 1 4} + +# Six columns of configuration data as follows: +# +# i The reference number of the test +# conf1 The conflict resolution algorithm on the UNIQUE constraint +# cmd An UPDATE command to execute against table t1 +# t0 True if there is an error from $cmd +# t1 Content of "b" column of t1 assuming no error in $cmd +# t2 Content of "x" column of t3 +# t3 Number of temporary files for tables +# t4 Number of temporary files for statement journals +# +# Update: Since temporary table files are now opened lazily, and none +# of the following tests use large quantities of data, t3 is always 0. +# +# Update (2016-03-04): Subjournals now only open when their size +# exceeds 64KB. +# +foreach {i conf1 cmd t0 t1 t2 t3 t4} { + 1 {} UPDATE 1 {6 7 8 9} 1 0 0 + 2 REPLACE UPDATE 0 {7 6 9} 1 0 0 + 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0 + 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0 + 5 ABORT UPDATE 1 {1 2 3 4} 1 0 0 + 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0 + 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0 + 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0 + 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0 + 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 0 + 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0 +} { + + # When using in-memory journals, no temporary files are required for + # statement journals. + if {[permutation] == "inmemory_journal"} { set t4 0 } + + if {$t0} {set t1 {UNIQUE constraint failed: t1.a}} + if {[info exists TEMP_STORE] && $TEMP_STORE==3} { + set t3 0 + } else { + set t3 [expr {$t3+$t4}] + } + do_test conflict2-6.$i { + db close + sqlite3 db test.db + if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} + execsql {pragma temp_store=file} + set ::sqlite_opentemp_count 0 + set r0 [catch {execsql [subst { + DROP TABLE t1; + CREATE TABLE t1(a,b,c, PRIMARY KEY(a) $conf1) WITHOUT rowid; + INSERT INTO t1 SELECT * FROM t2; + UPDATE t3 SET x=0; + BEGIN; + $cmd t3 SET x=1; + $cmd t1 SET b=b*2; + $cmd t1 SET a=c+5; + }]} r1] + catch {execsql {COMMIT}} + if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} + set r2 [execsql {SELECT x FROM t3}] + list $r0 $r1 $r2 $::sqlite_opentemp_count + } [list $t0 $t1 $t2 $t3] +} + +# Test to make sure a lot of IGNOREs don't cause a stack overflow +# +do_test conflict2-7.1 { + execsql { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a PRIMARY KEY, b) without rowid; + } + for {set i 1} {$i<=50} {incr i} { + execsql "INSERT into t1 values($i,[expr {$i+1}]);" + } + execsql { + SELECT count(*), min(a), max(b) FROM t1; + } +} {50 1 51} +do_test conflict2-7.2 { + execsql { + PRAGMA count_changes=on; + UPDATE OR IGNORE t1 SET a=1000; + } +} {1} +do_test conflict2-7.2.1 { + db changes +} {1} +do_test conflict2-7.3 { + execsql { + SELECT b FROM t1 WHERE a=1000; + } +} {2} +do_test conflict2-7.4 { + execsql { + SELECT count(*) FROM t1; + } +} {50} +do_test conflict2-7.5 { + execsql { + PRAGMA count_changes=on; + UPDATE OR REPLACE t1 SET a=1001; + } +} {50} +do_test conflict2-7.5.1 { + db changes +} {50} +do_test conflict2-7.7 { + execsql { + SELECT count(*) FROM t1; + } +} {1} + +# Update for version 3: A SELECT statement no longer resets the change +# counter (Test result changes from 0 to 50). +do_test conflict2-7.7.1 { + db changes +} {50} + +# Make sure the row count is right for rows that are ignored on +# an insert. +# +do_test conflict2-8.1 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(1,2); + } + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,3); + } +} {1} +do_test conflict2-8.1.1 { + db changes +} {1} +do_test conflict2-8.2 { + execsql { + INSERT OR IGNORE INTO t1 VALUES(2,4); + } +} {0} +do_test conflict2-8.2.1 { + db changes +} {0} +do_test conflict2-8.3 { + execsql { + INSERT OR REPLACE INTO t1 VALUES(2,4); + } +} {1} +do_test conflict2-8.3.1 { + db changes +} {1} +do_test conflict2-8.4 { + execsql { + INSERT OR IGNORE INTO t1 SELECT * FROM t1; + } +} {0} +do_test conflict2-8.4.1 { + db changes +} {0} +do_test conflict2-8.5 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; + } +} {2} +do_test conflict2-8.5.1 { + db changes +} {2} +do_test conflict2-8.6 { + execsql { + INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; + } +} {3} +do_test conflict2-8.6.1 { + db changes +} {3} + +integrity_check conflict2-8.99 + +do_test conflict2-9.1 { + execsql { + PRAGMA count_changes=0; + CREATE TABLE t2( + a INTEGER PRIMARY KEY ON CONFLICT IGNORE, + b INTEGER UNIQUE ON CONFLICT FAIL, + c INTEGER UNIQUE ON CONFLICT REPLACE, + d INTEGER UNIQUE ON CONFLICT ABORT, + e INTEGER UNIQUE ON CONFLICT ROLLBACK + ) WITHOUT rowid; + CREATE TABLE t3(x); + INSERT INTO t3 VALUES(1); + SELECT * FROM t3; + } +} {1} +do_test conflict2-9.2 { + catchsql { + INSERT INTO t2 VALUES(1,1,1,1,1); + INSERT INTO t2 VALUES(2,2,2,2,2); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.3 { + catchsql { + INSERT INTO t2 VALUES(1,3,3,3,3); + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.4 { + catchsql { + UPDATE t2 SET a=a+1 WHERE a=1; + SELECT * FROM t2; + } +} {0 {1 1 1 1 1 2 2 2 2 2}} +do_test conflict2-9.5 { + catchsql { + INSERT INTO t2 VALUES(3,1,3,3,3); + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.5b { + db eval {SELECT * FROM t2;} +} {1 1 1 1 1 2 2 2 2 2} +do_test conflict2-9.6 { + catchsql { + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.6b { + db eval {SELECT * FROM t2;} +} {1 1 1 1 1 2 2 2 2 2} +do_test conflict2-9.7 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,1,3,3,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.8 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {2} +do_test conflict2-9.9 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET b=b+1 WHERE b=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.b}} +do_test conflict2-9.10 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {3} +do_test conflict2-9.11 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.12 { + catchsql { + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.13 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,1,3); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.14 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {4} +do_test conflict2-9.15 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET d=d+1 WHERE d=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.d}} +do_test conflict2-9.16 { + execsql {COMMIT} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.17 { + catchsql { + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict2-9.18 { + catchsql { + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +do_test conflict2-9.19 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,3,3,1); + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict2-9.20 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.21 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + UPDATE t2 SET e=e+1 WHERE e=1; + SELECT * FROM t2; + } +} {1 {UNIQUE constraint failed: t2.e}} +verify_ex_errcode conflict2-9.21b SQLITE_CONSTRAINT_UNIQUE +do_test conflict2-9.22 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {5} +do_test conflict2-9.23 { + catchsql { + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {2 2 2 2 2 3 3 1 3 3}} +do_test conflict2-9.24 { + catchsql { + UPDATE t2 SET c=c-1 WHERE c=2; + SELECT * FROM t2; + } +} {0 {2 2 1 2 2}} +do_test conflict2-9.25 { + catchsql { + BEGIN; + UPDATE t3 SET x=x+1; + INSERT INTO t2 VALUES(3,3,1,3,3); + SELECT * FROM t2; + } +} {0 {3 3 1 3 3}} +do_test conflict2-9.26 { + catch {execsql {COMMIT}} + execsql {SELECT * FROM t3} +} {6} + +do_test conflict2-10.1 { + catchsql { + DELETE FROM t1; + BEGIN; + INSERT OR ROLLBACK INTO t1 VALUES(1,2); + INSERT OR ROLLBACK INTO t1 VALUES(1,3); + COMMIT; + } + execsql {SELECT * FROM t1} +} {} +do_test conflict2-10.2 { + catchsql { + CREATE TABLE t4(x); + CREATE UNIQUE INDEX t4x ON t4(x); + BEGIN; + INSERT OR ROLLBACK INTO t4 VALUES(1); + INSERT OR ROLLBACK INTO t4 VALUES(1); + COMMIT; + } + execsql {SELECT * FROM t4} +} {} + +# Ticket #1171. Make sure statement rollbacks do not +# damage the database. +# +do_test conflict2-11.1 { + execsql { + -- Create a database object (pages 2, 3 of the file) + BEGIN; + CREATE TABLE abc(a PRIMARY KEY, b, c) WITHOUT rowid; + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + INSERT INTO abc VALUES(7, 8, 9); + COMMIT; + } + + + # Set a small cache size so that changes will spill into + # the database file. + execsql { + PRAGMA cache_size = 10; + } + + # Make lots of changes. Because of the small cache, some + # (most?) of these changes will spill into the disk file. + # In other words, some of the changes will not be held in + # cache. + # + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + + # Execute a statement that does a statement rollback due to + # a constraint failure. + # + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + + # Rollback the database. Verify that the state of the ABC table + # is unchanged from the beginning of the transaction. In other words, + # make sure the DELETE on table ABC that occurred within the transaction + # had no effect. + # + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +integrity_check conflict2-11.2 + +# Repeat test conflict2-11.1 but this time commit. +# +do_test conflict2-11.3 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + UPDATE abc SET a=a+1; + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + ROLLBACK; + SELECT * FROM abc; + } +} {1 2 3 4 5 6 7 8 9} +# Repeat test conflict2-11.1 but this time commit. +# +do_test conflict2-11.5 { + execsql { + BEGIN; + -- Make sure the pager is in EXCLUSIVE state. + CREATE TABLE def(d, e, f); + INSERT INTO def VALUES + ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz'); + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + INSERT INTO def SELECT * FROM def; + DELETE FROM abc WHERE a = 4; + } + catchsql { + INSERT INTO abc SELECT 10, 20, 30 FROM def; + } + execsql { + COMMIT; + SELECT * FROM abc; + } +} {1 2 3 7 8 9} +integrity_check conflict2-11.6 + +# Make sure UPDATE OR REPLACE works on tables that have only +# an INTEGER PRIMARY KEY. +# +do_test conflict2-12.1 { + execsql { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b text) WITHOUT rowid; + INSERT INTO t5 VALUES(1,'one'); + INSERT INTO t5 VALUES(2,'two'); + SELECT * FROM t5 + } +} {1 one 2 two} +do_test conflict2-12.2 { + execsql { + UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {1 one 2 two} +do_test conflict2-12.3 { + catchsql { + UPDATE t5 SET a=a+1 WHERE a=1; + } +} {1 {UNIQUE constraint failed: t5.a}} +verify_ex_errcode conflict2-12.3b SQLITE_CONSTRAINT_PRIMARYKEY +do_test conflict2-12.4 { + execsql { + UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1; + SELECT * FROM t5; + } +} {2 one} + + +# Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437] +# REPLACE works like ABORT on a CHECK constraint. +# +do_test conflict2-13.1 { + execsql { + CREATE TABLE t13(a PRIMARY KEY CHECK(a!=2)) WITHOUT rowid; + BEGIN; + REPLACE INTO t13 VALUES(1); + } + catchsql { + REPLACE INTO t13 VALUES(2); + } +} {1 {CHECK constraint failed: a!=2}} +verify_ex_errcode conflict2-13.1b SQLITE_CONSTRAINT_CHECK +do_test conflict2-13.2 { + execsql { + REPLACE INTO t13 VALUES(3); + COMMIT; + SELECT * FROM t13; + } +} {1 3} + +# Test for an unreleased bug in the REPLACE conflict resolution +# discovered on 2013-11-09. +# +do_execsql_test conflict2-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x TEXT PRIMARY KEY NOT NULL, + y TEXT NOT NULL, + z INTEGER + ); + INSERT INTO t1 VALUES('alpha','beta',1); + CREATE UNIQUE INDEX t1xy ON t1(x,y); + REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1); + PRAGMA integrity_check; + SELECT x,y FROM t1 INDEXED BY t1xy; + SELECT x,y,z FROM t1 NOT INDEXED; +} {ok alpha gamma alpha gamma 1} +do_execsql_test conflict2-14.2 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x TEXT PRIMARY KEY NOT NULL, + y TEXT NOT NULL, + z INTEGER + ) WITHOUT ROWID; + INSERT INTO t1 VALUES('alpha','beta',1); + CREATE UNIQUE INDEX t1xy ON t1(x,y); + REPLACE INTO t1(x,y,z) VALUES('alpha','gamma',1); + PRAGMA integrity_check; + SELECT x,y FROM t1 INDEXED BY t1xy; + SELECT x,y,z FROM t1 NOT INDEXED; +} {ok alpha gamma alpha gamma 1} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict3.test new file mode 100644 index 0000000000000000000000000000000000000000..8eb4c1b0f770189c5988770d7001c83d332dfffd --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/conflict3.test @@ -0,0 +1,437 @@ +# 2013-11-05 +# +# 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. +# +# This file implements tests for the conflict resolution extension +# to SQLite. +# +# This file focuses on making sure that combinations of REPLACE, +# IGNORE, and FAIL conflict resolution play well together. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix conflict3 + +ifcapable !conflict { + finish_test + return +} + +do_execsql_test 1.1 { + CREATE TABLE t1( + a INTEGER PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 1.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 1.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 1.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Replete the tests above, but this time on a table non-INTEGER primary key. +# +do_execsql_test 2.1 { + DROP TABLE t1; + CREATE TABLE t1( + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 2.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 2.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 2.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Replete again on a WITHOUT ROWID table. +# +do_execsql_test 3.1 { + DROP TABLE t1; + CREATE TABLE t1( + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 3.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 3.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 3.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 4.1 { + DROP TABLE t1; + CREATE TABLE t1( + b UNIQUE ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL, + a INT PRIMARY KEY ON CONFLICT REPLACE + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 4.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 4.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 4.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 5.1 { + DROP TABLE t1; + CREATE TABLE t1( + b UNIQUE ON CONFLICT IGNORE, + a INT PRIMARY KEY ON CONFLICT REPLACE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 5.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 5.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 5.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Arrange the table rows in a different order and repeat. +# +do_execsql_test 6.1 { + DROP TABLE t1; + CREATE TABLE t1( + c UNIQUE ON CONFLICT FAIL, + a INT PRIMARY KEY ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 6.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 6.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 6.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 7.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INTEGER PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 7.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 7.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 7.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 8.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INT PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 8.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 8.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 8.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 9.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b INT PRIMARY KEY ON CONFLICT IGNORE, + c UNIQUE ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 9.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 9.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 9.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 10.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c INTEGER PRIMARY KEY ON CONFLICT FAIL + ); + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 10.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 10.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 10.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Change which column is the PRIMARY KEY +# +do_execsql_test 11.1 { + DROP TABLE t1; + CREATE TABLE t1( + a UNIQUE ON CONFLICT REPLACE, + b UNIQUE ON CONFLICT IGNORE, + c PRIMARY KEY ON CONFLICT FAIL + ) WITHOUT ROWID; + INSERT INTO t1(a,b,c) VALUES(1,2,3), (2,3,4); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert a row that conflicts on column B. The insert should be ignored. +# +do_execsql_test 11.2 { + INSERT INTO t1(a,b,c) VALUES(3,2,5); + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4} + +# Insert two rows where the second conflicts on C. The first row show go +# and and then there should be a constraint error. +# +do_test 11.3 { + catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);} +} {1 {UNIQUE constraint failed: t1.c}} +do_execsql_test 11.4 { + SELECT a,b,c FROM t1 ORDER BY a; +} {1 2 3 2 3 4 4 5 6} + +# Check that ticket [f68dc596c4] has been fixed. +# +do_execsql_test 12.1 { + CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t2 VALUES(111, '111'); +} +do_execsql_test 12.2 { + REPLACE INTO t2 VALUES(NULL, '112'), (111, '111B'); +} +do_execsql_test 12.3 { + SELECT * FROM t2; +} {111 111B 112 112} + +#------------------------------------------------------------------------- +ifcapable trigger { + reset_db + do_execsql_test 13.1.0 { + PRAGMA recursive_triggers = true; + CREATE TABLE t0 (c0 UNIQUE, c1 UNIQUE); + CREATE TRIGGER tr0 AFTER DELETE ON t0 BEGIN + DELETE FROM t0; + END; + + INSERT INTO t0 VALUES(1, NULL); + INSERT INTO t0 VALUES(0, NULL); + } + + do_catchsql_test 13.1.1 { + UPDATE OR REPLACE t0 SET c1 = 1; + } {1 {constraint failed}} + + integrity_check 13.1.2 + + do_execsql_test 13.1.3 { + SELECT * FROM t0 + } {1 {} 0 {}} + + do_execsql_test 13.2.0 { + CREATE TABLE t2 (a PRIMARY KEY, b UNIQUE, c UNIQUE) WITHOUT ROWID; + CREATE TRIGGER tr3 AFTER DELETE ON t2 BEGIN + DELETE FROM t2; + END; + + INSERT INTO t2 VALUES(1, 1, 1); + INSERT INTO t2 VALUES(2, 2, 2); + } + + do_catchsql_test 13.2.1 { + UPDATE OR REPLACE t2 SET c = 0; + } {1 {constraint failed}} + + integrity_check 13.2.2 + + do_execsql_test 13.2.3 { + SELECT * FROM t2 + } {1 1 1 2 2 2} + + do_execsql_test 13.3.0 { + CREATE TABLE t1(a, b); + CREATE TABLE log(x); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(1, 2); + + CREATE TRIGGER tb BEFORE UPDATE ON t1 BEGIN + DELETE FROM t1; + END; + CREATE TRIGGER ta AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES('fired!'); + END; + + UPDATE t1 SET b=3; + } + + do_execsql_test 13.3.1 { + SELECT * FROM t1; + } {} + do_execsql_test 13.3.2 { + SELECT * FROM log; + } {} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt2.test new file mode 100644 index 0000000000000000000000000000000000000000..fc24cb376f5909c601e878d259b801f68cd59eeb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt2.test @@ -0,0 +1,611 @@ +# 2004 August 30 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# +# $Id: corrupt2.test,v 1.20 2009/04/06 17:50:03 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corrupt2 + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +set presql "" +catch { set presql "$::G(perm:presql);" } +unset -nocomplain ::G(perm:presql) + +# The following tests - corrupt2-1.* - create some databases corrupted in +# specific ways and ensure that SQLite detects them as corrupt. +# +do_test corrupt2-1.1 { + execsql { + PRAGMA auto_vacuum=0; + PRAGMA page_size=1024; + CREATE TABLE abc(a, b, c); + } +} {} + +do_test corrupt2-1.2 { + + # Corrupt the 16 byte magic string at the start of the file + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + seek $f 8 start + puts $f blah + close $f + + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {file is not a database}} + +do_test corrupt2-1.3 { + db2 close + + # Corrupt the page-size (bytes 16 and 17 of page 1). + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -translation binary + seek $f 16 start + puts -nonewline $f "\x00\xFF" + close $f + + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {file is not a database}} + +do_test corrupt2-1.4 { + db2 close + + # Corrupt the free-block list on page 1. + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -translation binary + seek $f 101 start + puts -nonewline $f "\xFF\xFF" + close $f + + sqlite3 db2 corrupt.db + # Note: This test is no longer meaningful due to the deferred computation + # of MemPage.nFree + catchsql {PRAGMA quick_check} db2 +} {0 {{*** in database main *** +Tree 1 page 1: free space corruption}}} + +do_test corrupt2-1.5 { + db2 close + + # Corrupt the free-block list on page 1. + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + set f [open corrupt.db RDWR] + fconfigure $f -translation binary + seek $f 101 start + puts -nonewline $f "\x00\xC8" + seek $f 200 start + puts -nonewline $f "\x00\x00" + puts -nonewline $f "\x10\x00" + close $f + + sqlite3 db2 corrupt.db + catchsql {PRAGMA quick_check} db2 +} {0 {{*** in database main *** +Tree 1 page 1: free space corruption}}} +db2 close + +# Corrupt a database by having 2 indices of the same name: +do_test corrupt2-2.1 { + + forcedelete corrupt.db + forcedelete corrupt.db-journal + forcecopy test.db corrupt.db + + sqlite3 db2 corrupt.db + sqlite3_db_config db2 DEFENSIVE 0 + execsql " + $::presql + CREATE INDEX a1 ON abc(a); + CREATE INDEX a2 ON abc(b); + PRAGMA writable_schema = 1; + UPDATE sqlite_master + SET name = 'a3', sql = 'CREATE INDEX a3' || substr(sql, 16, 10000) + WHERE type = 'index'; + PRAGMA writable_schema = 0; + " db2 + + db2 close + sqlite3 db2 corrupt.db + catchsql " + $::presql + SELECT * FROM sqlite_master; + " db2 +} {1 {malformed database schema (a3) - index a3 already exists}} + +db2 close + +do_test corrupt2-3.1 { + forcedelete corrupt.db + forcedelete corrupt.db-journal + sqlite3 db2 corrupt.db + + execsql " + $::presql + PRAGMA auto_vacuum = 1; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(randomblob(100), randomblob(100), randomblob(100)); + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + " db2 + + db2 close + + # On the root page of table t2 (page 4), set one of the child page-numbers + # to 0. This corruption will be detected when SQLite attempts to update + # the pointer-map after moving the content of page 4 to page 3 as part + # of the DROP TABLE operation below. + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd [expr 1024*3 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 1024*3 + $iCelloffset] + puts -nonewline $fd "\00\00\00\00" + close $fd + + sqlite3 db2 corrupt.db + catchsql " + $::presql + DROP TABLE t1; + " db2 +} {1 {database disk image is malformed}} + +do_test corrupt2-4.1 { + catchsql { + SELECT * FROM t2; + } db2 +} {1 {database disk image is malformed}} + +db2 close + +unset -nocomplain result +do_test corrupt2-5.1 { + forcedelete corrupt.db + forcedelete corrupt.db-journal + sqlite3 db2 corrupt.db + + execsql " + $::presql + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(randomblob(100), randomblob(100), randomblob(100)); + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t2 SELECT * FROM t2; + INSERT INTO t1 SELECT * FROM t2; + " db2 + + db2 close + + # This block links a page from table t2 into the t1 table structure. + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd [expr 1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 1024 + $iCelloffset] + set zChildPage [read $fd 4] + seek $fd [expr 2*1024 + 12] + set zCelloffset [read $fd 2] + binary scan $zCelloffset S iCelloffset + seek $fd [expr 2*1024 + $iCelloffset] + puts -nonewline $fd $zChildPage + close $fd + + sqlite3 db2 corrupt.db + db2 eval $::presql + db2 eval {SELECT rowid FROM t1} { + set result [db2 eval {pragma integrity_check}] + break + } + set result +} {{*** in database main *** +Tree 2 page 2 cell 0: 2nd reference to page 10 +Page 4: never used}} + +db2 close + +proc corruption_test {args} { + set A(-corrupt) {} + set A(-sqlprep) {} + set A(-tclprep) {} + array set A $args + + catch {db close} + forcedelete corrupt.db + forcedelete corrupt.db-journal + + sqlite3 db corrupt.db + sqlite3_db_config db DEFENSIVE 0 + db eval $::presql + eval $A(-tclprep) + db eval $A(-sqlprep) + db close + + eval $A(-corrupt) + + sqlite3 db corrupt.db + eval $A(-test) +} + +ifcapable autovacuum { + # The tests within this block - corrupt2-6.* - aim to test corruption + # detection within an incremental-vacuum. When an incremental-vacuum + # step is executed, the last non-free page of the database file is + # moved into a free space in the body of the file. After doing so, + # the page reference in the parent page must be updated to refer + # to the new location. These tests test the outcome of corrupting + # that page reference before performing the incremental vacuum. + # + + # The last page in the database page is the second page + # in an overflow chain. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + hexio_write corrupt.db [expr 1024*5] 00000008 + } -test { + do_test corrupt2-6.1 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + # The last page in the database page is a non-root b-tree page. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(50)); + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + DELETE FROM t1 WHERE a = 1; + } -corrupt { + hexio_write corrupt.db [expr 1024*2 + 8] 00000009 + } -test { + do_test corrupt2-6.2 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + # Set up a pointer-map entry so that the last page of the database + # file appears to be a b-tree root page. This should be detected + # as corruption. + # + corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + INSERT INTO t1 VALUES(2, randomblob(2500)); + INSERT INTO t1 VALUES(3, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + set nPage [expr [file size corrupt.db] / 1024] + hexio_write corrupt.db [expr 1024 + ($nPage-3)*5] 010000000 + } -test { + do_test corrupt2-6.3 { + catchsql " $::presql pragma incremental_vacuum = 1 " + } {1 {database disk image is malformed}} + } + + if {![nonzero_reserved_bytes]} { + corruption_test -sqlprep { + PRAGMA auto_vacuum = 1; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(2500)); + DELETE FROM t1 WHERE a = 1; + } -corrupt { + set nAppend [expr 1024*207 - [file size corrupt.db]] + set fd [open corrupt.db r+] + seek $fd 0 end + puts -nonewline $fd [string repeat x $nAppend] + close $fd + hexio_write corrupt.db 28 00000000 + } -test { + do_test corrupt2-6.4 { + catchsql " + $::presql + BEGIN EXCLUSIVE; + COMMIT; + " + } {1 {database disk image is malformed}} + } + } +} + + +set sqlprep { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE INDEX i1 ON t1(b); + INSERT INTO t1 VALUES(1, randomblob(50)); + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; + INSERT INTO t1 SELECT NULL, randomblob(50) FROM t1; +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Set the page-flags of one of the leaf pages of the index B-Tree to + # 0x0D (interpreted by SQLite as "leaf page of a table B-Tree"). + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd [expr 1024*2 + 8] + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)] + puts -nonewline $fd "\x0D" + close $fd +} -test { + do_test corrupt2-7.1 { + catchsql " $::presql SELECT b FROM t1 ORDER BY b ASC " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Mess up the page-header of one of the leaf pages of the index B-Tree. + # The corruption is detected as part of an OP_Prev opcode. + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd [expr 1024*2 + 12] + set zCellOffset [read $fd 2] + binary scan $zCellOffset S iCellOffset + seek $fd [expr 1024*2 + $iCellOffset] + set zChild [read $fd 4] + binary scan $zChild I iChild + seek $fd [expr 1024*($iChild-1)+3] + puts -nonewline $fd "\xFFFF" + close $fd +} -test { + do_test corrupt2-7.1 { + catchsql " $::presql SELECT b FROM t1 ORDER BY b DESC " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep $sqlprep -corrupt { + # Set the page-flags of one of the leaf pages of the table B-Tree to + # 0x0A (interpreted by SQLite as "leaf page of an index B-Tree"). + # + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd [expr 1024*1 + 8] + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)] + puts -nonewline $fd "\x0A" + close $fd +} -test { + do_test corrupt2-8.1 { + catchsql " $::presql SELECT * FROM t1 WHERE rowid=1000 " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep { + CREATE TABLE t1(a, b, c); CREATE TABLE t8(a, b, c); CREATE TABLE tE(a, b, c); + CREATE TABLE t2(a, b, c); CREATE TABLE t9(a, b, c); CREATE TABLE tF(a, b, c); + CREATE TABLE t3(a, b, c); CREATE TABLE tA(a, b, c); CREATE TABLE tG(a, b, c); + CREATE TABLE t4(a, b, c); CREATE TABLE tB(a, b, c); CREATE TABLE tH(a, b, c); + CREATE TABLE t5(a, b, c); CREATE TABLE tC(a, b, c); CREATE TABLE tI(a, b, c); + CREATE TABLE t6(a, b, c); CREATE TABLE tD(a, b, c); CREATE TABLE tJ(a, b, c); + CREATE TABLE x1(a, b, c); CREATE TABLE x8(a, b, c); CREATE TABLE xE(a, b, c); + CREATE TABLE x2(a, b, c); CREATE TABLE x9(a, b, c); CREATE TABLE xF(a, b, c); + CREATE TABLE x3(a, b, c); CREATE TABLE xA(a, b, c); CREATE TABLE xG(a, b, c); + CREATE TABLE x4(a, b, c); CREATE TABLE xB(a, b, c); CREATE TABLE xH(a, b, c); + CREATE TABLE x5(a, b, c); CREATE TABLE xC(a, b, c); CREATE TABLE xI(a, b, c); + CREATE TABLE x6(a, b, c); CREATE TABLE xD(a, b, c); CREATE TABLE xJ(a, b, c); +} -corrupt { + set fd [open corrupt.db r+] + fconfigure $fd -translation binary + seek $fd 108 + set zRightChild [read $fd 4] + binary scan $zRightChild I iRightChild + seek $fd [expr 1024*($iRightChild-1)+3] + puts -nonewline $fd "\x00\x00" + close $fd +} -test { + do_test corrupt2-9.1 { + catchsql " $::presql SELECT sql FROM sqlite_master " + } {1 {database disk image is malformed}} +} + +corruption_test -sqlprep { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = NULL WHERE name = 't2'; +} -test { + do_test corrupt2-10.1 { + catchsql " $::presql SELECT * FROM t2 " + } {1 {malformed database schema (t2)}} + do_test corrupt2-10.2 { + sqlite3_errcode db + } {SQLITE_CORRUPT} +} + +corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randstr(100,100)); + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t2 SELECT * FROM t1; + DELETE FROM t1; +} -corrupt { + set offset [expr [file size corrupt.db] - 1024] + hexio_write corrupt.db $offset FF + hexio_write corrupt.db 24 12345678 +} -test { + do_test corrupt2-11.1 { + catchsql " $::presql PRAGMA incremental_vacuum " + } {1 {database disk image is malformed}} +} +corruption_test -sqlprep { + PRAGMA auto_vacuum = incremental; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randstr(100,100)); + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t1 SELECT NULL, randstr(100,100) FROM t1; + INSERT INTO t2 SELECT * FROM t1; + DELETE FROM t1; +} -corrupt { + set pgno [expr [file size corrupt.db] / 1024] + hexio_write corrupt.db [expr 1024+5*($pgno-3)] 03 + hexio_write corrupt.db 24 12345678 +} -test { + do_test corrupt2-12.1 { + catchsql " $::presql PRAGMA incremental_vacuum " + } {1 {database disk image is malformed}} +} + +ifcapable autovacuum { + # It is not possible for the last page in a database file to be the + # pending-byte page (AKA the locking page). This test verifies that if + # an attempt is made to commit a transaction to such an auto-vacuum + # database SQLITE_CORRUPT is returned. + # + corruption_test -tclprep { + db eval { + PRAGMA auto_vacuum = full; + PRAGMA page_size = 1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(NULL, randstr(50,50)); + } + for {set ii 0} {$ii < 10} {incr ii} { + db eval " $::presql INSERT INTO t1 SELECT NULL, randstr(50,50) FROM t1 " + } + } -corrupt { + do_test corrupt2-13.1 { + file size corrupt.db + } $::sqlite_pending_byte + hexio_write corrupt.db [expr $::sqlite_pending_byte+1023] 00 + hexio_write corrupt.db 28 00000000 + } -test { + do_test corrupt2-13.2 { + file size corrupt.db + } [expr $::sqlite_pending_byte + 1024] + do_test corrupt2-13.3 { + catchsql { DELETE FROM t1 WHERE rowid < 30; } + } {1 {database disk image is malformed}} + } +} + +#------------------------------------------------------------------------- +# Test that PRAGMA integrity_check detects cases where the freelist-count +# header field is smaller than the actual number of pages on the freelist. +# + +reset_db +do_execsql_test 14.0 { + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(3500)); + DELETE FROM t1; +} + +do_execsql_test 14.1 { + PRAGMA integrity_check; + PRAGMA freelist_count; +} {ok 3} + +# There are now 3 free pages. Modify the header-field so that it +# (incorrectly) says that just 2 are free. +do_test 14.2 { + db close + hexio_write test.db 36 [hexio_render_int32 2] + sqlite3 db test.db + execsql { PRAGMA freelist_count } +} {2} + +do_execsql_test 14.3 { + PRAGMA integrity_check; +} {{*** in database main *** +Freelist: size is 3 but should be 2}} + +# Use 2 of the free pages on the free-list. +# +do_execsql_test 14.4 { + INSERT INTO t1 VALUES(randomblob(2500)); + PRAGMA freelist_count; +} {0} + +do_execsql_test 14.5 { + PRAGMA integrity_check; +} {{*** in database main *** +Freelist: size is 1 but should be 0}} + + +finish_test + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt3.test new file mode 100644 index 0000000000000000000000000000000000000000..691302f7af5dc87d1e3a5de4d001a89abbb3101a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt3.test @@ -0,0 +1,121 @@ +# 2007 April 6 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# +# $Id: corrupt3.test,v 1.2 2007/04/06 21:42:22 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas||direct_read { + finish_test + return +} + +# Create a database with an overflow page. +# +do_test corrupt3-1.1 { + set bigstring [string repeat 0123456789 200] + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES($bigstring); + } + file size test.db +} [expr {1024*3}] + +# Verify that the file format is as we expect. The page size +# should be 1024 bytes. The only record should have a single +# overflow page. The overflow page is page 3. The pointer to +# the overflow page is on the last 4 bytes of page 2. +# +do_test corrupt3-1.2 { + hexio_get_int [hexio_read test.db 16 2] +} 1024 ;# The page size is 1024 +do_test corrupt3-1.3 { + hexio_get_int [hexio_read test.db 20 1] +} 0 ;# Unused bytes per page is 0 +do_test corrupt3-1.4 { + hexio_get_int [hexio_read test.db 2044 4] +} 3 ;# Overflow page is 3 +do_test corrupt3-1.5 { + hexio_get_int [hexio_read test.db 2048 4] +} 0 ;# First chained overflow is 0 + +integrity_check corrupt3-1.6 + +# Make the overflow chain loop back on itself. See if the +# corruption is detected. +# +do_test corrupt3-1.7 { + db close + hexio_write test.db 2048 [hexio_render_int32 3] + sqlite3 db test.db + catchsql { + SELECT x FROM t1 + } +} [list 0 $bigstring] +do_test corrupt3-1.8 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: 2nd reference to page 3}}} + +# Change the pointer for the first page of the overflow +# change to be a non-existant page. +# +do_test corrupt3-1.9 { + db close + hexio_write test.db 2044 [hexio_render_int32 4] + sqlite3 db test.db + catchsql { + SELECT substr(x,1,10) FROM t1 + } +} [list 1 {database disk image is malformed}] +do_test corrupt3-1.10 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: invalid page number 4 +Page 3: never used}}} +do_test corrupt3-1.11 { + db close + hexio_write test.db 2044 [hexio_render_int32 0] + sqlite3 db test.db + catchsql { + SELECT substr(x,1,10) FROM t1 + } +} [list 1 {database disk image is malformed}] +do_test corrupt3-1.12 { + catchsql { + PRAGMA integrity_check + } +} {0 {{*** in database main *** +Tree 2 page 2 cell 0: overflow list length is 0 but should be 1 +Page 3: never used}}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt4.test new file mode 100644 index 0000000000000000000000000000000000000000..544ac330534c1432d7a639075263161e35deb97e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt4.test @@ -0,0 +1,149 @@ +# 2007 Sept 7 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corrupt4 + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a database with a freelist containing at least two pages. +# +do_test corrupt4-1.1 { + set bigstring [string repeat 0123456789 200] + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES($bigstring); + CREATE TABLE t2(y); + INSERT INTO t2 VALUES(1); + DROP TABLE t1; + } + file size test.db +} [expr {1024*4}] + +# Verify that there are two pages on the freelist. +# +do_test corrupt4-1.2 { + execsql {PRAGMA freelist_count} +} {2} + +# Get the page number for the trunk of the freelist. +# +set trunkpgno [hexio_get_int [hexio_read test.db 32 4]] +set baseaddr [expr {($trunkpgno-1)*1024}] + +# Verify that the trunk of the freelist has exactly one +# leaf. +# +do_test corrupt4-1.3 { + hexio_get_int [hexio_read test.db [expr {$::baseaddr+4}] 4] +} {1} + +# Insert a negative number as the number of leaves on the trunk. +# Then try to add a new element to the freelist. +# +do_test corrupt4-1.4 { + hexio_write test.db [expr {$::baseaddr+4}] [hexio_render_int32 -100000000] + db close + sqlite3 db test.db + catchsql { + DROP TABLE t2 + } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- + +reset_db +do_execsql_test 2.0 { + PRAGMA page_size = 512; + CREATE TABLE t1(a, b, c); +} + +# Create a database with a schema so large that the root of the +# sqlite_schema table is the grandparent of its leaves. +# +set nView 1000 +do_test 2.1 { + execsql BEGIN + for {set ii 0} {$ii<$nView} {incr ii} { + execsql " CREATE VIEW v$ii AS SELECT a, b, c FROM t1 " + } + execsql COMMIT +} {} +db close + +proc get2byte {fd offset} { + seek $fd $offset + set bin [read $fd 2] + binary scan $bin S val + set val +} +proc get4byte {fd offset} { + seek $fd $offset + set bin [read $fd 4] + binary scan $bin I val + set val +} +proc put4byte {fd offset val} { + seek $fd $offset + set bin [binary format I $val] + puts -nonewline $fd $bin +} + +# Page 1 is now the grandparent of its leaves. Corrupt the database by setting +# the second rightmost child page number of page 1 to 1. +# +set fd [open test.db r+] +fconfigure $fd -translation binary +set nChild [get2byte $fd 103] +set offChild [get2byte $fd [expr 100+12+($nChild-2)*2]] +set pgnoChild [get4byte $fd $offChild] +put4byte $fd $offChild 1 +close $fd + +if {![info exists ::G(perm:presql)]} { + sqlite3 db test.db + + do_catchsql_test 2.2 { + PRAGMA writable_schema = 1; + SELECT * FROM sqlite_schema; + } {1 {database disk image is malformed}} + + do_test 2.3 { + list [catch { + for {set ii $nView} {$ii<$nView*2} {incr ii} { + execsql "INSERT INTO sqlite_master VALUES(1, 2, 3, 4, 5)" + } + } msg] $msg + } {1 {database disk image is malformed}} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt5.test new file mode 100644 index 0000000000000000000000000000000000000000..75097668c7e002e06b398ac08514caa937c9d8c7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt5.test @@ -0,0 +1,50 @@ +# 2008 Jan 22 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. Checks for +# malformed schema. +# +# $Id: corrupt5.test,v 1.3 2009/06/04 02:47:04 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a database with a freelist containing at least two pages. +# +do_test corrupt5-1.1 { + sqlite3_db_config db DEFENSIVE 0 + execsql { + CREATE TABLE t1(a,b,c); + CREATE INDEX i1 ON t1(a,b); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET name=NULL, sql=NULL WHERE name='i1'; + } + db close + sqlite3 db test.db + catchsql { + SELECT * FROM t1 + } +} {1 {malformed database schema (?)}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt6.test new file mode 100644 index 0000000000000000000000000000000000000000..dd773c926502c457d69da3fcd24f5947fbddfd71 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt6.test @@ -0,0 +1,259 @@ +# 2008 May 6 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt SerialTypeLen values. +# +# $Id: corrupt6.test,v 1.2 2008/05/19 15:37:10 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Create a simple, small database. +# +do_test corrupt6-1.1 { + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789'); + INSERT INTO t1(x) VALUES('varint32-01234567890123456789012345678901234567890123456789'); + } + file size test.db +} [expr {1024*2}] + +# Verify that the file format is as we expect. The page size +# should be 1024 bytes. +# +do_test corrupt6-1.2 { + hexio_get_int [hexio_read test.db 16 2] +} 1024 ;# The page size is 1024 +do_test corrupt6-1.3 { + hexio_get_int [hexio_read test.db 20 1] +} 0 ;# Unused bytes per page is 0 + +integrity_check corrupt6-1.4 + +# Verify SerialTypeLen for first field of two records as we expect. +# SerialTypeLen = (len*2+12) = 60*2+12 = 132 +do_test corrupt6-1.5.1 { + hexio_read test.db 1923 2 +} 8103 ;# First text field size is 81 03 == 131 +do_test corrupt6-1.5.2 { + hexio_read test.db 1987 2 +} 8103 ;# Second text field size is 81 03 == 131 + +# Verify simple query results as expected. +do_test corrupt6-1.6 { + db close + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.7 + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Increase SerialTypeLen by 2. +do_test corrupt6-1.8.1 { + db close + hexio_write test.db 1923 8105 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Decrease SerialTypeLen by 2. +do_test corrupt6-1.8.2 { + db close + hexio_write test.db 1923 8101 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Put value of record 1 / field 1 SerialTypeLen back. +do_test corrupt6-1.8.3 { + db close + hexio_write test.db 1923 8103 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.8.4 + +# Adjust value of record 2 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Increase SerialTypeLen by 2. +do_test corrupt6-1.9.1 { + db close + hexio_write test.db 1987 8105 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 2 / field 2 SerialTypeLen and see if the +# corruption is detected. +# Decrease SerialTypeLen by 2. +do_test corrupt6-1.9.2 { + db close + hexio_write test.db 1987 8101 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Put value of record 1 / field 2 SerialTypeLen back. +do_test corrupt6-1.9.3 { + db close + hexio_write test.db 1987 8103 + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 0 {varint32 varint32} ] +integrity_check corrupt6-1.9.4 + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF 7F (2 bytes) +do_test corrupt6-1.10.1 { + db close + hexio_write test.db 1923 FF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF 7F (3 bytes) +do_test corrupt6-1.10.2 { + db close + hexio_write test.db 1923 FFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF 7F (4 bytes) +do_test corrupt6-1.10.3 { + db close + hexio_write test.db 1923 FFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF 7F (5 bytes) +do_test corrupt6-1.10.4 { + db close + hexio_write test.db 1923 FFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF 7F (6 bytes, and overflows). +do_test corrupt6-1.10.5 { + db close + hexio_write test.db 1923 FFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF 7F (7 bytes, and overflows). +do_test corrupt6-1.10.6 { + db close + hexio_write test.db 1923 FFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF FF 7F (8 bytes, and overflows). +do_test corrupt6-1.10.7 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FF FF FF FF FF FF FF FF 7F (9 bytes, and overflows). +do_test corrupt6-1.10.8 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +# Adjust value of record 1 / field 1 SerialTypeLen and see if the +# corruption is detected. +# Set SerialTypeLen to FFFF FF FF FF FF FF FF FF 7F (10 bytes, and overflows). +do_test corrupt6-1.10.9 { + db close + hexio_write test.db 1923 FFFFFFFFFFFFFFFFFF7F + sqlite3 db test.db + catchsql { + SELECT substr(x,1,8) FROM t1 + } +} [list 1 {database disk image is malformed}] + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt8.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt8.test new file mode 100644 index 0000000000000000000000000000000000000000..d7bceba31c547b1d527cfcce5f8fe075da035a4c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt8.test @@ -0,0 +1,108 @@ +# 2008 July 9 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt pointer map pages. +# +# $Id: corrupt8.test,v 1.2 2008/07/11 03:34:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas||!autovacuum { + finish_test + return +} + +# Create a database to work with. +# +do_test corrupt8-1.1 { + execsql { + PRAGMA auto_vacuum=1; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + INSERT INTO t1(x) VALUES(2); + INSERT INTO t1(x) SELECT x+2 FROM t1; + INSERT INTO t1(x) SELECT x+4 FROM t1; + INSERT INTO t1(x) SELECT x+8 FROM t1; + INSERT INTO t1(x) SELECT x+16 FROM t1; + INSERT INTO t1(x) SELECT x+32 FROM t1; + INSERT INTO t1(x) SELECT x+64 FROM t1; + INSERT INTO t1(x) SELECT x+128 FROM t1; + INSERT INTO t1(x) SELECT x+256 FROM t1; + CREATE TABLE t2(a,b); + INSERT INTO t2 SELECT x, x*x FROM t1; + } + expr {[file size test.db]>1024*12} +} {1} +integrity_check corrupt8-1.2 + +# Loop through each ptrmap entry. Corrupt the entry and make sure the +# corruption is detected by the integrity_check. +# +for {set i 1024} {$i<2048} {incr i 5} { + set oldval [hexio_read test.db $i 1] + if {$oldval==0} break + hexio_write test.db $i 00 + do_test corrupt8-2.$i.0 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + for {set k 1} {$k<=5} {incr k} { + if {$k==$oldval} continue + hexio_write test.db $i 0$k + do_test corrupt8-2.$i.$k { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + } + hexio_write test.db $i 06 + do_test corrupt8-2.$i.6 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + hexio_write test.db $i $oldval + if {$oldval>2} { + set i2 [expr {$i+1+$i%4}] + set oldval [hexio_read test.db $i2 1] + hexio_write test.db $i2 [format %02x [expr {($oldval+1)&0xff}]] + do_test corrupt8-2.$i.7 { + db close + sqlite3 db test.db + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} + } {1} + hexio_write test.db $i2 $oldval + } +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt9.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt9.test new file mode 100644 index 0000000000000000000000000000000000000000..bb37758b17b48f0aadc2ba3a3e31e48e13ecdba8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corrupt9.test @@ -0,0 +1,140 @@ +# 2008 July 9 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corruption in the form of duplicate entries on the freelist. +# +# $Id: corrupt9.test,v 1.3 2009/06/04 02:47:04 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# We must have the page_size pragma for these tests to work. +# +ifcapable !pager_pragmas { + finish_test + return +} + +# Return the offset to the first (trunk) page of the freelist. Return +# zero of the freelist is empty. +# +proc freelist_trunk_offset {filename} { + if {[hexio_read $filename 36 4]==0} {return 0} + set pgno [hexio_get_int [hexio_read $filename 32 4]] + return [expr {($pgno-1)*[hexio_get_int [hexio_read $filename 16 2]]}] +} + +# This procedure looks at the first trunk page of the freelist and +# corrupts that page by overwriting up to N entries with duplicates +# of the first entry. +# +proc corrupt_freelist {filename N} { + set offset [freelist_trunk_offset $filename] + if {$offset==0} {error "Freelist is empty"} + set cnt [hexio_get_int [hexio_read $filename [expr {$offset+4}] 4]] + set pgno [hexio_read $filename [expr {$offset+8}] 4] + for {set i 12} {$N>0 && $i<8+4*$cnt} {incr i 4; incr N -1} { + hexio_write $filename [expr {$offset+$i}] $pgno + } +} + +# Create a database to work with. Make sure there are plenty of +# entries on the freelist. +# +do_test corrupt9-1.1 { + execsql { + PRAGMA auto_vacuum=NONE; + PRAGMA page_size=1024; + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + INSERT INTO t1(x) VALUES(2); + INSERT INTO t1(x) SELECT x+2 FROM t1; + INSERT INTO t1(x) SELECT x+4 FROM t1; + INSERT INTO t1(x) SELECT x+8 FROM t1; + INSERT INTO t1(x) SELECT x+16 FROM t1; + INSERT INTO t1(x) SELECT x+32 FROM t1; + INSERT INTO t1(x) SELECT x+64 FROM t1; + INSERT INTO t1(x) SELECT x+128 FROM t1; + INSERT INTO t1(x) SELECT x+256 FROM t1; + CREATE TABLE t2(a,b); + INSERT INTO t2 SELECT x, x*x FROM t1; + CREATE INDEX i1 ON t1(x); + CREATE INDEX i2 ON t2(b,a); + DROP INDEX i2; + } + expr {[file size test.db]>1024*24} +} {1} +integrity_check corrupt9-1.2 + +# Corrupt the freelist by adding duplicate entries to the freelist. +# Make sure the corruption is detected. +# +db close +forcecopy test.db test.db-template + +corrupt_freelist test.db 1 +sqlite3 db test.db +do_test corrupt9-2.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-2.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + + +db close +forcecopy test.db-template test.db +corrupt_freelist test.db 2 +sqlite3 db test.db +do_test corrupt9-3.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-3.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + +db close +forcecopy test.db-template test.db +corrupt_freelist test.db 3 +sqlite3 db test.db +do_test corrupt9-4.1 { + set x [db eval {PRAGMA integrity_check}] + expr {$x!="ok"} +} {1} +do_test corrupt9-4.2 { + catchsql { + CREATE INDEX i2 ON t2(b,a); + REINDEX; + } +} {1 {database disk image is malformed}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptA.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptA.test new file mode 100644 index 0000000000000000000000000000000000000000..12d918615fafd2aa5c0818283dbb83f906ef1c2f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptA.test @@ -0,0 +1,83 @@ +# 2008 July 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on corrupt database headers. +# +# $Id: corruptA.test,v 1.1 2008/07/11 16:39:23 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + + +# Create a database to work with. +# +do_test corruptA-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(1); + } + expr {[file size test.db]>=1024} +} {1} +integrity_check corruptA-1.2 + +# Corrupt the file header in various ways and make sure the corruption +# is detected when opening the database file. +# +db close +forcecopy test.db test.db-template + +set unreadable_version 02 +ifcapable wal { set unreadable_version 03 } +do_test corruptA-2.1 { + forcecopy test.db-template test.db + hexio_write test.db 19 $unreadable_version ;# the read format number + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.2 { + db close + forcecopy test.db-template test.db + hexio_write test.db 21 41 ;# max embedded payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.3 { + db close + forcecopy test.db-template test.db + hexio_write test.db 22 1f ;# min embedded payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + +do_test corruptA-2.4 { + db close + forcecopy test.db-template test.db + hexio_write test.db 23 21 ;# min leaf payload fraction + sqlite3 db test.db + catchsql {SELECT * FROM t1} +} {1 {file is not a database}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptB.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptB.test new file mode 100644 index 0000000000000000000000000000000000000000..c51cb5768026d0698b6d2d24211bdc8c3ed9d53b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptB.test @@ -0,0 +1,193 @@ +# 2008 Sep 10 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifically focuses +# on loops in the B-Tree structure. A loop is formed in a B-Tree structure +# when there exists a page that is both an a descendent or ancestor of +# itself. +# +# Also test that an SQLITE_CORRUPT error is returned if a B-Tree page +# contains a (corrupt) reference to a page greater than the configured +# maximum page number. +# +# $Id: corruptB.test,v 1.4 2009/07/21 19:25:24 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + + +do_test corruptB-1.1 { + execsql { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randomblob(200)); + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + } + expr {[file size test.db] > (1024*9)} +} {1} +integrity_check corruptB-1.2 + +forcecopy test.db bak.db + +# Set the right-child of a B-Tree rootpage to refer to the root-page itself. +# +do_test corruptB-1.3.1 { + set ::root [execsql {SELECT rootpage FROM sqlite_master}] + set ::offset [expr {($::root-1)*1024}] + hexio_write test.db [expr $offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.3.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child of a cell in a B-Tree rootpage to refer to the +# root-page itself. +# +do_test corruptB-1.4.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] + hexio_write test.db [expr $offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.4.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Now grow the table B-Tree so that it is more than 2 levels high. +# +do_test corruptB-1.5.1 { + db close + forcecopy bak.db test.db + sqlite3 db test.db + execsql { + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + INSERT INTO t1 SELECT randomblob(200) FROM t1; + } +} {} + +forcecopy test.db bak.db + +# Set the right-child pointer of the right-child of the root page to point +# back to the root page. +# +do_test corruptB-1.6.1 { + db close + set iRightChild [hexio_get_int [hexio_read test.db [expr $offset+8] 4]] + set c_offset [expr ($iRightChild-1)*1024] + hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.6.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child pointer of a cell of the right-child of the root page to +# point back to the root page. +# +do_test corruptB-1.7.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] + hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.7.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +do_test corruptB-1.8.1 { + db close + set cell_offset [hexio_get_int [hexio_read test.db [expr $offset+12] 2]] + set iLeftChild [ + hexio_get_int [hexio_read test.db [expr $offset+$cell_offset] 4] + ] + set c_offset [expr ($iLeftChild-1)*1024] + hexio_write test.db [expr $c_offset+8] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.8.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +# Set the left-child pointer of a cell of the right-child of the root page to +# point back to the root page. +# +do_test corruptB-1.9.1 { + db close + forcecopy bak.db test.db + set cell_offset [hexio_get_int [hexio_read test.db [expr $c_offset+12] 2]] + hexio_write test.db [expr $c_offset+$cell_offset] [hexio_render_int32 $::root] +} {4} +do_test corruptB-1.9.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +#--------------------------------------------------------------------------- + +do_test corruptB-2.1.1 { + db close + forcecopy bak.db test.db + hexio_write test.db [expr $offset+8] [hexio_render_int32 0x6FFFFFFF] +} {4} +do_test corruptB-2.1.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t1 } +} {1 {database disk image is malformed}} + +#--------------------------------------------------------------------------- + +# Corrupt the header-size field of a database record. +# +do_test corruptB-3.1.1 { + db close + forcecopy bak.db test.db + sqlite3 db test.db + set v [string repeat abcdefghij 200] + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES($v); + } + set t2_root [execsql {SELECT rootpage FROM sqlite_master WHERE name = 't2'}] + set iPage [expr ($t2_root-1)*1024] + set iCellarray [expr $iPage + 8] + set iRecord [hexio_get_int [hexio_read test.db $iCellarray 2]] + db close + hexio_write test.db [expr $iPage+$iRecord+3] FF00 +} {2} +do_test corruptB-3.1.2 { + sqlite3 db test.db + catchsql { SELECT * FROM t2 } +} {1 {database disk image is malformed}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptC.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptC.test new file mode 100644 index 0000000000000000000000000000000000000000..bf324c120f7d90b761b6c76ce87769b4cc0de70e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptC.test @@ -0,0 +1,428 @@ +# 2004 August 30 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It creates a base +# data base file, then tests that single byte corruptions in +# increasingly larger quantities are handled gracefully. +# +# $Id: corruptC.test,v 1.14 2009/07/11 06:55:34 danielk1977 Exp $ + +catch {forcedelete test.db test.db-journal test.bu} + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Construct a compact, dense database for testing. +# +do_test corruptC-1.1 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + PRAGMA auto_vacuum = 0; + BEGIN; + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES(1,1); + INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0; + COMMIT; + } +} {} + +ifcapable {integrityck} { + integrity_check corruptC-1.2 +} + +# Generate random integer +# +proc random {range} { + return [expr {round(rand()*$range)}] +} + +# Setup for the tests. Make a backup copy of the good database in test.bu. +# +db close +forcecopy test.db test.bu +sqlite3 db test.db +set fsize [file size test.db] + +# Set a quasi-random random seed. +if {[info exists ::G(issoak)]} { + # If we are doing SOAK tests, we want a different + # random seed for each run. Ideally we would like + # to use [clock clicks] or something like that here. + set qseed [file mtime test.db] +} else { + # If we are not doing soak tests, + # make it repeatable. + set qseed 0 +} +expr srand($qseed) + +# +# First test some specific corruption tests found from earlier runs +# with specific seeds. +# + +# test that a corrupt content offset size is handled (seed 5577) +do_test corruptC-2.1 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2053 [format %02x 0x04] + + sqlite3 db test.db + catchsql {PRAGMA integrity_check} +} {0 {{*** in database main *** +Tree 3 page 3: free space corruption} {wrong # of entries in index t1i1}}} + +# test that a corrupt content offset size is handled (seed 5649) +# +# Update 2016-12-27: As of check-in [0b86fbca66] "In sqlite3BtreeInsert() when +# replacing a re-existing row, try to overwrite the cell directly rather than +# deallocate and reallocate the cell" on 2016-12-09, this test case no longer +# detects the offset size problem during the UPDATE. We have to run a subsequent +# integrity_check to see it. +do_test corruptC-2.2 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 27 [format %02x 0x08] + hexio_write test.db 233 [format %02x 0x6a] + hexio_write test.db 328 [format %02x 0x67] + hexio_write test.db 750 [format %02x 0x1f] + hexio_write test.db 1132 [format %02x 0x52] + hexio_write test.db 1133 [format %02x 0x84] + hexio_write test.db 1220 [format %02x 0x01] + hexio_write test.db 3688 [format %02x 0xc1] + hexio_write test.db 3714 [format %02x 0x58] + hexio_write test.db 3746 [format %02x 0x9a] + + sqlite3 db test.db + db eval {UPDATE t1 SET y=1} + db eval {PRAGMA integrity_check} +} {/Offset .* out of range/} + +# test that a corrupt free cell size is handled (seed 13329) +do_test corruptC-2.3 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 1094 [format %02x 0x76] + + sqlite3 db test.db + catchsql {UPDATE t1 SET y=1} +} {1 {database disk image is malformed}} + +# test that a corrupt free cell size is handled (seed 169571) +do_test corruptC-2.4 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3119 [format %02x 0xdf] + + sqlite3 db test.db + catchsql {UPDATE t2 SET y='abcdef-uvwxyz'} +} {1 {database disk image is malformed}} + +# test that a corrupt free cell size is handled (seed 169571) +do_test corruptC-2.5 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3119 [format %02x 0xdf] + hexio_write test.db 4073 [format %02x 0xbf] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} + catchsql {PRAGMA integrity_check} +} {0 {{*** in database main *** +Tree 4 page 4 cell 19: Extends off end of page} {database disk image is malformed}}} + +# {0 {{*** in database main *** +# Corruption detected in cell 710 on page 4 +# Multiple uses for byte 661 of page 4 +# Fragmented space is 249 byte reported as 21 on page 4}}} + +# test that a corrupt free cell size is handled (seed 169595) +do_test corruptC-2.6 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 619 [format %02x 0xe2] + hexio_write test.db 3150 [format %02x 0xa8] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 178692) +do_test corruptC-2.7 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3074 [format %02x 0xa0] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + + +# corruption (seed 179069) +# Obsolete. With single-pass DELETE the corruption in the +# main database is not detected. +if 0 { +do_test corruptC-2.8 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 1393 [format %02x 0x7d] + hexio_write test.db 84 [format %02x 0x19] + hexio_write test.db 3287 [format %02x 0x3b] + hexio_write test.db 2564 [format %02x 0xed] + hexio_write test.db 2139 [format %02x 0x55] + + sqlite3 db test.db + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} +} {1 {database disk image is malformed}} +} + +# corruption (seed 170434) +# +# UPDATE: Prior to 3.8.2, this used to return SQLITE_CORRUPT. It no longer +# does. That is Ok, the point of these tests is to verify that no buffer +# overruns or overreads can be caused by corrupt databases. +do_test corruptC-2.9 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2095 [format %02x 0xd6] + + sqlite3 db test.db + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} +} {0 {}} + +# corruption (seed 186504) +do_test corruptC-2.10 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 3130 [format %02x 0x02] + + sqlite3 db test.db + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 1589) +do_test corruptC-2.11 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 55 [format %02x 0xa7] + + sqlite3 db test.db + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} +} {1 {database disk image is malformed}} + +# corruption (seed 14166) +do_test corruptC-2.12 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 974 [format %02x 0x2e] + + sqlite3 db test.db + catchsql {SELECT count(*) FROM sqlite_master;} +} {1 {malformed database schema (t1i1) - corrupt database}} + +# corruption (seed 218803) +do_test corruptC-2.13 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 102 [format %02x 0x12] + + sqlite3 db test.db + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} +} {1 {database disk image is malformed}} + +do_test corruptC-2.14 { + db close + forcecopy test.bu test.db + + sqlite3 db test.db + set blob [string repeat abcdefghij 10000] + execsql { INSERT INTO t1 VALUES (1, $blob) } + + sqlite3 db test.db + set filesize [file size test.db] + hexio_write test.db [expr $filesize-2048] 00000001 + catchsql {DELETE FROM t1 WHERE rowid = (SELECT max(rowid) FROM t1)} +} {1 {database disk image is malformed}} + +# At one point this particular corrupt database was causing a buffer +# overread. Which caused a crash in a run of all.test once. +# +do_test corruptC-2.15 { + db close + forcecopy test.bu test.db + hexio_write test.db 986 b9 + sqlite3 db test.db + catchsql {SELECT count(*) FROM sqlite_master;} +} {1 {database disk image is malformed}} + +# +# Now test for a series of quasi-random seeds. +# We loop over the entire file size and touch +# each byte at least once. +for {set tn 0} {$tn<$fsize} {incr tn 1} { + + # setup for test + db close + forcecopy test.bu test.db + sqlite3 db test.db + + # Seek to a random location in the file, and write a random single byte + # value. Then do various operations on the file to make sure that + # the database engine can handle the corruption gracefully. + # + set last 0 + for {set i 1} {$i<=512 && !$last} {incr i 1} { + + db close + if {$i==1} { + # on the first corrupt value, use location $tn + # this ensures that we touch each location in the + # file at least once. + set roffset $tn + } else { + # insert random byte at random location + set roffset [random $fsize] + } + set rbyte [format %02x [random 255]] + + # You can uncomment the following to have it trace + # exactly how it's corrupting the file. This is + # useful for generating the "seed specific" tests + # above. + # set rline "$roffset $rbyte" + # puts stdout $rline + + hexio_write test.db $roffset $rbyte + sqlite3 db test.db + + # do a few random operations to make sure that if + # they error, they error gracefully instead of crashing. + do_test corruptC-3.$tn.($qseed).$i.1 { + catchsql {SELECT count(*) FROM sqlite_master} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.2 { + catchsql {SELECT count(*) FROM t1} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.3 { + catchsql {SELECT count(*) FROM t1 WHERE x>13} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.4 { + catchsql {SELECT count(*) FROM t2} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.5 { + catchsql {SELECT count(*) FROM t2 WHERE x<13} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.6 { + catchsql {BEGIN; UPDATE t1 SET y=1; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.7 { + catchsql {BEGIN; UPDATE t2 SET y='abcdef-uvwxyz'; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.8 { + catchsql {BEGIN; DELETE FROM t1 WHERE x>13; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.9 { + catchsql {BEGIN; DELETE FROM t2 WHERE x<13; ROLLBACK;} + set x {} + } {} + do_test corruptC-3.$tn.($qseed).$i.10 { + catchsql {BEGIN; CREATE TABLE t3 AS SELECT x,3 as y FROM t2 WHERE rowid%5!=0; ROLLBACK;} + set x {} + } {} + + # check the integrity of the database. + # once the corruption is detected, we can stop. + ifcapable {integrityck} { + set res [ catchsql {PRAGMA integrity_check} ] + set ans [lindex $res 1] + if { [ string compare $ans "ok" ] != 0 } { + set last -1 + } + } + # if we are not capable of doing an integrity check, + # stop after corrupting 5 bytes. + ifcapable {!integrityck} { + if { $i > 5 } { + set last -1 + } + } + + # Check that no page references were leaked. + # TBD: need to figure out why this doesn't work + # work with ROLLBACKs... + if {0} { + do_test corruptC-3.$tn.($qseed).$i.11 { + set bt [btree_from_db db] + db_enter db + array set stats [btree_pager_stats $bt] + db_leave db + set stats(ref) + } {0} + } + } + # end for i + +} +# end for tn + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptD.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptD.test new file mode 100644 index 0000000000000000000000000000000000000000..381e52c8083a44479d354ee19038659e04166846 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptD.test @@ -0,0 +1,145 @@ +# 2009 June 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. +# +#*********************************************************************** +# +# $Id: corruptD.test,v 1.2 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +#-------------------------------------------------------------------------- +# OVERVIEW +# +# This test file attempts to verify that SQLite does not read past the +# end of any in-memory buffers as a result of corrupted database page +# images. Usually this happens because a field within a database page +# that contains an offset to some other structure within the same page +# is set to too large a value. A database page contains the following +# such fields: +# +# 1. The page header field that contains the offset to the first +# free block of space. +# +# 2. The first two bytes of all but the last free block on the free-block +# list (the offset to the next free block). +# +# 3. The page header field containing the number of cells on the page +# (implicitly defines the offset to the final element in the cell offset +# array, which could potentially be off the end of the page). +# +# 4. The page header field containing the offset to the start of the cell +# content area. +# +# 5. The contents of the cell offset array. +# +# 6. The first few bytes of each cell determine the size of the cell +# stored within the page, and hence the offset to the final byte of +# the cell. +# +# If any of the above fields are set to too large a value, then a buffer +# overread may occur. This test script creates and operates on various +# strategically corrupted database files to attempt to provoke such buffer +# overreads. +# +# Very often, a buffer overread passes unnoticed, particularly in workstation +# environments. For this reason, this test script should be run using valgrind +# (or similar) in order to verify that no overreads occur. +# +# TEST PLAN +# +# Test cases corruptD-1.* are white-box tests. They attempt to corrupt +# one of the above fields, then exercise each part of the code in btree.c +# that uses said field. +# +# Offset variables 1, 2, 3 and 4 are all checked to make sure they +# will not result in buffer overruns as part of page initialization in +# sqlite3BtreeInitPage(). Offsets 5 and 6 cannot be tested as part of +# page initialization, as trying to do so causes a performance hit. +# + +do_test corruptD-1.0 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + } + for {set ii 1} {$ii < 50} {incr ii} { + execsql { INSERT INTO t1 VALUES($ii, $ii * $ii) } + } + execsql { + DELETE FROM t1 WHERE a = 10; + DELETE FROM t1 WHERE a = 20; + DELETE FROM t1 WHERE a = 30; + DELETE FROM t1 WHERE a = 40; + } + forcecopy test.db test.bu +} {} + +proc incr_change_counter {} { + hexio_write test.db 24 [ + hexio_render_int32 [expr [hexio_get_int [hexio_read test.db 24 4]] + 1] + ] +} + +proc restore_file {} { + db close + forcecopy test.bu test.db + sqlite3 db test.db +} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.1.*, focus on the page header field +# containing the offset of the first free block in a page. +# +do_test corruptD-1.1.1 { + incr_change_counter + hexio_write test.db [expr 1024+1] FFFF + catchsql { PRAGMA quick_check } +} {0 {{*** in database main *** +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] + catchsql { SELECT * FROM t1 ORDER BY rowid } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.2.*, focus on the offsets contained +# in the first 2 byte of each free-block on the free-list. +# +do_test corruptD-1.2.1 { + restore_file +} {} +do_test corruptD-1.2.2 { +} {} + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.4.*, ... +# + + +#------------------------------------------------------------------------- +# The following tests, corruptD-1.5.*, focus on the offsets contained +# in the cell offset array. +# +# defragmentPage +# + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptE.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptE.test new file mode 100644 index 0000000000000000000000000000000000000000..8c55623ea4fbdee8c02a8ed9d38c7fcfcbc38967 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptE.test @@ -0,0 +1,152 @@ +# 2010 February 18 +# +# 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. +# +# This file implements tests to make sure SQLite does not crash or +# segfault if it sees a corrupt database file. It specifcally +# focuses on rowid order corruption. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +# Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on. +# +ifcapable oversize_cell_check { + finish_test + return +} + +# Construct a compact, dense database for testing. +# +do_test corruptE-1.1 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + PRAGMA auto_vacuum = 0; + BEGIN; + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES(1,1); + INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1; + INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0 ORDER BY rowid; + COMMIT; + } +} {} + +ifcapable {integrityck} { + integrity_check corruptE-1.2 +} + +# Setup for the tests. Make a backup copy of the good database in test.bu. +# +db close +forcecopy test.db test.bu +sqlite3 db test.db +set fsize [file size test.db] + + +do_test corruptE-2.1 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2041 [format %02x 0x2e] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/ out of order/} + +do_test corruptE-2.2 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 2047 [format %02x 0x84] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/ Extends off end of page/} + +do_test corruptE-2.3 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 7420 [format %02x 0xa8] + hexio_write test.db 10459 [format %02x 0x8d] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/out of order/} + +do_test corruptE-2.4 { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db 10233 [format %02x 0xd0] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} +} {/out of order/} + + +set tests [list {10233 0xd0} \ + {941 0x42} \ + {2041 0xd0} \ + {2042 0x1f} \ + {2274 0x75} \ + {3267 0xf2} \ + {5113 0x36} \ + {10233 0x84} \ + {10234 0x74} \ + {10239 0x41} \ + {11273 0x28} \ + {11461 0xe6} \ + {12297 0xd7} \ + {13303 0x53} ] + +set tc 1 +foreach test $tests { + do_test corruptE-3.$tc { + db close + forcecopy test.bu test.db + + # insert corrupt byte(s) + hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]] + + sqlite3 db test.db + + catchsql {PRAGMA integrity_check} + } {/out of order/} + incr tc 1 +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptF.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptF.test new file mode 100644 index 0000000000000000000000000000000000000000..8c4fd84219365cea4a3d7fa7e89b343cfd95a33a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptF.test @@ -0,0 +1,153 @@ +# 2012 January 12 +# +# 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 corruptF + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +proc str {i} { format %08d $i } + +# Create a 6 page database containing a single table - t1. Table t1 +# consists of page 2 (the root page) and pages 5 and 6 (leaf pages). +# Database pages 3 and 4 are on the free list. +# +proc create_test_db {} { + catch { db close } + forcedelete test.db + sqlite3 db test.db + db func str str + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); /* root page = 2 */ + CREATE TABLE t2(x); /* root page = 3 */ + CREATE TABLE t3(x); /* root page = 4 */ + + INSERT INTO t1 VALUES(str(1)); + INSERT INTO t1 SELECT str(rowid+1) FROM t1; + INSERT INTO t1 SELECT str(rowid+2) FROM t1; + INSERT INTO t1 SELECT str(rowid+4) FROM t1; + INSERT INTO t1 SELECT str(rowid+8) FROM t1; + INSERT INTO t1 SELECT str(rowid+16) FROM t1; + INSERT INTO t1 SELECT str(rowid+32) FROM t1; + INSERT INTO t1 SELECT str(rowid+64) FROM t1; + DROP TABLE t2; + DROP TABLE t3; + } + db close +} + +do_test 1.1 { create_test_db } {} + +# Check the db is as we expect. 6 pages in total, with 3 and 4 on the free +# list. Page 3 is the free list trunk and page 4 is a leaf. +# +do_test 1.2 { file size test.db } [expr 6*1024] +do_test 1.3 { hexio_read test.db 32 4 } 00000003 +do_test 1.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004 + +# Change the free-list entry to page 6 and reopen the db file. +do_test 1.5 { + hexio_write test.db [expr 2*1024 + 8] 00000006 + sqlite3 db test.db +} {} + +# Now create a new table in the database file. The root of the new table +# is page 6, which is also the right-most leaf page in table t1. +# +do_execsql_test 1.6 { + CREATE TABLE t4(x); + SELECT * FROM sqlite_master; +} { + table t1 t1 2 {CREATE TABLE t1(x)} + table t4 t4 6 {CREATE TABLE t4(x)} +} + +# At one point this was causing an assert to fail. +# +# This statement opens a cursor on table t1 and does a full table scan. As +# each row is visited, it is copied into table t4. There is no temporary +# table. +# +# When the t1 cursor reaches page 6 (which is both the right-most leaf of +# t1 and the root of t4), it continues to iterate through the keys within +# it (which at this point are keys that have been inserted into t4). And +# for each row visited, another row is inserted into page 6 - it being the +# root page of t4. Eventually, page 6 becomes full and the height of the +# b-tree for table t4 increased. From the point of view of the t1 cursor, +# this unexpectedly reduces the number of keys on page 6 in the middle of +# its iteration, which causes an assert() to fail. +# +db_save_and_close +if 1 { +for {set i 0} {$i < 128} {incr i} { + db_restore_and_reopen + do_test 1.7.$i { + set res [ + catchsql { INSERT INTO t4 SELECT x FROM t1 WHERE rowid>$i } + ] + if {$res == "0 {}" || $res == "1 {database disk image is malformed}"} { + set res "" + } + set res + } {} +} +} + +do_test 2.1 { create_test_db } {} +do_test 2.2 { file size test.db } [expr 6*1024] +do_test 2.3 { hexio_read test.db 32 4 } 00000003 +do_test 2.4 { hexio_read test.db [expr 2*1024] 12 } 000000000000000100000004 + +# Change the free-list entry to page 5 and reopen the db file. +do_test 2.5 { + hexio_write test.db [expr 2*1024 + 8] 00000005 + sqlite3 db test.db +} {} + +# Now create a new table in the database file. The root of the new table +# is page 5, which is also the right-most leaf page in table t1. +# +do_execsql_test 2.6 { + CREATE TABLE t4(x); + SELECT * FROM sqlite_master; +} { + table t1 t1 2 {CREATE TABLE t1(x)} + table t4 t4 5 {CREATE TABLE t4(x)} +} + +db_save_and_close +for {set i 127} {$i >= 0} {incr i -1} { + db_restore_and_reopen + do_test 2.7.$i { + set res [ + catchsql { + INSERT INTO t4 SELECT x FROM t1 WHERE rowid<$i ORDER BY rowid DESC + } + ] + if {$res == "0 {}" || $res == "1 {database disk image is malformed}"} { + set res "" + } + set res + } {} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptH.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptH.test new file mode 100644 index 0000000000000000000000000000000000000000..9ba7522422be7214f861cfcb55f9c6736500bc42 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptH.test @@ -0,0 +1,176 @@ +# 2014-01-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 corruptH + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# The corruption migrations tested by the code in this file are not detected +# mmap mode. +# +# The reason is that in mmap mode, the different queries may use different +# PgHdr objects for the same page (same data, but different PgHdr container +# objects). And so the corruption is not detected. +# +if {[permutation]=="mmap"} { + finish_test + return +} + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t2(x); + INSERT INTO t2 VALUES(randomblob(200)); + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; + INSERT INTO t2 SELECT randomblob(200) FROM t2; +} {} + +# Corrupt the file so that the root page of t1 is also linked into t2 as +# a leaf page. +# +do_test 1.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + hexio_write test.db [expr {($r(t2)-1)*1024 + 11}] [format %.2X $r(t1)] + sqlite3 db test.db +} {} + +do_test 1.3 { + db eval { PRAGMA secure_delete=1 } + list [catch { + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { DELETE FROM t2 } + } + } msg] $msg +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db + +# Initialize the database. +# +do_execsql_test 2.1 { + PRAGMA auto_vacuum=0; + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t3(x); + + CREATE TABLE t2(x PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t2 VALUES(randomblob(100)); + + DROP TABLE t3; +} {} + +do_test 2.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + set fl [hexio_get_int [hexio_read test.db 32 4]] + + hexio_write test.db [expr {($fl-1) * 1024 + 0}] 00000000 + hexio_write test.db [expr {($fl-1) * 1024 + 4}] 00000001 + hexio_write test.db [expr {($fl-1) * 1024 + 8}] [format %.8X $r(t1)] + hexio_write test.db 36 00000002 + + sqlite3 db test.db +} {} + + +# The trick here is that the root page of the tree scanned by the outer +# query is also currently on the free-list. So while the first seek on +# the table (for a==1) works, by the time the second is attempted The +# "INSERT INTO t2..." statements have recycled the root page of t1 and +# used it as an index leaf. Normally, BtreeMovetoUnpacked() detects +# that the PgHdr object associated with said root page does not match +# the cursor (as it is now marked with PgHdr.intKey==0) and returns +# SQLITE_CORRUPT. +# +set res23 {1 {database disk image is malformed}} +do_test 2.3 { + list [catch { + set res [list] + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + INSERT INTO t2 SELECT randomblob(100) FROM t2; + } + lappend res $b + } + set res + } msg] $msg +} $res23 + +#------------------------------------------------------------------------- +reset_db + +# Initialize the database. +# +do_execsql_test 3.1 { + PRAGMA page_size=1024; + + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + + CREATE TABLE t2(c INTEGER PRAGMA KEY, d); + INSERT INTO t2 VALUES(1, randomblob(1100)); +} {} + +do_test 3.2 { + db eval { SELECT name, rootpage FROM sqlite_master } { + set r($name) $rootpage + } + db close + + hexio_write test.db [expr {($r(t2)-1) * 1024 + 1020}] 00000002 + + sqlite3 db test.db +} {} + +do_test 3.3 { + list [catch { + db eval { SELECT * FROM t1 WHERE a IN (1, 2) } { + db eval { + DELETE FROM t2 WHERE c=1; + } + } + } msg] $msg +} {1 {database disk image is malformed}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptI.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptI.test new file mode 100644 index 0000000000000000000000000000000000000000..65ef3762586aab1da2da0b33788ee19c439503c4 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptI.test @@ -0,0 +1,258 @@ +# 2014-01-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 corruptI + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES('abcdefghijklmnop'); +} {} +db close + +do_test 1.2 { + set offset [hexio_get_int [hexio_read test.db [expr 2*1024 + 8] 2]] + set off [expr 2*1024 + $offset + 1] + hexio_write test.db $off 7f06 + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE a = 10 } +} {0 {}} + +do_test 1.3 { + db close + set offset [hexio_get_int [hexio_read test.db [expr 2*1024 + 8] 2]] + set off [expr 2*1024 + $offset + 1] + hexio_write test.db $off FFFF7f02 + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE a = 10 } +} {1 {database disk image is malformed}} + +do_test 2.0 { + execsql { + CREATE TABLE r(x); + INSERT INTO r VALUES('ABCDEFGHIJK'); + CREATE INDEX r1 ON r(x); + } + set pg [db one {SELECT rootpage FROM sqlite_master WHERE name = 'r1'}] +} {5} + +do_test 2.1 { + db close + set offset [hexio_get_int [hexio_read test.db [expr (5-1)*1024 + 8] 2]] + set off [expr (5-1)*1024 + $offset + 1] + hexio_write test.db $off FFFF0004 + sqlite3 db test.db + catchsql { SELECT * FROM r WHERE x >= 10.0 } +} {1 {database disk image is malformed}} + +do_test 2.2 { + catchsql { SELECT * FROM r WHERE x >= 10 } +} {1 {database disk image is malformed}} + +if {[db one {SELECT sqlite_compileoption_used('ENABLE_OVERSIZE_CELL_CHECK')}]} { + # The following tests only work if OVERSIZE_CELL_CHECK is disabled +} else { + reset_db + do_execsql_test 3.1 { + PRAGMA auto_vacuum=0; + PRAGMA page_size = 512; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + WITH s(a, b) AS ( + SELECT 2, 'abcdefghij' + UNION ALL + SELECT a+2, b FROM s WHERe a < 40 + ) + INSERT INTO t1 SELECT * FROM s; + } {} + + do_test 3.2 { + hexio_write test.db [expr 512+3] 0054 + db close + sqlite3 db test.db + execsql { INSERT INTO t1 VALUES(5, 'klmnopqrst') } + execsql { INSERT INTO t1 VALUES(7, 'klmnopqrst') } + } {} + + db close + sqlite3 db test.db + do_catchsql_test 3.3 { + INSERT INTO t1 VALUES(9, 'klmnopqrst'); + } {1 {database disk image is malformed}} +} ;# end-if !defined(ENABLE_OVERSIZE_CELL_CHECK) + + +#------------------------------------------------------------------------- +# Test that an assert() failure discovered by AFL corrupt database file +# testing has been fixed. +# +reset_db +do_execsql_test 4.0 { + PRAGMA page_size = 65536; + PRAGMA autovacuum = 0; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(-1, 'abcdefghij'); + INSERT INTO t1 VALUES(0, 'abcdefghij'); +} + +set root [db one {SELECT rootpage FROM sqlite_master}] +set offset [expr ($root-1) * 65536] + +do_test 4.1 { + db close + hexio_write test.db [expr $offset + 8 + 2] 0000 + hexio_write test.db [expr $offset + 5] 0000 + sqlite3 db test.db + catchsql { DELETE FROM t1 WHERE a=0 } +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +# Database properties: +# +# * Incremental vacuum mode. +# * Database root table has a single leaf page. +# * Free list consists of a single trunk page. +# +# The db is then corrupted by adding the root table leaf page as a free-list +# leaf page (so that it is referenced twice). +# +# Then, a new table is created. The new root page is the current free-list +# trunk. This means that the root table leaf page is made into the new +# free list trunk, which corrupts its header. Then, when the new entry is +# inserted into the root table, things would get chaotic. +# +reset_db +do_test 5.0 { + execsql { + PRAGMA page_size = 512; + PRAGMA auto_vacuum = 2; + } + for {set i 3} {1} {incr i} { + execsql "CREATE TABLE t${i}(x)" + if {[db one {PRAGMA page_count}]>$i} break + } + set nPage [db one {PRAGMA page_count}] + execsql { + CREATE TABLE t100(x); + DROP TABLE t100; + } +} {} + +do_execsql_test 5.1 { + PRAGMA page_count +} [expr $nPage+1] + +do_test 5.2 { + # The last page of the db is now the only leaf of the sqlite_master table. + # Corrupt the db by adding it to the free-list as well (the second last + # page of the db is the free-list trunk). + db close + hexio_write test.db [expr 512*($nPage-1)] [ + format "%.8X%.8X%.8X" 0 1 [expr $nPage+1] + ] +} {12} + +do_test 5.3 { + sqlite3 db test.db + catchsql { CREATE TABLE tx(x); } +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +# Set the payload size of a cell to just less than 2^32 bytes (not +# possible in an uncorrupted db). Then try to delete the cell. At one +# point this led to an integer overflow that caused an assert() to fail. +# +reset_db +do_execsql_test 6.0 { + PRAGMA page_size = 512; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(600)); +} {} +do_test 6.1 { + db close + hexio_write test.db 616 8FFFFFFF7F02 + sqlite3 db test.db + execsql { DELETE FROM t1 WHERE rowid=2 } +} {} + +#------------------------------------------------------------------------- +# See what happens if the sqlite_master entry associated with a PRIMARY +# KEY or UNIQUE index is removed. +# +reset_db +do_execsql_test 7.0 { + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x PRIMARY KEY, y); + INSERT INTO t1 VALUES('a', 'A'); + INSERT INTO t1 VALUES('b', 'A'); + INSERT INTO t1 VALUES('c', 'A'); + SELECT name FROM sqlite_master; +} {t1 sqlite_autoindex_t1_1} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 7.1 { + PRAGMA writable_schema = 1; + DELETE FROM sqlite_master WHERE name = 'sqlite_autoindex_t1_1'; +} +do_test 7.2 { + db close + sqlite3 db test.db + catchsql { UPDATE t1 SET x='d' AND y='D' WHERE rowid = 2 } +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# At one point an assert() would fail if attempt was made to free page 1. +# +reset_db +do_execsql_test 8.0 { + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); + INSERT INTO t1 VALUES(zeroblob(300)); +} {} + +do_test 8.1 { + db close + hexio_write test.db [expr 1024 + 8] 00000001 + sqlite3 db test.db + catchsql { DELETE FROM t1 } +} {1 {database disk image is malformed}} + +do_test 8.2 { + db close + sqlite3 db test.db + execsql { PRAGMA integrity_check } +} {/.*in database main.*/} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptJ.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptJ.test new file mode 100644 index 0000000000000000000000000000000000000000..732adb085cd8d4df5eb5888e68981bb61b0e8c1b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptJ.test @@ -0,0 +1,80 @@ +# 2015-03-30 +# +# 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. +# +#*********************************************************************** +# +# Corruption consisting of a database page that thinks it is a child +# of itself. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix corruptJ + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b); + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) + INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c; +} {} +db close + +# Corrupt the root page of the t1 table such that the left-child pointer +# for the very first cell points back to the root. Then try to DROP the +# table. The clearDatabasePage() routine should not loop. +# +do_test 1.2 { + hexio_write test.db [expr {2*1024-2}] 02 + sqlite3 db test.db + catchsql { DROP TABLE t1 } +} {1 {database disk image is malformed}} + +# Similar test using a WITHOUT ROWID table +# +do_test 2.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; + WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) + INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; + } +} {} + +# The table is three levels deep. Corrupt the left child of an intermediate +# page so that it points back to the root page. +# +do_test 2.2 { + db close + hexio_read test.db [expr {9*1024+391}] 8 +} {00000008814D0401} +do_test 2.2b { + hexio_write test.db [expr {9*1024+391}] 00000002 + sqlite3 db test.db + catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; } +} {1 {database disk image is malformed}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptK.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptK.test new file mode 100644 index 0000000000000000000000000000000000000000..0bdb3c45b5f0dd7697193455120dbc804283271b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptK.test @@ -0,0 +1,234 @@ +# 2017-03-03 +# +# 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 corruptK + +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} +database_may_be_corrupt + +# Initialize the database. +# +do_execsql_test 1.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(100)); -- make this into a free slot + INSERT INTO t1 VALUES(randomblob(27)); -- this one will be corrupt + INSERT INTO t1 VALUES(randomblob(800)); + + DELETE FROM t1 WHERE rowid=2; -- free the 100 byte slot + PRAGMA page_count +} {2} + + +# Corrupt the database so that the blob stored immediately before +# the free slot (rowid==3) has an overlarge length field. So that +# we can use sqlite3_blob_write() to manipulate the size field of +# the free slot. +# +# Then use sqlite3_blob_write() to set the size of said free slot +# to 24 bytes (instead of the actual 100). +# +# Then use the new 24 byte slot. Leaving the in-memory version of +# the page with zero free slots and a large nFree value. Then try +# to allocate another slot to get to defragmentPage(). +# +do_test 1.2 { + db close + hexio_write test.db [expr 1024 + 0x360] 21 + hexio_write test.db [expr 1024 + 0x363] [format %x [expr 31*2 + 12]] + sqlite3 db test.db + + set fd [db incrblob t1 x 3] + fconfigure $fd -translation binary + seek $fd 30 + puts -nonewline $fd "\x18" + close $fd +} {} +do_execsql_test 1.3 { + INSERT INTO t1 VALUES(randomblob(20)); +} + +# This test no longer functions due to the deferred computation of +# MemPage.nFree. +# +if 0 { +do_catchsql_test 1.4 { + INSERT INTO t1 VALUES(randomblob(90)); +} {1 {database disk image is malformed}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.1 { + PRAGMA page_size=1024; + PRAGMA auto_vacuum=0; + CREATE TABLE t1(x); + + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(20)); -- free this one + INSERT INTO t1 VALUES(randomblob(20)); + INSERT INTO t1 VALUES(randomblob(20)); -- and this one + INSERT INTO t1 VALUES(randomblob(20)); -- corrupt this one. + + DELETE FROM t1 WHERE rowid IN(2, 4); + PRAGMA page_count +} {2} + +do_test 2.2 { + db close + hexio_write test.db [expr 1024 + 0x388] 53 + hexio_write test.db [expr 1024 + 0x38A] 03812C + + sqlite3 db test.db + set fd [db incrblob t1 x 5] + fconfigure $fd -translation binary + + seek $fd 22 + puts -nonewline $fd "\x5d" + close $fd +} {} + +do_catchsql_test 2.3 { + INSERT INTO t1 VALUES(randomblob(900)); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- + +ifcapable vtab { +if {[permutation]!="inmemory_journal"} { + + proc hex2blob {hex} { + # Split on newlines: + set bytes [list] + foreach l [split $hex "\n"] { + if {[string is space $l]} continue + set L [list] + foreach b [split $l] { + if {[string is xdigit $b] && [string length $b]==2} { + lappend L [expr "0x$b"] + } + } + if {[llength $L]!=16} { + error "Badly formed hex (1)" + } + set bytes [concat $bytes $L] + } + + binary format c* $bytes + } + + reset_db + db func hex2blob hex2blob + + do_execsql_test 3.1 { + PRAGMA page_size=1024; + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(a, b, c); + CREATE TABLE t3(a, b, c); + CREATE TABLE t4(a, b, c); + CREATE TABLE t5(a, b, c); + } + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 3.2 { + UPDATE sqlite_dbpage SET data = hex2blob(' + 000: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3. + 010: 04 00 01 01 20 40 20 20 00 00 3e d9 00 00 00 06 .... @ ..>..... + 020: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ + 030: 0f 00 00 00 00 00 00 00 00 00 00 01 00 00 83 00 ................ + 040: 00 00 00 00 00 00 00 00 00 00 00 00 00 38 00 00 .............8.. + 050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3e d9 ..............>. + 060: 00 2d e6 07 0d 00 00 00 01 03 a0 00 03 e0 00 00 .-.............. + 070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0d0: 00 00 00 00 00 c1 00 00 00 00 00 00 00 00 00 00 ................ + 0e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 160: 00 83 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 180: 00 00 00 00 00 00 00 00 00 00 07 00 30 00 00 00 ............0... + 190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1c0: 02 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 ................ + 1d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 1f0: 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 210: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 220: 00 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 230: 0c 00 00 00 00 00 00 60 00 00 00 06 00 00 c3 00 .......`........ + 240: 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 250: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 260: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 270: 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 290: 04 00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2b0: 00 00 00 00 83 00 8c 00 00 00 00 00 00 00 00 00 ................ + 2c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 2f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 310: 00 78 00 00 00 00 00 00 00 00 00 00 00 00 70 00 .x............p. + 320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 340: 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 350: 00 00 00 00 00 68 00 00 00 00 00 00 00 00 00 00 .....h.......... + 360: 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 ................ + 370: 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 ................ + 380: 00 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 ....p........... + 390: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + 3a0: 5e 01 07 17 1b 1b 01 81 13 74 61 62 6c 65 73 65 ^........tablese + 3b0: 6e 73 6f 32 73 73 65 6e 73 6f 72 73 02 43 52 45 nso2ssensors.CRE + 3c0: 41 54 45 20 54 41 42 4c 45 20 73 65 6e 73 6f 72 ATE TABLE sensor + 3d0: 73 20 0a 20 20 24 20 20 20 20 20 20 20 20 20 20 s . $ + 3e0: b8 6e 61 6d 65 21 74 65 78 74 2c 20 79 61 6c 20 .name!text, yal + 3f0: 72 65 61 6c 2c 20 74 69 6d 65 20 74 65 78 74 29 real, time text) + ') WHERE pgno=1 + } + + db close + sqlite3 db test.db + + do_catchsql_test 3.3 { + PRAGMA integrity_check; + } {1 {database disk image is malformed}} + +} ;# [permutation]!="inmemory_journal" +} ;# ifcapable vtab + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptL.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptL.test new file mode 100644 index 0000000000000000000000000000000000000000..52adf6fd72bb114a9915177fca3094371240f6ac --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptL.test @@ -0,0 +1,1593 @@ +# 2019-01-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 corruptL + +database_may_be_corrupt + +#------------------------------------------------------------------------- +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 356352 pagesize 4096 filename crash-acaae0347204ae.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 d0 00 00 00 .....@ ........ +| 32: 40 00 ea 00 00 00 00 00 00 40 00 00 00 40 00 00 @........@...@.. +| 96: 00 00 00 00 0d 00 00 00 04 0e 9c 00 0f ad 0f 4f ...............O +| 112: 0e fc 0e 9c 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3728: 00 00 00 00 00 00 00 00 00 00 00 00 5e 04 07 17 ............^... +| 3744: 1f 1f 01 81 0b 74 61 62 6c 65 74 31 5f 70 61 72 .....tablet1_par +| 3760: 65 6e 74 74 31 5f 70 61 72 65 6e 74 04 43 52 45 entt1_parent.CRE +| 3776: 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 70 61 ATE TABLE .t1_pa +| 3792: 72 65 6e 74 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 rent.(nodeno INT +| 3808: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 EGER PRIMARY KEY +| 3824: 2c 70 61 72 65 6e 74 6e 6f 64 65 29 51 03 06 17 ,parentnode)Q... +| 3840: 1b 1b 01 7b 74 61 62 6c 65 74 31 5f 6e 6f 64 65 ....tablet1_node +| 3856: 74 31 5f 6e 6f 64 65 03 43 52 45 41 54 45 20 54 t1_node.CREATE T +| 3872: 41 42 4c 45 20 22 74 31 5f 6e 6f 64 65 22 28 6e ABLE .t1_node.(n +| 3888: 6f 64 65 6e 6f 20 49 4e 54 45 47 45 52 20 50 52 odeno INTEGER PR +| 3904: 49 4d 41 52 59 20 4b 45 59 2c 64 61 74 61 29 5c IMARY KEY,data). +| 3920: 02 07 17 1d 1d 01 81 0b 74 61 62 6c 65 74 31 5f ........tablet1_ +| 3936: 72 6f 77 69 64 74 31 5f 72 6f 77 69 64 02 43 52 rowidt1_rowid.CR +| 3952: 45 41 54 45 20 54 41 42 4c 45 20 22 74 31 5f 72 EATE TABLE .t1_r +| 3968: 6f 77 69 64 22 28 72 6f 77 69 64 20 49 4e 54 45 owid.(rowid INTE +| 3984: 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c GER PRIMARY KEY, +| 4000: 6e 6f 64 65 6e 6f 2c 61 30 2c 61 31 29 51 01 07 nodeno,a0,a1)Q.. +| 4016: 17 11 11 08 81 0f 74 61 62 6c 65 74 31 74 31 43 ......tablet1t1C +| 4032: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 REATE VIRTUAL TA +| 4048: 42 4c 45 20 74 31 20 55 53 49 4e 47 20 72 74 72 BLE t1 USING rtr +| 4064: 65 65 28 69 64 2c 78 30 20 50 52 49 4d 41 52 59 ee(id,x0 PRIMARY +| 4080: 20 4b 45 59 2c 70 61 72 65 6e 74 6e 6f 64 65 29 KEY,parentnode) +| page 2 offset 4096 +| 0: 51 03 06 17 1b 1b 01 7b 74 61 62 6c 65 74 31 5f Q.......tablet1_ +| 16: 6e 6f 64 65 74 31 5f 6e 6f 64 65 03 43 52 45 41 nodet1_node.CREA +| 32: 54 45 20 54 41 42 4c 45 20 22 74 31 5f 6e 6f 64 TE TABLE .t1_nod +| 48: 65 22 28 6e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 e.(nodeno INTEGE +| 64: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 80: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 96: 65 74 31 5f 72 6f 77 69 64 74 31 5f 72 6f 77 69 et1_rowidt1_rowi +| 112: 64 02 43 52 45 41 54 45 20 54 41 42 4c 45 00 00 d.CREATE TABLE.. +| 128: 01 0a 02 00 00 00 01 0e 0d 00 00 00 00 24 0e 0d .............$.. +| 144: 0c 1a 06 85 50 46 60 27 70 08 00 00 00 00 00 00 ....PF`'p....... +| 3824: 00 00 00 00 00 00 00 0d 0e 05 00 09 1d 00 74 6f ..............to +| 3840: 79 20 68 61 6c 66 10 0d 05 00 09 23 00 62 6f 74 y half.....#.bot +| 3856: 74 6f 6d 20 68 61 6c 66 0f 0c 05 00 09 21 00 72 tom half.....!.r +| 3872: 69 67 68 74 20 68 61 6c 66 0e 0b 05 00 09 1f 00 ight half....... +| 3888: 6c 65 66 74 20 43 15 f6 e6 f6 46 50 34 35 24 54 left C....FP45$T +| 3904: 15 44 52 05 44 14 24 c4 52 02 27 43 15 f6 e6 f6 .DR.D.$.R.'C.... +| 3920: 46 52 22 8e 6f 64 65 6e 6f 20 49 4e 54 45 47 45 FR..odeno INTEGE +| 3936: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 64 61 R PRIMARY KEY,da +| 3952: 74 61 29 5c 02 07 17 1d 1d 01 81 0b 74 61 62 6c ta).........tabl +| 3968: 65 74 31 5f 72 6f 74 74 6f 6d 20 65 64 67 65 0f et1_rottom edge. +| 3984: 07 05 00 09 21 00 72 69 67 68 74 20 65 64 67 65 ....!.right edge +| 4000: 0e 06 05 00 09 1f 00 6c 65 66 74 20 65 64 67 65 .......left edge +| 4016: 0b 05 05 00 09 19 00 63 65 6e 74 65 72 17 04 05 .......center... +| 4032: 00 09 31 00 75 70 70 65 72 2d 72 69 67 68 74 20 ..1.upper-right +| 4048: 63 6f 72 6e 65 72 17 03 05 00 09 31 00 6c 6f 77 corner.....1.low +| 4064: 65 72 2d 72 69 67 68 74 20 63 6f 72 6e 65 72 16 er-right corner. +| 4080: 02 05 00 09 2f 00 75 70 70 65 72 2d 6c 65 66 74 ..../.upper-left +| page 3 offset 8192 +| 0: 20 63 6f 72 6e 65 72 16 01 05 00 09 2f 01 8c 6f corner...../..o +| 16: 77 65 72 2d 6c 53 51 4c 69 74 65 20 66 6f 72 6d wer-lSQLite form +| 32: 61 74 20 33 00 10 00 01 01 00 40 20 20 00 00 00 at 3......@ ... +| 48: 00 00 00 00 2f 00 00 0d eb 13 00 00 00 03 00 00 ..../........... +| 64: 00 04 00 00 00 00 00 00 00 06 00 00 00 01 00 00 ................ +| 80: 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| page 6 offset 20480 +| 128: 00 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 .........=..|... +| 624: 00 00 00 00 00 00 21 97 3d 04 ae 7c 01 00 00 00 ......!.=..|.... +| 1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00 ..... .=..|..... +| 1616: 00 00 00 00 1f 97 3d 04 ae 7c 01 00 00 00 00 00 ......=..|...... +| 2112: 00 00 00 1e 97 3d 04 ae 7c 01 00 00 00 00 00 00 .....=..|....... +| 2608: 00 00 1d 97 d3 d0 4a e7 c0 00 00 00 00 00 00 00 ......J......... +| 3088: 00 00 00 00 00 00 00 00 00 00 00 00 01 f3 00 00 ................ +| 3600: 23 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00 #.=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26 ...............& +| page 8 offset 28672 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 97 4d 1e 14 00 ae 7c 00 00 00 00 00 00 00 00 00 .M....|......... +| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................ +| page 10 offset 36864 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 9a ee c1 80 fd 78 1f ce 1b ae eb b4 00 00 00 00 .....x.......... +| 1088: 13 20 ff 20 00 70 00 00 00 60 50 00 00 00 11 e0 . . .p...`P..... +| 1104: 00 00 00 70 00 00 00 60 50 05 35 14 c6 97 46 52 ...p...`P.5...FR +| 1120: 06 66 f7 26 d6 17 42 03 30 01 00 00 10 10 04 02 .f.&..B.0....... +| 1136: 02 00 00 00 00 00 00 00 00 40 00 00 00 00 00 00 .........@...... +| 1152: 00 00 00 00 00 40 00 00 00 40 00 00 00 00 00 00 .....@...@...... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................ +| page 12 offset 45056 +| 0: 0d 00 00 00 01 04 30 00 04 30 e1 b4 30 97 4d 46 ......0..0..0.MF +| 16: 14 00 ae 7c 00 00 00 00 00 00 00 03 00 00 43 00 ...|..........C. +| page 47 offset 188416 +| 2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00 ................ +| page 87 offset 352256 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| end crash-acaae0347204ae.db +}]} {} + +do_catchsql_test 1.1 { + PRAGMA cell_size_check = off; + DROP INDEX t1x1; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.2 { + SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.3 { + REINDEX t1; +} {1 {database disk image is malformed}} + +do_catchsql_test 1.4 { + PRAGMA integrity_check +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +reset_db +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash.txt.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 05 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c ..........U..t.< +| 112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00 .....U.......... +| 3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69 .....z.......cvi +| 3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45 ewv1v1CREATE VIE +| 3696: 57 20 76 31 28 78 2c 79 29 20 41 53 0a 53 45 4c W v1(x,y) AS.SEL +| 3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52 ECT t1.b,t2.b FR +| 3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74 OM t1,t2 WHERE t +| 3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42 1.a=t2.a GROUP B +| 3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20 Y 1 HAVING t2.c +| 3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31 NOT NULL.LIMIT 1 +| 3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32 0&......9tablet2 +| 3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 t2.CREATE TABLE +| 3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01 t2(a,b,c)A...... +| 3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 04 43 52 45 kindext1x1t1.CRE +| 3856: 41 54 45 20 49 4e 44 45 58 20 73 31 78 31 20 4f ATE INDEX s1x1 O +| 3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65 N t1(d) WHERE ee +| 3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17 IS NOT NULL6... +| 3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31 ...Sindext1abct1 +| 3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b abc ON t1(a,b,c+ +| 3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61 d+e)..........ta +| 3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54 blet1t1.CREATE T +| 3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c ABLE t1(a,b,c,d, +| 4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a e,f,g,h,j,jj,jjj +| 4016: 2c 6b 2c 61 61 2c 62 62 2c 63 63 2c 64 64 2c 65 ,k,aa,bb,cc,dd,e +| 4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a e DEFAULT 3.14,. +| 4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63 ff DEFAULT('hicc +| 4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c up'),gg NOT NULL +| 4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29 DEFAULT(false)) +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68 ...............h +| 16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 7b 00 00 00 00 .A.............. +| 3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01 ...........&.... +| 3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 85 1f 68 69 63 ..Z..@...Q...hic +| 3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00 cup&............ +| 3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e ..........P..@.. +| 3776: b8 51 eb 85 1f 68 69 63 63 75 70 26 08 14 01 01 .Q...hiccup&.... +| 3792: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63 ..F..@...Q...hic +| 3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00 cup%............ +| 3840: 00 00 00 00 00 00 07 b9 08 06 3c 78 40 09 1e b8 .............|......... +| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 ................ +| page 26 offset 102400 +| 2512: 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 ................ +| page 27 offset 106496 +| 0: 00 00 00 00 00 00 00 12 00 00 00 07 00 00 00 1d ................ +| 16: 00 00 00 09 00 00 00 1f 00 00 00 0b 00 00 00 21 ...............! +| 32: 00 00 00 0d 00 00 00 25 00 00 00 0f 00 00 00 19 .......%........ +| 48: 00 00 00 11 00 00 00 29 00 00 00 13 00 00 00 2b .......).......+ +| 64: 00 00 00 15 00 00 00 2d 00 00 00 2e 00 00 00 17 .......-........ +| page 28 offset 110592 +| 2512: 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 ................ +| page 30 offset 118784 +| 2512: 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 .......2........ +| page 32 offset 126976 +| 2512: 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00 .......F........ +| page 34 offset 135168 +| 2512: 00 00 00 00 00 00 00 5a 00 00 00 00 00 00 00 00 .......Z........ +| page 35 offset 139264 +| 0: 0a 08 44 00 05 02 77 00 0e 11 0a 33 06 55 02 77 ..D...w....3.U.w +| 16: 04 66 00 88 00 88 00 88 00 00 00 00 00 00 00 00 .f.............. +| 128: 00 00 00 00 00 00 00 00 04 66 01 ef 00 00 00 00 .........f...... +| 624: 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 00 ........=..|.... +| 1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00 ..... .=..|..... +| 1616: 00 00 00 00 22 97 3d 04 ae 7c 01 00 00 00 00 00 ......=..|...... +| 2112: 00 00 00 1e 0c 22 01 ef 00 00 00 00 00 00 00 00 ................ +| 2608: 00 00 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 ....=..|........ +| 3104: 00 1c 00 00 01 ef 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00 ..=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ +| page 36 offset 143360 +| 0: 0a 08 44 00 04 02 77 00 06 55 02 77 04 66 0e 11 ..D...w..U.w.f.. +| 16: 00 88 00 88 00 88 0e 11 00 00 00 00 00 00 00 00 ................ +| 128: 00 00 00 00 00 00 00 00 04 76 01 ef 00 00 00 00 .........v...... +| 624: 00 00 00 00 00 00 00 97 3e 04 ae 7c 02 00 00 00 ........>..|.... +| 1120: 00 00 00 00 00 2a 97 3e 04 ae 7c 02 00 00 00 00 .....*.>..|..... +| 1616: 00 00 00 00 2c 97 3e 04 ae 7c 02 00 00 00 00 00 ....,.>..|...... +| 2112: 00 00 00 28 00 00 05 cd 00 00 00 00 00 00 00 00 ...(............ +| 3600: 00 97 3e 04 ae 7c 02 00 00 00 00 00 00 00 00 00 ..>..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2f .............../ +| page 38 offset 151552 +| 2512: 00 00 00 00 00 00 00 6e 00 00 00 00 00 00 00 00 .......n........ +| page 40 offset 159744 +| 2512: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 ................ +| page 42 offset 167936 +| 2512: 00 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00 ................ +| page 44 offset 176128 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| page 47 offset 188416 +| 2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00 ................ +| end crash-9ae5502296c949.db +}]} {} + +do_catchsql_test 5.1 { + INSERT INTO t1(b) VALUES(zeroblob(40000)); +} {1 {database disk image is malformed}} + +do_catchsql_test 5.2 { + DROP INDEX t1x2; +} {0 {}} + +do_catchsql_test 5.3 { + INSERT INTO t1(b) VALUES(zeroblob(40000)); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 6.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash-d260f001fa015c.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 ff ff f0 00 00 00 02 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 64 00 00 00 01 00 00 00 00 .......d........ +| 96: 00 00 00 00 0d 0f f8 00 04 0e ce 00 0f 4c 0f d3 .............L.. +| 112: 0e fa 0e ce 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2a 04 ..............*. +| 3792: 06 17 13 11 01 3f 69 6e 64 65 78 74 31 62 74 31 .....?indext1bt1 +| 3808: 05 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3824: 62 20 4f 4e 20 74 31 28 62 29 50 03 06 17 2b 2b b ON t1(b)P...++ +| 3840: 01 59 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 65 .Ytablesqlite_se +| 3856: 71 75 65 6e 63 65 73 71 6c 69 74 65 5f 73 65 71 quencesqlite_seq +| 3872: 75 65 6e 63 65 04 43 52 45 41 54 45 20 54 41 42 uence.CREATE TAB +| 3888: 4c 45 20 73 71 6c 69 74 65 5f 73 65 71 75 65 6e LE sqlite_sequen +| 3904: 63 65 28 6e 61 6d 65 2c 73 65 71 29 81 04 01 07 ce(name,seq).... +| 3920: 17 11 11 01 81 73 74 61 62 6c 65 74 31 74 31 02 .....stablet1t1. +| 3936: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 CREATE TABLE t1( +| 3952: 61 20 52 45 41 4c 20 4e 4f 54 20 4e 55 4c 4c 20 a REAL NOT NULL +| 3968: 44 45 46 41 55 4c 54 28 32 35 2b 33 32 29 2c 62 DEFAULT(25+32),b +| 3984: 20 46 4c 4f 41 54 2c 63 20 44 4f 55 42 4c 45 20 FLOAT,c DOUBLE +| 4000: 55 4e 49 51 55 45 2c 0a 64 20 43 4c 4f 42 2c 65 UNIQUE,.d CLOB,e +| 4016: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY +| 4032: 20 4b 45 59 20 41 55 54 4f 49 4e 43 52 45 4d 45 KEY AUTOINCREME +| 4048: 4e 54 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 NT)#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 05 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 4 offset 12288 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| end crash-d260f001fa015c.db +}]} {} + +do_catchsql_test 6.1 { + BEGIN; + INSERT INTO t1(b) VALUES(1); + INSERT INTO t1(b) VALUES(2); + COMMIT; +} {1 {malformed database schema (t1b) - invalid rootpage}} + +#------------------------------------------------------------------------- +reset_db +do_test 7.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 20480 pagesize 4096 filename crash-8391315d75edff.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 05 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c ..........U..t.< +| 112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00 .....U.......... +| 3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69 .....z.......cvi +| 3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45 ewv1v1CREATE VIE +| 3696: 57 20 76 31 28 78 2c 69 29 20 41 53 0a 53 45 4c W v1(x,i) AS.SEL +| 3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52 ECT t1.b,t2.b FR +| 3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74 OM t1,t2 WHERE t +| 3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42 1.a=t2.a GROUP B +| 3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20 Y 1 HAVING t2.c +| 3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31 NOT NULL.LIMIT 1 +| 3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32 0&......9tablet2 +| 3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 t2.CREATE TABLE +| 3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01 t2(a,b,c)A...... +| 3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 03 43 52 45 kindext1x1t1.CRE +| 3856: 41 54 45 20 49 4e 44 45 58 20 74 31 78 31 20 4f ATE INDEX t1x1 O +| 3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65 N t1(d) WHERE ee +| 3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17 IS NOT NULL6... +| 3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31 ...Sindext1abct1 +| 3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 .CREATE INDEX t1 +| 3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b abc ON t1(a,b,c+ +| 3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61 d+e)..........ta +| 3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54 blet1t1.CREATE T +| 3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c ABLE t1(a,b,c,d, +| 4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a e,f,g,h,j,jj,jjj +| 4016: 2c 6b 2c 61 61 2c 62 69 8c 63 63 2c 64 64 2c 65 ,k,aa,bi.cc,dd,e +| 4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a e DEFAULT 3.14,. +| 4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63 ff DEFAULT('hicc +| 4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c up'),gg NOT NULL +| 4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29 DEFAULT(false)) +| page 2 offset 4096 +| 0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68 ...............h +| 16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 22 00 00 00 00 .A.............. +| 3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01 ...........&.... +| 3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 95 1f 68 69 63 ..Z..@...Q...hic +| 3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00 cup&............ +| 3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e ..........P..@.. +| 3776: b8 51 eb 85 1f 68 69 63 63 74 70 26 08 14 01 01 .Q...hicctp&.... +| 3792: 03 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 ................ +| 3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63 ..F..@...Q...hic +| 3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00 cup%............ +| 3840: 00 00 00 00 00 10 07 19 08 06 3c 78 40 09 1e b8 .................. +| 1616: 00 00 00 00 1f 97 00 00 00 00 00 00 00 00 00 00 ................ +| 2112: 00 00 00 1e 97 3d 00 00 00 00 00 00 00 00 00 00 .....=.......... +| 2608: 00 1d 97 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 8 offset 28672 +| 1184: 00 00 00 00 00 00 00 00 00 97 4d 1e 13 ff ae 7c ..........M....| +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 90 ................ +| page 9 offset 32768 +| 256: 0d 01 c0 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| page 10 offset 36864 +| 0: 0d 00 22 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 ................ +| page 12 offset 45056 +| 0: 0d 00 00 00 01 04 30 00 00 00 00 00 00 00 00 00 ......0......... +| page 14 offset 53248 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 96 4d 5a 14 00 00 00 00 00 00 00 00 00 00 00 00 .MZ............. +| page 16 offset 61440 +| 0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00 ......0..0...... +| 1072: 97 4d 6e 14 00 ae 7b ff ff ff ff 00 00 00 00 00 .Mn............. +| page 18 offset 69632 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 M............... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| page 20 offset 77824 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 16 14 00 ae 00 00 00 00 00 00 00 00 00 00 M............... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f ................ +| page 22 offset 86016 +| 0: 0d 00 00 00 01 04 2f 00 04 2f 01 00 00 00 00 00 ....../../...... +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 2a 14 00 00 00 00 00 00 00 00 00 00 00 00 M.*............. +| page 24 offset 94208 +| 1072: 00 97 4c 0a 14 00 ae 7c 00 00 00 00 00 00 00 00 ..L....|........ +| page 25 offset 98304 +| 1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97 ................ +| 1072: 4d 81 3e 14 00 ae 7c 00 00 18 ff 00 00 00 00 00 M.>...|......... +| page 27 offset 106496 +| 0: 00 00 00 00 00 00 00 12 00 00 00 07 00 00 00 1d ................ +| 16: 00 00 00 09 00 00 00 1f 00 00 00 0b 00 00 00 21 ...............! +| 32: 00 00 00 0d 00 10 00 25 00 00 00 0f 00 00 00 27 .......%.......' +| 48: 00 00 00 11 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 32 offset 126976 +| 2512: 00 00 00 00 00 00 00 45 21 00 00 00 00 00 00 00 .......E!....... +| page 35 offset 139264 +| 0: 00 0a 08 44 00 05 02 77 00 0e 11 0a 92 00 00 00 ...D...w........ +| 1120: 00 00 00 00 00 20 97 00 00 00 00 00 00 00 00 00 ..... .......... +| 1616: 00 00 00 00 22 00 00 00 00 00 00 00 00 00 00 00 ................ +| 2608: 00 00 00 97 3d 04 00 00 00 00 00 00 00 00 00 00 ....=........... +| 3104: 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 3d 04 ae 7c 00 00 00 00 00 00 00 00 00 00 ..=..|.......... +| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ +| page 36 offset 143360 +| 0: 0a 08 44 00 04 02 00 00 00 00 00 00 00 00 00 00 ..D............. +| 1120: 00 00 00 00 00 2a 97 3e 04 00 00 00 00 00 00 00 .....*.>........ +| 1616: 00 00 00 00 2c 97 3e 00 00 00 00 00 00 00 00 00 ....,.>......... +| 2112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 38 ...............8 +| 2128: 00 00 05 cd 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3600: 00 97 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 38 offset 151552 +| 2464: 00 00 00 00 00 00 00 00 00 6e 00 00 00 00 00 00 .........n...... +| page 40 offset 159744 +| 2512: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 ................ +| page 42 offset 167936 +| 2512: 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00 00 ................ +| page 44 offset 176128 +| 2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00 ................ +| end crash-41390d95d613b6.db +}]} {} + +do_catchsql_test 10.1 { + PRAGMA writable_schema=ON; -- bypass improved sqlite_master consistency checking + SELECT * FROM t1 WHERE a<='2019-05-09' ORDER BY a DESC; +} {1 {database disk image is malformed}} + + +#------------------------------------------------------------------------- +reset_db +do_test 11.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 595 pagesize 512 filename x.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: 02 00 00 01 00 40 20 20 00 01 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 05 07 a1 1f fa 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 01 00 00 49 00 00 00 00 00 05 00 00 00 00 .....I.......... +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 62 00 00 00 00 00 .V...*....b..... +| 128: 00 ed e2 78 74 64 33 ff 43 52 45 41 54 45 20 49 ...xtd3.CREATE I +| 144: 4e 44 45 58 20 74 33 78 20 4f 4e 20 74 33 28 38 NDEX t3x ON t3(8 +| 160: 29 2e 04 06 17 15 11 01 45 69 6e 64 65 68 74 32 ).......Eindeht2 +| 176: 63 64 74 31 e5 43 52 45 41 54 45 20 49 4e 44 45 cdt1.CREATE INDE +| 192: 58 20 74 32 63 c4 20 4f 4e 20 74 32 28 63 2c 64 X t2c. ON t2(c,d +| 208: 29 28 05 06 17 01 11 11 3d 74 61 6c 36 74 62 74 )(......=tal6tbt +| 224: 65 32 04 43 52 45 41 54 45 20 54 41 42 4c 45 20 e2.CREATE TABLE +| 240: 74 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 t............... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 30 e8 03 .............0.. +| 272: 62 6c 65 74 34 74 35 02 43 52 45 41 54 45 20 54 blet4t5.CREATE T +| 288: 41 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 ABLE t4(.)*..... +| 304: 01 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 .?i3tnexxtd3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 31 28 38 29 2e 04 06 17 15 11 01 45 69 6e t1(8).......Ein +| 352: 64 65 68 74 32 63 64 74 31 e5 43 52 45 41 54 45 deht2cdt1.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 c4 20 4f 4e 20 74 INDEX t2c. ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 01 11 11 3d 74 61 2(c,d)(......=ta +| 400: 6c 32 74 62 74 65 32 04 43 52 45 41 54 45 20 54 l2tbte2.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 9e 93 65 74 32 74 (......=ta..et2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 55 61 62 6c 88 74 31 74 31 02 43 52 45 41 .5Uabl.t1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 0d 25 00 01 cf 00 01 fa 01 f3 01 de .....%.......... +| 16: 01 00 00 00 fd 00 00 0d 00 00 00 00 45 20 54 41 ............E TA +| 32: 42 4c 45 20 74 34 28 94 29 2a 06 06 17 13 11 01 BLE t4(.)*...... +| 48: 3f 69 33 74 6e 65 78 78 74 64 33 ff 43 52 45 a0 ?i3tnexxtd3.CRE. +| 64: a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 a0 74 13 11 01 ............t... +| 80: 49 45 74 00 00 00 00 00 00 00 00 00 00 00 00 00 IEt............. +| end x.db +}]} {} + +do_catchsql_test 11.1 { + PRAGMA writable_schema=ON; -- bypass improved sqlite_master consistency checking + DELETE FROM t3 WHERE x IN (SELECT x FROM t4); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 12.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 12288 pagesize 4096 filename crash-e6d070858a3a85.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 00 .....@ ........ +| 96: 00 00 00 00 0d 00 00 00 02 0f 8f 00 0f bf 0f 8f ................ +| 3968: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2e ................ +| 3984: 02 06 17 15 11 01 45 69 6e 64 65 78 74 31 63 62 ......Eindext1cb +| 4000: 74 31 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 t1.CREATE INDEX +| 4016: 74 31 63 62 20 4f 4e 20 74 31 28 63 2c 62 29 3f t1cb ON t1(c,b)? +| 4032: 01 06 17 11 11 01 6b 74 61 62 6c 65 74 31 74 31 ......ktablet1t1 +| 4048: 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 .CREATE TABLE t1 +| 4064: 28 61 20 49 4e 54 2c 20 62 20 49 4e 54 2c 20 43 (a INT, b INT, C +| 4080: 20 49 4e 54 20 44 45 46 41 55 4c 54 20 31 36 29 INT DEFAULT 16) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4000: 00 00 00 00 00 00 00 00 07 0b 04 01 01 01 63 63 ..............cc +| 4016: 11 05 0a 04 00 00 01 11 05 09 04 08 08 01 0f 05 ................ +| 4032: 08 04 00 00 01 01 56 07 04 01 08 01 07 10 07 06 ......V......... +| 4048: 14 01 01 01 06 08 10 06 05 04 f5 00 01 05 10 07 ................ +| 4064: 04 04 01 01 01 04 03 10 06 03 04 01 09 01 03 10 ................ +| 4080: 06 02 04 01 00 01 02 10 06 01 04 09 01 01 02 10 ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 0b 0f b0 00 0f f9 0f f2 0f eb 0f e4 ................ +| 16: 0f dd 0f d6 0f 9f 0f c7 0f be 00 00 00 00 00 00 ................ +| 4016: 07 04 01 01 01 11 e2 0b 06 04 91 00 01 11 0a 07 ................ +| 4032: 04 01 01 01 10 08 06 07 04 01 01 01 10 04 04 06 ................ +| 4048: 04 01 01 09 10 02 06 04 01 0a 01 10 00 00 00 00 ................ +| end crash-e6d070858a3a85.db +}]} {} + +do_catchsql_test 12.1 { + SELECT CAST((SELECT b FROM t1 WHERE 16=c) AS int) FROM t1 WHERE 16=c; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 13.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 8192 pagesize 4096 filename crash-81dd2952aef34f.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 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 01 0f c4 00 0f c4 00 00 ................ +| 4032: 00 00 00 00 3a 11 06 17 11 11 01 61 74 61 62 6c ....:......atabl +| 4048: 65 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 et1t1.CREATE TAB +| 4064: 4c 45 20 74 31 28 61 20 49 4e 54 45 47 45 52 20 LE t1(a INTEGER +| 4080: 50 52 49 4d 41 52 59 20 4b 45 59 2c 62 2c 63 29 PRIMARY KEY,b,c) +| page 2 offset 4096 +| 0: 0d 07 70 00 02 0f eb 00 0f fa 00 00 00 00 00 00 ..p............. +| 4064: 00 00 00 00 00 00 00 00 00 00 00 05 bf ff ff ff ................ +| 4080: ff ff ff ff ff 04 00 01 00 02 04 01 00 00 00 00 ................ +| end crash-81dd2952aef34f.db +}]} {} + +do_catchsql_test 13.1 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x-2019 FROM c WHERE x<2) + INSERT INTO t1(b,c) SELECT last_insert_rowid(), x FROM c; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_test 14.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 512 pagesize 65536 filename clusterfuzz-testcase-minimized-sqlite3_dbfuzz2_fuzzer-4806406219825152 +| 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: 00 01 02 01 00 40 20 20 00 63 2e 78 00 00 00 07 .....@ .c.x.... +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 01 00 35 05 43 00 04 00 00 00 ........5.C..... +| 80: 00 00 00 00 00 00 00 00 08 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 03 00 00 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 02 00 00 00 00 00 00 00 1c .V...*.......... +| 128: 00 38 80 b2 e6 0e 00 00 00 00 00 00 00 00 00 10 .8.............. +| 144: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ +| 160: 00 00 00 00 00 00 00 00 00 00 00 00 45 20 54 41 ............E TA +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 35 74 61 .............5ta +| 272: 62 6c 00 10 00 00 34 07 43 52 54 45 20 54 41 42 bl....4.CRTE TAB +| 288: 4c 45 20 74 33 28 63 2e 78 2c 65 2c 66 15 28 3a LE t3(c.x,e,f.(: +| 304: 06 17 11 11 01 65 78 8c cc 87 85 35 05 43 72 45 .....ex....5.CrE +| 320: 41 54 48 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATH INDEX t3x ON +| 336: 20 74 33 28 78 39 2e 04 06 17 15 11 01 45 69 6e t3(x9.......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2a 44 29 28 05 fa e8 ee ed 01 3d 74 63 2(c*D)(......=tc +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2e 78 2c 65 2c 66 15 ABLE t3(c.x,e,f. +| 432: 28 3a 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (:.....=tablet2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 63 29 TE TABLE t1(a,c) +| end clusterfuzz-testcase-minimized-sqlite3_dbfuzz2_fuzzer-4806406219825152 +}]} {} + +extra_schema_checks 0 +do_catchsql_test 14.1 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} + +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file. +ifcapable altertable { + do_catchsql_test 14.2 { + ALTER TABLE t1 RENAME TO alkjalkjdfiiiwuer987lkjwer82mx97sf98788s9789s; + } {1 {database disk image is malformed}} +} +extra_schema_checks 1 + +#------------------------------------------------------------------------- +reset_db +do_test 15.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 28672 pagesize 4096 filename crash-3afa1ca9e9c1bd.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 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 00 00 00 06 0e 88 00 0f b8 0f 6d ...............m +| 112: 0f 3a 0f 0b 0e d5 0e 88 01 00 00 00 00 00 00 00 .:.............. +| 3712: 00 00 00 00 00 00 00 00 4b 06 06 17 25 25 01 5b ........K...%%.[ +| 3728: 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 74 tablesqlite_stat +| 3744: 31 73 71 6c 69 74 65 5f 73 74 61 74 31 07 43 52 1sqlite_stat1.CR +| 3760: 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 74 EATE TABLE sqlit +| 3776: 65 5f 73 74 61 74 31 28 74 62 6c 2c 69 64 78 2c e_stat1(tbl,idx, +| 3792: 73 74 61 74 29 34 05 06 17 13 11 01 53 69 6e 64 stat)4......Sind +| 3808: 65 78 63 31 63 63 31 06 43 52 45 41 54 45 20 55 exc1cc1.CREATE U +| 3824: 4e 49 51 55 45 20 49 4e 44 45 58 20 63 31 63 20 NIQUE INDEX c1c +| 3840: 4f 4e 20 63 31 28 63 2c 20 62 29 2d 04 06 17 13 ON c1(c, b)-.... +| 3856: 11 01 45 69 6e 64 65 78 63 31 64 63 31 05 43 52 ..Eindexc1dc1.CR +| 3872: 45 41 54 45 20 49 4e 44 45 58 20 63 31 64 20 4f EATE INDEX c1d O +| 3888: 4e 20 63 31 28 64 2c 20 62 29 31 03 06 17 13 11 N c1(d, b)1..... +| 3904: 01 4d 69 6e 64 65 78 62 31 63 62 31 05 43 52 45 .Mindexb1cb1.CRE +| 3920: 41 54 45 20 55 4e 49 51 55 45 20 49 4e 44 45 58 ATE UNIQUE INDEX +| 3936: 20 62 31 63 20 4f 4e 20 62 31 28 63 29 49 02 06 b1c ON b1(c)I.. +| 3952: 17 11 11 0f 7f 74 61 62 6c 65 63 31 63 31 03 43 .....tablec1c1.C +| 3968: 52 45 41 54 45 20 54 41 42 4c 45 20 63 31 28 61 REATE TABLE c1(a +| 3984: 20 49 4e 54 20 50 52 49 4d 41 52 59 20 4b 45 59 INT PRIMARY KEY +| 4000: 2c 20 62 2c 20 63 2c 20 64 29 20 57 49 54 48 4f , b, c, d) WITHO +| 4016: 55 54 20 52 4f 57 49 44 46 01 06 17 11 11 01 79 UT ROWIDF......y +| 4032: 74 61 62 6c 65 62 31 62 31 02 43 52 45 41 54 45 tableb1b1.CREATE +| 4048: 20 54 41 42 4c 45 20 62 31 28 61 20 49 4e 54 20 TABLE b1(a INT +| 4064: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c 20 PRIMARY KEY, b, +| 4080: 63 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 c) WITHOUT ROWID +| page 2 offset 4096 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f e2 ................ +| 16: 0f da 00 00 00 01 00 00 00 00 00 00 00 00 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 06 ................ +| 4048: 67 07 07 04 01 0f 01 06 66 06 07 04 01 0f 01 05 g.......f....... +| 4064: 65 05 07 04 01 0f 01 04 64 04 07 04 01 0f 01 03 e.......d....... +| 4080: 63 03 07 04 01 0f 01 02 62 0f 05 04 09 0f 09 61 c.......b......a +| page 3 offset 8192 +| 0: 0a 00 00 00 07 0f bd 00 0f f9 0f ef 0f e5 0f db ................ +| 16: 0f d1 0f c7 0f bd 00 00 00 00 01 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 09 05 01 ................ +| 4032: 0f 01 01 07 61 07 07 09 05 01 0f 01 01 06 61 06 ....a.........a. +| 4048: 06 09 05 01 0f 01 01 05 61 05 05 09 05 01 0f 01 ........a....... +| 4064: 01 04 61 04 04 09 05 01 0f 01 01 03 61 03 03 09 ..a.........a... +| 4080: 05 01 0f 01 01 02 61 0f 02 06 05 09 0f 09 09 61 ......a........a +| page 4 offset 12288 +| 0: 0a 00 00 00 07 0f d8 00 0f fc 0f f0 0f ea 0f e4 ................ +| 16: 0f de 0f d8 0f f6 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 00 05 03 01 01 07 07 05 03 ................ +| 4064: 01 01 06 06 05 03 01 01 05 05 05 03 01 01 04 04 ................ +| 4080: 05 03 01 01 03 03 05 03 01 01 0f 02 03 03 09 09 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 1f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 02 61 02 05 04 09 0f 09 61 a.......a......a +| page 6 offset 20480 +| 0: 0a 00 00 00 07 0f ca 00 0f fa 0f ea 0f e2 00 00 ................ +| 4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07 ................ +| 4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05 a.......a....... +| 4064: 61 05 07 04 01 0f 01 04 61 04 07 04 01 0f 01 03 a.......a....... +| 4080: 61 03 07 04 01 0f 01 0f 61 02 05 04 09 0f 09 61 a.......a......a +| page 7 offset 24576 +| 0: 0d 00 00 00 05 0f 1c 00 0f f0 0f e0 0f d3 0f c5 ................ +| 16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4016: 00 00 00 00 00 00 00 00 0b 05 04 11 11 13 62 31 ..............b1 +| 4032: 62 31 37 20 31 0c 04 04 11 13 13 62 31 62 31 63 b17 1......b1b1c +| 4048: 37 20 31 0b 03 04 11 11 13 63 31 63 31 37 20 31 7 1......c1c17 1 +| 4064: 0e 02 04 11 13 07 63 31 63 31 64 37 20 31 20 31 ......c1c1d7 1 1 +| 4080: 0e 01 04 11 13 17 63 31 63 31 63 37 20 31 00 00 ......c1c1c7 1.. +| end crash-3afa1ca9e9c1bd.db +}]} {} + +extra_schema_checks 0 +optimization_control db one-pass off +do_catchsql_test 15.1 { + PRAGMA cell_size_check = 0; + UPDATE c1 SET c= NOT EXISTS(SELECT 1 FROM c1 ORDER BY (SELECT 1 FROM c1 ORDER BY a)) +10 WHERE d BETWEEN 4 AND 7; +} {1 {database disk image is malformed}} +extra_schema_checks 1 +do_execsql_test 15.2 { + PRAGMA integrity_check; +} {/in database main/} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 16.0 { + CREATE TABLE t1(w, x, y, z, UNIQUE(w, x), UNIQUE(y, z)); + INSERT INTO t1 VALUES(1, 1, 1, 1); + + CREATE TABLE t1idx(x, y, i INTEGER, PRIMARY KEY(x)) WITHOUT ROWID; + INSERT INTO t1idx VALUES(10, NULL, 5); + + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = ( + SELECT rootpage FROM sqlite_master WHERE name='t1idx' + ) WHERE type = 'index'; +} + +extra_schema_checks 0 +db close +sqlite3 db test.db +extra_schema_checks 1 + +do_catchsql_test 16.1 { + PRAGMA writable_schema = ON; + INSERT INTO t1(rowid, w, x, y, z) VALUES(5, 10, 11, 10, NULL); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# Test that corruption is reported from within a checkpoint if the +# expected final size of the database (according to the last commit +# frame in the wal file) is greater than the combined initial sizes +# of the database and wal file. +# +if {[wal_is_capable]} { + reset_db + do_execsql_test 17.0 { + CREATE TABLE t1(o INTEGER PRIMARY KEY, t UNIQUE); + INSERT INTO t1(t) VALUES(randomblob(123)); + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + INSERT INTO t1(t) SELECT randomblob(123) FROM t1; + + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(-1, 'b'); + } {wal} + + do_test 17.1 { + set fd [open test.db r+] + chan truncate $fd 2048 + file size test.db + } {2048} + + do_catchsql_test 17.2 { + PRAGMA wal_checkpoint + } {1 {database disk image is malformed}} + + do_test 17.3 { + close $fd + } {} +} + +#------------------------------------------------------------------------- +reset_db +do_test 18.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 12288 pagesize 4096 filename crash-40d5739835cbdb.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 00 .....@ ........ +| 96: 00 00 00 00 0d 00 00 00 02 0f 4e 00 0f a2 0f 4e ..........N....N +| 3904: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 52 02 ..............R. +| 3920: 07 17 11 11 01 81 0f 74 61 62 6c 65 74 32 74 32 .......tablet2t2 +| 3936: 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 32 .CREATE TABLE t2 +| 3952: 28 61 20 49 4e 54 2c 20 62 20 49 4e 54 45 47 45 (a INT, b INTEGE +| 3968: 52 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28 61 R, PRIMARY KEY(a +| 3984: 2c 62 29 29 20 57 49 54 48 4f 55 54 20 52 4f 57 ,b)) WITHOUT ROW +| 4000: 49 44 5c 01 07 16 11 11 01 81 23 74 61 62 6c 65 ID........#table +| 4016: 74 31 74 31 02 43 52 45 41 54 45 20 54 41 42 4c t1t1.CREATE TABL +| 4032: 45 20 74 31 28 61 20 49 4e 54 20 50 52 49 4d 41 E t1(a INT PRIMA +| 4048: 52 59 20 4b 45 59 2c 20 62 20 54 45 58 54 2c 20 RY KEY, b TEXT, +| 4064: 63 20 54 45 58 54 2c 20 64 20 49 4e 54 45 47 45 c TEXT, d INTEGE +| 4080: 52 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 R) WITHOUT ROWID +| page 2 offset 4096 +| 0: 0a 00 00 00 06 0f a7 00 0f f4 0f e5 0f d5 0f c5 ................ +| 16: 0f b6 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4000: 00 00 00 00 00 00 00 0f 05 01 15 13 01 06 65 7f ..............e. +| 4016: 25 6e 73 69 78 06 0e 05 01 13 15 03 b5 6f 64 64 %nsix........odd +| 4032: 66 69 76 65 05 0f 05 01 15 15 01 04 65 76 65 61 five........evea +| 4048: e6 6f 75 82 04 0f 05 01 13 17 01 03 6f 64 64 74 .ou.........oddt +| 4064: 68 72 61 15 03 0e 05 01 15 12 01 02 64 76 64 6e hra.........dvdn +| 4080: 74 77 6f 02 00 00 00 00 00 00 00 00 00 00 00 00 two............. +| page 3 offset 8192 +| 2816: 00 00 00 00 00 00 00 00 00 00 00 06 03 02 01 00 ................ +| 2832: c8 07 06 03 02 01 00 c7 11 06 03 02 01 02 a6 52 ...............R +| 2848: 06 d5 02 01 10 c5 1b 06 03 02 00 ef c4 53 06 03 .............S.. +| 2864: 02 01 00 c3 22 06 04 02 01 00 c2 26 06 03 02 01 ...........&.... +| 2880: 00 c2 1e 02 b3 02 01 00 c0 3a 06 03 3c 01 00 bf .........:..<... +| 2896: 2c 06 03 02 01 00 be 27 00 83 02 01 01 bd 15 06 ,......'........ +| 2912: 03 02 01 00 bc 21 06 03 02 01 00 bb 54 16 13 02 .....!......T... +| 2928: 01 09 9a 0a 06 03 02 01 00 b9 53 06 03 02 01 00 ..........S..... +| 2944: b8 52 06 13 02 01 00 b7 1e 06 03 02 01 00 b6 34 .R.............4 +| 2960: 06 13 02 01 00 b5 3a 05 f3 12 01 00 b4 45 05 03 ......:......E.. +| 2976: 02 00 00 b4 6f 06 03 02 01 00 b2 03 06 03 02 01 ....o........... +| 2992: 00 b1 63 06 03 02 01 00 b0 24 06 03 02 01 00 9f ..c......$...... +| 3008: ac 06 03 02 01 00 a2 2f 07 03 02 01 01 ad 21 06 ......./......!. +| 3024: 03 02 01 fb cd 5b 06 c0 01 f1 00 ab 23 06 03 02 .....[......#... +| 3040: 01 00 aa 5b 06 03 02 01 00 a3 ce 06 02 03 01 00 ...[............ +| 3056: a8 0e 06 03 02 01 00 a7 0c 06 02 f1 01 00 a6 0d ................ +| 3072: 06 03 02 01 00 95 25 06 03 02 01 00 a4 17 06 03 ......%......... +| 3088: 02 01 00 a3 09 06 03 02 01 00 a2 51 06 03 02 02 ...........Q.... +| 3104: 00 a1 40 06 01 e2 00 00 a0 4b 06 13 02 00 00 9e ..@......K...... +| 3120: 5d 06 03 02 01 10 9e 81 06 03 02 01 00 9d 42 06 ].............B. +| 3136: 03 69 01 00 9c 48 06 03 02 01 00 9b 48 06 03 01 .i...H......H... +| 3152: 01 00 9a 09 06 03 02 01 00 99 2f 06 03 02 01 00 ........../..... +| 3168: 98 3a 06 03 02 01 00 97 24 06 03 02 01 00 96 4a .:......$......J +| 3184: 06 03 02 11 00 f9 50 02 93 02 01 00 94 2f 06 03 ......P....../.. +| 3200: 02 11 04 93 1a 06 03 01 04 e0 92 1a 06 03 02 01 ................ +| 3216: 00 91 27 06 03 02 01 00 90 23 06 03 02 01 00 8f ..'......#...... +| 3232: 3b 06 03 02 01 00 8e 46 06 16 02 01 00 8d 1d 07 ;......F........ +| 3248: 23 12 01 00 8c 5a 06 03 02 01 00 8a 39 06 03 02 #....Z......9... +| 3264: 00 ff 84 b5 06 03 02 01 00 89 07 06 03 02 11 00 ................ +| 3280: 88 02 06 03 02 01 00 87 19 06 03 02 01 00 86 4d ...............M +| 3296: 06 13 12 00 00 85 4b 06 03 02 01 00 84 37 06 13 ......K......7.. +| 3312: 02 01 00 83 2c 06 03 02 01 00 81 60 06 13 02 11 ....,......`.... +| 3328: 00 81 3b 06 03 02 01 0a b0 5a 06 03 01 01 7f 22 ..;......Z...... +| 3344: 05 03 01 01 7e 21 05 03 01 01 7d 0b 15 03 01 02 ....~!.......... +| 3360: 7b 08 05 03 06 91 7b 22 05 03 01 01 7a 58 05 03 ............zX.. +| 3376: 01 01 7a 4f 05 03 01 01 78 49 05 03 01 01 77 16 ..zO....xI....w. +| 3392: 05 03 01 01 76 5f 05 03 01 01 75 0f 05 03 01 01 ....v_....u..... +| 3408: 74 2f 05 03 01 01 3f 1f 05 03 01 02 72 14 05 03 t/....?.....r... +| 3424: 00 f1 71 08 05 03 01 01 70 0c 05 03 01 47 7f 29 ..q.....p....G.) +| 3440: 05 03 01 01 6e 57 05 03 01 01 6d 33 05 13 00 f1 ....nW....m3.... +| 3456: 6c 0b 05 03 01 01 6b 49 05 03 01 01 69 05 05 03 l.....kI....i... +| 3472: 01 02 ed 23 00 00 01 00 00 00 00 00 00 00 00 00 ...#............ +| end crash-40d5739835cbdb.db +}]} {} + +ifcapable json1 { +do_catchsql_test 18.1 { + SELECT + json_group_array(c) OVER win4 + FROM t1 + WINDOW win4 AS ( + ORDER BY a COLLATE nocase RANGE BETWEEN 1.0 PRECEDING AND CURRENT ROW + ) +} {1 {JSON cannot hold BLOB values}} +} ;# ifcapable json1 + +#------------------------------------------------------------------------- +reset_db +do_test 19.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 20480 pagesize 4096 filename crash-f022eb0ce64d27.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 02 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 04 0e d2 00 0f 08 0f d3 ................ +| 112: 0f ae 0e d2 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 3792: 00 00 34 04 06 17 0f 11 01 57 69 6e 64 65 78 61 ..4......Windexa +| 3808: 74 31 05 43 52 45 41 54 45 20 55 4e 49 51 55 45 t1.CREATE UNIQUE +| 3824: 20 49 4e 44 45 58 20 61 20 4f 4e 20 74 31 28 61 INDEX a ON t1(a +| 3840: 2c 20 30 20 7c 20 61 29 81 23 01 07 17 11 11 01 , 0 | a).#...... +| 3856: 82 31 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .1tablet1t1.CREA +| 3872: 54 45 20 54 41 42 4c 45 20 74 31 28 0a 20 20 20 TE TABLE t1(. +| 3888: 20 67 63 62 20 41 53 20 28 62 2a 31 29 2c 0a 20 gcb AS (b*1),. +| 3904: 20 20 20 61 20 49 34 54 45 47 45 52 20 50 52 49 a I4TEGER PRI +| 3920: 4d 41 52 59 20 4b 45 59 2c 0a 20 20 20 20 67 63 MARY KEY,. gc +| 3936: 63 20 41 53 20 28 74 32 2b 30 29 2c 0a 20 20 20 c AS (t2+0),. +| 3952: 20 62 20 55 4e 49 51 55 45 2c 0a 20 20 20 20 67 b UNIQUE,. g +| 3968: 63 61 20 41 53 20 28 31 2a 61 2b 30 29 2c 0a 20 ca AS (1*a+0),. +| 3984: 20 20 20 74 32 20 55 4e 49 51 55 45 0a 20 20 29 t2 UNIQUE. ) +| 4000: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 23 03 WITHOUT ROWID#. +| 4016: 06 17 37 11 01 00 69 6e 64 65 78 73 71 6c 69 74 ..7...indexsqlit +| 4032: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 33 e_autoindex_t1_3 +| 4048: 74 31 02 23 02 06 17 37 11 01 00 69 6e 64 65 78 t1.#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 32 74 31 02 00 00 00 08 00 00 00 00 _t1_2t1......... +| page 2 offset 4096 +| 0: 0a 00 00 00 05 0f d8 00 0f f8 0f f8 9f e8 0f e0 ................ +| 16: 0f d8 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4048: 00 00 00 00 00 00 00 00 07 04 01 02 00 0f 13 88 ................ +| 4064: 07 04 01 02 00 0e 0f a0 07 04 01 02 00 0d 0b b8 ................ +| 4080: 07 04 01 02 00 0c 07 d0 07 04 01 02 00 0b 03 e8 ................ +| page 5 offset 16384 +| 0: 0a 00 00 00 05 0f e2 00 0f fa 0f f4 0f ee 0f e8 ................ +| 16: 0f e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 4064: 00 00 05 03 01 01 0f 0f 05 03 01 01 0e 0e 05 03 ................ +| 4080: 01 01 0d 0d 05 03 01 01 0c 0c 05 03 01 01 0b 0b ................ +| end crash-f022eb0ce64d27.db +}]} {} + +do_execsql_test 19.1 { + PRAGMA writable_schema=ON; +} +do_catchsql_test 19.2 { + UPDATE t1 SET a=1; +} {1 {database disk image is malformed}} + +reset_db +do_execsql_test 19.3 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c INTEGER, d TEXT); + CREATE INDEX i1 ON t1((NULL)); + INSERT INTO t1 VALUES(1, NULL, 1, 'text value'); + PRAGMA writable_schema = on; + UPDATE sqlite_schema SET + sql = 'CREATE INDEX i1 ON t1(b, c, d)', + tbl_name = 't1', + type='index' + WHERE name='i1'; +} +db close +sqlite3 db test.db +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/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptN.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptN.test new file mode 100644 index 0000000000000000000000000000000000000000..8108609c090145ba5617c9698c011e4799714909 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/corruptN.test @@ -0,0 +1,306 @@ +# 2020-12-16 +# +# 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 corruptN + +# These tests deal with corrupt database files +# +database_may_be_corrupt + +reset_db +do_test 1.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +.open --hexdb +| size 4096 pagesize 512 filename sql024239.txt.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: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 89 00 00 04 00 10 00 01 0a 00 00 01 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 .............1ta +| 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T +| 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... +| 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 05 43 52 45 .?indext3xt3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t +| 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 04 01 41 00 01 fa 01 f3 01 de 01 cf ......A......... +| 160: 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .. ............. +| 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. +| 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... +| 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ +| page 3 offset 1024 +| 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... +| 16: 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 112: 00 00 dd 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74 ...........eight +| 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e 25 eightsevenseven% +| 368: 07 05 07 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 432: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................ +| 480: 00 00 0f 04 17 17 01 65 69 67 68 74 65 69 67 68 .......eighteigh +| 496: 74 08 15 04 07 07 01 40 18 00 00 00 00 00 00 40 t......@.......@ +| page 4 offset 1536 +| 0: 18 00 00 00 00 00 00 07 07 04 01 01 01 04 04 06 ................ +| 16: 07 04 01 01 01 02 02 05 0f 04 17 17 01 73 6d 76 .............smv +| 32: 65 6e 65 69 67 68 74 04 15 04 07 07 01 40 14 00 eneight......@.. +| page 5 offset 2048 +| 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ +| 16: 01 dc 01 e1 01 96 01 cc 00 00 00 00 00 00 00 00 ................ +| 160: 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00 00 ......2......... +| 368: 00 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 400: 00 00 00 00 00 00 0f 04 17 17 01 85 69 67 68 74 ............ight +| 416: 65 69 67 68 74 08 15 04 07 07 01 40 18 00 00 00 eight......@.... +| 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ +| 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ +| 464: 01 73 6d 76 65 6e 65 69 67 68 74 04 15 04 07 07 .smveneight..... +| 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... +| 496: 00 03 07 04 01 01 01 03 04 02 05 04 03 01 09 02 ................ +| page 6 offset 2560 +| 0: 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 16: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 ................ +| 304: 00 00 00 26 00 00 00 00 00 00 00 00 00 00 00 00 ...&............ +| page 7 offset 3072 +| 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ +| 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ +| 128: 00 00 00 00 00 00 00 00 00 00 00 00 00 20 00 04 ............. .. +| 384: 00 00 00 00 00 00 00 00 00 07 08 02 17 65 69 fc .............ei. +| 400: 68 74 07 07 02 17 65 69 67 68 74 0a fb fd f8 bf ht....eight..... +| 416: e7 ff ff ff 00 00 00 0a 05 02 07 40 18 00 00 00 ...........@.... +| 432: 00 00 00 03 04 02 01 04 03 03 02 01 04 03 02 01 ................ +| 448: ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 ................ +| end sql024239.txt.db +}]} {} + +do_catchsql_test 1.1 { + VACUUM; +} {1 {database disk image is malformed}} + +# 2021-04-05 dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 +do_test 2.0 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 16384 pagesize 4096 filename c-b92b.txt.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 04 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 96: 00 00 00 00 0d 0f f8 00 04 0f 12 00 0f 91 0f d3 ................ +| 112: 0f 67 0f 12 00 00 00 00 00 00 00 00 00 00 00 00 .g.............. +| 3856: 00 00 53 04 07 1b 13 11 08 81 0d 74 72 69 67 67 ..S........trigg +| 3872: 65 72 74 72 30 74 31 43 52 45 41 54 45 20 54 52 ertr0t1CREATE TR +| 3888: 49 47 47 45 52 20 74 72 30 20 44 45 4c 45 54 45 IGGER tr0 DELETE +| 3904: 20 4f 4e 20 74 31 20 42 45 47 49 4e 0a 20 20 55 ON t1 BEGIN. U +| 3920: 50 44 41 54 45 20 74 31 20 53 45 54 20 62 20 3d PDATE t1 SET b = +| 3936: 20 61 3b 0a 45 4e 44 28 03 06 17 11 11 01 3d 69 a;.END(......=i +| 3952: 6e 64 65 78 69 30 74 31 04 43 52 45 41 54 45 20 ndexi0t1.CREATE +| 3968: 49 4e 44 45 58 20 69 30 20 4f 4e 20 74 31 28 62 INDEX i0 ON t1(b +| 3984: 29 40 01 06 17 11 11 01 6d 74 61 62 6c 65 74 31 )@......mtablet1 +| 4000: 74 31 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 t1.CREATE TABLE +| 4016: 74 31 28 61 20 55 4e 49 51 55 45 20 4f 4e 20 43 t1(a UNIQUE ON C +| 4032: 4f 4e 46 4c 49 43 54 20 52 45 50 4c 41 43 45 2c ONFLICT REPLACE, +| 4048: 20 62 29 23 02 06 17 37 11 01 00 69 6e 64 65 78 b)#...7...index +| 4064: 73 71 6c 69 74 65 5f 61 75 74 6f 69 6e 64 65 78 sqlite_autoindex +| 4080: 5f 74 31 5f 31 74 31 03 00 00 00 08 00 00 00 00 _t1_1t1......... +| page 2 offset 4096 +| 0: 0d 00 00 00 02 0f 00 00 00 00 00 00 00 00 00 00 ................ +| 4080: 00 00 05 02 03 01 01 09 0d 05 01 03 01 01 04 0c ................ +| page 3 offset 8192 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 03 01 01 09 02 04 03 01 09 04 ................ +| page 4 offset 12288 +| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................ +| 4080: 00 00 00 00 00 05 03 01 01 0d 02 04 03 00 00 00 ................ +| end c-b92b.txt.db +}]} {} + +# This test only works with the legacy RC4 PRNG +if 0 { + prng_seed 0 db + do_catchsql_test 2.1 { + SELECT count(*) FROM sqlite_schema; + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t1(a) SELECT randomblob(null) FROM c; + } {1 {database disk image is malformed}} +} + +reset_db +if {![info exists ::G(perm:presql)]} { + do_execsql_test 3.0 { + CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT, y); + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = 'CREATE TABLE sqlite_sequence(name-seq)' + WHERE name = 'sqlite_sequence'; + } + db close + sqlite3 db test.db + do_catchsql_test 3.1 { + PRAGMA writable_schema = 1; + INSERT INTO t1(y) VALUES('abc'); + } {1 {database disk image is malformed}} + reset_db + + do_execsql_test 4.1 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b UNIQUE, c UNIQUE); + INSERT INTO x1 VALUES(1, 1, 2); + INSERT INTO x1 VALUES(2, 2, 3); + INSERT INTO x1 VALUES(3, 3, 4); + INSERT INTO x1 VALUES(4, 5, 6); + PRAGMA writable_schema = 1; + + UPDATE sqlite_schema SET rootpage = ( + SELECT rootpage FROM sqlite_schema WHERE name = 'sqlite_autoindex_x1_2' + ) WHERE name = 'sqlite_autoindex_x1_1'; + } + + db close + sqlite3 db test.db + breakpoint + do_catchsql_test 4.2 { + PRAGMA writable_schema = 1; + REPLACE INTO x1 VALUES(5, 2, 3); + } {0 {}} + +} + +#------------------------------------------------------------------------- + +reset_db + +ifcapable json1&&vtab { + db func strreplace strreplace + proc strreplace {orig a b} { + string map [list $a $b] $orig + } + + do_execsql_test 5.0 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1b ON t1(b); + + PRAGMA writable_schema = 1; + UPDATE sqlite_schema + SET sql = strreplace(sql, 't1', 'json_each') + WHERE type='index'; + } + + # Do not run this tests if there is any presql (SQL run from within + # the [sqlite3] command) configured. In this case the schema is parsed + # before the "PRAGMA writable_schema" command is executed and the + # script throws and exception. + if {[info exists ::G(perm:presql)]==0 || $::G(perm:presql)==""} { + db close + sqlite3 db test.db + + do_execsql_test 5.1 { + PRAGMA writable_schema = 1; + SELECT * FROM t1 + } + } +}; # ifcapable json1&&vtab + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 6.0 { + PRAGMA auto_vacuum = 0; + PRAGMA page_size=1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1(b) VALUES(zeroblob(300)),(zeroblob(300)),(zeroblob(300)),(zeroblob(300)); + CREATE TABLE t2(a); + CREATE TRIGGER t1tr BEFORE UPDATE ON t1 BEGIN DELETE FROM t2; END; + PRAGMA writable_schema=ON; + UPDATE sqlite_schema SET rootpage=3 WHERE rowid=2; + PRAGMA writable_schema=RESET; + INSERT INTO t2 VALUES('active'),('boomer'),('atom'),('atomic'), + ('alpha channel backup abandon test aback boomer atom alpha active'); +} +do_catchsql_test 6.1 { + UPDATE t1 SET b=zeroblob(299); +} {1 {database disk image is malformed}} + +reset_db +do_execsql_test 6.2 { + -- Make "t1" a large table. Large enough that the children of the root + -- node are interior nodes. + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(x); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500 + ) + INSERT INTO t1 SELECT zeroblob(300) FROM s; + + CREATE TABLE t2(y); + CREATE TRIGGER tr BEFORE UPDATE ON t1 BEGIN + DELETE FROM t2; + END; + + -- Set the root of table t2 to 137 - the leftmost child of the root of t1. + PRAGMA writable_schema = ON; + UPDATE sqlite_schema SET rootpage = 137 WHERE name='t2'; + PRAGMA writable_schema = RESET; +} + +do_catchsql_test 6.3 { + -- Run an UPDATE on t1 that will hit a child of page 136. Have the trigger + -- clear page 136 and its children. Assert fails. + UPDATE t1 SET x='hello world' WHERE rowid=1; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.0 { + BEGIN; + CREATE TABLE p1(x PRIMARY KEY); + CREATE TABLE c1(y); + + PRAGMA schema_version = 0; + PRAGMA writable_schema = RESET; + + INSERT INTO c1 VALUES(1000); + ROLLBACK; +} + +do_execsql_test 7.1 { + PRAGMA table_info = p1; +} {0 x {} 0 {} 1} + +do_catchsql_test 7.2 { + SELECT * FROM p1; +} {1 {database disk image is malformed}} + +do_catchsql_test 7.3 { + PRAGMA integrity_check +} {1 {database disk image is malformed}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cost.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cost.test new file mode 100644 index 0000000000000000000000000000000000000000..6106caba8ca934b63744864faea42c4045de972b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cost.test @@ -0,0 +1,289 @@ +# 2014-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 cost + + +do_execsql_test 1.1 { + CREATE TABLE t3(id INTEGER PRIMARY KEY, b NOT NULL); + CREATE TABLE t4(c, d, e); + CREATE UNIQUE INDEX i3 ON t3(b); + CREATE UNIQUE INDEX i4 ON t4(c, d); +} +do_eqp_test 1.2 { + SELECT e FROM t3, t4 WHERE b=c ORDER BY b, d; +} { + QUERY PLAN + |--SCAN t3 USING COVERING INDEX i3 + `--SEARCH t4 USING INDEX i4 (c=?) +} + + +do_execsql_test 2.1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); +} + +# It is better to use an index for ORDER BY than sort externally, even +# if the index is a non-covering index. +do_eqp_test 2.2 { + SELECT * FROM t1 ORDER BY a; +} {SCAN t1 USING INDEX i1} + +do_execsql_test 3.1 { + CREATE TABLE t5(a INTEGER PRIMARY KEY,b,c,d,e,f,g); + CREATE INDEX t5b ON t5(b); + CREATE INDEX t5c ON t5(c); + CREATE INDEX t5d ON t5(d); + CREATE INDEX t5e ON t5(e); + CREATE INDEX t5f ON t5(f); + CREATE INDEX t5g ON t5(g); +} + +do_eqp_test 3.2 { + SELECT a FROM t5 + WHERE b IS NULL OR c IS NULL OR d IS NULL + ORDER BY a; +} { + QUERY PLAN + |--MULTI-INDEX OR + | |--INDEX 1 + | | `--SEARCH t5 USING INDEX t5b (b=?) + | |--INDEX 2 + | | `--SEARCH t5 USING INDEX t5c (c=?) + | `--INDEX 3 + | `--SEARCH t5 USING INDEX t5d (d=?) + `--USE TEMP B-TREE FOR ORDER BY +} + +#------------------------------------------------------------------------- +# If there is no likelihood() or stat3 data, SQLite assumes that a closed +# range scan (e.g. one constrained by "col BETWEEN ? AND ?" constraint) +# visits 1/64 of the rows in a table. +# +# Note: 1/63 =~ 0.016 +# Note: 1/65 =~ 0.015 +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t1(b); +} +do_eqp_test 4.2 { + SELECT * FROM t1 WHERE likelihood(a=?, 0.014) AND b BETWEEN ? AND ?; +} {SEARCH t1 USING INDEX i1 (a=?)} + +do_eqp_test 4.3 { + SELECT * FROM t1 WHERE likelihood(a=?, 0.016) AND b BETWEEN ? AND ?; +} {SEARCH t1 USING INDEX i2 (b>? AND b? AND x? AND b=950 AND b<=1010) OR (b IS NULL AND c NOT NULL) + ORDER BY a +} { + QUERY PLAN + |--MULTI-INDEX OR + | |--INDEX 1 + | | `--SEARCH t1 USING INDEX t1b (b>? AND b=0} { + return 1; + } + return 0 +} + +do_test count-2.1 { + execsql { + CREATE TABLE t2(a, b); + } + uses_op_count {SELECT count(*) FROM t2} +} {1} +do_test count-2.2 { + catchsql {SELECT count(DISTINCT *) FROM t2} +} {1 {near "*": syntax error}} +do_test count-2.3 { + uses_op_count {SELECT count(DISTINCT a) FROM t2} +} {0} +do_test count-2.4 { + uses_op_count {SELECT count(a) FROM t2} +} {0} +do_test count-2.5 { + uses_op_count {SELECT count() FROM t2} +} {1} +do_test count-2.6 { + catchsql {SELECT count(DISTINCT) FROM t2} +} {1 {DISTINCT aggregates must have exactly one argument}} +do_test count-2.7 { + uses_op_count {SELECT count(*)+1 FROM t2} +} {0} +do_test count-2.8 { + uses_op_count {SELECT count(*) FROM t2 WHERE a IS NOT NULL} +} {0} +do_execsql_test count-2.9a { + SELECT count(*) FROM t2 HAVING count(*)>1; +} {} +do_execsql_test count-2.9b { + SELECT count(*) FROM t2 HAVING count(*)<10; +} {0} +do_test count-2.10 { + uses_op_count {SELECT count(*) FROM (SELECT 1)} +} {0} +do_test count-2.11 { + execsql { CREATE VIEW v1 AS SELECT 1 AS a } + uses_op_count {SELECT count(*) FROM v1} +} {0} +do_test count-2.12 { + uses_op_count {SELECT count(*), max(a) FROM t2} +} {0} +do_test count-2.13 { + uses_op_count {SELECT count(*) FROM t1, t2} +} {0} + +ifcapable vtab { + register_echo_module [sqlite3_connection_pointer db] + do_test count-2.14 { + execsql { CREATE VIRTUAL TABLE techo USING echo(t1); } + uses_op_count {SELECT count(*) FROM techo} + } {0} +} + +do_test count-3.1 { + execsql { + CREATE TABLE t3(a, b); + SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==0; + } +} {0} +do_test count-3.2 { + execsql { + SELECT a FROM (SELECT count(*) AS a FROM t3) WHERE a==1; + } +} {} + +do_test count-4.1 { + execsql { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES('a', 'b'); + CREATE INDEX t4i1 ON t4(b, a); + SELECT count(*) FROM t4; + } +} {1} +do_test count-4.2 { + execsql { + CREATE INDEX t4i2 ON t4(b); + SELECT count(*) FROM t4; + } +} {1} +do_test count-4.3 { + execsql { + DROP INDEX t4i1; + CREATE INDEX t4i1 ON t4(b, a); + SELECT count(*) FROM t4; + } +} {1} + +do_execsql_test count-5.1 { + CREATE TABLE t5(a TEXT PRIMARY KEY, b VARCHAR(50)) WITHOUT ROWID; + INSERT INTO t5 VALUES('bison','jazz'); + SELECT count(*) FROM t5; +} {1} + +do_catchsql_test count-6.1 { + CREATE TABLE t6(x); + SELECT count(DISTINCT) FROM t6 GROUP BY x; +} {1 {DISTINCT aggregates must have exactly one argument}} + +# 2020-05-08. +# The count() optimization should honor the NOT INDEXED clause +# +reset_db +do_execsql_test count-7.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c VARCHAR(1000)); + CREATE INDEX t1b ON t1(b); + INSERT INTO t1(a,b,c) values(1,2,'count.test cases for NOT INDEXED'); + ANALYZE; + UPDATE sqlite_stat1 SET stat='1000000 10' WHERE idx='t1b'; + ANALYZE sqlite_master; +} +do_eqp_test count-7.2 { + SELECT count(1) FROM t1; +} { + QUERY PLAN + `--SCAN t1 USING COVERING INDEX t1b +} +do_eqp_test count-7.3 { + SELECT count(1) FROM t1 NOT INDEXED +} { + QUERY PLAN + `--SCAN t1 +} +do_eqp_test count-7.3 { + SELECT count(*) FROM t1; +} { + QUERY PLAN + `--SCAN t1 USING COVERING INDEX t1b +} +do_eqp_test count-7.4 { + SELECT count(*) FROM t1 NOT INDEXED +} { + QUERY PLAN + `--SCAN t1 +} + +do_execsql_test count-8.0 { + CREATE TABLE t7(a INT,b TEXT,c BLOB,d REAL); + CREATE TABLE t8(a INT,b TEXT,c BLOB,d REAL); + CREATE INDEX t8a ON t8(a); +} +do_catchsql_test count-8.1 { + SELECT * FROM t8 WHERE (a, b) IN ( + SELECT count(t8.b), count(*) FROM t7 AS ra0 ORDER BY count(*) + ) AND t8.b=0; +} {1 {misuse of aggregate: count()}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/countofview.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/countofview.test new file mode 100644 index 0000000000000000000000000000000000000000..cea6fa4274035a7270eb93700f8c4bbec7ae1a86 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/countofview.test @@ -0,0 +1,107 @@ +# 2018-08-04 +# +# 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 +source $testdir/malloc_common.tcl +set testprefix countofview + +do_execsql_test 1.0 { + CREATE TABLE t2(c); + CREATE TABLE t3(f); + + INSERT INTO t2 VALUES(1), (2); + INSERT INTO t3 VALUES(3); +} + +do_execsql_test 1.1 { + select c from t2 union all select f from t3 limit 1 offset 1 +} {2} + +do_execsql_test 1.2 { + select count(*) from ( + select c from t2 union all select f from t3 limit 1 offset 1 + ) +} {1} + +do_execsql_test 1.3 { + select count(*) from ( + select c from t2 union all select f from t3 + ) +} {3} + +# 2019-05-15 +do_execsql_test 2.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1),(99),('abc'); + CREATE VIEW v1(x,y) AS SELECT x,1 FROM t1 UNION ALL SELECT x,2 FROM t1; + SELECT count(*) FROM v1 WHERE x<>1; +} {4} +do_execsql_test 2.1 { + SELECT count(*) FROM v1 GROUP BY y; +} {3 3} + +# 2023-03-01 dbsqlfuzz ef8623915d843b150c159166ee4548c78cc6895a +# count-of-view should not apply to CTEs. +# +ifcapable progress { + proc progress_stop args {return 1} + db progress 1000 progress_stop + do_catchsql_test 3.1 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c) + SELECT count(*) FROM c; + } {1 interrupted} +} + +# 2023-03-07 dbsqlfuzz 23d782160b71c3f8f535ccb2da313dfc8eb8c631 +# +do_execsql_test 4.1 { + DROP TABLE t1; + DROP TABLE t2; + DROP TABLE t3; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(4,'four'); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d TEXT); + CREATE VIEW t3 AS SELECT a, b FROM t1 UNION ALL SELECT c, d FROM t2; + SELECT count(*) FROM t3 ORDER BY sum(a); +} 1 + +# 2023-03-31 dbsqlfuzz 6a107e3055bd22afab31cfddabc2d9d54fcbaf69 +# Having clauses should disqualify count-of-view +# +reset_db +do_execsql_test 5.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1 VALUES(1,'one'),(4,'four'); + CREATE TABLE t2(c INTEGER PRIMARY KEY, d TEXT); + INSERT INTO t2 VALUES(2,'two'),(5,'five'); + CREATE VIEW t3 AS SELECT a, b FROM t1 UNION ALL SELECT c, d FROM t2; + SELECT count(*) FROM t3 HAVING count(*)>0; +} 4 +do_execsql_test 5.2 { + SELECT count(*) FROM t3 HAVING count(*)>5; +} {} +do_execsql_test 5.3 { + SELECT count(*) FROM t3 HAVING max(b)>'mmm'; +} 4 +do_execsql_test 5.4 { + SELECT count(*) FROM t3 HAVING min(b)>'mmm'; +} {} +do_execsql_test 5.5 { + SELECT count(*) FROM ( + SELECT a, max(b) FROM t1 HAVING a<100 UNION ALL SELECT c, d FROM t2 + ) +} 3 + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/coveridxscan.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/coveridxscan.test new file mode 100644 index 0000000000000000000000000000000000000000..c87227cabc0de9ca171e3c5172bd771c12133166 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/coveridxscan.test @@ -0,0 +1,119 @@ +# 2012 September 17 +# +# 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 optimization which attempts to use a covering index +# for a full-table scan (under the theory that the index will be smaller +# and require less I/O and hence will run faster.) +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix coveridxscan + +do_test 1.1 { + db eval { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(5,4,3), (4,8,2), (3,2,1); + CREATE INDEX t1ab ON t1(a,b); + CREATE INDEX t1b ON t1(b); + SELECT a FROM t1; + } + # covering index used for the scan, hence values are increasing +} {3 4 5} + +do_test 1.2 { + db eval { + SELECT a, c FROM t1; + } + # There is no covering index, hence the values are in rowid order +} {5 3 4 2 3 1} + +do_test 1.3 { + db eval { + SELECT b FROM t1; + } + # Choice of two indices: use the one with fewest columns +} {2 4 8} + +do_test 2.1 { + optimization_control db cover-idx-scan 0 + db eval {SELECT a FROM t1} + # With the optimization turned off, output in rowid order +} {5 4 3} +do_test 2.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 2.3 { + db eval {SELECT b FROM t1} +} {4 8 2} + +db close +sqlite3_shutdown +sqlite3_config_cis 0 +sqlite3 db test.db + +do_test 3.1 { + db eval {SELECT a FROM t1} + # With the optimization configured off, output in rowid order +} {5 4 3} +do_test 3.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 3.3 { + db eval {SELECT b FROM t1} +} {4 8 2} + +db close +sqlite3_shutdown +sqlite3_config_cis 1 +sqlite3 db test.db + +# The CIS optimization is enabled again. Covering indices are once again +# used for all table scans. +do_test 4.1 { + db eval {SELECT a FROM t1} +} {3 4 5} +do_test 4.2 { + db eval {SELECT a, c FROM t1} +} {5 3 4 2 3 1} +do_test 4.3 { + db eval {SELECT b FROM t1} +} {2 4 8} + +#------------------------------------------------------------------------- +# Test that indexes with large numbers of columns can be correctly +# identified as covering indexes. +reset_db +set L [list] +for {set i 1} {$i<120} {incr i} { + lappend L "c$i" +} +set cols [join $L ,] + +do_execsql_test 5.1.0 " + CREATE TABLE t1(a, b, c, $cols, PRIMARY KEY(a, b, c)) WITHOUT ROWID; + CREATE INDEX i1 ON t1($cols); + + CREATE TABLE t2(i INTEGER PRIMARY KEY, $cols); + CREATE INDEX i2 ON t2($cols); +" + +do_eqp_test 5.1.1 { + SELECT * FROM t1 ORDER BY c1, c2; +} {SCAN t1 USING COVERING INDEX i1} + +do_eqp_test 5.1.2 { + SELECT * FROM t2 ORDER BY c1, c2; +} {SCAN t2 USING COVERING INDEX i2} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash.test new file mode 100644 index 0000000000000000000000000000000000000000..f63163659915ebdead9a5ad7fb6b28d3a5f58b04 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash.test @@ -0,0 +1,411 @@ +# 2001 September 15 +# +# 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. +# +# The focus of this file is testing the ability of the database to +# uses its rollback journal to recover intact (no database corruption) +# from a power failure during the middle of a COMMIT. The OS interface +# modules are overloaded using the modified I/O routines found in test6.c. +# These routines allow us to simulate the kind of file damage that +# occurs after a power failure. +# +# $Id: crash.test,v 1.27 2008/01/08 15:18:52 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +set repeats 100 +#set repeats 10 + +# The following procedure computes a "signature" for table "abc". If +# abc changes in any way, the signature should change. +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} +proc signature2 {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc2}] +} + +#-------------------------------------------------------------------------- +# Simple crash test: +# +# crash-1.1: Create a database with a table with two rows. +# crash-1.2: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the first journal-sync. +# crash-1.3: Ensure the database is in the same state as after crash-1.1. +# crash-1.4: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the first database-sync. +# crash-1.5: Ensure the database is in the same state as after crash-1.1. +# crash-1.6: Run a 'DELETE FROM abc WHERE a = 1' that crashes during +# the second journal-sync. +# crash-1.7: Ensure the database is in the same state as after crash-1.1. +# +# Tests 1.8 through 1.11 test for crashes on the third journal sync and +# second database sync. Neither of these is required in such a small test +# case, so these tests are just to verify that the test infrastructure +# operates as expected. +# +do_test crash-1.1 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc VALUES(4, 5, 6); + } + set ::sig [signature] + expr 0 +} {0} +for {set i 0} {$i<10} {incr i} { + set seed [expr {int(abs(rand()*10000))}] + do_test crash-1.2.$i { + crashsql -delay 1 -file test.db-journal -seed $seed { + DELETE FROM abc WHERE a = 1; + } + } {1 {child process exited abnormally}} + do_test crash-1.3.$i { + signature + } $::sig +} +do_test crash-1.4 { + crashsql -delay 1 -file test.db { + DELETE FROM abc WHERE a = 1; + } +} {1 {child process exited abnormally}} +do_test crash-1.5 { + signature +} $::sig +do_test crash-1.6 { + crashsql -delay 2 -file test.db-journal { + DELETE FROM abc WHERE a = 1; + } +} {1 {child process exited abnormally}} +do_test crash-1.7 { + catchsql { + SELECT * FROM abc; + } +} {0 {1 2 3 4 5 6}} + +do_test crash-1.8 { + crashsql -delay 3 -file test.db-journal { + DELETE FROM abc WHERE a = 1; + } +} {0 {}} +do_test crash-1.9 { + catchsql { + SELECT * FROM abc; + } +} {0 {4 5 6}} +do_test crash-1.10 { + crashsql -delay 2 -file test.db { + DELETE FROM abc WHERE a = 4; + } +} {0 {}} +do_test crash-1.11 { + catchsql { + SELECT * FROM abc; + } +} {0 {}} + +#-------------------------------------------------------------------------- +# The following tests test recovery when both the database file and the +# journal file contain corrupt data. This can happen after pages are +# written to the database file before a transaction is committed due to +# cache-pressure. +# +# crash-2.1: Insert 18 pages of data into the database. +# crash-2.2: Check the database file size looks ok. +# crash-2.3: Delete 15 or so pages (with a 10 page page-cache), then crash. +# crash-2.4: Ensure the database is in the same state as after crash-2.1. +# +# Test cases crash-2.5 and crash-2.6 check that the database is OK if the +# crash occurs during the main database file sync. But this isn't really +# different from the crash-1.* cases. +# +do_test crash-2.1 { + execsql { BEGIN } + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { COMMIT } + set ::sig [signature] + execsql { SELECT sum(a), sum(b), sum(c) from abc } +} {499500 999000 1498500} +do_test crash-2.2 { + expr ([file size test.db] / 1024)>16 +} {1} +do_test crash-2.3 { + crashsql -delay 2 -file test.db-journal { + DELETE FROM abc WHERE a < 800; + } +} {1 {child process exited abnormally}} +do_test crash-2.4 { + signature +} $sig +do_test crash-2.5 { + crashsql -delay 1 -file test.db { + DELETE FROM abc WHERE a<800; + } +} {1 {child process exited abnormally}} +do_test crash-2.6 { + signature +} $sig + +#-------------------------------------------------------------------------- +# The crash-3.* test cases are essentially the same test as test case +# crash-2.*, but with a more complicated data set. +# +# The test is repeated a few times with different seeds for the random +# number generator in the crashing executable. Because there is no way to +# seed the random number generator directly, some SQL is added to the test +# case to 'use up' a different quantity random numbers before the test SQL +# is executed. +# + +# Make sure the file is much bigger than the pager-cache (10 pages). This +# ensures that cache-spills happen regularly. +do_test crash-3.0 { + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + expr ([file size test.db] / 1024) > 450 +} {1} +for {set i 1} {$i < $repeats} {incr i} { + set sig [signature] + do_test crash-3.$i.1 { + set seed [expr {int(abs(rand()*10000))}] + crashsql -delay [expr $i%5 + 1] -file test.db-journal -seed $seed " + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash-3.$i.2 { + signature + } $sig +} + +#-------------------------------------------------------------------------- +# The following test cases - crash-4.* - test the correct recovery of the +# database when a crash occurs during a multi-file transaction. +# +# crash-4.1.*: Test recovery when crash occurs during sync() of the +# main database journal file. +# crash-4.2.*: Test recovery when crash occurs during sync() of an +# attached database journal file. +# crash-4.3.*: Test recovery when crash occurs during sync() of the master +# journal file. +# +ifcapable attach { + do_test crash-4.0 { + forcedelete test2.db + forcedelete test2.db-journal + execsql { + ATTACH 'test2.db' AS aux; + PRAGMA aux.default_cache_size = 10; + CREATE TABLE aux.abc2 AS SELECT 2*a as a, 2*b as b, 2*c as c FROM abc; + } + expr ([file size test2.db] / 1024) > 450 + } {1} + + set fin 0 + for {set i 1} {$i<$repeats} {incr i} { + set seed [expr {int(abs(rand()*10000))}] + set sig [signature] + set sig2 [signature2] + do_test crash-4.1.$i.1 { + set c [crashsql -delay $i -file test.db-journal -seed $::seed " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT randstr($i,$i) FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + "] + if { $c == {0 {}} } { + set ::fin 1 + set c {1 {child process exited abnormally}} + } + set c + } {1 {child process exited abnormally}} + if {$::fin} break + do_test crash-4.1.$i.2 { + signature + } $sig + do_test crash-4.1.$i.3 { + signature2 + } $sig2 + } + set i 0 + set fin 0 + while {[incr i]} { + set seed [expr {int(abs(rand()*10000))}] + set sig [signature] + set sig2 [signature2] + set ::fin 0 + do_test crash-4.2.$i.1 { + set c [crashsql -delay $i -file test2.db-journal -seed $::seed " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT randstr($i,$i) FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + "] + if { $c == {0 {}} } { + set ::fin 1 + set c {1 {child process exited abnormally}} + } + set c + } {1 {child process exited abnormally}} + if { $::fin } break + do_test crash-4.2.$i.2 { + signature + } $sig + do_test crash-4.2.$i.3 { + signature2 + } $sig2 + } + for {set i 1} {$i < 5} {incr i} { + set sig [signature] + set sig2 [signature2] + do_test crash-4.3.$i.1 { + crashsql -delay 1 -file test.db-mj* " + ATTACH 'test2.db' AS aux; + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc VALUES(randstr(10,10), 0, 0); + DELETE FROM abc WHERE random()%10!=0; + INSERT INTO abc2 VALUES(randstr(10,10), 0, 0); + DELETE FROM abc2 WHERE random()%10!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash-4.3.$i.2 { + signature + } $sig + do_test crash-4.3.$i.3 { + signature2 + } $sig2 + } +} + +#-------------------------------------------------------------------------- +# The following test cases - crash-5.* - exposes a bug that existed in the +# sqlite3pager_movepage() API used by auto-vacuum databases. +# database when a crash occurs during a multi-file transaction. See comments +# in test crash-5.3 for details. +# +db close +forcedelete test.db +sqlite3 db test.db +do_test crash-5.1 { + execsql { + CREATE TABLE abc(a, b, c); -- Root page 3 + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); -- Overflow page 4 + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } +} {} +do_test crash-5.2 { + expr [file size test.db] / 1024 +} [expr [string match [execsql {pragma auto_vacuum}] 1] ? 11 : 10] +set sig [signature] +do_test crash-5.3 { +# The SQL below is used to expose a bug that existed in +# sqlite3pager_movepage() during development of the auto-vacuum feature. It +# functions as follows: +# +# 1: Begin a transaction. +# 2: Put page 4 on the free-list (was the overflow page for the row deleted). +# 3: Write data to page 4 (it becomes the overflow page for the row inserted). +# The old page 4 data has been written to the journal file, but the +# journal file has not been sync()hronized. +# 4: Create a table, which calls sqlite3pager_movepage() to move page 4 +# to the end of the database (page 12) to make room for the new root-page. +# 5: Put pressure on the pager-cache. This results in page 4 being written +# to the database file to make space in the cache to load a new page. The +# bug was that page 4 was written to the database file before the journal +# is sync()hronized. +# 6: Commit. A crash occurs during the sync of the journal file. +# +# End result: Before the bug was fixed, data has been written to page 4 of the +# database file and the journal file does not contain trustworthy rollback +# data for this page. +# + crashsql -delay 1 -file test.db-journal { + BEGIN; -- 1 + DELETE FROM abc WHERE oid = 1; -- 2 + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); -- 3 + CREATE TABLE abc2(a, b, c); -- 4 + SELECT * FROM abc; -- 5 + COMMIT; -- 6 + } +} {1 {child process exited abnormally}} +integrity_check crash-5.4 +do_test crash-5.5 { + signature +} $sig + +#-------------------------------------------------------------------------- +# The following test cases - crash-6.* - test that a DROP TABLE operation +# is correctly rolled back in the event of a crash while the database file +# is being written. This is mainly to test that all pages are written to the +# journal file before truncation in an auto-vacuum database. +# +do_test crash-6.1 { + crashsql -delay 1 -file test.db { + DROP TABLE abc; + } +} {1 {child process exited abnormally}} +do_test crash-6.2 { + signature +} $sig + +#-------------------------------------------------------------------------- +# These test cases test the case where the master journal file name is +# corrupted slightly so that the corruption has to be detected by the +# checksum. +do_test crash-7.1 { + crashsql -delay 1 -file test.db { + ATTACH 'test2.db' AS aux; + BEGIN; + INSERT INTO abc VALUES(randstr(1500,1500), 0, 0); + INSERT INTO abc2 VALUES(randstr(1500,1500), 0, 0); + COMMIT; + } + + # Change the checksum value for the master journal name. + set f [open test.db-journal a] + fconfigure $f -translation binary + seek $f [expr [file size test.db-journal] - 12] + puts -nonewline $f "\00\00\00\00" + close $f +} {} +do_test crash-7.2 { + signature +} $sig + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash2.test new file mode 100644 index 0000000000000000000000000000000000000000..c74f6c2ffa27c0461deab93f502c15f10808a9fa --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash2.test @@ -0,0 +1,133 @@ +# 2001 September 15 +# +# 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. +# +# The focus of this file is testing the ability of the database to +# uses its rollback journal to recover intact (no database corruption) +# from a power failure during the middle of a COMMIT. Even more +# specifically, the tests in this file verify this functionality +# for storage mediums with various sector sizes. +# +# $Id: crash2.test,v 1.6 2008/08/25 07:12:29 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +db close + +# This test is designed to check that the crash-test infrastructure +# can create files that do not consist of an integer number of +# simulated disk blocks (i.e. 3KB file using 2KB disk blocks). +# +do_test crash2-1.1 { + crashsql -delay 500 -file test.db -blocksize 2048 { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=1024; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f; + COMMIT; + } + file size test.db +} {3072} + +for {set ii 0} {$ii < 5} {incr ii} { + + # Simple test using the database created above: Create a new + # table so that page 1 and page 4 are modified. Using a + # block-size of 2048 and page-size of 1024, this means + # pages 2 and 3 must also be saved in the journal to avoid + # risking corruption. + # + # The loop is so that this test can be run with a couple + # of different seeds for the random number generator. + # + do_test crash2-1.2.$ii { + crashsql -file test.db -blocksize 2048 [subst { + [string repeat {SELECT random();} $ii] + CREATE TABLE hij(h, i, j); + }] + sqlite3 db test.db + db eval {PRAGMA integrity_check} + } {ok} +} + +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} + +# Test case for crashing during journal sync with simulated +# sector-size values from 1024 to 8192. +# +do_test crash2-2.0 { + execsql BEGIN + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + execsql COMMIT + expr ([file size test.db] / 1024) > 450 +} {1} +for {set i 1} {$i < 30} {incr i} { + set sig [signature] + set sector [expr 1024 * 1<<($i%4)] + db close + do_test crash2-2.$i.1 { + crashsql -blocksize $sector -delay [expr $i%5 + 1] -file test.db-journal " + PRAGMA temp_store = memory; + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash2-2.$i.2 { + sqlite3 db test.db + signature + } $sig +} + + +# Test case for crashing during database sync with simulated +# sector-size values from 1024 to 8192. +# +for {set i 1} {$i < 10} {incr i} { + set sig [signature] + set sector [expr 1024 * 1<<($i%4)] + db close + do_test crash2-3.$i.1 { + crashsql -blocksize $sector -file test.db " + BEGIN; + SELECT random() FROM abc LIMIT $i; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + do_test crash2-3.$i.2 { + sqlite3 db test.db + signature + } $sig +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash4.test new file mode 100644 index 0000000000000000000000000000000000000000..f68caecdef3eeb4252907264201666a8ccd83388 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash4.test @@ -0,0 +1,102 @@ +# 2008 January 8 +# +# 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 additional tests to verify that SQLite database +# file survive a power loss or OS crash. +# +# $Id: crash4.test,v 1.3 2008/01/16 17:46:38 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + + +# A sequence of SQL commands: +# +set sql_cmd_list { + {CREATE TABLE a(id INTEGER, name CHAR(50))} + {INSERT INTO a(id,name) VALUES(1,'one')} + {INSERT INTO a(id,name) VALUES(2,'two')} + {INSERT INTO a(id,name) VALUES(3,'three')} + {INSERT INTO a(id,name) VALUES(4,'four')} + {INSERT INTO a(id,name) VALUES(5,'five')} + {INSERT INTO a(id,name) VALUES(6,'six')} + {INSERT INTO a(id,name) VALUES(7,'seven')} + {INSERT INTO a(id,name) VALUES(8,'eight')} + {INSERT INTO a(id,name) VALUES(9,'nine')} + {INSERT INTO a(id,name) VALUES(10,'ten')} + {UPDATE A SET name='new text for row 3' WHERE id=3} +} + +# Assume that a database is created by evaluating the SQL statements +# in $sql_cmd_list. Compute a set of checksums that capture the state +# of the database after each statement. Also include a checksum for +# the state of the database prior to any of these statements. +# +set crash4_cksum_set {} +lappend crash4_cksum_set [allcksum db] +foreach cmd $sql_cmd_list { + db eval $cmd + lappend crash4_cksum_set [allcksum db] +} + +# Run the sequence of SQL statements shown above repeatedly. +# Close and reopen the database right before the UPDATE statement. +# On each repetition, introduce database corruption typical of +# what might be seen in a power loss or OS crash. +# +# Slowly increase the delay before the crash, repeating the test +# over and over. Stop testing when the entire sequence of SQL +# statements runs to completing without hitting the crash. +# +for {set cnt 1; set fin 0} {!$fin} {incr cnt} { + db close + forcedelete test.db test.db-journal + do_test crash4-1.$cnt.1 { + set seed [expr {int(abs(rand()*10000))}] + set delay [expr {int($cnt/50)+1}] + set file [expr {($cnt&1)?"test.db":"test.db-journal"}] + set c [crashsql -delay $delay -file $file -seed $seed -tclbody { + db eval {CREATE TABLE a(id INTEGER, name CHAR(50))} + db eval {INSERT INTO a(id,name) VALUES(1,'one')} + db eval {INSERT INTO a(id,name) VALUES(2,'two')} + db eval {INSERT INTO a(id,name) VALUES(3,'three')} + db eval {INSERT INTO a(id,name) VALUES(4,'four')} + db eval {INSERT INTO a(id,name) VALUES(5,'five')} + db eval {INSERT INTO a(id,name) VALUES(6,'six')} + db eval {INSERT INTO a(id,name) VALUES(7,'seven')} + db eval {INSERT INTO a(id,name) VALUES(8,'eight')} + db eval {INSERT INTO a(id,name) VALUES(9,'nine')} + db eval {INSERT INTO a(id,name) VALUES(10,'ten')} + db close + sqlite3 db test.db + db eval {UPDATE A SET name='new text for row 3' WHERE id=3} + db close + } {}] + if {$c==[list 0 {}]} { + set ::fin 1 + set c [list 1 {child process exited abnormally}] + } + set c + } {1 {child process exited abnormally}} + sqlite3 db test.db + integrity_check crash4-1.$cnt.2 + do_test crash4-1.$cnt.3 { + set x [lsearch $::crash4_cksum_set [allcksum db]] + expr {$x>=0} + } {1} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash5.test new file mode 100644 index 0000000000000000000000000000000000000000..fc078b3504cb1673d3f1b46ee6d02c60c6ad13ca --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash5.test @@ -0,0 +1,127 @@ + +# 2007 Aug 13 +# +# 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 tests aspects of recovery from a malloc() failure +# in a CREATE INDEX statement. +# +# $Id: crash5.test,v 1.3 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Only run these tests if memory debugging is turned on. +# +ifcapable !crashtest||!memorymanage { + puts "Skipping crash5 tests: not compiled with -DSQLITE_ENABLE_MEMORY_MANAGEMENT..." + finish_test + return +} + +db close + +for {set ii 0} {$ii < 10} {incr ii} { + for {set jj 1} {$jj < 100} {incr jj} { + + # Set up the database so that it is an auto-vacuum database + # containing a single table (root page 3) with a single row. + # The row has an overflow page (page 4). + forcedelete test.db test.db-journal + sqlite3 db test.db + set c [string repeat 3 1500] + db eval { + pragma auto_vacuum = 1; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('1111111111', '2222222222', $c); + } + db close + + do_test crash5-$ii.$jj.1 { + crashsql -delay 1 -file test.db-journal -seed $ii -tclbody [join [list \ + [list set iFail $jj] { + proc get_pwd {} { + if {$::tcl_platform(platform) eq "windows"} { + if {[info exists ::env(ComSpec)]} { + set comSpec $::env(ComSpec) + } else { + # NOTE: Hard-code the typical default value. + set comSpec {C:\Windows\system32\cmd.exe} + } + return [string map [list \\ /] \ + [string trim [exec -- $comSpec /c echo %CD%]]] + } else { + return [pwd] + } + } + sqlite3_crashparams 0 [file join [get_pwd] test.db-journal] + + # Begin a transaction and evaluate a "CREATE INDEX" statement + # with the iFail'th malloc() set to fail. This operation will + # have to move the current contents of page 4 (the overflow + # page) to make room for the new root page. The bug is that + # if malloc() fails at a particular point in sqlite3PagerMovepage(), + # sqlite mistakenly thinks that the page being moved (page 4) has + # been safely synced into the journal. If the page is written + # to later in the transaction, it may be written out to the database + # before the relevant part of the journal has been synced. + # + db eval BEGIN + sqlite3_memdebug_fail $iFail -repeat 0 + set rc [catch {db eval { CREATE UNIQUE INDEX i1 ON t1(a); }} msg] +# puts "$msg ac=[sqlite3_get_autocommit db] iFail=$iFail" +# puts "fail=[sqlite3_memdebug_fail -1]" + + if {$rc} { + # If the transaction is still active (it may not be if the malloc() + # failure occurred in the OS layer), write to the database. Make sure + # page 4 is among those written. + # + if {![sqlite3_get_autocommit db]} { + db eval { + DELETE FROM t1; -- This will put page 4 on the free list. + INSERT INTO t1 VALUES('111111111', '2222222222', '33333333'); + INSERT INTO t1 SELECT * FROM t1; -- 2 + INSERT INTO t1 SELECT * FROM t1; -- 4 + INSERT INTO t1 SELECT * FROM t1; -- 8 + INSERT INTO t1 SELECT * FROM t1; -- 16 + INSERT INTO t1 SELECT * FROM t1; -- 32 + INSERT INTO t1 SELECT * FROM t1 WHERE rowid%2; -- 48 + } + } + + # If the right malloc() failed during the 'CREATE INDEX' above and + # the transaction was not rolled back, then the sqlite cache now + # has a dirty page 4 that it incorrectly believes is already safely + # in the synced part of the journal file. When + # sqlite3_release_memory() is called sqlite tries to free memory + # by writing page 4 out to the db file. If it crashes later on, + # before syncing the journal... Corruption! + # + sqlite3_crashparams 1 [file join [get_pwd] test.db-journal] + sqlite3_release_memory 8092 + } + }]] {} + expr 1 + } {1} + + sqlite3 db test.db + do_test crash5-$ii.$jj.2 { + db eval {pragma integrity_check} + } {ok} + do_test crash5-$ii.$jj.3 { + db eval {SELECT * FROM t1} + } [list 1111111111 2222222222 $::c] + db close + } +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash6.test new file mode 100644 index 0000000000000000000000000000000000000000..69c19464b3f4ad55318cd98280f24322b6492557 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash6.test @@ -0,0 +1,118 @@ +# 2001 September 15 +# +# 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 tests that rollback journals for databases that use a +# page-size other than the default page-size can be rolled back Ok. +# +# $Id: crash6.test,v 1.2 2008/04/14 15:27:19 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} + +for {set ii 0} {$ii < 10} {incr ii} { + catch {db close} + forcedelete test.db test.db-journal + crashsql -delay 2 -file test.db { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=4096; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + COMMIT; + BEGIN; + CREATE TABLE def AS SELECT 1 AS d, 2 AS e, 3 AS f; + COMMIT; + } + sqlite3 db test.db + integrity_check crash6-1.$ii +} + +for {set ii 0} {$ii < 10} {incr ii} { + catch {db close} + forcedelete test.db test.db-journal + sqlite3 db test.db + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size=2048; + BEGIN; + CREATE TABLE abc AS SELECT 1 AS a, 2 AS b, 3 AS c; + COMMIT; + } + db close + crashsql -delay 1 -file test.db { + INSERT INTO abc VALUES(5, 6, 7); + } + sqlite3 db test.db + integrity_check crash6-2.$ii +} + +proc signature {} { + return [db eval {SELECT count(*), md5sum(a), md5sum(b), md5sum(c) FROM abc}] +} + +# Test case for crashing during database sync with page-size values +# from 1024 to 8192. +# +for {set ii 0} {$ii < 30} {incr ii} { + db close + forcedelete test.db + sqlite3 db test.db + + set pagesize [expr 1024 << ($ii % 4)] + if {$pagesize>$::SQLITE_MAX_PAGE_SIZE} { + set pagesize $::SQLITE_MAX_PAGE_SIZE + } + do_test crash6-3.$ii.0 { + execsql "pragma page_size = $pagesize" + execsql "pragma page_size" + } $pagesize + + do_test crash6-3.$ii.1 { + + execsql BEGIN + execsql {CREATE TABLE abc(a, b, c)} + for {set n 0} {$n < 1000} {incr n} { + execsql "INSERT INTO abc VALUES($n, [expr 2*$n], [expr 3*$n])" + } + execsql { + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + INSERT INTO abc SELECT * FROM abc; + } + execsql COMMIT + expr ([file size test.db] / 1024) > 450 + } {1} + + set sig [signature] + db close + + do_test crash6-3.$ii.2 { + crashsql -file test.db " + BEGIN; + SELECT random() FROM abc LIMIT $ii; + INSERT INTO abc SELECT randstr(10,10), 0, 0 FROM abc WHERE random()%2==0; + DELETE FROM abc WHERE random()%2!=0; + COMMIT; + " + } {1 {child process exited abnormally}} + + do_test crash6-3.$ii.3 { + sqlite3 db test.db + signature + } $sig +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crash8.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash8.test new file mode 100644 index 0000000000000000000000000000000000000000..c07829979fb5f5964bf1a441f820c532f7608162 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crash8.test @@ -0,0 +1,419 @@ +# 2009 January 8 +# +# 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 test verifies a couple of specific potential data corruption +# scenarios involving crashes or power failures. +# +# Later: Also, some other specific scenarios required for coverage +# testing that do not lead to corruption. +# +# $Id: crash8.test,v 1.4 2009/01/11 00:44:48 drh Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !crashtest { + finish_test + return +} +do_not_use_codec + +do_test crash8-1.1 { + execsql { + PRAGMA auto_vacuum=OFF; + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + INSERT INTO t1 VALUES(1, randstr(1000,1000)); + INSERT INTO t1 VALUES(2, randstr(1000,1000)); + INSERT INTO t1 VALUES(3, randstr(1000,1000)); + INSERT INTO t1 VALUES(4, randstr(1000,1000)); + INSERT INTO t1 VALUES(5, randstr(1000,1000)); + INSERT INTO t1 VALUES(6, randstr(1000,1000)); + CREATE TABLE t2(a, b); + CREATE TABLE t3(a, b); + CREATE TABLE t4(a, b); + CREATE TABLE t5(a, b); + CREATE TABLE t6(a, b); + CREATE TABLE t7(a, b); + CREATE TABLE t8(a, b); + CREATE TABLE t9(a, b); + CREATE TABLE t10(a, b); + PRAGMA integrity_check + } +} {ok} + + +# Potential corruption scenario 1. A second process opens the database +# and modifies a large portion of it. It then opens a second transaction +# and modifies a small part of the database, but crashes before it commits +# the transaction. +# +# When the first process accessed the database again, it was rolling back +# the aborted transaction, but was not purging its in-memory cache (which +# was loaded before the second process made its first, successful, +# modification). Producing an inconsistent cache. +# +do_test crash8-1.2 { + crashsql -delay 2 -file test.db { + PRAGMA cache_size = 10; + UPDATE t1 SET b = randstr(1000,1000); + INSERT INTO t9 VALUES(1, 2); + } +} {1 {child process exited abnormally}} +do_test crash8-1.3 { + execsql {PRAGMA integrity_check} +} {ok} + +# Potential corruption scenario 2. The second process, operating in +# persistent-journal mode, makes a large change to the database file +# with a small in-memory cache. Such that more than one journal-header +# was written to the file. It then opens a second transaction and makes +# a smaller change that requires only a single journal-header to be +# written to the journal file. The second change is such that the +# journal content written to the persistent journal file exactly overwrites +# the first journal-header and set of subsequent records written by the +# first, successful, change. The second process crashes before it can +# commit its second change. +# +# When the first process accessed the database again, it was rolling back +# the second aborted transaction, then continuing to rollback the second +# and subsequent journal-headers written by the first, successful, change. +# Database corruption. +# +do_test crash8.2.1 { + crashsql -delay 2 -file test.db { + PRAGMA journal_mode = persist; + PRAGMA cache_size = 10; + UPDATE t1 SET b = randstr(1000,1000); + PRAGMA cache_size = 100; + BEGIN; + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t3 VALUES('a', 'b'); + INSERT INTO t4 VALUES('a', 'b'); + INSERT INTO t5 VALUES('a', 'b'); + INSERT INTO t6 VALUES('a', 'b'); + INSERT INTO t7 VALUES('a', 'b'); + INSERT INTO t8 VALUES('a', 'b'); + INSERT INTO t9 VALUES('a', 'b'); + INSERT INTO t10 VALUES('a', 'b'); + COMMIT; + } +} {1 {child process exited abnormally}} + +do_test crash8-2.3 { + execsql {PRAGMA integrity_check} +} {ok} + +proc read_file {zFile} { + set fd [open $zFile] + fconfigure $fd -translation binary + set zData [read $fd] + close $fd + return $zData +} +proc write_file {zFile zData} { + set fd [open $zFile w] + fconfigure $fd -translation binary + puts -nonewline $fd $zData + close $fd +} + +# The following tests check that SQLite will not roll back a hot-journal +# file if the sector-size field in the first journal file header is +# suspect. Definition of suspect: +# +# a) Not a power of 2, or (crash8-3.5) +# b) Greater than 0x01000000 (16MB), or (crash8-3.6) +# c) Less than 512. (crash8-3.7) +# +# Also test that SQLite will not rollback a hot-journal file with a +# suspect page-size. In this case "suspect" means: +# +# a) Not a power of 2, or +# b) Less than 512, or +# c) Greater than SQLITE_MAX_PAGE_SIZE +# +if {[atomic_batch_write test.db]==0} { +do_test crash8-3.1 { + list [file exists test.db-joural] [file exists test.db] +} {0 1} +do_test crash8-3.2 { + execsql { + PRAGMA synchronous = off; + BEGIN; + DELETE FROM t1; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.3 { + set zJournal [read_file test.db-journal] + execsql { + COMMIT; + SELECT count(*) FROM t1; + } +} {0} +do_test crash8-3.4 { + binary scan [string range $zJournal 20 23] I nSector + set nSector +} {512} + +do_test crash8-3.5 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 513]] + write_file test.db-journal $zJournal2 + + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.6 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 0x2000000]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.7 { + set zJournal2 [string replace $zJournal 20 23 [binary format I 256]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} + +do_test crash8-3.8 { + set zJournal2 [string replace $zJournal 24 27 [binary format I 513]] + write_file test.db-journal $zJournal2 + + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.9 { + set big [expr $SQLITE_MAX_PAGE_SIZE * 2] + set zJournal2 [string replace $zJournal 24 27 [binary format I $big]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} +do_test crash8-3.10 { + set zJournal2 [string replace $zJournal 24 27 [binary format I 256]] + write_file test.db-journal $zJournal2 + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {0 ok} + +do_test crash8-3.11 { + set fd [open test.db-journal w] + fconfigure $fd -translation binary + puts -nonewline $fd $zJournal + close $fd + execsql { + SELECT count(*) FROM t1; + PRAGMA integrity_check + } +} {6 ok} +} + + +# If a connection running in persistent-journal mode is part of a +# multi-file transaction, it must ensure that the master-journal name +# appended to the journal file contents during the commit is located +# at the end of the physical journal file. If there was already a +# large journal file allocated at the start of the transaction, this +# may mean truncating the file so that the master journal name really +# is at the physical end of the file. +# +# This block of tests test that SQLite correctly truncates such +# journal files, and that the results behave correctly if a hot-journal +# rollback occurs. +# +ifcapable pragma { + reset_db + forcedelete test2.db + + do_test crash8-4.1 { + execsql { + PRAGMA journal_mode = persist; + CREATE TABLE ab(a, b); + INSERT INTO ab VALUES(0, 'abc'); + INSERT INTO ab VALUES(1, NULL); + INSERT INTO ab VALUES(2, NULL); + INSERT INTO ab VALUES(3, NULL); + INSERT INTO ab VALUES(4, NULL); + INSERT INTO ab VALUES(5, NULL); + INSERT INTO ab VALUES(6, NULL); + UPDATE ab SET b = randstr(1000,1000); + ATTACH 'test2.db' AS aux; + PRAGMA aux.journal_mode = persist; + CREATE TABLE aux.ab(a, b); + INSERT INTO aux.ab SELECT * FROM main.ab; + + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + } {persist persist} + if {[atomic_batch_write test.db]==0} { + do_test crash8.4.1.1 { + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + } + + do_test crash8-4.2 { + execsql { + BEGIN; + UPDATE aux.ab SET b = 'def' WHERE a = 0; + UPDATE main.ab SET b = 'def' WHERE a = 0; + COMMIT; + } + } {} + + do_test crash8-4.3 { + execsql { + UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1; + UPDATE ab SET b = randstr(1000,1000) WHERE a>=1; + } + } {} + + set contents_main [db eval {SELECT b FROM main.ab WHERE a = 1}] + set contents_aux [db eval {SELECT b FROM aux.ab WHERE a = 1}] + + do_test crash8-4.4 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'ghi' WHERE a = 0; + UPDATE main.ab SET b = 'ghi' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.5 { + list [file exists test.db-journal] [file exists test2.db-journal] + } {1 1} + + do_test crash8-4.6 { + execsql { + SELECT b FROM main.ab WHERE a = 0; + SELECT b FROM aux.ab WHERE a = 0; + } + } {def def} + + do_test crash8-4.7 { + crashsql -file test2.db -delay 1 { + ATTACH 'test2.db' AS aux; + BEGIN; + UPDATE aux.ab SET b = 'jkl' WHERE a = 0; + UPDATE main.ab SET b = 'jkl' WHERE a = 0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_test crash8-4.8 { + set fd [open test.db-journal] + fconfigure $fd -translation binary + seek $fd -16 end + binary scan [read $fd 4] I len + + seek $fd [expr {-1 * ($len + 16)}] end + set zMasterJournal [read $fd $len] + close $fd + + file exists $zMasterJournal + } {1} + + do_test crash8-4.9 { + execsql { SELECT b FROM aux.ab WHERE a = 0 } + } {def} + + do_test crash8-4.10 { + delete_file $zMasterJournal + execsql { SELECT b FROM main.ab WHERE a = 0 } + } {jkl} +} + +# +# Since the following tests (crash8-5.*) rely upon being able +# to copy a file while open, they will not work on Windows. +# +# They also depend on being able to copy the journal file, which +# is not created on F2FS file-systems that support atomic +# write. So do not run these tests in that case either. +# +if {$::tcl_platform(platform)=="unix" && [atomic_batch_write test.db]==0 } { + for {set i 1} {$i < 10} {incr i} { + catch { db close } + forcedelete test.db test.db-journal + sqlite3 db test.db + do_test crash8-5.$i.1 { + execsql { + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES(randomblob(900)); + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 rows */ + } + crashsql -file test.db -delay [expr ($::i%2) + 1] { + PRAGMA cache_size = 10; + BEGIN; + UPDATE t1 SET x = randomblob(900); + ROLLBACK; + INSERT INTO t1 VALUES(randomblob(900)); + } + execsql { PRAGMA integrity_check } + } {ok} + + catch { db close } + forcedelete test.db test.db-journal + sqlite3 db test.db + do_test crash8-5.$i.2 { + execsql { + PRAGMA cache_size = 10; + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES(randomblob(900)); + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; + INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 rows */ + BEGIN; + UPDATE t1 SET x = randomblob(900); + } + forcedelete testX.db testX.db-journal testX.db-wal + forcecopy test.db testX.db + forcecopy test.db-journal testX.db-journal + db close + + crashsql -file test.db -delay [expr ($::i%2) + 1] { + SELECT * FROM sqlite_master; + INSERT INTO t1 VALUES(randomblob(900)); + } + + sqlite3 db2 testX.db + execsql { PRAGMA integrity_check } db2 + } {ok} + } + catch {db2 close} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crashM.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/crashM.test new file mode 100644 index 0000000000000000000000000000000000000000..de10c4589a5bf6eeb1b64234430b583ce49c5599 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crashM.test @@ -0,0 +1,80 @@ +# 2015 Mar 13 +# +# 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. +# +#*********************************************************************** +# +# Crash tests for the multiplex module with 8.3 filenames enabled. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix crashM + +ifcapable !crashtest||!8_3_names { + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 + +foreach f [glob -nocomplain test1.* test2.*] { forcedelete $f } +sqlite3_multiplex_initialize "" 1 +sqlite3 db file:test1.db?8_3_names=1 +sqlite3_multiplex_control db main chunk_size [expr 64*1024] + +do_execsql_test 1.0 { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + + CREATE TABLE t1(x, y); + CREATE INDEX t1x ON t1(x); + CREATE INDEX t1y ON t1(y); + + CREATE TABLE aux.t2(x, y); + CREATE INDEX aux.t2x ON t2(x); + CREATE INDEX aux.t2y ON t2(y); + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t1 SELECT a, randomblob(500) FROM s; + + WITH s(a) AS ( + SELECT 1 UNION ALL SELECT a+1 FROM s WHERE a<1000 + ) + INSERT INTO t2 SELECT a, randomblob(500) FROM s; +} {} + +for {set i 0} {$i < 20} {incr i} { + do_test 2.$i.1 { + crashsql -delay 1 -file test1.db -opendb { + sqlite3_shutdown + sqlite3_config_uri 1 + sqlite3_multiplex_initialize crash 1 + sqlite3 db file:test1.db?8_3_names=1 + sqlite3_multiplex_control db main chunk_size [expr 64*1024] + } { + ATTACH 'file:test2.db?8_3_names=1' AS aux; + BEGIN; + UPDATE t1 SET y = randomblob(500) WHERE (x%10)==0; + UPDATE t2 SET y = randomblob(500) WHERE (x%10)==0; + COMMIT; + } + } {1 {child process exited abnormally}} + + do_execsql_test 2.$i.2 { + PRAGMA main.integrity_check; + PRAGMA aux.integrity_check; + } {ok ok} +} + +catch { db close } +sqlite3_multiplex_shutdown +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/crashtest1.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/crashtest1.c new file mode 100644 index 0000000000000000000000000000000000000000..1f7035d18ea78d137272a6d76edbe1909549c414 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/crashtest1.c @@ -0,0 +1,96 @@ +/* +** This program tests the ability of SQLite database to recover from a crash. +** This program runs under Unix only, but the results are applicable to all +** systems. +** +** The main process first constructs a test database, then starts creating +** subprocesses that write to that database. Each subprocess is killed off, +** without a chance to clean up its database connection, after a random +** delay. This killing of the subprocesses simulates a crash or power +** failure. The next subprocess to open the database should rollback +** whatever operation was in process at the time of the simulated crash. +** +** If any problems are encountered, an error is reported and the test stops. +** If no problems are seen after a large number of tests, we assume that +** the rollback mechanism is working. +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include "sqlite.h" + +static void do_some_sql(int parent){ + char *zErr; + int rc = SQLITE_OK; + sqlite *db; + int cnt = 0; + static char zBig[] = + "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + if( access("./test.db-journal",0)==0 ){ + /*printf("pid %d: journal exists. rollback will be required\n",getpid());*/ unlink("test.db-saved"); + system("cp test.db test.db-saved"); + unlink("test.db-journal-saved"); + system("cp test.db-journal test.db-journal-saved"); + } + db = sqlite_open("./test.db", 0, &zErr); + if( db==0 ){ + printf("ERROR: %s\n", zErr); + if( strcmp(zErr,"database disk image is malformed")==0 ){ + kill(parent, SIGKILL); + } + exit(1); + } + srand(getpid()); + while( rc==SQLITE_OK ){ + cnt++; + rc = sqlite_exec_printf(db, + "INSERT INTO t1 VALUES(%d,'%d%s')", 0, 0, &zErr, + rand(), rand(), zBig); + } + if( rc!=SQLITE_OK ){ + printf("ERROR #%d: %s\n", rc, zErr); + if( rc==SQLITE_CORRUPT ){ + kill(parent, SIGKILL); + } + } + printf("pid %d: cnt=%d\n", getpid(), cnt); +} + + +int main(int argc, char **argv){ + int i; + sqlite *db; + char *zErr; + int status; + int parent = getpid(); + + unlink("test.db"); + unlink("test.db-journal"); + db = sqlite_open("test.db", 0, &zErr); + if( db==0 ){ + printf("Cannot initialize: %s\n", zErr); + return 1; + } + sqlite_exec(db, "CREATE TABLE t1(a,b)", 0, 0, 0); + sqlite_close(db); + for(i=0; i<10000; i++){ + int pid = fork(); + if( pid==0 ){ + sched_yield(); + do_some_sql(parent); + return 0; + } + printf("test %d, pid=%d\n", i, pid); + usleep(rand()%10000 + 1000); + kill(pid, SIGKILL); + waitpid(pid, &status, 0); + } + return 0; +} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/createtab.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/createtab.test new file mode 100644 index 0000000000000000000000000000000000000000..5773fbf5f62b1797c548e2ab948ff02fac338cae --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/createtab.test @@ -0,0 +1,154 @@ +# 2007 May 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing that it is OK to create new tables +# and indices while creating existing tables and indices. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable autovacuum { + set upperBound 2 +} else { + set upperBound 0 +} + +# Run these tests for all possible values of autovacuum. +# +for {set av 0} {$av<=$upperBound} {incr av} { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + + # Create a table that spans multiple pages. It is important + # that part of the database be in pages beyond the root page. + # + do_test createtab-$av.1 { + execsql "PRAGMA auto_vacuum=$av" + execsql { + PRAGMA page_size=1024; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(1, hex(randomblob(200))); + INSERT INTO t1 VALUES(2, hex(randomblob(200))); + INSERT INTO t1 VALUES(3, hex(randomblob(200))); + INSERT INTO t1 VALUES(4, hex(randomblob(200))); + SELECT count(*) FROM t1; + } + } {4} + + set isUtf16 0 + ifcapable utf16 { + set isUtf16 [expr {[execsql {PRAGMA encoding}] != "UTF-8"}] + } + + do_test createtab-$av.2 { + file size test.db + } [expr {1024*(4+($av!=0)+(${isUtf16}*2))}] + + # Start reading the table + # + do_test createtab-$av.3 { + set STMT [sqlite3_prepare db {SELECT x FROM t1} -1 TAIL] + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.4 { + sqlite3_column_int $STMT 0 + } {1} + + # While still reading the table, create a new table. + # + do_test createtab-$av.5 { + execsql { + CREATE TABLE t2(a,b); + INSERT INTO t2 VALUES(1,2); + SELECT * FROM t2; + } + } {1 2} + + # Continue reading the original table. + # + do_test createtab-$av.6 { + sqlite3_column_int $STMT 0 + } {1} + do_test createtab-$av.7 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.8 { + sqlite3_column_int $STMT 0 + } {2} + + # Do another cycle of creating a new database table while contining + # to read the original table. + # + do_test createtab-$av.11 { + execsql { + CREATE TABLE t3(a,b); + INSERT INTO t3 VALUES(4,5); + SELECT * FROM t3; + } + } {4 5} + do_test createtab-$av.12 { + sqlite3_column_int $STMT 0 + } {2} + do_test createtab-$av.13 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.14 { + sqlite3_column_int $STMT 0 + } {3} + + # One more cycle. + # + do_test createtab-$av.21 { + execsql { + CREATE TABLE t4(a,b); + INSERT INTO t4 VALUES('abc','xyz'); + SELECT * FROM t4; + } + } {abc xyz} + do_test createtab-$av.22 { + sqlite3_column_int $STMT 0 + } {3} + do_test createtab-$av.23 { + sqlite3_step $STMT + } {SQLITE_ROW} + do_test createtab-$av.24 { + sqlite3_column_int $STMT 0 + } {4} + + # Finish reading. Do an integrity check on the database. + # + do_test createtab-$av.30 { + sqlite3_step $STMT + } {SQLITE_DONE} + do_test createtab-$av.31 { + sqlite3_finalize $STMT + } {SQLITE_OK} + do_test createtab-$av.32 { + execsql { + SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1 + } + } {t1 t2 t3 t4} + integrity_check createtab-$av.40 + +} + +# 2019-03-31 Ensure that a proper error is returned for an index +# with too many columns. +# +do_test createtab-3.1 { + db eval {DROP TABLE IF EXISTS t1;} + set sql "CREATE TABLE t1(x,UNIQUE(x[string repeat ,x 100000]))" + catchsql $sql +} {1 {too many columns in index}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cse.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cse.test new file mode 100644 index 0000000000000000000000000000000000000000..3912bc326cafb8c4a4049c0dadabdf70292715ef --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cse.test @@ -0,0 +1,200 @@ +# 2008 April 1 +# +# 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. +# +#*********************************************************************** +# +# Test cases designed to exercise and verify the logic for +# factoring constant expressions out of loops and for +# common subexpression eliminations. +# +# $Id: cse.test,v 1.6 2008/08/04 03:51:24 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix cse + +do_test cse-1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, d, e, f); + INSERT INTO t1 VALUES(1,11,12,13,14,15); + INSERT INTO t1 VALUES(2,21,22,23,24,25); + } + execsql { + SELECT b, -b, ~b, NOT b, NOT NOT b, b-b, b+b, b*b, b/b, b FROM t1 + } +} {11 -11 -12 0 1 0 22 121 1 11 21 -21 -22 0 1 0 42 441 1 21} +do_test cse-1.2 { + execsql { + SELECT b, b%b, b==b, b!=b, b49} {set r [expr {99-$r}]} + lappend colset a$j a$r + lappend answer $j $r + } + set sql "SELECT [join $colset ,] FROM t2" + do_test cse-2.2.$i { + # explain $::sql + execsql $::sql + } $answer +} + +#------------------------------------------------------------------------- +# Ticket fd1bda016d1a +# +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a TEXT, b); + INSERT INTO t1 VALUES('hello', 0); + INSERT INTO t1 VALUES('world', 0); + + CREATE TABLE t2(x TEXT); + INSERT INTO t2 VALUES('hello'); + INSERT INTO t2 VALUES('world'); + + CREATE TABLE t3(y); + INSERT INTO t3 VALUES(1000); +} {} + +do_execsql_test 3.1 { + SELECT 1000 = y FROM t3 +} {1} + +do_execsql_test 3.2 { + SELECT 1000 IN (SELECT x FROM t2), 1000 = y FROM t3 +} {0 1} + +do_execsql_test 3.3 { + SELECT 0 IN (SELECT a), (SELECT a LIMIT 0) FROM t1 +} {0 {} 0 {}} + +do_execsql_test 3.4 { + SELECT 0 IN (SELECT a) FROM t1 WHERE a = 'hello' OR (SELECT a LIMIT 0); +} {0} + +do_execsql_test 3.5 { + CREATE TABLE v0(v1 VARCHAR0); + INSERT INTO v0 VALUES(2), (3); + SELECT 0 IN(SELECT v1) FROM v0 WHERE v1 = 2 OR(SELECT v1 LIMIT 0); +} {0} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/ctime.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/ctime.test new file mode 100644 index 0000000000000000000000000000000000000000..26b2fa2ee2ded74a5830d656df29720dcb6ffe1b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/ctime.test @@ -0,0 +1,259 @@ +# 2009 February 24 +# +# 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. +# +# This file implements tests for the compile time diagnostic +# functions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Test organization: +# +# ctime-1.*: Test pragma support. +# ctime-2.*: Test function support. +# + +ifcapable !pragma||!compileoption_diags { + finish_test + return +} + +##################### +# ctime-1.*: Test pragma support. + +do_test ctime-1.1.1 { + catchsql { + PRAGMA compile_options(); + } +} {1 {near ")": syntax error}} +do_test ctime-1.1.2 { + catchsql { + PRAGMA compile_options(NULL); + } +} {1 {near "NULL": syntax error}} +do_test ctime-1.1.3 { + catchsql { + PRAGMA compile_options *; + } +} {1 {near "*": syntax error}} + +do_test ctime-1.2.1 { + set ans [ catchsql { + PRAGMA compile_options; + } ] + list [ lindex $ans 0 ] +} {0} +# the results should be in sorted order already +do_test ctime-1.2.2 { + set ans [ catchsql { + PRAGMA compile_options; + } ] + list [ lindex $ans 0 ] [ expr { [lsort [lindex $ans 1]]==[lindex $ans 1] } ] +} {0 1} + +# Check the THREADSAFE option for SQLITE_THREADSAFE=2 builds (there are +# a couple of these configurations in releasetest.tcl). +# +ifcapable threadsafe2 { + foreach {tn opt res} { + 1 SQLITE_THREADSAFE 1 + 2 THREADSAFE 1 + 3 THREADSAFE=0 0 + 4 THREADSAFE=1 0 + 5 THREADSAFE=2 1 + 6 THREADSAFE= 0 + } { + do_execsql_test ctime-1.3.$tn { + SELECT sqlite_compileoption_used($opt) + } $res + } +} + +# SQLITE_THREADSAFE should pretty much always be defined +# one way or the other, and it must have a value of 0 or 1. +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test ctime-1.4.1 { + catchsql { + SELECT sqlite_compileoption_used('SQLITE_THREADSAFE'); + } +} {0 1} +do_test ctime-1.4.2 { + catchsql { + SELECT sqlite_compileoption_used('THREADSAFE'); + } +} {0 1} +do_test ctime-1.4.3 { + catchsql { + SELECT sqlite_compileoption_used("THREADSAFE"); + } +} {0 1} + +do_test ctime-1.5 { + set ans1 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=0'); + } ] + set ans2 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=1'); + } ] + set ans3 [ catchsql { + SELECT sqlite_compileoption_used('THREADSAFE=2'); + } ] + lsort [ list $ans1 $ans2 $ans3 ] +} {{0 0} {0 0} {0 1}} + +do_test ctime-1.6 { + execsql { + SELECT sqlite_compileoption_used('THREADSAFE='); + } +} {0} + +do_test ctime-1.7.1 { + execsql { + SELECT sqlite_compileoption_used('SQLITE_OMIT_COMPILEOPTION_DIAGS'); + } +} {0} +do_test ctime-1.7.2 { + execsql { + SELECT sqlite_compileoption_used('OMIT_COMPILEOPTION_DIAGS'); + } +} {0} + +##################### +# ctime-2.*: Test function support. + +do_test ctime-2.1.1 { + catchsql { + SELECT sqlite_compileoption_used(); + } +} {1 {wrong number of arguments to function sqlite_compileoption_used()}} +do_test ctime-2.1.2 { + catchsql { + SELECT sqlite_compileoption_used(NULL); + } +} {0 {{}}} +do_test ctime-2.1.3 { + catchsql { + SELECT sqlite_compileoption_used(""); + } +} {0 0} +do_test ctime-2.1.4 { + catchsql { + SELECT sqlite_compileoption_used(''); + } +} {0 0} +do_test ctime-2.1.5 { + catchsql { + SELECT sqlite_compileoption_used(foo); + } +} {1 {no such column: foo}} +do_test ctime-2.1.6 { + catchsql { + SELECT sqlite_compileoption_used('THREADSAFE', 0); + } +} {1 {wrong number of arguments to function sqlite_compileoption_used()}} +do_test ctime-2.1.7 { + catchsql { + SELECT sqlite_compileoption_used(0); + } +} {0 0} +do_test ctime-2.1.8 { + catchsql { + SELECT sqlite_compileoption_used('0'); + } +} {0 0} +do_test ctime-2.1.9 { + catchsql { + SELECT sqlite_compileoption_used(1.0); + } +} {0 0} + +do_test ctime-2.2.1 { + catchsql { + SELECT sqlite_compileoption_get(); + } +} {1 {wrong number of arguments to function sqlite_compileoption_get()}} +do_test ctime-2.2.2 { + catchsql { + SELECT sqlite_compileoption_get(0, 0); + } +} {1 {wrong number of arguments to function sqlite_compileoption_get()}} + +# This assumes there is at least 1 compile time option +# (see SQLITE_THREADSAFE above). +do_test ctime-2.3 { + catchsql { + SELECT sqlite_compileoption_used(sqlite_compileoption_get(0)); + } +} {0 1} + +# This assumes there is at least 1 compile time option +# (see SQLITE_THREADSAFE above). +do_test ctime-2.4 { + set ans [ catchsql { + SELECT sqlite_compileoption_get(0); + } ] + list [lindex $ans 0] +} {0} + +# Get the list of defines using the pragma, +# then try querying each one with the functions. +set ans [ catchsql { + PRAGMA compile_options; +} ] +set opts [ lindex $ans 1 ] +set tc 1 +foreach opt $opts { + do_test ctime-2.5.$tc { + set N [ expr {$tc-1} ] + set ans1 [catch {db one { + SELECT sqlite_compileoption_get($N); + }} msg] + lappend ans1 $msg + set ans2 [ catchsql { + SELECT sqlite_compileoption_used($opt); + } ] + list [ lindex $ans1 0 ] [ expr { [lindex $ans1 1]==$opt } ] \ + [ expr { $ans2 } ] + } {0 1 {0 1}} + incr tc 1 +} +# test 1 past array bounds +do_test ctime-2.5.$tc { + set N [ expr {$tc-1} ] + set ans [ catchsql { + SELECT sqlite_compileoption_get($N); + } ] +} {0 {{}}} +incr tc 1 +# test 1 before array bounds (N=-1) +do_test ctime-2.5.$tc { + set N -1 + set ans [ catchsql { + SELECT sqlite_compileoption_get($N); + } ] +} {0 {{}}} + +#-------------------------------------------------------------------------- +# Test that SQLITE_DIRECT_OVERFLOW_READ is reflected in the output of +# "PRAGMA compile_options". +# +ifcapable direct_read { + set res 1 +} else { + set res 0 +} +do_test ctime-3.0.1 { + expr [lsearch [db eval {PRAGMA compile_options}] DIRECT_OVERFLOW_READ]>=0 +} $res + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/cursorhint.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/cursorhint.test new file mode 100644 index 0000000000000000000000000000000000000000..d1bd4e8e7811133606fc9ce7eac0cbc46313edd5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/cursorhint.test @@ -0,0 +1,214 @@ +# 2014 July 15 +# +# 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 cursorhint + +ifcapable !cursorhints { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a,b,c,d); + CREATE TABLE t2(x,y,z); + INSERT INTO t1(a,b) VALUES(10, 15); + INSERT INTO t1(a,b) VALUES(20, 25); + INSERT INTO t2(x,y) VALUES('ten', 'fifteen'); + INSERT INTO t2(x,y) VALUES('twenty', 'twentyfive'); + CREATE TABLE t3(id TEXT PRIMARY KEY, a, b, c, d) WITHOUT ROWID; + INSERT INTO t3(id,a,b,c,d) SELECT rowid, a, b, c, d FROM t1; + PRAGMA automatic_index = 0; +} + +# Run EXPLAIN on $sql. Return a list of P4 values for all $opcode +# opcodes. +# +proc p4_of_opcode {db opcode sql} { + set res {} + $db eval "EXPLAIN $sql" x { + if {$x(opcode)==$opcode} {lappend res $x(p4)} + } + return $res +} + +# Run EXPLAIN on $sql. Return a list of P5 values for all $opcode +# opcodes that contain regexp $comment in their comment +# +proc p5_of_opcode {db opcode sql} { + set res {} + $db eval "EXPLAIN $sql" x { + if {$x(opcode)==$opcode} { + lappend res $x(p5) + } + } + return $res +} + +# Verify that when t1 is in the outer loop and t2 is in the inner loop, +# no cursor hints occur for t1 (since it is a full table scan) but that +# each t2 access has a cursor hint based on the current t1.a value. +# +do_test 1.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t1 CROSS JOIN t2 WHERE a=x + } +} {{EQ(r[1],c0)}} +do_test 1.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t1 CROSS JOIN t2 WHERE a=x + } +} {0 0} + +# Do the same test the other way around. +# +do_test 2.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t2 CROSS JOIN t1 WHERE a=x + } +} {{EQ(c0,r[1])}} +do_test 2.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t2 CROSS JOIN t1 WHERE a=x + } +} {0 0} + +# Various expressions captured by CursorHint +# +do_test 3.1 { + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE a=15 AND c=22 AND rowid!=98 + } +} {AND(AND(EQ(c0,15),EQ(c2,22)),NE(rowid,98))} +do_test 3.2 { + p4_of_opcode db CursorHint { + SELECT * FROM t3 WHERE a<15 AND b>22 AND id!=98 + } +} {AND(AND(LT(c1,15),GT(c2,22)),NE(c0,98))} + +# Indexed queries +# +do_test 4.1asc { + db eval { + CREATE INDEX t1bc ON t1(b,c); + CREATE INDEX t2yz ON t2(y,z); + } + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE b>11 ORDER BY b ASC; + } +} {} +do_test 4.1desc { + p4_of_opcode db CursorHint { + SELECT * FROM t1 WHERE b>11 ORDER BY b DESC; + } +} {GT(c0,11)} +do_test 4.2 { + p5_of_opcode db OpenRead { + SELECT * FROM t1 WHERE b>11; + } +} {2 0} +do_test 4.3asc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b<11 ORDER BY b ASC; + } +} {LT(c0,11)} +do_test 4.3desc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b<11 ORDER BY b DESC; + } +} {} +do_test 4.4 { + p5_of_opcode db OpenRead { + SELECT c FROM t1 WHERE b<11; + } +} {0} + +do_test 4.5asc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b>=10 AND b<=20 ORDER BY b ASC; + } +} {LE(c0,20)} +do_test 4.5desc { + p4_of_opcode db CursorHint { + SELECT c FROM t1 WHERE b>=10 AND b<=20 ORDER BY b DESC; + } +} {GE(c0,10)} + +# If there are any equality terms used in the constraint, then all terms +# should be hinted. +# +do_test 4.6asc { + p4_of_opcode db CursorHint { + SELECT rowid FROM t1 WHERE b=22 AND c>=10 AND c<=20 ORDER BY b,c ASC; + } +} {AND(AND(EQ(c0,22),GE(c1,10)),LE(c1,20))} +do_test 4.6desc { + p4_of_opcode db CursorHint { + SELECT rowid FROM t1 WHERE b=22 AND c>=10 AND c<=20 ORDER BY b,c DESC; + } +} {AND(AND(EQ(c0,22),GE(c1,10)),LE(c1,20))} + +# 2023-03-24 https://sqlite.org/forum/forumpost/591006b1cc +# +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(x TEXT PRIMARY KEY) WITHOUT ROWID; + CREATE VIEW t2 AS SELECT 0 FROM t1 WHERE x>='a' OR x='1'; + SELECT * FROM t2 RIGHT JOIN t1 ON true; +} +# Additional test case from https://sqlite.org/forum/forumpost/d34ad68c36?t=c +# which is a different way to acces the same problem. +# +do_execsql_test 5.1 { + CREATE TABLE v1 (c1, PRIMARY KEY( c1 )) WITHOUT ROWID; + CREATE VIEW v2 AS SELECT 0 FROM v1 WHERE c1 IS '' OR c1 > ''; + CREATE VIEW v3 AS SELECT 0 FROM v2 JOIN (v2 RIGHT JOIN v1); + CREATE VIEW v4 AS SELECT 0 FROM v3, v3; + SELECT * FROM v3 JOIN v3 AS a0, v4 AS a1, v4 AS a2, v3 AS a3, + v3 AS a4, v4 AS a5 + ORDER BY 1; +} + +# 2023-04-10 https://sqlite.org/forum/forumpost/0b53708c95 +# +do_execsql_test 6.0 { + CREATE TABLE t6(a TEXT UNIQUE, b TEXT); + INSERT INTO t6(a,b) VALUES('uvw','xyz'),('abc','def'); + WITH v1(a) AS (SELECT a COLLATE NOCASE FROM t6) + SELECT v1.a, count(*) FROM t6 LEFT JOIN v1 ON true + GROUP BY 1 + HAVING (SELECT true FROM t6 AS aa LEFT JOIN t6 AS bb ON length(v1.a)>5); +} {abc 2 uvw 2} + + +# 2023-05-04 https://sqlite.org/forum/forumpost/29a47cf6d1 +# +# codeCursorHint() should not walk expressions that have been optimized +# out and converted to TRUE or FALSE. This only comes up when compiling +# with SQLITE_ENABLE_CURSOR_HINTS +# +reset_db +do_execsql_test 7.1 { + CREATE TABLE t1(a INT PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t2(b INT PRIMARY KEY) WITHOUT ROWID; + CREATE TABLE t3(c INT PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t1(a) VALUES(1),(2); + INSERT INTO t2(b) VALUES(4),(8); + INSERT INTO t3(c) VALUES(16),(32); + CREATE VIEW v4(d) AS SELECT c FROM t3; + SELECT * FROM t1 RIGHT JOIN t2 ON true JOIN v4 ON (d IS NULL); +} {} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/customfuzz3.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/customfuzz3.c new file mode 100644 index 0000000000000000000000000000000000000000..3a226cec1d559252c9abc748ecd3ce2fa69deff2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/customfuzz3.c @@ -0,0 +1,30 @@ +/* +** This module interfaces SQLite to the Google OSS-Fuzz, fuzzer as a service. +** (https://github.com/google/oss-fuzz) +*/ +#include +#if !defined(_MSC_VER) +#include +#endif +#include +#include +#include "sqlite3.h" +#include "shell.h" + +/* +** Main entry point. The fuzzer invokes this function with each +** fuzzed input. +*/ +int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + char *command = sqlite3_mprintf("%.*s", (int)size, data); + int argc = 3; + char *shellCmd[argc]; + shellCmd[0] = "./sqlite"; + shellCmd[1] = ":memory:"; + shellCmd[2] = command; + + shell_main(argc, shellCmd); + sqlite3_free(command); + return 0; +} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dataversion1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/dataversion1.test new file mode 100644 index 0000000000000000000000000000000000000000..55f7aada0c6f7026612cb3f62eab9111155ed375 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dataversion1.test @@ -0,0 +1,87 @@ +# 2018-07-18 +# +# 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. +# +#*********************************************************************** +# +# Test case for SQLITE_FCNTL_DATA_VERSION +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Construct a database and get its initial data version +sqlite3 db test.db +do_test dataversion1-100 { + db eval { + CREATE TABLE t1(x); + INSERT INTO t1(x) VALUES(99); + SELECT * FROM t1; + } +} {99} +set dv1 [file_control_data_version db main] + +# The data version does not change by ATTACH or by changes to +# other schemas within the same connection. +# +do_test dataversion1-101 { + db eval { + ATTACH ':memory:' AS aux1; + CREATE TABLE aux1.t2(y); + CREATE TEMP TABLE t3(z); + } + file_control_data_version db main +} $dv1 + +# The data version does change when SQL modifies the table +do_test dataversion1-110 { + db eval { + UPDATE t1 SET x=x+1; + } + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {0} + +# But the data version is constant if there are changes to other +# schemas +set dv1 [file_control_data_version db main] +do_test dataversion1-120 { + db eval { + UPDATE t2 SET y=y+1; + } + file_control_data_version db +} $dv1 + +# Changes to the database via another connection are not detected +# until there is a read transaction. +# +sqlite3 db2 test.db +do_test dataversion1-130 { + db2 eval { + SELECT * FROM t1 + } +} {100} +do_test dataversion1-131 { + file_control_data_version db +} $dv1 +do_test dataversion1-132 { + db2 eval { + UPDATE t1 SET x=x+1; + } + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {1} +do_test dataversion1-133 { + db eval {SELECT * FROM t1} + set dv2 [file_control_data_version db] + expr {$::dv1==$dv2} +} {0} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/date.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/date.test new file mode 100644 index 0000000000000000000000000000000000000000..d22b652b474a3f070ba0a24f054c1611cf343567 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/date.test @@ -0,0 +1,655 @@ +# 2003 October 31 +# +# 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. The +# focus of this file is testing date and time functions. +# +# $Id: date.test,v 1.34 2009/04/16 12:58:03 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +proc datetest {tnum expr result} { + do_test date-$tnum [subst { + execsql "SELECT coalesce($expr,'NULL')" + }] [list $result] +} +set tcl_precision 15 +datetest 1.1 julianday('2000-01-01') 2451544.5 +datetest 1.2 julianday('1970-01-01') 2440587.5 +datetest 1.3 julianday('1910-04-20') 2418781.5 +datetest 1.4 julianday('1986-02-09') 2446470.5 +datetest 1.5 julianday('12:00:00') 2451545.0 +datetest 1.6 {julianday('2000-01-01 12:00:00')} 2451545.0 +datetest 1.7 {julianday('2000-01-01 12:00')} 2451545.0 +datetest 1.8 julianday('bogus') NULL +datetest 1.9 julianday('1999-12-31') 2451543.5 +datetest 1.10 julianday('1999-12-32') NULL +datetest 1.11 julianday('1999-13-01') NULL +datetest 1.12 julianday('2003-02-31') 2452701.5 +datetest 1.13 julianday('2003-03-03') 2452701.5 +datetest 1.14 julianday('+2000-01-01') NULL +datetest 1.15 julianday('200-01-01') NULL +datetest 1.16 julianday('2000-1-01') NULL +datetest 1.17 julianday('2000-01-1') NULL +datetest 1.18.1 {julianday('2000-01-01 12:00:00')} 2451545.0 +datetest 1.18.2 {julianday('2000-01-01T12:00:00')} 2451545.0 +datetest 1.18.3 {julianday('2000-01-01 T12:00:00')} 2451545.0 +datetest 1.18.4 {julianday('2000-01-01T 12:00:00')} 2451545.0 +datetest 1.18.4 {julianday('2000-01-01 T 12:00:00')} 2451545.0 +datetest 1.19 {julianday('2000-01-01 12:00:00.1')} 2451545.00000116 +datetest 1.20 {julianday('2000-01-01 12:00:00.01')} 2451545.00000012 +datetest 1.21 {julianday('2000-01-01 12:00:00.001')} 2451545.00000001 +datetest 1.22 {julianday('2000-01-01 12:00:00.')} NULL +datetest 1.23 julianday(12345.6) 12345.6 +datetest 1.23b julianday(1721059.5) 1721059.5 +datetest 1.24 {julianday('2001-01-01 12:00:00 bogus')} NULL +datetest 1.25 {julianday('2001-01-01 bogus')} NULL +datetest 1.26 {julianday('2001-01-01 12:60:00')} NULL +datetest 1.27 {julianday('2001-01-01 12:59:60')} NULL +datetest 1.28 {julianday('2001-00-01')} NULL +datetest 1.29 {julianday('2001-01-00')} NULL + +datetest 2.1 datetime(0,'unixepoch') {1970-01-01 00:00:00} +datetest 2.1b datetime(0,'unixepoc') NULL +datetest 2.1c datetime(0,'unixepochx') NULL +datetest 2.1d datetime('2003-10-22','unixepoch') NULL +datetest 2.2 datetime(946684800,'unixepoch') {2000-01-01 00:00:00} +datetest 2.2b datetime('946684800','unixepoch') {2000-01-01 00:00:00} +for {set i 0} {$i<1000} {incr i} { + set sql [format {strftime('%%H:%%M:%%f',1237962480.%03d,'unixepoch')} $i] + set res [format {06:28:00.%03d} $i] + datetest 2.2c-$i $sql $res +} +datetest 2.3 {date('2003-10-22','weekday 0')} 2003-10-26 +datetest 2.4 {date('2003-10-22','weekday 1')} 2003-10-27 +datetest 2.4a {date('2003-10-22','weekday 1')} 2003-10-27 +datetest 2.4b {date('2003-10-22','weekday 1x')} NULL +datetest 2.4c {date('2003-10-22','weekday -1')} NULL +datetest 2.4d {date('2003-10-22','weakday 1x')} NULL +datetest 2.4e {date('2003-10-22','weekday ')} NULL +datetest 2.5 {date('2003-10-22','weekday 2')} 2003-10-28 +datetest 2.6 {date('2003-10-22','weekday 3')} 2003-10-22 +datetest 2.7 {date('2003-10-22','weekday 4')} 2003-10-23 +datetest 2.8 {date('2003-10-22','weekday 5')} 2003-10-24 +datetest 2.9 {date('2003-10-22','weekday 6')} 2003-10-25 +datetest 2.10 {date('2003-10-22','weekday 7')} NULL +datetest 2.11 {date('2003-10-22','weekday 5.5')} NULL +datetest 2.12 {datetime('2003-10-22 12:34','weekday 0')} {2003-10-26 12:34:00} +datetest 2.13 {datetime('2003-10-22 12:34','start of month')} \ + {2003-10-01 00:00:00} +datetest 2.14 {datetime('2003-10-22 12:34','start of year')} \ + {2003-01-01 00:00:00} +datetest 2.15 {datetime('2003-10-22 12:34','start of day')} \ + {2003-10-22 00:00:00} +datetest 2.15a {datetime('2003-10-22 12:34','start of')} NULL +datetest 2.15b {datetime('2003-10-22 12:34','start of bogus')} NULL +datetest 2.16 time('12:34:56.43') 12:34:56 +datetest 2.17 {datetime('2003-10-22 12:34','1 day')} {2003-10-23 12:34:00} +datetest 2.18 {datetime('2003-10-22 12:34','+1 day')} {2003-10-23 12:34:00} +datetest 2.19 {datetime('2003-10-22 12:34','+1.25 day')} {2003-10-23 18:34:00} +datetest 2.20 {datetime('2003-10-22 12:34','-1.0 day')} {2003-10-21 12:34:00} +datetest 2.21 {datetime('2003-10-22 12:34','1 month')} {2003-11-22 12:34:00} +datetest 2.22 {datetime('2003-10-22 12:34','11 month')} {2004-09-22 12:34:00} +datetest 2.23 {datetime('2003-10-22 12:34','-13 month')} {2002-09-22 12:34:00} +datetest 2.24 {datetime('2003-10-22 12:34','1.5 months')} {2003-12-07 12:34:00} +datetest 2.25 {datetime('2003-10-22 12:34','-5 years')} {1998-10-22 12:34:00} +datetest 2.26 {datetime('2003-10-22 12:34','+10.5 minutes')} \ + {2003-10-22 12:44:30} +datetest 2.27 {datetime('2003-10-22 12:34','-1.25 hours')} \ + {2003-10-22 11:19:00} +datetest 2.28 {datetime('2003-10-22 12:34','11.25 seconds')} \ + {2003-10-22 12:34:11} +datetest 2.29 {datetime('2003-10-22 12:24','+5 bogus')} NULL +datetest 2.30 {datetime('2003-10-22 12:24','+++')} NULL +datetest 2.31 {datetime('2003-10-22 12:24','+12.3e4 femtoseconds')} NULL +datetest 2.32 {datetime('2003-10-22 12:24','+12.3e4 uS')} NULL +datetest 2.33 {datetime('2003-10-22 12:24','+1 abc')} NULL +datetest 2.34 {datetime('2003-10-22 12:24','+1 abcd')} NULL +datetest 2.35 {datetime('2003-10-22 12:24','+1 abcde')} NULL +datetest 2.36 {datetime('2003-10-22 12:24','+1 abcdef')} NULL +datetest 2.37 {datetime('2003-10-22 12:24','+1 abcdefg')} NULL +datetest 2.38 {datetime('2003-10-22 12:24','+1 abcdefgh')} NULL +datetest 2.39 {datetime('2003-10-22 12:24','+1 abcdefghi')} NULL +set sqlite_current_time 1199243045 +datetest 2.40 {datetime()} {2008-01-02 03:04:05} +set sqlite_current_time 0 +datetest 2.41 {datetime('2003-10-22 12:24','23 seconds')} {2003-10-22 12:24:23} +datetest 2.42 {datetime('2003-10-22 12:24','345 second')} {2003-10-22 12:29:45} +datetest 2.43 {datetime('2003-10-22 12:24','4 second')} {2003-10-22 12:24:04} +datetest 2.44 {datetime('2003-10-22 12:24','56 second')} {2003-10-22 12:24:56} +datetest 2.45 {datetime('2003-10-22 12:24','60 second')} {2003-10-22 12:25:00} +datetest 2.46 {datetime('2003-10-22 12:24','70 second')} {2003-10-22 12:25:10} +datetest 2.47 {datetime('2003-10-22 12:24','8.6 seconds')} {2003-10-22 12:24:08} +datetest 2.48 {datetime('2003-10-22 12:24','9.4 second')} {2003-10-22 12:24:09} +datetest 2.49 {datetime('2003-10-22 12:24','0000 second')} {2003-10-22 12:24:00} +datetest 2.50 {datetime('2003-10-22 12:24','0001 second')} {2003-10-22 12:24:01} +datetest 2.51 {datetime('2003-10-22 12:24','nonsense')} NULL + +datetest 2.60 {datetime('2023-02-31')} {2023-03-03 00:00:00} + +datetest 3.1 {strftime('%d','2003-10-31 12:34:56.432')} 31 +datetest 3.2.1 {strftime('pre%fpost','2003-10-31 12:34:56.432')} pre56.432post +datetest 3.2.2 {strftime('%f','2003-10-31 12:34:59.9999999')} 59.999 +datetest 3.3 {strftime('%H','2003-10-31 12:34:56.432')} 12 +datetest 3.4 {strftime('%j','2003-10-31 12:34:56.432')} 304 +datetest 3.5 {strftime('%J','2003-10-31 12:34:56.432')} 2452944.024264259 +datetest 3.6 {strftime('%m','2003-10-31 12:34:56.432')} 10 +datetest 3.7 {strftime('%M','2003-10-31 12:34:56.432')} 34 +datetest 3.8.1 {strftime('%s','2003-10-31 12:34:56.432')} 1067603696 +datetest 3.8.2 {strftime('%s','2038-01-19 03:14:07')} 2147483647 +datetest 3.8.3 {strftime('%s','2038-01-19 03:14:08')} 2147483648 +datetest 3.8.4 {strftime('%s','2201-04-09 12:00:00')} 7298164800 +datetest 3.8.5 {strftime('%s','9999-12-31 23:59:59')} 253402300799 +datetest 3.8.6 {strftime('%s','1969-12-31 23:59:59')} -1 +datetest 3.8.7 {strftime('%s','1901-12-13 20:45:52')} -2147483648 +datetest 3.8.8 {strftime('%s','1901-12-13 20:45:51')} -2147483649 +datetest 3.8.9 {strftime('%s','1776-07-04 00:00:00')} -6106060800 +datetest 3.9 {strftime('%S','2003-10-31 12:34:56.432')} 56 +datetest 3.10 {strftime('%w','2003-10-31 12:34:56.432')} 5 +datetest 3.11.1 {strftime('%W','2003-10-31 12:34:56.432')} 43 +datetest 3.11.2 {strftime('%W','2004-01-01')} 00 +datetest 3.11.3 {strftime('%W','2004-01-02')} 00 +datetest 3.11.4 {strftime('%W','2004-01-03')} 00 +datetest 3.11.5 {strftime('abc%Wxyz','2004-01-04')} abc00xyz +datetest 3.11.6 {strftime('%W','2004-01-05')} 01 +datetest 3.11.7 {strftime('%W','2004-01-06')} 01 +datetest 3.11.8 {strftime('%W','2004-01-07')} 01 +datetest 3.11.9 {strftime('%W','2004-01-08')} 01 +datetest 3.11.10 {strftime('%W','2004-01-09')} 01 +datetest 3.11.11 {strftime('%W','2004-07-18')} 28 +datetest 3.11.12 {strftime('%W','2004-12-31')} 52 +datetest 3.11.13 {strftime('%W','2007-12-31')} 53 +datetest 3.11.14 {strftime('%W','2007-01-01')} 01 +datetest 3.11.15 {strftime('%W %j',2454109.04140970)} {02 008} +datetest 3.11.16 {strftime('%W %j',2454109.04140971)} {02 008} +datetest 3.11.17 {strftime('%W %j',2454109.04140972)} {02 008} +datetest 3.11.18 {strftime('%W %j',2454109.04140973)} {02 008} +datetest 3.11.19 {strftime('%W %j',2454109.04140974)} {02 008} +datetest 3.11.20 {strftime('%W %j',2454109.04140975)} {02 008} +datetest 3.11.21 {strftime('%W %j',2454109.04140976)} {02 008} +datetest 3.11.22 {strftime('%W %j',2454109.04140977)} {02 008} +datetest 3.11.23 {strftime('%W %j',2454109.04140978)} {02 008} +datetest 3.11.24 {strftime('%W %j',2454109.04140979)} {02 008} +datetest 3.11.25 {strftime('%W %j',2454109.04140980)} {02 008} +datetest 3.11.99 {strftime('%W %j','2454109.04140970')} {02 008} +datetest 3.12 {strftime('%Y','2003-10-31 12:34:56.432')} 2003 +datetest 3.13 {strftime('%%','2003-10-31 12:34:56.432')} % +datetest 3.14 {strftime('%_','2003-10-31 12:34:56.432')} NULL +datetest 3.15 {strftime('%Y-%m-%d','2003-10-31')} 2003-10-31 +proc repeat {n txt} { + set x {} + while {$n>0} { + append x $txt + incr n -1 + } + return $x +} +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 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 +} +datetest 3.20 {strftime('%e','2023-08-09')} { 9} +datetest 3.21 {strftime('%F %T','2023-08-09 01:23')} {2023-08-09 01:23:00} +datetest 3.22 {strftime('%k','2023-08-09 04:59:59')} { 4} +datetest 3.23 {strftime('%I%P','2023-08-09 11:59:59')} {11am} +datetest 3.24 {strftime('%I%p','2023-08-09 12:00:00')} {12PM} +datetest 3.25 {strftime('%I%P','2023-08-09 12:59:59.9')} {12pm} +datetest 3.26 {strftime('%I%p','2023-08-09 13:00:00')} {01PM} +datetest 3.27 {strftime('%I%P','2023-08-09 23:59:59')} {11pm} +datetest 3.28 {strftime('%I%p','2023-08-09 00:00:00')} {12AM} +datetest 3.29 {strftime('%l:%M%P','2023-08-09 13:00:00')} { 1:00pm} +datetest 3.30 {strftime('%F %R','2023-08-09 12:34:56')} {2023-08-09 12:34} +datetest 3.31 {strftime('%w %u','2023-01-01')} {0 7} +datetest 3.32 {strftime('%w %u','2023-01-02')} {1 1} +datetest 3.33 {strftime('%w %u','2023-01-03')} {2 2} +datetest 3.34 {strftime('%w %u','2023-01-04')} {3 3} +datetest 3.35 {strftime('%w %u','2023-01-05')} {4 4} +datetest 3.36 {strftime('%w %u','2023-01-06')} {5 5} +datetest 3.37 {strftime('%w %u','2023-01-07')} {6 6} + +# Ticket #2276. Make sure leading zeros are inserted where appropriate. +# +datetest 3.40 \ + {strftime('%d/%f/%H/%W/%j/%m/%M/%S/%Y','0421-01-02 03:04:05.006')} \ + 02/05.006/03/00/002/01/04/05/0421 + +set sqlite_current_time 1157124367 +datetest 4.1 {date('now')} {2006-09-01} +set sqlite_current_time 0 + +datetest 5.1 {datetime('1994-04-16 14:00:00 +05:00')} {1994-04-16 09:00:00} +datetest 5.2 {datetime('1994-04-16 14:00:00 -05:15')} {1994-04-16 19:15:00} +datetest 5.3 {datetime('1994-04-16 05:00:00 +08:30')} {1994-04-15 20:30:00} +datetest 5.4 {datetime('1994-04-16 14:00:00 -11:55')} {1994-04-17 01:55:00} +datetest 5.5 {datetime('1994-04-16 14:00:00 -11:60')} NULL +datetest 5.6 {datetime('1994-04-16 14:00:00 -11:55 ')} {1994-04-17 01:55:00} +datetest 5.7 {datetime('1994-04-16 14:00:00 -11:55 x')} NULL +datetest 5.8 {datetime('1994-04-16T14:00:00Z')} {1994-04-16 14:00:00} +datetest 5.9 {datetime('1994-04-16 14:00:00z')} {1994-04-16 14:00:00} +datetest 5.10 {datetime('1994-04-16 14:00:00 Z')} {1994-04-16 14:00:00} +datetest 5.11 {datetime('1994-04-16 14:00:00z ')} {1994-04-16 14:00:00} +datetest 5.12 {datetime('1994-04-16 14:00:00 z ')} {1994-04-16 14:00:00} +datetest 5.13 {datetime('1994-04-16 14:00:00Zulu')} NULL +datetest 5.14 {datetime('1994-04-16 14:00:00Z +05:00')} NULL +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. The testing localtime_r() +# operates as follows: +# +# (1) Localtime is 30 minutes earlier than (west of) UTC on +# even days (counting from 1970-01-01) +# +# (2) Localtime is 30 minutes later than (east of) UTC on odd days. +# +# (3) The function fails for the specific date/time value +# of 2000-05-29 14:16:00 in order to test the ability of +# SQLite to deal with localtime_r() failures. +# +proc local_to_utc {tn utc local} { + do_execsql_test date-$tn "SELECT datetime('$utc','localtime')" [list $local] +} +proc utc_to_local {tn local utc} { + do_execsql_test date-$tn "SELECT datetime('$local','utc')" [list $utc] +} + +sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 2 +local_to_utc 6.1 {2000-10-29 12:00:00} {2000-10-29 12:30:00} +utc_to_local 6.2 {2000-10-29 12:30:00} {2000-10-29 12:00:00} +local_to_utc 6.3 {2000-10-30 12:00:00} {2000-10-30 11:30:00} +utc_to_local 6.4 {2000-10-30 11:30:00} {2000-10-30 12:00:00} + +local_to_utc 6.5 {2000-10-28 23:59:59} {2000-10-28 23:29:59} +local_to_utc 6.6 {2000-10-29 00:00:00} {2000-10-29 00:30:00} + +# The previous two cases establish that no such localtime as +# 2000-10-29 00:10:00 exists. Verify that we get a reasonable +# answer if we try to convert this non-existant localtime to utc? +# +utc_to_local 6.7 {2000-10-29 00:10:00} {2000-10-28 23:40:00} + +local_to_utc 6.8 {2022-02-10 23:59:59} {2022-02-11 00:29:59} +local_to_utc 6.9 {2022-02-11 00:00:00} {2022-02-10 23:30:00} +local_to_utc 6.10 {2022-02-10 23:45:00} {2022-02-11 00:15:00} +local_to_utc 6.11 {2022-02-11 00:45:00} {2022-02-11 00:15:00} + +# The previous two cases show that two different UTC values give +# the same localtime of 2022-02-11 00:15:00. When converting from +# that localtime back to UTC, we should get one or the other of +# the two UTC values. +# +utc_to_local 6.12 {2022-02-11 00:15:00} {2022-02-11 00:45:00} + +# If localtime_r() fails, the datetime() SQL function should raise an error +# +do_catchsql_test date-6.20 { + SELECT datetime('2000-05-29 14:16:00','localtime'); +} {1 {local time unavailable}} + +# Modifiers work for dates that are way out of band for localtime_r() +# +local_to_utc 6.21 {1800-10-29 12:00:00} {1800-10-29 12:30:00} +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 + +# Date-time functions that contain NULL arguments return a NULL +# result. +# +datetest 7.1 {datetime(null)} NULL +datetest 7.2 {datetime('now',null)} NULL +datetest 7.3 {datetime('now','localtime',null)} NULL +datetest 7.4 {time(null)} NULL +datetest 7.5 {time('now',null)} NULL +datetest 7.6 {time('now','localtime',null)} NULL +datetest 7.7 {date(null)} NULL +datetest 7.8 {date('now',null)} NULL +datetest 7.9 {date('now','localtime',null)} NULL +datetest 7.10 {julianday(null)} NULL +datetest 7.11 {julianday('now',null)} NULL +datetest 7.12 {julianday('now','localtime',null)} NULL +datetest 7.13 {strftime(null,'now')} NULL +datetest 7.14 {strftime('%s',null)} NULL +datetest 7.15 {strftime('%s','now',null)} NULL +datetest 7.16 {strftime('%s','now','localtime',null)} NULL + +# Test modifiers when the date begins as a julian day number - to +# make sure the HH:MM:SS is preserved. Ticket #551. +# +set sqlite_current_time [db eval {SELECT strftime('%s','2003-10-22 12:34:00')}] +datetest 8.1 {datetime('now','weekday 0')} {2003-10-26 12:34:00} +datetest 8.2 {datetime('now','weekday 1')} {2003-10-27 12:34:00} +datetest 8.3 {datetime('now','weekday 2')} {2003-10-28 12:34:00} +datetest 8.4 {datetime('now','weekday 3')} {2003-10-22 12:34:00} +datetest 8.5 {datetime('now','start of month')} {2003-10-01 00:00:00} +datetest 8.6 {datetime('now','start of year')} {2003-01-01 00:00:00} +datetest 8.7 {datetime('now','start of day')} {2003-10-22 00:00:00} +datetest 8.8 {datetime('now','1 day')} {2003-10-23 12:34:00} +datetest 8.9 {datetime('now','+1 day')} {2003-10-23 12:34:00} +datetest 8.10 {datetime('now','+1.25 day')} {2003-10-23 18:34:00} +datetest 8.11 {datetime('now','-1.0 day')} {2003-10-21 12:34:00} +datetest 8.12 {datetime('now','1 month')} {2003-11-22 12:34:00} +datetest 8.13 {datetime('now','11 month')} {2004-09-22 12:34:00} +datetest 8.14 {datetime('now','-13 month')} {2002-09-22 12:34:00} +datetest 8.15 {datetime('now','1.5 months')} {2003-12-07 12:34:00} +datetest 8.16 {datetime('now','-5 years')} {1998-10-22 12:34:00} +datetest 8.17 {datetime('now','+10.5 minutes')} {2003-10-22 12:44:30} +datetest 8.18 {datetime('now','-1.25 hours')} {2003-10-22 11:19:00} +datetest 8.19 {datetime('now','11.25 seconds')} {2003-10-22 12:34:11} +datetest 8.90 {datetime('now','abcdefghijklmnopqrstuvwyxzABCDEFGHIJLMNOP')} NULL +set sqlite_current_time 0 + +# Negative years work. Example: '-4713-11-26' is JD 1.5. +# +datetest 9.1 {julianday('-4713-11-24 12:00:00')} {0.0} +datetest 9.2 {julianday(datetime(5))} {5.0} +datetest 9.3 {julianday(datetime(10))} {10.0} +datetest 9.4 {julianday(datetime(100))} {100.0} +datetest 9.5 {julianday(datetime(1000))} {1000.0} +datetest 9.6 {julianday(datetime(10000))} {10000.0} +datetest 9.7 {julianday(datetime(100000))} {100000.0} + +# datetime() with just an HH:MM:SS correctly inserts the date 2000-01-01. +# +datetest 10.1 {datetime('01:02:03')} {2000-01-01 01:02:03} +datetest 10.2 {date('01:02:03')} {2000-01-01} +datetest 10.3 {strftime('%Y-%m-%d %H:%M','01:02:03')} {2000-01-01 01:02} + +# Test the new HH:MM:SS modifier +# +datetest 11.1 {datetime('2004-02-28 20:00:00', '-01:20:30')} \ + {2004-02-28 18:39:30} +datetest 11.2 {datetime('2004-02-28 20:00:00', '+12:30:00')} \ + {2004-02-29 08:30:00} +datetest 11.3 {datetime('2004-02-28 20:00:00', '+12:30')} \ + {2004-02-29 08:30:00} +datetest 11.4 {datetime('2004-02-28 20:00:00', '12:30')} \ + {2004-02-29 08:30:00} +datetest 11.5 {datetime('2004-02-28 20:00:00', '-12:00')} \ + {2004-02-28 08:00:00} +datetest 11.6 {datetime('2004-02-28 20:00:00', '-12:01')} \ + {2004-02-28 07:59:00} +datetest 11.7 {datetime('2004-02-28 20:00:00', '-11:59')} \ + {2004-02-28 08:01:00} +datetest 11.8 {datetime('2004-02-28 20:00:00', '11:59')} \ + {2004-02-29 07:59:00} +datetest 11.9 {datetime('2004-02-28 20:00:00', '12:01')} \ + {2004-02-29 08:01:00} +datetest 11.10 {datetime('2004-02-28 20:00:00', '12:60')} NULL + +# Ticket #1964 +datetest 12.1 {datetime('2005-09-01')} {2005-09-01 00:00:00} +datetest 12.2 {datetime('2005-09-01','+0 hours')} {2005-09-01 00:00:00} + +# Ticket #1991 +do_test date-13.1 { + execsql { + SELECT strftime('%Y-%m-%d %H:%M:%f', julianday('2006-09-24T10:50:26.047')) + } +} {{2006-09-24 10:50:26.047}} + +# Ticket #2153 +datetest 13.2 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 12:34:59.6')} \ + {2007-01-01 12:34:59} +datetest 13.3 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 12:34:59.6')} \ + {2007-01-01 12:34:59.600} +datetest 13.4 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 12:59:59.6')} \ + {2007-01-01 12:59:59} +datetest 13.5 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 12:59:59.6')} \ + {2007-01-01 12:59:59.600} +datetest 13.6 {strftime('%Y-%m-%d %H:%M:%S', '2007-01-01 23:59:59.6')} \ + {2007-01-01 23:59:59} +datetest 13.7 {strftime('%Y-%m-%d %H:%M:%f', '2007-01-01 23:59:59.6')} \ + {2007-01-01 23:59:59.600} + +# Ticket #3618 +datetest 13.11 {julianday(2454832.5,'-1 day')} {2454831.5} +datetest 13.12 {julianday(2454832.5,'+1 day')} {2454833.5} +datetest 13.13 {julianday(2454832.5,'-1.5 day')} {2454831.0} +datetest 13.14 {julianday(2454832.5,'+1.5 day')} {2454834.0} +datetest 13.15 {julianday(2454832.5,'-3 hours')} {2454832.375} +datetest 13.16 {julianday(2454832.5,'+3 hours')} {2454832.625} +datetest 13.17 {julianday(2454832.5,'-45 minutes')} {2454832.46875} +datetest 13.18 {julianday(2454832.5,'+45 minutes')} {2454832.53125} +datetest 13.19 {julianday(2454832.5,'-675 seconds')} {2454832.4921875} +datetest 13.20 {julianday(2454832.5,'+675 seconds')} {2454832.5078125} +datetest 13.21 {julianday(2454832.5,'-1.5 months')} {2454786.5} +datetest 13.22 {julianday(2454832.5,'+1.5 months')} {2454878.5} +datetest 13.23 {julianday(2454832.5,'-1.5 years')} {2454284.0} +datetest 13.24 {julianday(2454832.5,'+1.5 years')} {2455380.0} + +datetest 13.30 {date('2000-01-01','+1.5 years')} {2001-07-02} +datetest 13.31 {date('2001-01-01','+1.5 years')} {2002-07-02} +datetest 13.32 {date('2002-01-01','+1.5 years')} {2003-07-02} +datetest 13.33 {date('2002-01-01','-1.5 years')} {2000-07-02} +datetest 13.34 {date('2001-01-01','-1.5 years')} {1999-07-02} +datetest 13.35 {date('2023-02-28')} {2023-02-28} +datetest 13.36 {date('2023-02-29')} {2023-03-01} +datetest 13.37 {date('2023-04-31')} {2023-05-01} + +# Test for issues reported by BareFeet (list.sql at tandb.com.au) +# on mailing list on 2008-06-12. +# +# Put a floating point number in the database so that we can manipulate +# raw bits using the hexio interface. +# +if {0==[sqlite3 -has-codec]} { + do_test date-14.1 { + execsql { + PRAGMA auto_vacuum=OFF; + PRAGMA page_size = 1024; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1.1); + } + db close + hexio_write test.db 2040 4142ba32bffffff9 + sqlite3 db test.db + db eval {SELECT * FROM t1} + } {2454629.5} + + # Changing the least significant byte of the floating point value between + # 00 and FF should always generate a time of either 23:59:59 or 00:00:00, + # never 24:00:00 + # + for {set i 0} {$i<=255} {incr i} { + db close + hexio_write test.db 2047 [format %02x $i] + sqlite3 db test.db + do_test date-14.2.$i { + set date [db one {SELECT datetime(x) FROM t1}] + expr {$date eq "2008-06-12 00:00:00" || $date eq "2008-06-11 23:59:59"} + } {1} + } +} + +# Verify that multiple calls to date functions with 'now' return the +# same answer. +# +# EVIDENCE-OF: R-34818-13664 The 'now' argument to date and time +# functions always returns exactly the same value for multiple +# invocations within the same sqlite3_step() call. +# +proc sleeper {} {after 100} +do_test date-15.1 { + db func sleeper sleeper + db eval { + SELECT c - a FROM (SELECT julianday('now') AS a, + sleeper(), julianday('now') AS c); + } +} {0.0} +do_test date-15.2 { + db eval { + SELECT a==b FROM (SELECT current_timestamp AS a, + sleeper(), current_timestamp AS b); + } +} {1} + +# Tests of extreme values in date/time functions. Run with UBSan or the +# equivalent to verify no signed interger overflow warnings. +# +datetest 16.1 {date(147483649)} NULL +datetest 16.2 {datetime(0)} {-4713-11-24 12:00:00} +datetest 16.3 {datetime(5373484.49999999)} {9999-12-31 23:59:59} +datetest 16.4 {julianday('-4713-11-24 12:00:00')} 0.0 +datetest 16.5 {julianday('9999-12-31 23:59:59.999')} 5373484.49999999 +datetest 16.6 {datetime(0,'+464269060799 seconds')} {9999-12-31 23:59:59} +datetest 16.7 {datetime(0,'+464269060800 seconds')} NULL +datetest 16.8 {datetime(0,'+7737817679 minutes')} {9999-12-31 23:59:00} +datetest 16.9 {datetime(0,'+7737817680 minutes')} NULL +datetest 16.10 {datetime(0,'+128963627 hours')} {9999-12-31 23:00:00} +datetest 16.11 {datetime(0,'+128963628 hours')} NULL +datetest 16.12 {datetime(0,'+5373484 days')} {9999-12-31 12:00:00} +datetest 16.13 {datetime(0,'+5373485 days')} NULL +datetest 16.14 {datetime(0,'+176545 months')} {9999-12-24 12:00:00} +datetest 16.15 {datetime(0,'+176546 months')} NULL +datetest 16.16 {datetime(0,'+14712 years')} {9999-11-24 12:00:00} +datetest 16.17 {datetime(0,'+14713 years')} NULL +datetest 16.20 {datetime(5373484.4999999,'-464269060799 seconds')} \ + {-4713-11-24 12:00:00} +datetest 16.21 {datetime(5373484,'-464269060800 seconds')} NULL +datetest 16.22 {datetime(5373484.4999999,'-7737817679 minutes')} \ + {-4713-11-24 12:00:59} +datetest 16.23 {datetime(5373484,'-7737817680 minutes')} NULL +datetest 16.24 {datetime(5373484.4999999,'-128963627 hours')} \ + {-4713-11-24 12:59:59} +datetest 16.25 {datetime(5373484,'-128963628 hours')} NULL +datetest 16.26 {datetime(5373484,'-5373484 days')} {-4713-11-24 12:00:00} +datetest 16.27 {datetime(5373484,'-5373485 days')} NULL +datetest 16.28 {datetime(5373484,'-176545 months')} {-4713-12-01 12:00:00} +datetest 16.29 {datetime(5373484,'-176546 months')} NULL +datetest 16.30 {datetime(5373484,'-14712 years')} {-4713-12-31 12:00:00} +datetest 16.31 {datetime(5373484,'-14713 years')} NULL + +# 2017-03-02: Wrong 'start of day' computation. +# https://www.sqlite.org/src/info/6097cb92745327a1 +# +datetest 17.1 {datetime(2457754, 'start of day')} {2016-12-31 00:00:00} +datetest 17.2 {datetime(2457828)} {2017-03-15 12:00:00} +datetest 17.3 {datetime(2457828,'start of day')} {2017-03-15 00:00:00} +datetest 17.4 {datetime(2457828,'start of month')} {2017-03-01 00:00:00} +datetest 17.5 {datetime(2457828,'start of year')} {2017-01-01 00:00:00} +datetest 17.6 {datetime(37,'start of year')} NULL +datetest 17.7 {datetime(38,'start of year')} {-4712-01-01 00:00:00} + +# 2022-03-04 https://sqlite.org/forum/forumpost/2ffbaa2c3fd7fb82 +# The 'localtime' modifier should preserve fractional seconds. +# +datetest 18.1 {strftime('%f',1.234,'unixepoch','localtime')} {01.234} + +# 2023-04 The 'subsecond' (or 'subsec') modifier alters resolutions +# to at least milliseconds. Added for release 3.42.0 . +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/local-test-sqlite3-delta-01/afc-sqlite3/test/date2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/date2.test new file mode 100644 index 0000000000000000000000000000000000000000..a16e25c448b7483107e90bc7e705cc3a296afaae --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/date2.test @@ -0,0 +1,176 @@ +# 2017-07-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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing date and time functions used in +# check constraints and index expressions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +do_execsql_test date2-100 { + CREATE TABLE t1(x, y, CHECK( date(x) BETWEEN '2017-07-01' AND '2017-07-31' )); + INSERT INTO t1(x,y) VALUES('2017-07-20','one'); +} {} +do_catchsql_test date2-110 { + INSERT INTO t1(x,y) VALUES('now','two'); +} {1 {non-deterministic use of date() in a CHECK constraint}} +do_execsql_test date2-120 { + SELECT * FROM t1; +} {2017-07-20 one} +do_catchsql_test date2-130 { + INSERT INTO t1(x,y) VALUES('2017-08-01','two'); +} {1 {CHECK constraint failed: date(x) BETWEEN '2017-07-01' AND '2017-07-31'}} + +# 2021-03-16 Forum post https://sqlite.org/forum/forumpost/464afd4086 +do_catchsql_test date2-140 { + DROP TABLE t1; + CREATE TABLE t1(x, y, z AS (date())); + INSERT INTO t1(x,y) VALUES(1,2); +} {1 {non-deterministic use of date() in a generated column}} + +do_execsql_test date2-200 { + CREATE TABLE t2(x,y); + INSERT INTO t2(x,y) VALUES(1, '2017-07-20'), (2, 'xyzzy'); + CREATE INDEX t2y ON t2(date(y)); +} +do_catchsql_test date2-210 { + INSERT INTO t2(x,y) VALUES(3, 'now'); +} {1 {non-deterministic use of date() in an index}} +do_execsql_test date2-220 { + SELECT x, y FROM t2 ORDER BY x; +} {1 2017-07-20 2 xyzzy} + +do_execsql_test date2-300 { + CREATE TABLE t3(a INTEGER PRIMARY KEY,b); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t3(a,b) SELECT x, julianday('2017-07-01')+x FROM c; + UPDATE t3 SET b='now' WHERE a=500; +} +do_catchsql_test date2-310 { + CREATE INDEX t3b1 ON t3(datetime(b)); +} {1 {non-deterministic use of datetime() in an index}} +do_catchsql_test date2-320 { + CREATE INDEX t3b1 ON t3(datetime(b)) WHERE typeof(b)='real'; +} {0 {}} +do_execsql_test date2-330 { + EXPLAIN QUERY PLAN + SELECT a FROM t3 + WHERE typeof(b)='real' + AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08'; +} {/USING INDEX t3b/} +do_execsql_test date2-331 { + SELECT a FROM t3 + WHERE typeof(b)='real' + AND datetime(b) BETWEEN '2017-07-04' AND '2017-07-08' + ORDER BY a; +} {3 4 5 6} + +do_execsql_test date2-400 { + CREATE TABLE t4(a INTEGER PRIMARY KEY,b); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<1000) + INSERT INTO t4(a,b) SELECT x, julianday('2017-07-01')+x FROM c; + UPDATE t4 SET b='now' WHERE a=500; +} +do_catchsql_test date2-410 { + CREATE INDEX t4b1 ON t4(b) + WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31'; +} {1 {non-deterministic use of date() in an index}} +do_execsql_test date2-420 { + DELETE FROM t4 WHERE a=500; + CREATE INDEX t4b1 ON t4(b) + WHERE date(b) BETWEEN '2017-06-01' AND '2017-08-31'; +} +do_catchsql_test date2-430 { + INSERT INTO t4(a,b) VALUES(9999,'now'); +} {1 {non-deterministic use of date() in an index}} + +do_execsql_test date2-500 { + CREATE TABLE mods(x); + INSERT INTO mods(x) VALUES + ('+10 days'), + ('-10 days'), + ('+10 hours'), + ('-10 hours'), + ('+10 minutes'), + ('-10 minutes'), + ('+10 seconds'), + ('-10 seconds'), + ('+10 months'), + ('-10 months'), + ('+10 years'), + ('-10 years'), + ('start of month'), + ('start of year'), + ('start of day'), + ('weekday 1'), + ('unixepoch'); + CREATE TABLE t5(y,m); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<5) + INSERT INTO t5(y,m) SELECT julianday('2017-07-01')+c.x, mods.x FROM c, mods; + CREATE INDEX t5x1 on t5(y) WHERE datetime(y,m) IS NOT NULL; +} +do_catchsql_test date2-510 { + INSERT INTO t5(y,m) VALUES('2017-07-20','localtime'); +} {1 {non-deterministic use of datetime() in an index}} +do_catchsql_test date2-520 { + INSERT INTO t5(y,m) VALUES('2017-07-20','utc'); +} {1 {non-deterministic use of datetime() in an index}} + +# 2019-10-30 Ticket 830277d9db6c3ba1 +# +do_catchsql_test date2-600 { + CREATE TABLE t600(a REAL CHECK( a datetime(unixepoch('1970-01-01',format('%+d days',x)),'auto'); +} {63} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/date4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/date4.test new file mode 100644 index 0000000000000000000000000000000000000000..56a9090b1b06d2057b6e3227686c3d955a643db0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/date4.test @@ -0,0 +1,38 @@ +# 2023-08-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. +# +#*********************************************************************** +# +# Test cases for the strftime() SQL function. Comparisons against the +# C-library strftime() function. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +if {$tcl_platform(os)=="Linux"} { + 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<=24858} {incr i} { + set TS [expr {$i*86390}] + do_execsql_test date4-$i { + SELECT strftime($::FMT,$::TS,'unixepoch'); + } [list [strftime $FMT $TS]] +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/date5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/date5.test new file mode 100644 index 0000000000000000000000000000000000000000..688f84d0f1d0f1ec53d6826a73a8ad51b7af44e0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/date5.test @@ -0,0 +1,86 @@ +# 2024-08-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. +# +#*********************************************************************** +# +# https://sqlite.org/forum/forumpost/eaa0a09786c6368b +# +# Apparently SQLite has been miscomputing leap-year dates before +# the year 0400. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this whole file if date and time functions are omitted +# at compile-time +# +ifcapable {!datetime} { + finish_test + return +} + +# Data sources: +# 1-10 https://ssd.jpl.nasa.gov/tools/jdc/#/cd +# 11 Jean Meeus, Astronomical Algorithms, ISBN 0-943396-61-1, p.59 +# 12 https://en.wikipedia.org/wiki/Julian_day +# +# ID YEAR MONTH DAY JD +set date5data { + 1 2024 2 29 2460369.5 + 2 2024 3 1 2460370.5 + 3 2023 2 28 2460003.5 + 4 2023 3 1 2460004.5 + 5 2000 2 29 2451603.5 + 6 2000 3 1 2451604.5 + 7 1900 2 28 2415078.5 + 8 1900 3 1 2415079.5 + 9 1712 2 29 2346413.5 + 10 1712 3 1 2346414.5 + 11 1977 4 26 2443259.5 + 12 2013 1 1 2456293.5 +} + +foreach {id y m d jd} $date5data { + set date [format %04d-%02d-%02d $y $m $d] + do_execsql_test date5-jd$jd { + SELECT date($::jd); + } $date + do_execsql_test date5-cal/$date { + SELECT julianday($::date); + } $jd + for {set i 1} {$y+400*$i<=9999} {incr i} { + set y2 [expr {$y+400*$i}] + set date2 [format %04d-%02d-%02d $y2 $m $d] + set jd2 [expr {$jd+146097*$i}] + do_execsql_test date5-jd$jd2 { + SELECT date($::jd2); + } $date2 + do_execsql_test date5-cal/$date2 { + SELECT julianday($::date2); + } $jd2 + } + for {set i 1} {$y-400*$i>=-4712} {incr i} { + set y2 [expr {$y-400*$i}] + if {$y2<0} { + set date2 [format -%04d-%02d-%02d [expr {-$y2}] $m $d] + } else { + set date2 [format %04d-%02d-%02d $y2 $m $d] + } + set jd2 [expr {$jd-146097*$i}] + do_execsql_test date5-jd$jd2 { + SELECT date($::jd2); + } $date2 + do_execsql_test date5-cal/$date2 { + SELECT julianday($::date2); + } $jd2 + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbdata.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbdata.test new file mode 100644 index 0000000000000000000000000000000000000000..5b1150c78f18322e8f9dfde6bdde6bfd6d686369 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbdata.test @@ -0,0 +1,115 @@ +# 2019-04-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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing the sqlite_dbpage virtual table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix dbdata + +ifcapable !vtab||!compound { + finish_test + return +} +if { [catch { db enable_load_extension 1 }] + || [catch { db eval { SELECT load_extension('../dbdata') } }] +} { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE T1(a, b); + INSERT INTO t1(rowid, a ,b) VALUES(5, 'v', 'five'); + INSERT INTO t1(rowid, a, b) VALUES(10, 'x', 'ten'); +} + +do_execsql_test 1.1 { + SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata WHERE pgno=2; +} { + 2 0 -1 5 + 2 0 0 'v' + 2 0 1 'five' + 2 1 -1 10 + 2 1 0 'x' + 2 1 1 'ten' +} + +breakpoint +do_execsql_test 1.2 { + SELECT pgno, cell, field, quote(value) FROM sqlite_dbdata; +} { + 1 0 -1 1 + 1 0 0 'table' + 1 0 1 'T1' + 1 0 2 'T1' + 1 0 3 2 + 1 0 4 {'CREATE TABLE T1(a, b)'} + 2 0 -1 5 + 2 0 0 'v' + 2 0 1 'five' + 2 1 -1 10 + 2 1 0 'x' + 2 1 1 'ten' +} + +set big [string repeat big 2000] +do_execsql_test 1.3 { + INSERT INTO t1 VALUES(NULL, $big); + SELECT value FROM sqlite_dbdata WHERE pgno=2 AND cell=2 AND field=1; +} $big + +do_execsql_test 1.4 { + DELETE FROM t1; + INSERT INTO t1 VALUES(NULL, randomblob(5050)); +} +do_test 1.5 { + execsql { + SELECT quote(value) FROM sqlite_dbdata WHERE pgno=2 AND cell=0 AND field=1; + } +} [db one {SELECT quote(b) FROM t1}] + +#------------------------------------------------------------------------- +reset_db +db enable_load_extension 1 +db eval { SELECT load_extension('../dbdata') } + +do_execsql_test 2.0 { + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<10 + ) + INSERT INTO t1 SELECT randomblob(900) FROM s; +} + +do_execsql_test 2.1 { + SELECT * FROM sqlite_dbptr WHERE pgno=2; +} { + 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21 +} + +do_execsql_test 2.2 { + SELECT * FROM sqlite_dbptr WHERE pgno=3; +} { + 3 24 3 23 +} + +do_execsql_test 2.3 { + SELECT * FROM sqlite_dbptr +} { + 2 25 2 6 2 7 2 9 2 11 2 13 2 15 2 17 2 19 2 21 + 3 24 3 23 +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz.c new file mode 100644 index 0000000000000000000000000000000000000000..ca1c6ea2177f533670d6f79995d874f21e5af252 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz.c @@ -0,0 +1,754 @@ +/* +** 2016-12-17 +** +** 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 program is designed for fuzz-testing SQLite database files. +** +** This program reads fuzzed database files from the disk files named +** on the command-line. Each database is loaded into an in-memory +** filesystem so that the original database file is unmolested. +** +** The fuzzed database is then opened, and series of SQL statements +** are run against the database to ensure that SQLite can safely handle +** the fuzzed database. +*/ +#include +#include +#include +#include +#include +#include +#define ISSPACE(X) isspace((unsigned char)(X)) +#define ISDIGIT(X) isdigit((unsigned char)(X)) +#include "sqlite3.h" +#ifdef __unix__ +# include +# include +#endif + +/* +** Print sketchy documentation for this utility program +*/ +static void showHelp(const char *zArgv0){ + printf("Usage: %s [options] DATABASE ...\n", zArgv0); + printf( +"Read databases into an in-memory filesystem. Run test SQL as specified\n" +"by command-line arguments or from\n" +"\n" +" SELECT group_concat(sql) FROM autoexec;\n" +"\n" +"Options:\n" +" --help Show this help text\n" +" -q|--quiet Reduced output\n" +" --limit-mem N Limit memory used by test SQLite instances to N bytes\n" +" --limit-vdbe Panic if any test runs for more than 100,000 cycles\n" +" --no-lookaside Disable the lookaside memory allocator\n" +" --timeout N Timeout after N seconds.\n" +" --trace Show the results of each SQL command\n" +" -v|--verbose Increased output. Repeat for more output.\n" + ); + exit(0); +} + +/* +** Print an error message and quit. +*/ +static void fatalError(const char *zFormat, ...){ + va_list ap; + va_start(ap, zFormat); + vfprintf(stderr, zFormat, ap); + va_end(ap); + fprintf(stderr, "\n"); + exit(1); +} + +/* +** Files in the virtual file system. +*/ +typedef struct VFile VFile; +typedef struct VHandle VHandle; +struct VFile { + char *zFilename; /* Filename. NULL for delete-on-close. From malloc() */ + int sz; /* Size of the file in bytes */ + int nRef; /* Number of references to this file */ + unsigned char *a; /* Content of the file. From malloc() */ +}; +struct VHandle { + sqlite3_file base; /* Base class. Must be first */ + VFile *pVFile; /* The underlying file */ +}; + +/* +** Maximum number of files in the in-memory virtual filesystem. +*/ +#define MX_FILE 10 + +/* +** Maximum allowed file size +*/ +#define MX_FILE_SZ 1000000 + +/* +** All global variables are gathered into the "g" singleton. +*/ +static struct GlobalVars { + VFile aFile[MX_FILE]; /* The virtual filesystem */ +} g; + + +/* +** Initialize the virtual file system. +*/ +static void formatVfs(void){ + int i; + for(i=0; i0 ){ + fatalError("file %d still open. nRef=%d", i, g.aFile[i].nRef); + } + g.aFile[i].sz = -1; + free(g.aFile[i].a); + g.aFile[i].a = 0; + g.aFile[i].nRef = 0; + } +} + +/* +** Find a VFile by name +*/ +static VFile *findVFile(const char *zName){ + int i; + if( zName==0 ) return 0; + for(i=0; i=0; i++){} + if( i>=MX_FILE ) return 0; + if( zDiskFile ){ + in = fopen(zDiskFile, "rb"); + if( in==0 ) fatalError("no such file: \"%s\"", zDiskFile); + fseek(in, 0, SEEK_END); + sz = ftell(in); + rewind(in); + } + pNew = &g.aFile[i]; + if( zName ){ + int nName = (int)strlen(zName)+1; + pNew->zFilename = malloc(nName); + if( pNew->zFilename==0 ){ + if( in ) fclose(in); + return 0; + } + memcpy(pNew->zFilename, zName, nName); + }else{ + pNew->zFilename = 0; + } + pNew->nRef = 0; + pNew->sz = sz; + pNew->a = malloc(sz); + if( sz>0 ){ + if( pNew->a==0 || fread(pNew->a, sz, 1, in)<1 ){ + free(pNew->zFilename); + free(pNew->a); + pNew->a = 0; + pNew->zFilename = 0; + pNew->sz = -1; + pNew = 0; + } + } + if( in ) fclose(in); + return pNew; +} + +/* Methods for the VHandle object +*/ +static int inmemClose(sqlite3_file *pFile){ + VHandle *p = (VHandle*)pFile; + VFile *pVFile = p->pVFile; + pVFile->nRef--; + if( pVFile->nRef==0 && pVFile->zFilename==0 ){ + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + } + return SQLITE_OK; +} +static int inmemRead( + sqlite3_file *pFile, /* Read from this open file */ + void *pData, /* Store content in this buffer */ + int iAmt, /* Bytes of content */ + sqlite3_int64 iOfst /* Start reading here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst<0 || iOfst>=pVFile->sz ){ + memset(pData, 0, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + if( iOfst+iAmt>pVFile->sz ){ + memset(pData, 0, iAmt); + iAmt = (int)(pVFile->sz - iOfst); + memcpy(pData, pVFile->a, iAmt); + return SQLITE_IOERR_SHORT_READ; + } + memcpy(pData, pVFile->a + iOfst, iAmt); + return SQLITE_OK; +} +static int inmemWrite( + sqlite3_file *pFile, /* Write to this file */ + const void *pData, /* Content to write */ + int iAmt, /* bytes to write */ + sqlite3_int64 iOfst /* Start writing here */ +){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( iOfst+iAmt > pVFile->sz ){ + unsigned char *aNew; + if( iOfst+iAmt >= MX_FILE_SZ ){ + return SQLITE_FULL; + } + aNew = realloc(pVFile->a, (int)(iOfst+iAmt)); + if( aNew==0 ){ + return SQLITE_FULL; + } + pVFile->a = aNew; + if( iOfst > pVFile->sz ){ + memset(pVFile->a + pVFile->sz, 0, (int)(iOfst - pVFile->sz)); + } + pVFile->sz = (int)(iOfst + iAmt); + } + memcpy(pVFile->a + iOfst, pData, iAmt); + return SQLITE_OK; +} +static int inmemTruncate(sqlite3_file *pFile, sqlite3_int64 iSize){ + VHandle *pHandle = (VHandle*)pFile; + VFile *pVFile = pHandle->pVFile; + if( pVFile->sz>iSize && iSize>=0 ) pVFile->sz = (int)iSize; + return SQLITE_OK; +} +static int inmemSync(sqlite3_file *pFile, int flags){ + return SQLITE_OK; +} +static int inmemFileSize(sqlite3_file *pFile, sqlite3_int64 *pSize){ + *pSize = ((VHandle*)pFile)->pVFile->sz; + return SQLITE_OK; +} +static int inmemLock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemUnlock(sqlite3_file *pFile, int type){ + return SQLITE_OK; +} +static int inmemCheckReservedLock(sqlite3_file *pFile, int *pOut){ + *pOut = 0; + return SQLITE_OK; +} +static int inmemFileControl(sqlite3_file *pFile, int op, void *pArg){ + return SQLITE_NOTFOUND; +} +static int inmemSectorSize(sqlite3_file *pFile){ + return 512; +} +static int inmemDeviceCharacteristics(sqlite3_file *pFile){ + return + SQLITE_IOCAP_SAFE_APPEND | + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | + SQLITE_IOCAP_POWERSAFE_OVERWRITE; +} + + +/* Method table for VHandle +*/ +static sqlite3_io_methods VHandleMethods = { + /* iVersion */ 1, + /* xClose */ inmemClose, + /* xRead */ inmemRead, + /* xWrite */ inmemWrite, + /* xTruncate */ inmemTruncate, + /* xSync */ inmemSync, + /* xFileSize */ inmemFileSize, + /* xLock */ inmemLock, + /* xUnlock */ inmemUnlock, + /* xCheck... */ inmemCheckReservedLock, + /* xFileCtrl */ inmemFileControl, + /* xSectorSz */ inmemSectorSize, + /* xDevchar */ inmemDeviceCharacteristics, + /* xShmMap */ 0, + /* xShmLock */ 0, + /* xShmBarrier */ 0, + /* xShmUnmap */ 0, + /* xFetch */ 0, + /* xUnfetch */ 0 +}; + +/* +** Open a new file in the inmem VFS. All files are anonymous and are +** delete-on-close. +*/ +static int inmemOpen( + sqlite3_vfs *pVfs, + const char *zFilename, + sqlite3_file *pFile, + int openFlags, + int *pOutFlags +){ + VFile *pVFile = createVFile(zFilename, 0); + VHandle *pHandle = (VHandle*)pFile; + if( pVFile==0 ){ + return SQLITE_FULL; + } + pHandle->pVFile = pVFile; + pVFile->nRef++; + pFile->pMethods = &VHandleMethods; + if( pOutFlags ) *pOutFlags = openFlags; + return SQLITE_OK; +} + +/* +** Delete a file by name +*/ +static int inmemDelete( + sqlite3_vfs *pVfs, + const char *zFilename, + int syncdir +){ + VFile *pVFile = findVFile(zFilename); + if( pVFile==0 ) return SQLITE_OK; + if( pVFile->nRef==0 ){ + free(pVFile->zFilename); + pVFile->zFilename = 0; + pVFile->sz = -1; + free(pVFile->a); + pVFile->a = 0; + return SQLITE_OK; + } + return SQLITE_IOERR_DELETE; +} + +/* Check for the existance of a file +*/ +static int inmemAccess( + sqlite3_vfs *pVfs, + const char *zFilename, + int flags, + int *pResOut +){ + VFile *pVFile = findVFile(zFilename); + *pResOut = pVFile!=0; + return SQLITE_OK; +} + +/* Get the canonical pathname for a file +*/ +static int inmemFullPathname( + sqlite3_vfs *pVfs, + const char *zFilename, + int nOut, + char *zOut +){ + sqlite3_snprintf(nOut, zOut, "%s", zFilename); + return SQLITE_OK; +} + +/* +** Register the VFS that reads from the g.aFile[] set of files. +*/ +static void inmemVfsRegister(void){ + static sqlite3_vfs inmemVfs; + sqlite3_vfs *pDefault = sqlite3_vfs_find(0); + inmemVfs.iVersion = 3; + inmemVfs.szOsFile = sizeof(VHandle); + inmemVfs.mxPathname = 200; + inmemVfs.zName = "inmem"; + inmemVfs.xOpen = inmemOpen; + inmemVfs.xDelete = inmemDelete; + inmemVfs.xAccess = inmemAccess; + inmemVfs.xFullPathname = inmemFullPathname; + inmemVfs.xRandomness = pDefault->xRandomness; + inmemVfs.xSleep = pDefault->xSleep; + inmemVfs.xCurrentTimeInt64 = pDefault->xCurrentTimeInt64; + sqlite3_vfs_register(&inmemVfs, 0); +}; + +/* +** Timeout handler +*/ +#ifdef __unix__ +static void timeoutHandler(int NotUsed){ + (void)NotUsed; + fatalError("timeout\n"); +} +#endif + +/* +** Set the an alarm to go off after N seconds. Disable the alarm +** if N==0 +*/ +static void setAlarm(int N){ +#ifdef __unix__ + alarm(N); +#else + (void)N; +#endif +} +/*************************************************************************** +** String accumulator object +*/ +typedef struct Str Str; +struct Str { + char *z; /* The string. Memory from malloc() */ + sqlite3_uint64 n; /* Bytes of input used */ + sqlite3_uint64 nAlloc; /* Bytes allocated to z[] */ + int oomErr; /* OOM error has been seen */ +}; + +/* Initialize a Str object */ +static void StrInit(Str *p){ + memset(p, 0, sizeof(*p)); +} + +/* Append text to the end of a Str object */ +static void StrAppend(Str *p, const char *z){ + sqlite3_uint64 n = strlen(z); + if( p->n + n >= p->nAlloc ){ + char *zNew; + sqlite3_uint64 nNew; + if( p->oomErr ) return; + nNew = p->nAlloc*2 + 100 + n; + zNew = sqlite3_realloc64(p->z, nNew); + if( zNew==0 ){ + sqlite3_free(p->z); + memset(p, 0, sizeof(*p)); + p->oomErr = 1; + return; + } + p->z = zNew; + p->nAlloc = nNew; + } + memcpy(p->z + p->n, z, (int)n); + p->n += n; + p->z[p->n] = 0; +} + +/* Return the current string content */ +static char *StrStr(Str *p){ + return p->z; +} + +/* Free the string */ +static void StrFree(Str *p){ + sqlite3_free(p->z); + StrInit(p); +} + +/* +** Return the value of a hexadecimal digit. Return -1 if the input +** is not a hex digit. +*/ +static int hexDigitValue(char c){ + if( c>='0' && c<='9' ) return c - '0'; + if( c>='a' && c<='f' ) return c - 'a' + 10; + if( c>='A' && c<='F' ) return c - 'A' + 10; + return -1; +} + +/* +** Interpret zArg as an integer value, possibly with suffixes. +*/ +static int integerValue(const char *zArg){ + sqlite3_int64 v = 0; + static const struct { char *zSuffix; int iMult; } aMult[] = { + { "KiB", 1024 }, + { "MiB", 1024*1024 }, + { "GiB", 1024*1024*1024 }, + { "KB", 1000 }, + { "MB", 1000000 }, + { "GB", 1000000000 }, + { "K", 1000 }, + { "M", 1000000 }, + { "G", 1000000000 }, + }; + int i; + int isNeg = 0; + if( zArg[0]=='-' ){ + isNeg = 1; + zArg++; + }else if( zArg[0]=='+' ){ + zArg++; + } + if( zArg[0]=='0' && zArg[1]=='x' ){ + int x; + zArg += 2; + while( (x = hexDigitValue(zArg[0]))>=0 ){ + v = (v<<4) + x; + zArg++; + } + }else{ + while( ISDIGIT(zArg[0]) ){ + v = v*10 + zArg[0] - '0'; + zArg++; + } + } + for(i=0; i0x7fffffff ) fatalError("parameter too large - max 2147483648"); + return (int)(isNeg? -v : v); +} + +/* +** This callback is invoked by sqlite3_log(). +*/ +static void sqlLog(void *pNotUsed, int iErrCode, const char *zMsg){ + printf("LOG: (%d) %s\n", iErrCode, zMsg); + fflush(stdout); +} + +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK +/* +** This an SQL progress handler. After an SQL statement has run for +** many steps, we want to interrupt it. This guards against infinite +** loops from recursive common table expressions. +** +** *pVdbeLimitFlag is true if the --limit-vdbe command-line option is used. +** In that case, hitting the progress handler is a fatal error. +*/ +static int progressHandler(void *pVdbeLimitFlag){ + if( *(int*)pVdbeLimitFlag ) fatalError("too many VDBE cycles"); + return 1; +} +#endif + +/* +** Allowed values for the runFlags parameter to runSql() +*/ +#define SQL_TRACE 0x0001 /* Print each SQL statement as it is prepared */ +#define SQL_OUTPUT 0x0002 /* Show the SQL output */ + +/* +** Run multiple commands of SQL. Similar to sqlite3_exec(), but does not +** stop if an error is encountered. +*/ +static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){ + const char *zMore; + const char *zEnd = &zSql[strlen(zSql)]; + sqlite3_stmt *pStmt; + + while( zSql && zSql[0] ){ + zMore = 0; + pStmt = 0; + sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore); + assert( zMore<=zEnd ); + if( zMore==zSql ) break; + if( runFlags & SQL_TRACE ){ + const char *z = zSql; + int n; + while( z0 && ISSPACE(z[n-1]) ) n--; + if( n==0 ) break; + if( pStmt==0 ){ + printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db)); + }else{ + printf("TRACE: %.*s\n", n, z); + } + } + zSql = zMore; + if( pStmt ){ + if( (runFlags & SQL_OUTPUT)==0 ){ + while( SQLITE_ROW==sqlite3_step(pStmt) ){} + }else{ + int nCol = -1; + int nRow; + for(nRow=0; SQLITE_ROW==sqlite3_step(pStmt); nRow++){ + int i; + if( nCol<0 ){ + nCol = sqlite3_column_count(pStmt); + } + for(i=0; i0 ){ + void *pHeap = malloc( nHeap ); + if( pHeap==0 ) fatalError("cannot allocate %d-byte heap\n", nHeap); + rc = sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nHeap, 32); + if( rc ) fatalError("heap configuration failed: %d\n", rc); + } + if( noLookaside ){ + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, 0, 0); + } + inmemVfsRegister(); + formatVfs(); + StrInit(&sql); +#ifdef __unix__ + signal(SIGALRM, timeoutHandler); +#endif + for(i=0; i1 ){ + printf("DATABASE-FILE: %s\n", azDb[i]); + fflush(stdout); + } + if( iTimeout ) setAlarm(iTimeout); + createVFile("test.db", azDb[i]); + rc = sqlite3_open_v2("test.db", &db, SQLITE_OPEN_READWRITE, "inmem"); + if( rc ){ + printf("cannot open test.db for \"%s\"\n", azDb[i]); + reformatVfs(); + continue; + } +#ifndef SQLITE_OMIT_PROGRESS_CALLBACK + if( vdbeLimitFlag ){ + sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag); + } +#endif + rc = sqlite3_prepare_v2(db, "SELECT sql FROM autoexec", -1, &pStmt, 0); + if( rc==SQLITE_OK ){ + while( SQLITE_ROW==sqlite3_step(pStmt) ){ + StrAppend(&sql, (const char*)sqlite3_column_text(pStmt, 0)); + StrAppend(&sql, "\n"); + } + } + sqlite3_finalize(pStmt); + StrAppend(&sql, "PRAGMA integrity_check;\n"); + runSql(db, StrStr(&sql), runFlags); + sqlite3_close(db); + reformatVfs(); + StrFree(&sql); + if( sqlite3_memory_used()>0 ){ + free(azDb); + reformatVfs(); + fatalError("memory leak of %lld bytes", sqlite3_memory_used()); + } + } + StrFree(&sql); + reformatVfs(); + return 0; +} diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz001.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz001.test new file mode 100644 index 0000000000000000000000000000000000000000..228dd16db6ccd1992e4ce0e02ae433cf56bb8268 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz001.test @@ -0,0 +1,397 @@ +# 2012-12-13 +# +# 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. +# +#*********************************************************************** +# +# Test cases for corrupt database files. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !deserialize { + finish_test + return +} +database_may_be_corrupt + +# In the following database file, there is 384 bytes of free space +# on page 8 that does not appear on the freeblock list. +# +do_test dbfuzz001-100 { + sqlite3 db {} + db deserialize [decode_hexdb { + | size 5632 pagesize 512 filename c4.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: 02 00 01 01 00 40 20 20 00 00 00 02 00 00 00 0b .....@ ........ + | 32: 00 00 00 06 00 00 00 01 00 00 00 28 00 00 00 04 ...........(.... + | 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ + | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................ + | 96: 00 2e 30 38 0d 00 00 00 06 01 06 00 01 da 01 b0 ..08............ + | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... + | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta + | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T + | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... + | 304: 01 3f 69 6e 64 65 78 00 00 00 00 00 00 00 00 00 .?index......... + | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein + | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE + | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t + | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta + | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T + | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) + | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t + | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t + | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... + | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA + | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) + | page 2 offset 512 + | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 3 offset 1024 + | 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 4 offset 1536 + | 0: 05 00 00 00 03 01 f1 00 00 00 00 0b 01 fb 01 f6 ................ + | 16: 01 f1 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 32: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ + | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight + | 64: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... + | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 96: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... + | 112: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ + | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ + | 496: 00 00 00 00 0a 3e 00 00 00 09 21 00 00 00 08 06 .....>....!..... + | page 5 offset 2048 + | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ + | page 7 offset 3072 + | 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ + | 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ + | 96: 00 00 00 00 13 00 00 00 00 00 00 00 00 00 00 00 ................ + | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 ................ + | 288: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................ + | 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e + | 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@....... + | 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@........... + | 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................ + | page 8 offset 3584 + | 0: 0d 00 21 00 01 00 16 00 00 16 00 16 00 16 00 16 ..!............. + | 16: 00 16 00 16 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 32: 03 00 00 00 5f 01 09 09 02 02 00 00 00 56 17 17 ...._........V.. + | 48: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight + | 64: 73 65 76 65 6e 00 00 00 3b 07 07 07 40 14 00 00 seven...;...@... + | 80: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 96: 00 00 00 00 40 14 00 00 00 00 00 00 00 00 00 14 ....@........... + | 112: 01 01 01 03 04 04 03 00 00 00 09 01 01 09 02 02 ................ + | 352: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a ................ + | page 9 offset 4096 + | 0: 0d 00 00 00 1b 00 47 00 01 d9 01 be 01 af 01 a0 ......G......... + | 16: 01 91 01 82 01 73 01 64 01 55 01 46 01 37 01 28 .....s.d.U.F.7.( + | 32: 01 19 01 0a 00 fb 00 ec 00 dd 00 ce 00 bf 00 b0 ................ + | 48: 00 a1 00 92 00 83 00 74 00 65 00 56 00 47 00 00 .......t.e.V.G.. + | 64: 00 00 00 00 00 00 00 0d 21 00 00 48 01 54 00 01 ........!..H.T.. + | 80: f7 01 ec 01 c5 01 0d 20 00 00 48 01 54 00 01 f7 ....... ..H.T... + | 96: 01 ec 01 c5 01 0d 1f 00 00 48 01 54 00 01 f7 01 .........H.T.... + | 112: ec 01 c5 01 0d 1e 00 00 48 01 54 00 01 f7 01 ec ........H.T..... + | 128: 01 c5 01 0d 1d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T...... + | 144: c5 01 0d 1c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T....... + | 160: 01 0d 1b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........ + | 176: 0d 1a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T......... + | 192: 19 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 18 ...H.T.......... + | 208: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 17 00 ..H.T........... + | 224: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 16 00 00 .H.T............ + | 240: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 15 00 00 48 H.T............H + | 256: 01 54 00 01 f7 01 ec 01 c5 01 0d 14 00 00 48 01 .T............H. + | 272: 54 00 01 f7 01 ec 01 c5 01 0d 13 00 00 48 01 54 T............H.T + | 288: 00 01 f7 01 ec 01 c5 01 0d 12 00 00 48 01 54 00 ............H.T. + | 304: 01 f7 01 ec 01 c5 01 0d 11 00 00 48 01 54 00 01 ...........H.T.. + | 320: f7 01 ec 01 c5 01 0d 10 00 00 48 01 54 00 01 f7 ..........H.T... + | 336: 01 ec 01 c5 01 0d 0f 00 00 48 01 54 00 01 f7 01 .........H.T.... + | 352: ec 01 c5 01 0d 0e 00 00 48 01 54 00 01 f7 01 ec ........H.T..... + | 368: 01 c5 01 0d 0d 00 00 48 01 54 00 01 f7 01 ec 01 .......H.T...... + | 384: c5 01 0d 0c 00 00 48 01 54 00 01 f7 01 ec 01 c5 ......H.T....... + | 400: 01 0d 0b 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .....H.T........ + | 416: 0d 0a 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d ....H.T......... + | 432: 09 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 19 08 ...H.T.......... + | 448: 05 17 17 17 17 65 69 67 68 74 65 69 67 68 74 73 .....eighteights + | 464: 65 76 65 6e 73 65 76 65 6e 25 07 05 07 07 07 07 evenseven%...... + | 480: 40 18 00 00 00 00 00 00 40 18 00 00 00 00 00 00 @.......@....... + | 496: 40 14 00 00 00 00 00 00 40 14 00 00 00 00 00 00 @.......@....... + | page 10 offset 4608 + | 0: 0d 00 00 00 1d 00 4d 00 01 f1 01 e2 01 d3 01 c4 ......M......... + | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 01 5b 01 4c .........y.j.[.L + | 32: 01 3d 01 2e 01 1f 01 10 01 01 00 f2 00 e3 00 d4 .=.............. + | 48: 00 c5 00 b6 00 a7 00 98 00 89 00 7a 00 6b 00 5c ...........z.k.\ + | 64: 00 4d 00 00 00 00 00 00 00 00 00 00 00 0d 3e 00 .M............>. + | 80: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3d 00 00 .H.T.........=.. + | 96: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 3c 00 00 48 H.T.........<..H + | 112: 01 54 00 01 f7 01 ec 01 c5 01 0d 3b 00 00 48 01 .T.........;..H. + | 128: 54 00 01 f7 01 ec 01 c5 01 0d 3a 00 00 48 01 54 T.........:..H.T + | 144: 00 01 f7 01 ec 01 c5 01 0d 39 00 00 48 01 54 00 .........9..H.T. + | 160: 01 f7 01 ec 01 c5 01 0d 38 00 00 48 01 54 00 01 ........8..H.T.. + | 176: f7 01 ec 01 c5 01 0d 37 00 00 48 01 54 00 01 f7 .......7..H.T... + | 192: 01 ec 01 c5 01 0d 36 00 00 48 01 54 00 01 f7 01 ......6..H.T.... + | 208: ec 01 c5 01 0d 35 00 00 48 01 54 00 01 f7 01 ec .....5..H.T..... + | 224: 01 c5 01 0d 34 00 00 48 01 54 00 01 f7 01 ec 01 ....4..H.T...... + | 240: c5 01 0d 33 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...3..H.T....... + | 256: 01 0d 32 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..2..H.T........ + | 272: 0d 31 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d .1..H.T......... + | 288: 30 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2f 0..H.T........./ + | 304: 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2e 00 ..H.T........... + | 320: 00 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2d 00 00 .H.T.........-.. + | 336: 48 01 54 00 01 f7 01 ec 01 c5 01 0d 2c 00 00 48 H.T.........,..H + | 352: 01 54 00 01 f7 01 ec 01 c5 01 0d 2b 00 00 48 01 .T.........+..H. + | 368: 54 00 01 f7 01 ec 01 c5 01 0d 2a 00 00 48 01 54 T.........*..H.T + | 384: 00 01 f7 01 ec 01 c5 01 0d 29 00 00 48 01 54 00 .........)..H.T. + | 400: 01 f7 01 ec 01 c5 01 0d 28 00 00 48 01 54 00 01 ........(..H.T.. + | 416: f7 01 ec 01 c5 01 0d 27 00 00 48 01 54 00 01 f7 .......'..H.T... + | 432: 01 ec 01 c5 01 0d 26 00 00 48 01 54 00 01 f7 01 ......&..H.T.... + | 448: ec 01 c5 01 0d 25 00 00 48 01 54 00 01 f7 01 ec .....%..H.T..... + | 464: 01 c5 01 0d 24 00 00 48 01 54 00 01 f7 01 ec 01 ....$..H.T...... + | 480: c5 01 0d 23 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...#..H.T....... + | 496: 01 0d 22 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 .."..H.T........ + | page 11 offset 5120 + | 0: 0d 00 00 00 0a 01 6a 00 01 f1 01 e2 01 d3 01 c4 ......j......... + | 16: 01 b5 01 a6 01 97 01 88 01 79 01 6a 00 00 00 00 .........y.j.... + | 352: 00 00 00 00 00 00 00 00 00 00 0d 48 00 00 48 01 ...........H..H. + | 368: 54 00 01 f7 01 ec 01 c5 01 0d 47 00 00 48 01 54 T.........G..H.T + | 384: 00 01 f7 01 ec 01 c5 01 0d 46 00 00 48 01 54 00 .........F..H.T. + | 400: 01 f7 01 ec 01 c5 01 0d 45 00 00 48 01 54 00 01 ........E..H.T.. + | 416: f7 01 ec 01 c5 01 0d 44 00 00 48 01 54 00 01 f7 .......D..H.T... + | 432: 01 ec 01 c5 01 0d 43 00 00 48 01 54 00 01 f7 01 ......C..H.T.... + | 448: ec 01 c5 01 0d 42 00 00 48 01 54 00 01 f7 01 ec .....B..H.T..... + | 464: 01 c5 01 0d 41 00 00 48 01 54 00 01 f7 01 ec 01 ....A..H.T...... + | 480: c5 01 0d 40 00 00 48 01 54 00 01 f7 01 ec 01 c5 ...@..H.T....... + | 496: 01 0d 3f 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 ..?..H.T........ + | end c4.db + }] +} {} + +ifcapable !oversize_cell_check { + # Non SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds: + do_test dbfuzz001-101a { + db eval {PRAGMA writable_schema=on; PRAGMA integrity_check} + } {/Fragmentation of 384 bytes reported as 0 on page 8/} +} else { + # SQLITE_ENABLE_OVERSIZE_CELL_CHECK builds: + do_catchsql_test dbfuzz001-101b { + PRAGMA writable_schema=on; + PRAGMA integrity_check; + } {1 {database disk image is malformed}} +} + +# The DELETE query below deletes the very last cell from page 8. +# Prior to a certain fix to sqlite3BtreeDelete() and because of the +# corruption to the freeblock list on page 8, this would fail to +# cause a rebalance operation, which would leave the btree in a weird +# state that would lead to segfaults and or assertion faults. +# +do_execsql_test dbfuzz001-110 { + DELETE FROM t3 WHERE x IS NOT NULL AND +rowid=6; +} {} + +# This is a dbfuzz2-generate test case that can cause a page with +# pPage->nCell==0 to enter the balancer. +# +do_test dbfuzz001-200 { + db deserialize [decode_hexdb { + | size 3076 pagesize 512 filename c03.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: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ + | 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ + | 48: 00 00 00 00 00 00 00 03 e8 00 00 01 00 00 00 00 ................ + | 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ + | 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ + | 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... + | 128: 00 00 00 00 00 00 00 00 ef 00 00 00 00 00 00 00 ................ + | 192: 00 7f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 224: 00 00 00 00 00 00 00 00 00 00 00 00 00 ff e9 00 ................ + | 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta + | 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T + | 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... + | 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 06 43 52 45 .?indext3xt3.CRE + | 320: 41 54 45 20 49 4e 44 45 58 20 74 33 64 20 4f 4e ATE INDEX t3d ON + | 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein + | 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE + | 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t + | 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta + | 400: 62 6c 65 74 33 74 33 04 43 52 45 41 54 45 20 54 blet3t3.CREATE T + | 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) + | 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t + | 448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 2.CREATE TABLE t + | 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... + | 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA + | 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) + | page 2 offset 512 + | 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................ + | 176: 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 256: 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 368: 00 00 00 00 00 00 00 00 00 00 00 00 1e 00 00 00 ................ + | 416: 00 00 00 1b 00 00 00 00 04 00 00 00 00 00 00 00 ................ + | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ + | 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. + | 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... + | 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ + | page 3 offset 1024 + | 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... + | 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........ + | 32: 00 00 00 00 00 00 00 03 e8 00 00 00 00 00 00 00 ................ + | 336: 00 00 00 00 19 08 05 16 17 17 17 65 69 67 68 74 ...........eight + | 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 ff ff ff eightsevensev... + | 368: 0e 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@. + | 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@. + | 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................ + | 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ + | 432: 17 73 65 6f 65 6e 65 69 67 68 74 65 69 67 68 74 .seoeneighteight + | 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... + | 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... + | 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... + | 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ + | page 4 offset 1536 + | 0: 0d 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 ................ + | 160: 00 00 00 ea 00 00 00 00 00 00 00 00 00 00 00 00 ................ + | 336: 00 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 ............ ... + | page 5 offset 2048 + | 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ + | 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................ + | 48: 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 ................ + | 288: 00 00 00 00 00 00 00 00 00 64 00 00 00 2b 00 00 .........d...+.. + | 400: 00 00 00 00 00 00 0f 04 17 17 01 65 69 67 68 74 ...........eight + | 416: 65 69 6f 68 74 08 15 04 07 07 01 40 18 00 00 00 eioht......@.... + | 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ + | 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ + | 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight..... + | 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... + | 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................ + | page 6 offset 2560 + | 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 0d 00 00 ................ + | 16: 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec 01 e0 01 ................ + | 32: d4 01 cb 01 c2 00 00 00 00 00 00 00 00 00 00 00 ................ + | 160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 ................ + | 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 ................ + | 464: 08 02 17 65 69 67 68 74 07 07 02 17 65 69 67 68 ...eight....eigh + | 480: 74 0a 06 02 07 40 18 00 00 00 00 00 00 0a 05 02 t....@.......... + | 496: 07 40 18 00 04 02 01 04 03 03 02 01 04 03 02 02 .@.............. + | end x/c03.db + }] + catchsql {INSERT INTO t3 SELECT * FROM t2;} +} {1 {database disk image is malformed}} + + +do_test dbfuzz001-310 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 3584 pagesize 512 filename x/c02.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: 02 00 01 01 00 40 20 20 00 00 00 0c 00 00 00 07 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 04 00 00 00 01 00 00 00 00 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c ................ +| 96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0 ..,P............ +| 112: 01 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00 .V...*.......... +| 256: 00 00 00 00 00 00 22 07 06 17 11 11 01 31 74 61 ......"......1ta +| 272: 62 6c 65 74 34 74 34 07 43 52 45 41 54 45 20 54 blet4t4.CREATE T +| 288: 41 42 4c 45 20 74 34 28 78 29 2a 06 06 17 13 11 ABLE t4(x)*..... +| 304: 01 3f 69 6e 64 65 78 74 33 78 74 33 05 43 52 45 .?indext3xt3.CRE +| 320: 41 54 45 20 49 4e 44 45 58 20 74 33 78 20 4f 4e ATE INDEX t3x ON +| 336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e t3(x).......Ein +| 352: 64 65 78 74 32 63 64 74 32 05 43 52 45 41 54 45 dext2cdt2.CREATE +| 368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74 INDEX t2cd ON t +| 384: 32 28 63 2c 64 29 28 05 06 17 11 11 01 3d 74 61 2(c,d)(......=ta +| 400: 62 6c 65 74 33 74 33 07 43 52 45 41 54 45 20 54 blet3t3.CREATE T +| 416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29 ABLE t3(c,x,e,f) +| 432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74 (......=tablet2t +| 448: 32 32 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 22CREATE TABLE t +| 464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11 2(c,d,e,f)$..... +| 480: 01 35 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .5tablet1t1.CREA +| 496: 54 45 20 54 41 42 4c 45 20 74 31 28 61 2c 62 29 TE TABLE t1(a,b) +| page 2 offset 512 +| 0: 0d 00 00 00 04 01 cf 00 01 fa 01 f3 01 de 01 cf ................ +| 160: 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 .. ............. +| 448: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d ................ +| 464: 04 03 17 17 73 65 76 65 6e 65 69 67 68 74 13 03 ....seveneight.. +| 480: 03 07 07 40 14 00 00 00 00 00 00 40 18 00 00 00 ...@.......@.... +| 496: 00 00 00 05 02 03 01 01 03 04 04 01 03 09 01 02 ................ +| page 3 offset 1024 +| 0: 0d 00 00 00 08 01 54 00 01 f7 01 ec 01 c5 01 aa ......T......... +| 16: 01 a1 01 96 01 6f 01 54 00 00 00 00 00 00 00 00 .....o.T........ +| 112: 00 00 dd 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| 336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74 ...........eight +| 352: 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e 25 eightsevenseven% +| 368: 07 05 07 07 07 07 40 18 00 00 00 00 00 00 40 18 ......@.......@. +| 384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14 ......@.......@. +| 400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03 ................ +| 416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17 ................ +| 432: 17 73 65 76 65 6e 65 69 67 68 74 65 69 67 68 74 .seveneighteight +| 448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00 seven%......@... +| 464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00 ....@.......@... +| 480: 00 00 00 00 40 14 00 00 00 00 00 00 09 02 05 01 ....@........... +| 496: 01 01 01 03 04 04 03 07 01 05 09 01 01 09 02 02 ................ +| page 4 offset 1536 +| 0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ +| 192: 00 00 00 00 00 00 7f 00 00 00 00 00 00 00 00 00 ................ +| 208: 00 e5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +| page 5 offset 2048 +| 0: 0a 00 00 00 08 01 96 00 01 fa 01 c4 01 f2 01 bc ................ +| 16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00 ................ +| 240: 00 00 00 00 00 00 00 00 00 00 00 00 00 0e 00 00 ................ +| 400: 00 00 00 00 00 00 0f 04 17 07 01 65 69 67 68 74 ...........eight +| 416: 65 69 67 68 74 08 15 04 07 07 01 40 18 00 00 00 eight......@.... +| 432: 00 00 00 40 18 00 00 00 00 00 00 07 07 04 01 01 ...@............ +| 448: 01 04 04 06 07 04 01 01 01 02 02 05 0f 04 17 17 ................ +| 464: 01 73 65 76 65 6e 65 69 67 68 74 04 15 04 07 07 .seveneight..... +| 480: 01 40 14 00 00 00 00 00 00 40 18 00 00 00 00 00 .@.......@...... +| 496: 00 03 07 04 01 01 01 03 04 02 05 04 09 01 09 02 ................ +| page 6 offset 2560 +| 0: 0a 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 ................ +| 464: 00 00 00 00 00 00 00 00 00 00 7f 00 00 00 00 00 ................ +| page 7 offset 3072 +| 0: 0d 00 00 00 08 01 c2 00 01 fb 01 f6 01 f1 01 ec ................ +| 16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00 ................ +| 448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65 ......eight....e +| 464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00 ight....@....... +| 480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01 ....@........... +| 496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02 ................ +| end x/c02.db + }] +} {} + +extra_schema_checks 0 +do_catchsql_test dbfuzz001-320 { + PRAGMA integrity_check; +} {1 {database disk image is malformed}} + +do_catchsql_test dbfuzz001-330 { + DELETE FROM t3 WHERE x IN (SELECT x FROM t4); +} {1 {database disk image is malformed}} +extra_schema_checks 1 + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test dbfuzz001-430 { + CREATE TABLE t1(a INTEGER, b INT, c DEFAULT 0); +} + +do_execsql_test dbfuzz001-420 { + PRAGMA locking_mode=EXCLUSIVE; + PRAGMA journal_mode = memory; + INSERT INTO t1 VALUES(1,2,3); + PRAGMA journal_mode=PERSIST; +} {exclusive memory persist} + +do_execsql_test dbfuzz001-430 { + INSERT INTO t1 VALUES(4, 5, 6); +} + +do_execsql_test dbfuzz001-440 { + PRAGMA journal_mode=MEMORY; + INSERT INTO t1 VALUES(7, 8, 9); +} {memory} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2-seed1.db b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2-seed1.db new file mode 100644 index 0000000000000000000000000000000000000000..17f0550d61626eef82b17461866eb43d5500980a Binary files /dev/null and b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2-seed1.db differ diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2.c new file mode 100644 index 0000000000000000000000000000000000000000..f0062915df067b208aa739a309d4c6d64c5f57ad --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbfuzz2.c @@ -0,0 +1,402 @@ +/* +** 2018-10-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. +** +************************************************************************* +** +** This program is designed for fuzz-testing SQLite database files using +** the -fsanitize=fuzzer option of clang. +** +** The -fsanitize=fuzzer option causes a main() to be inserted automatically. +** That main() invokes LLVMFuzzerTestOneInput(D,S) to be invoked repeatedly. +** Each D is a fuzzed database file. The code in this file runs various +** SQL statements against that database, trying to provoke a failure. +** +** For best results the seed database files should have these tables: +** +** Table "t1" with columns "a" and "b" +** Tables "t2" and "t3 with the same number of compatible columns +** "t3" should have a column names "x" +** Table "t4" with a column "x" that is compatible with t3.x. +** +** Any of these tables can be virtual tables, for example FTS or RTree tables. +** +** To run this test: +** +** mkdir dir +** cp dbfuzz2-seed*.db dir +** clang-6.0 -I. -g -O1 -fsanitize=fuzzer -DTHREADSAFE=0 \ +** -DSQLITE_ENABLE_DBSTAT_VTAB dbfuzz2.c sqlite3.c -ldl +** ./a.out dir +*/ +#include +#include +#include +#include +#include +#include +#include +#ifndef _WIN32 +#include +#include +#endif +#include "sqlite3.h" + +/* +** This is the is the SQL that is run against the database. +*/ +static const char *azSql[] = { + "PRAGMA integrity_check;", + "SELECT * FROM sqlite_schema;", + "SELECT sum(length(name)) FROM dbstat;", + "UPDATE t1 SET b=a, a=b WHERE a %d bytes\n", + memtraceBase.xSize(p), memtraceBase.xRoundup(n)); + } + return memtraceBase.xRealloc(p, n); +} +static int memtraceSize(void *p){ + return memtraceBase.xSize(p); +} +static int memtraceRoundup(int n){ + return memtraceBase.xRoundup(n); +} +static int memtraceInit(void *p){ + return memtraceBase.xInit(p); +} +static void memtraceShutdown(void *p){ + memtraceBase.xShutdown(p); +} + +/* The substitute memory allocator */ +static sqlite3_mem_methods ersaztMethods = { + memtraceMalloc, + memtraceFree, + memtraceRealloc, + memtraceSize, + memtraceRoundup, + memtraceInit, + memtraceShutdown +}; + +/* Begin tracing memory allocations to out. */ +int sqlite3MemTraceActivate(FILE *out){ + int rc = SQLITE_OK; + if( memtraceBase.xMalloc==0 ){ + rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase); + if( rc==SQLITE_OK ){ + rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods); + } + } + memtraceOut = out; + return rc; +} + +/* Deactivate memory tracing */ +int sqlite3MemTraceDeactivate(void){ + int rc = SQLITE_OK; + if( memtraceBase.xMalloc!=0 ){ + rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase); + if( rc==SQLITE_OK ){ + memset(&memtraceBase, 0, sizeof(memtraceBase)); + } + } + memtraceOut = 0; + return rc; +} +/***** End copy/paste from ext/misc/memtrace.c ***************************/ + +/* +** Progress handler callback +** +** Count the number of callbacks and cause an abort once the limit is +** reached. +*/ +static int progress_handler(void *pNotUsed){ + nCb++; + if( nCb=1 ){ + printf("-- Progress limit of %d reached\n", mxCb); + } + return 1; +} + +/* libFuzzer invokes this routine with fuzzed database files (in aData). +** This routine run SQLite against the malformed database to see if it +** can provoke a failure or malfunction. +*/ +int LLVMFuzzerTestOneInput(const uint8_t *aData, size_t nByte){ + unsigned char *a; + sqlite3 *db; + int rc; + int i; + sqlite3_int64 x; + char *zErr = 0; + + if( eVerbosity>=1 ){ + printf("************** nByte=%d ***************\n", (int)nByte); + fflush(stdout); + } + if( sqlite3_initialize() ) return 0; + rc = sqlite3_open(0, &db); + if( rc ) return 1; + a = sqlite3_malloc64(nByte+1); + if( a==0 ) return 1; + memcpy(a, aData, nByte); + sqlite3_deserialize(db, "main", a, nByte, nByte, + SQLITE_DESERIALIZE_RESIZEABLE | + SQLITE_DESERIALIZE_FREEONCLOSE); + x = szMax; +#ifdef SQLITE_FCNTL_SIZE_LIMIT + sqlite3_file_control(db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x); +#endif + if( bVdbeDebug ){ + sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0); + } + if( mxCb>0 ){ + sqlite3_progress_handler(db, 10, progress_handler, 0); + } +#ifdef SQLITE_TESTCTRL_PRNG_SEED + sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED, 1, db); +#endif + for(i=0; i=1 ){ + printf("%s\n", azSql[i]); + fflush(stdout); + } + zErr = 0; + nCb = 0; + rc = sqlite3_exec(db, azSql[i], 0, 0, &zErr); + if( rc && eVerbosity>=1 ){ + printf("-- rc=%d zErr=%s\n", rc, zErr); + } + sqlite3_free(zErr); + } + rc = sqlite3_close(db); + if( rc!=SQLITE_OK ){ + fprintf(stdout, "sqlite3_close() returns %d\n", rc); + } + if( sqlite3_memory_used()!=0 ){ + int nAlloc = 0; + int nNotUsed = 0; + sqlite3_status(SQLITE_STATUS_MALLOC_COUNT, &nAlloc, &nNotUsed, 0); + fprintf(stderr,"Memory leak: %lld bytes in %d allocations\n", + sqlite3_memory_used(), nAlloc); + exit(1); + } + return 0; +} + +/* +** Return the number of "v" characters in a string. Return 0 if there +** are any characters in the string other than "v". +*/ +static int numberOfVChar(const char *z){ + int N = 0; + while( z[0] && z[0]=='v' ){ + z++; + N++; + } + return z[0]==0 ? N : 0; +} + +/* libFuzzer invokes this routine once when the executable starts, to +** process the command-line arguments. +*/ +int LLVMFuzzerInitialize(int *pArgc, char ***pArgv){ + int i, j, n; + int argc = *pArgc; + char **argv = *pArgv; + for(i=j=1; i0 ){ + eVerbosity += n; + continue; + } + if( strcmp(z,"vdbe-debug")==0 ){ + bVdbeDebug = 1; + continue; + } + if( strcmp(z,"limit")==0 ){ + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + mxCb = strtol(argv[++i], 0, 0); + continue; + } + if( strcmp(z,"memtrace")==0 ){ + sqlite3MemTraceActivate(stdout); + continue; + } + if( strcmp(z,"max-db-size")==0 ){ + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + szMax = strtol(argv[++i], 0, 0); + continue; + } + if( strcmp(z, "lookaside")==0 ){ + int sz, nSlot; + if( i+2>=argc ){ + fprintf(stderr, + "--lookaside requires two arguments: slot-size num-slots\n"); + exit(1); + } + sz = atoi(argv[++i]); + nSlot = atoi(argv[++i]); + sqlite3_config(SQLITE_CONFIG_LOOKASIDE, sz, nSlot); + continue; + } +#ifndef _WIN32 + if( strcmp(z,"max-stack")==0 + || strcmp(z,"max-data")==0 + || strcmp(z,"max-as")==0 + ){ + struct rlimit x,y; + int resource = RLIMIT_STACK; + char *zType = "RLIMIT_STACK"; + if( i+1==argc ){ + fprintf(stderr, "missing argument to %s\n", argv[i]); + exit(1); + } + if( z[4]=='d' ){ + resource = RLIMIT_DATA; + zType = "RLIMIT_DATA"; + } + if( z[4]=='a' ){ + resource = RLIMIT_AS; + zType = "RLIMIT_AS"; + } + memset(&x,0,sizeof(x)); + getrlimit(resource, &x); + y.rlim_cur = atoi(argv[++i]); + y.rlim_max = x.rlim_cur; + setrlimit(resource, &y); + memset(&y,0,sizeof(y)); + getrlimit(resource, &y); + printf("%s changed from %d to %d\n", + zType, (int)x.rlim_cur, (int)y.rlim_cur); + continue; + } +#endif /* _WIN32 */ + } + argv[j++] = argv[i]; + } + argv[j] = 0; + *pArgc = j; + return 0; +} + +#ifdef STANDALONE +/* +** Read an entire file into memory. Space to hold the file comes +** from malloc(). +*/ +static unsigned char *readFile(const char *zName, int *pnByte){ + FILE *in = fopen(zName, "rb"); + long nIn; + size_t nRead; + unsigned char *pBuf; + if( in==0 ) return 0; + fseek(in, 0, SEEK_END); + nIn = ftell(in); + rewind(in); + pBuf = malloc( nIn+1 ); + if( pBuf==0 ){ fclose(in); return 0; } + nRead = fread(pBuf, nIn, 1, in); + fclose(in); + if( nRead!=1 ){ + free(pBuf); + return 0; + } + pBuf[nIn] = 0; + if( pnByte ) *pnByte = nIn; + return pBuf; +} +#endif /* STANDALONE */ + +#ifdef STANDALONE +int main(int argc, char **argv){ + int i; + LLVMFuzzerInitialize(&argc, &argv); + for(i=1; i0 ){ + struct rusage x; + printf("SQLite %s\n", sqlite3_sourceid()); + memset(&x, 0, sizeof(x)); + if( getrusage(RUSAGE_SELF, &x)==0 ){ + printf("Maximum RSS = %ld KB\n", x.ru_maxrss); + } + } +#endif + return 0; +} +#endif /*STANDALONE*/ diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbpagefault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbpagefault.test new file mode 100644 index 0000000000000000000000000000000000000000..f27741cba1084b7c25997cb7d12170d8e8471de3 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbpagefault.test @@ -0,0 +1,86 @@ +# 2022 July 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl +source $testdir/malloc_common.tcl + +if {[permutation] == "inmemory_journal"} { + finish_test + return +} + +ifcapable !vtab { + finish_test + return +} + +set testprefix dbpagefault + +faultsim_save_and_close +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + execsql { ATTACH 'test.db2' AS aux; } +} -body { + execsql { + CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); + } +} -test { + execsql { PRAGMA journal_mode = off } + faultsim_test_result {0 {}} +} + +do_faultsim_test 2 -prep { + sqlite3 db "xyz.db" -vfs memdb + execsql { ATTACH 'test.db2' AS aux; } +} -body { + execsql { + CREATE VIRTUAL TABLE t1 USING sqlite_dbpage(); + UPDATE t1 SET data=zeroblob(1024) WHERE pgno=1 AND schema='aux'; + } +} -test { + execsql { PRAGMA journal_mode = off } + faultsim_test_result {0 {}} {1 {no such schema}} {1 {SQL logic error}} {1 {unable to open a temporary database file for storing temporary tables}} +} + +reset_db +do_execsql_test 3.0 { + CREATE TABLE x1(z, b); + CREATE TRIGGER BEFORE INSERT ON x1 BEGIN + DELETE FROM sqlite_dbpage WHERE pgno=100; + UPDATE sqlite_dbpage SET data=null WHERE pgno=100; + END; +} + +# This test case no longer works, as it is no longer possible to use +# virtual table sqlite_dbpage from within a trigger. +# +do_execsql_test 3.1 { + PRAGMA trusted_schema = 1; +} +do_catchsql_test 3.2 { + PRAGMA trusted_schema = 1; + INSERT INTO x1 DEFAULT VALUES; +} {1 {unsafe use of virtual table "sqlite_dbpage"}} +#do_faultsim_test 3 -prep { +# catch { db close } +# sqlite3 db test.db +# execsql { PRAGMA trusted_schema = 1 } +#} -body { +# execsql { INSERT INTO x1 DEFAULT VALUES; } +#} -test { +# faultsim_test_result {0 {}} +#} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/dbstatus2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbstatus2.test new file mode 100644 index 0000000000000000000000000000000000000000..5e9ea888a6b54ab67d9ad0883f7d47ba0e6e3c19 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/dbstatus2.test @@ -0,0 +1,115 @@ +# 2011 September 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. +# +#*********************************************************************** +# +# Tests for the sqlite3_db_status() function +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix dbstatus2 + +do_execsql_test 1.0 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(1, randomblob(600)); + INSERT INTO t1 VALUES(2, randomblob(600)); + INSERT INTO t1 VALUES(3, randomblob(600)); +} + +proc db_hit_miss {db {reset 0}} { + set nHit [sqlite3_db_status $db CACHE_HIT $reset] + set nMiss [sqlite3_db_status $db CACHE_MISS $reset] + list $nHit $nMiss +} + +proc db_write {db {reset 0}} { + sqlite3_db_status $db CACHE_WRITE $reset +} + +proc db_spill {db {reset 0}} { + sqlite3_db_status $db CACHE_SPILL $reset +} + +do_test 1.1 { + db close + sqlite3 db test.db + execsql { PRAGMA mmap_size = 0 } + expr {[file size test.db] / 1024} +} 6 + +do_test 1.2 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 2 0} {0 4 0}} + +do_test 1.3 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 6 0} {0 4 0}} + +do_test 1.4 { + execsql { SELECT b FROM t1 WHERE a=2 } + db_hit_miss db +} {{0 10 0} {0 4 0}} + +do_test 1.5 { + db_hit_miss db 1 +} {{0 10 0} {0 4 0}} + +do_test 1.6 { + db_hit_miss db 0 +} {{0 0 0} {0 0 0}} + +do_test 1.7 { + set fd [db incrblob main t1 b 1] + fconfigure $fd -translation binary + set len [string length [read $fd]] + close $fd + set len +} 600 +do_test 1.8 { sqlite3_db_status db CACHE_HIT 0 } {0 2 0} +do_test 1.9 { sqlite3_db_status db CACHE_MISS 0 } {0 1 0} + +do_test 2.1 { db_write db } {0 0 0} +do_test 2.2 { + execsql { INSERT INTO t1 VALUES(4, randomblob(600)) } + db_write db +} {0 4 0} +do_test 2.3 { db_write db 1 } {0 4 0} +do_test 2.4 { db_write db 0 } {0 0 0} +do_test 2.5 { db_write db 1 } {0 0 0} + +if {[wal_is_capable]} { + do_test 2.6 { + execsql { PRAGMA journal_mode = WAL } + db_write db 1 + } {0 1 0} +} +do_test 2.7 { + execsql { INSERT INTO t1 VALUES(5, randomblob(600)) } + db_write db +} {0 4 0} +do_test 2.8 { db_write db 1 } {0 4 0} +do_test 2.9 { db_write db 0 } {0 0 0} + +do_test 3.0 { db_spill db 1 } {0 0 0} +do_test 3.1 { db_spill db 0 } {0 0 0} +do_execsql_test 3.2 { + PRAGMA journal_mode=DELETE; + PRAGMA cache_size=3; + UPDATE t1 SET b=randomblob(1000); +} {delete} +do_test 3.3 { db_spill db 0 } {0 8 0} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/decimal.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/decimal.test new file mode 100644 index 0000000000000000000000000000000000000000..cf4e06ad929e86667fab65415e0437d7522a19ce --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/decimal.test @@ -0,0 +1,193 @@ +# 2017 December 9 +# +# 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 decimal + +if {[catch {load_static_extension db decimal} error]} { + puts "Skipping decimal tests, hit load error: $error" + finish_test; return +} + +do_execsql_test 1000 { + SELECT decimal(1); +} {1} +do_execsql_test 1010 { + SELECT decimal('1.0'); +} {1.0} +do_execsql_test 1020 { + SELECT decimal('0001.0'); +} {1.0} +do_execsql_test 1030 { + SELECT decimal('+0001.0'); +} {1.0} +do_execsql_test 1040 { + SELECT decimal('-0001.0'); +} {-1.0} +do_execsql_test 1050 { + SELECT decimal('1.0e72'); +} {1000000000000000000000000000000000000000000000000000000000000000000000000} +# 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123 +do_execsql_test 1060 { + SELECT decimal('1.0e-72'); +} {0.0000000000000000000000000000000000000000000000000000000000000000000000010} +# 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123 +do_execsql_test 1070 { + SELECT decimal('-123e-4'); +} {-0.0123} +do_execsql_test 1080 { + SELECT decimal('+123e+4'); +} {1230000} +do_execsql_test 1081 { + SELECT decimal_exp('+123e+4'); +} {+1.23e+06} + + +do_execsql_test 2000 { + CREATE TABLE t1(seq INTEGER PRIMARY KEY, val TEXT); + INSERT INTO t1 VALUES + (1, '-9999e99'), + (2, '-9998.000e+99'), + (3, '-9999.0'), + (4, '-1'), + (5, '-9999e-20'), + (6, '0'), + (7, '1e-30'), + (8, '1e-29'), + (9, '1'), + (10,'1.00000000000000001'), + (11,'+1.00001'), + (12,'99e+99'); + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq=0; +} {} +do_execsql_test 2010 { + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq<>b.seq + AND decimal_cmp(a.val,b.val)==0; +} {} +do_execsql_test 2020 { + SELECT *, '|' + FROM t1 AS a, t1 AS b + WHERE a.seq>b.seq + AND decimal_cmp(a.val,b.val)<=0; +} {} +do_execsql_test 2030 { + SELECT seq FROM t1 ORDER BY val COLLATE decimal; +} {1 2 3 4 5 6 7 8 9 10 11 12} +do_execsql_test 2040 { + SELECT seq FROM t1 ORDER BY val COLLATE decimal DESC; +} {12 11 10 9 8 7 6 5 4 3 2 1} + +do_execsql_test 3000 { + CREATE TABLE t3(seq INTEGER PRIMARY KEY, val TEXT); + WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<10) + INSERT INTO t3(seq, val) SELECT x, x FROM c; + WITH RECURSIVE c(x) AS (VALUES(1) UNION SELECT x+1 FROM c WHERE x<5) + INSERT INTO t3(seq, val) SELECT x+10, x*1000 FROM c; + SELECT decimal(val) FROM t3 ORDER BY seq; +} {1 2 3 4 5 6 7 8 9 10 1000 2000 3000 4000 5000} +do_execsql_test 3020 { + SELECT decimal_add(val,'0.5') FROM t3 WHERE seq>5 ORDER BY seq +} {6.5 7.5 8.5 9.5 10.5 1000.5 2000.5 3000.5 4000.5 5000.5} +do_execsql_test 3030 { + SELECT decimal_add(val,'-10') FROM t3 ORDER BY seq; +} {-9 -8 -7 -6 -5 -4 -3 -2 -1 0 990 1990 2990 3990 4990} + +do_execsql_test 4000 { + SELECT decimal_sum(val) FROM t3; +} {15055} +do_execsql_test 4010 { + SELECT decimal_sum(decimal_add(val,val||'e+10')) FROM t3; +} {150550000015055} +do_execsql_test 4010 { + SELECT decimal_sum(decimal_add(val||'e+20',decimal_add(val,val||'e-20'))) + FROM t3; +} {1505500000000000000015055.00000000000000015055} + +do_execsql_test 5000 { + WITH RECURSIVE c(x,y,z) AS ( + VALUES(0,'1','1') + UNION ALL + SELECT x+1, decimal_mul(y,'2'), decimal_mul(z,'0.5') + FROM c WHERE x<32 + ) + SELECT count(*) FROM c WHERE decimal_mul(y,z)='1'; +} {33} + +do_execsql_test 5100 { + SELECT decimal_mul('1234.00','2.00'); +} {2468.00} +do_execsql_test 5101 { + SELECT decimal_mul('1234.00','2.0000'); +} {2468.00} +do_execsql_test 5102 { + SELECT decimal_mul('1234.0000','2.000'); +} {2468.000} +do_execsql_test 5103 { + SELECT decimal_mul('1234.0000','2'); +} {2468} + +if {[catch {load_static_extension db ieee754} error]} { + puts "Skipping ieee754 tests, hit load error: $error" + finish_test; return +} + +do_execsql_test 6000 { + CREATE TABLE pow2(x INTEGER PRIMARY KEY, v TEXT); + WITH RECURSIVE c(x,v) AS ( + VALUES(0,'1') + UNION ALL + SELECT x+1, decimal_mul(v,'2') FROM c WHERE x+1<=971 + ) INSERT INTO pow2(x,v) SELECT x, v FROM c; + WITH RECURSIVE c(x,v) AS ( + VALUES(-1,'0.5') + UNION ALL + SELECT x-1, decimal_mul(v,'0.5') FROM c WHERE x-1>=-1075 + ) INSERT INTO pow2(x,v) SELECT x, v FROM c; +} {} +do_execsql_test 6010 { + WITH c(n) AS (SELECT ieee754_from_blob(x'0000000000000001')) +SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) + FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); +} {0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625} +do_execsql_test 6011 { + WITH c(n) AS (SELECT ieee754_from_blob(x'0000000000000001')) +SELECT decimal(c.n) FROM c; +} {0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004940656458412465441765687928682213723650598026143247644255856825006755072702087518652998363616359923797965646954457177309266567103559397963987747960107818781263007131903114045278458171678489821036887186360569987307230500063874091535649843873124733972731696151400317153853980741262385655911710266585566867681870395603106249319452715914924553293054565444011274801297099995419319894090804165633245247571478690147267801593552386115501348035264934720193790268107107491703332226844753335720832431936092382893458368060106011506169809753078342277318329247904982524730776375927247874656084778203734469699533647017972677717585125660551199131504891101451037862738167250955837389733598993664809941164205702637090279242767544565229087538682506419718265533447265625} +do_execsql_test 6020 { + WITH c(n) AS (SELECT ieee754_from_blob(x'7fefffffffffffff')) +SELECT decimal_mul(ieee754_mantissa(c.n),pow2.v) + FROM pow2, c WHERE pow2.x=ieee754_exponent(c.n); +} {179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368} + +do_execsql_test 6100 { + SELECT ieee754(ieee754_from_blob(x'0000000000000001')); +} {ieee754(1,-1074)} +do_execsql_test 6110 { + SELECT ieee754(ieee754_from_blob(x'7fefffffffffffff')); +} {ieee754(9007199254740991,971)} +do_execsql_test 6120 { + SELECT printf('%.8e',ieee754_from_blob(x'0000000000000001')); +} {4.94065646e-324} +do_execsql_test 6130 { + SELECT printf('%.8e',ieee754_from_blob(x'ffefffffffffffff')); +} {-1.79769313e+308} + + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/default.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/default.test new file mode 100644 index 0000000000000000000000000000000000000000..192b3d2ff364880982e3076ce00004a69f82f74f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/default.test @@ -0,0 +1,144 @@ +# 2005 August 18 +# +# 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. The +# focus of this file is testing corner cases of the DEFAULT syntax +# on table definitions. +# +# $Id: default.test,v 1.3 2009/02/19 14:39:25 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable bloblit { + do_test default-1.1 { + execsql { + CREATE TABLE t1( + a INTEGER, + b BLOB DEFAULT x'6869' + ); + INSERT INTO t1(a) VALUES(1); + SELECT * from t1; + } + } {1 hi} +} +do_test default-1.2 { + execsql { + CREATE TABLE t2( + x INTEGER, + y INTEGER DEFAULT NULL + ); + INSERT INTO t2(x) VALUES(1); + SELECT * FROM t2; + } +} {1 {}} +do_test default-1.3 { + catchsql { + CREATE TABLE t3( + x INTEGER, + y INTEGER DEFAULT (max(x,5)) + ) + } +} {1 {default value of column [y] is not constant}} + +ifcapable pragma { + do_test default-2.1 { + execsql { + CREATE TABLE t4(c DEFAULT 'abc'); + PRAGMA table_info(t4); + } + } {0 c {} 0 'abc' 0} + do_test default-2.2 { + execsql { + INSERT INTO t4 DEFAULT VALUES; + PRAGMA table_info(t4); + } + } {0 c {} 0 'abc' 0} +} + +do_execsql_test default-3.1 { + CREATE TABLE t3( + a INTEGER PRIMARY KEY AUTOINCREMENT, + b INT DEFAULT 12345 UNIQUE NOT NULL CHECK( b>=0 AND b<99999 ), + c VARCHAR(123,456) DEFAULT 'hello' NOT NULL ON CONFLICT REPLACE, + d REAL, + e FLOATING POINT(5,10) DEFAULT 4.36, + f NATIONAL CHARACTER(15) COLLATE RTRIM, + g LONG INTEGER DEFAULT( 3600*12 ) + ); + INSERT INTO t3 VALUES(null, 5, 'row1', '5.25', 'xyz', 321, '432'); + SELECT a, typeof(a), b, typeof(b), c, typeof(c), + d, typeof(d), e, typeof(e), f, typeof(f), + g, typeof(g) FROM t3; +} {1 integer 5 integer row1 text 5.25 real xyz text 321 text 432 integer} +do_execsql_test default-3.2 { + DELETE FROM t3; + INSERT INTO t3 DEFAULT VALUES; + SELECT * FROM t3; +} {2 12345 hello {} 4.36 {} 43200} +do_execsql_test default-3.3 { + CREATE TABLE t300( + a INT DEFAULT 2147483647, + b INT DEFAULT 2147483648, + c INT DEFAULT +9223372036854775807, + d INT DEFAULT -2147483647, + e INT DEFAULT -2147483648, + f INT DEFAULT -9223372036854775808, + g INT DEFAULT (-(-9223372036854775808)), + h INT DEFAULT (-(-9223372036854775807)) + ); + INSERT INTO t300 DEFAULT VALUES; + SELECT * FROM t300; +} {2147483647 2147483648 9223372036854775807 -2147483647 -2147483648 -9223372036854775808 9.22337203685478e+18 9223372036854775807} + +# Do now allow bound parameters in new DEFAULT values. +# Silently convert bound parameters to NULL in DEFAULT causes +# in the sqlite_master table, for backwards compatibility. +# +db close +forcedelete test.db +sqlite3 db test.db +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test default-4.0 { + CREATE TABLE t1(a TEXT, b TEXT DEFAULT(99)); + PRAGMA writable_schema=ON; + UPDATE sqlite_master SET sql='CREATE TABLE t1(a TEXT, b TEXT DEFAULT(:xyz))'; +} {} +db close +sqlite3 db test.db +do_execsql_test default-4.1 { + INSERT INTO t1(a) VALUES('xyzzy'); + SELECT a, quote(b) FROM t1; +} {xyzzy NULL} +do_catchsql_test default-4.2 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(:xyz)); +} {1 {default value of column [b] is not constant}} +do_catchsql_test default-4.3 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(abs(:xyz))); +} {1 {default value of column [b] is not constant}} +do_catchsql_test default-4.4 { + CREATE TABLE t2(a TEXT, b TEXT DEFAULT(98+coalesce(5,:xyz))); +} {1 {default value of column [b] is not constant}} + +# 2020-03-09 out-of-bounds memory access discovered by "Eternal Sakura" +# and reported to chromium. +# +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 {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 {default value of column [Col0] is not constant}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/delete.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete.test new file mode 100644 index 0000000000000000000000000000000000000000..214bae6f703937266e682816264ce310fb30799d --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete.test @@ -0,0 +1,443 @@ +# 2001 September 15 +# +# 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. The +# focus of this file is testing the DELETE FROM statement. +# +# $Id: delete.test,v 1.26 2009/06/05 17:09:12 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Try to delete from a non-existant table. +# +do_test delete-1.1 { + set v [catch {execsql {DELETE FROM test1}} msg] + lappend v $msg +} {1 {no such table: test1}} + +# Try to delete from sqlite_master +# +do_test delete-2.1 { + set v [catch {execsql {DELETE FROM sqlite_master}} msg] + lappend v $msg +} {1 {table sqlite_master may not be modified}} + +# Delete selected entries from a table with and without an index. +# +do_test delete-3.1.1 { + execsql {CREATE TABLE table1(f1 int, f2 int)} + execsql {INSERT INTO table1 VALUES(1,2)} + execsql {INSERT INTO table1 VALUES(2,4)} + execsql {INSERT INTO table1 VALUES(3,8)} + execsql {INSERT INTO table1 VALUES(4,16)} + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 3 8 4 16} +do_test delete-3.1.2 { + execsql {DELETE FROM table1 WHERE f1=3} +} {} +do_test delete-3.1.3 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 4 16} +do_test delete-3.1.4 { + execsql {CREATE INDEX index1 ON table1(f1)} + execsql {PRAGMA count_changes=on} + ifcapable explain { + execsql {EXPLAIN DELETE FROM table1 WHERE f1=3} + } + execsql {DELETE FROM 'table1' WHERE f1=3} +} {0} +do_test delete-3.1.5 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 2 4 4 16} +do_test delete-3.1.6.1 { + execsql {DELETE FROM table1 WHERE f1=2} +} {1} +do_test delete-3.1.6.2 { + db changes +} 1 +do_test delete-3.1.7 { + execsql {SELECT * FROM table1 ORDER BY f1} +} {1 2 4 16} +integrity_check delete-3.2 + +# Semantic errors in the WHERE clause +# +do_test delete-4.1 { + execsql {CREATE TABLE table2(f1 int, f2 int)} + set v [catch {execsql {DELETE FROM table2 WHERE f3=5}} msg] + lappend v $msg +} {1 {no such column: f3}} + +do_test delete-4.2 { + set v [catch {execsql {DELETE FROM table2 WHERE xyzzy(f1+4)}} msg] + lappend v $msg +} {1 {no such function: xyzzy}} +integrity_check delete-4.3 + +# Lots of deletes +# +do_test delete-5.1.1 { + execsql {DELETE FROM table1} +} {2} +do_test delete-5.1.2 { + execsql {SELECT count(*) FROM table1} +} {0} +do_test delete-5.2.1 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.2.2 { + execsql {DELETE FROM table1} +} {200} +do_test delete-5.2.3 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.2.4 { + execsql {PRAGMA count_changes=off} + execsql {DELETE FROM table1} +} {} +do_test delete-5.2.5 { + execsql {SELECT count(*) FROM table1} +} {0} +do_test delete-5.2.6 { + execsql {BEGIN TRANSACTION} + for {set i 1} {$i<=200} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {200} +do_test delete-5.3 { + for {set i 1} {$i<=200} {incr i 4} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT count(*) FROM table1} +} {150} +do_test delete-5.4.1 { + execsql "DELETE FROM table1 WHERE f1>50" + db changes +} [db one {SELECT count(*) FROM table1 WHERE f1>50}] +do_test delete-5.4.2 { + execsql {SELECT count(*) FROM table1} +} {37} +do_test delete-5.5 { + for {set i 1} {$i<=70} {incr i 3} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {2 3 6 8 11 12 14 15 18 20 23 24 26 27 30 32 35 36 38 39 42 44 47 48 50} +do_test delete-5.6 { + for {set i 1} {$i<40} {incr i} { + execsql "DELETE FROM table1 WHERE f1==$i" + } + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {42 44 47 48 50} +do_test delete-5.7 { + execsql "DELETE FROM table1 WHERE f1!=48" + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {48} +integrity_check delete-5.8 + + +# Delete large quantities of data. We want to test the List overflow +# mechanism in the vdbe. +# +do_test delete-6.1 { + execsql {BEGIN; DELETE FROM table1} + for {set i 1} {$i<=3000} {incr i} { + execsql "INSERT INTO table1 VALUES($i,[expr {$i*$i}])" + } + execsql {DELETE FROM table2} + for {set i 1} {$i<=3000} {incr i} { + execsql "INSERT INTO table2 VALUES($i,[expr {$i*$i}])" + } + execsql {COMMIT} + execsql {SELECT count(*) FROM table1} +} {3000} +do_test delete-6.2 { + execsql {SELECT count(*) FROM table2} +} {3000} +do_test delete-6.3 { + execsql {SELECT f1 FROM table1 WHERE f1<10 ORDER BY f1} +} {1 2 3 4 5 6 7 8 9} +do_test delete-6.4 { + execsql {SELECT f1 FROM table2 WHERE f1<10 ORDER BY f1} +} {1 2 3 4 5 6 7 8 9} +do_test delete-6.5.1 { + execsql {DELETE FROM table1 WHERE f1>7} + db changes +} {2993} +do_test delete-6.5.2 { + execsql {SELECT f1 FROM table1 ORDER BY f1} +} {1 2 3 4 5 6 7} +do_test delete-6.6 { + execsql {DELETE FROM table2 WHERE f1>7} + execsql {SELECT f1 FROM table2 ORDER BY f1} +} {1 2 3 4 5 6 7} +do_test delete-6.7 { + execsql {DELETE FROM table1} + execsql {SELECT f1 FROM table1} +} {} +do_test delete-6.8 { + execsql {INSERT INTO table1 VALUES(2,3)} + execsql {SELECT f1 FROM table1} +} {2} +do_test delete-6.9 { + execsql {DELETE FROM table2} + execsql {SELECT f1 FROM table2} +} {} +do_test delete-6.10 { + execsql {INSERT INTO table2 VALUES(2,3)} + execsql {SELECT f1 FROM table2} +} {2} +integrity_check delete-6.11 + +do_test delete-7.1 { + execsql { + CREATE TABLE t3(a); + INSERT INTO t3 VALUES(1); + INSERT INTO t3 SELECT a+1 FROM t3; + INSERT INTO t3 SELECT a+2 FROM t3; + SELECT * FROM t3; + } +} {1 2 3 4} +ifcapable {trigger} { + do_test delete-7.2 { + execsql { + CREATE TABLE cnt(del); + INSERT INTO cnt VALUES(0); + CREATE TRIGGER r1 AFTER DELETE ON t3 FOR EACH ROW BEGIN + UPDATE cnt SET del=del+1; + END; + DELETE FROM t3 WHERE a<2; + SELECT * FROM t3; + } + } {2 3 4} + do_test delete-7.3 { + execsql { + SELECT * FROM cnt; + } + } {1} + do_test delete-7.4 { + execsql { + DELETE FROM t3; + SELECT * FROM t3; + } + } {} + do_test delete-7.5 { + execsql { + SELECT * FROM cnt; + } + } {4} + do_test delete-7.6 { + execsql { + INSERT INTO t3 VALUES(1); + INSERT INTO t3 SELECT a+1 FROM t3; + INSERT INTO t3 SELECT a+2 FROM t3; + CREATE TABLE t4 AS SELECT * FROM t3; + PRAGMA count_changes=ON; + DELETE FROM t3; + DELETE FROM t4; + } + } {4 4} +} ;# endif trigger +ifcapable {!trigger} { + execsql {DELETE FROM t3} +} +integrity_check delete-7.7 + +# Make sure error messages are consistent when attempting to delete +# from a read-only database. Ticket #304. +# +do_test delete-8.0 { + execsql { + PRAGMA count_changes=OFF; + INSERT INTO t3 VALUES(123); + SELECT * FROM t3; + } +} {123} +db close +catch {forcedelete test.db-journal} +catch {file attributes test.db -permissions 0444} +catch {file attributes test.db -readonly 1} +sqlite3 db test.db +set ::DB [sqlite3_connection_pointer db] +do_test delete-8.1 { + catchsql { + DELETE FROM t3; + } +} {1 {attempt to write a readonly database}} +do_test delete-8.2 { + execsql {SELECT * FROM t3} +} {123} +do_test delete-8.3 { + catchsql { + DELETE FROM t3 WHERE 1; + } +} {1 {attempt to write a readonly database}} +do_test delete-8.4 { + execsql {SELECT * FROM t3} +} {123} + +# Update for v3: In v2 the DELETE statement would succeed because no +# database writes actually occur. Version 3 refuses to open a transaction +# on a read-only file, so the statement fails. +do_test delete-8.5 { + catchsql { + DELETE FROM t3 WHERE a<100; + } +# v2 result: {0 {}} +} {1 {attempt to write a readonly database}} +do_test delete-8.6 { + execsql {SELECT * FROM t3} +} {123} +integrity_check delete-8.7 + +# Need to do the following for tcl 8.5 on mac. On that configuration, the +# -readonly flag is taken so seriously that a subsequent [forcedelete] +# (required before the next test file can be executed) will fail. +# +catch {file attributes test.db -readonly 0} +db close +forcedelete test.db test.db-journal + +# The following tests verify that SQLite correctly handles the case +# where an index B-Tree is being scanned, the rowid column being read +# from each index entry and another statement deletes some rows from +# the index B-Tree. At one point this (obscure) scenario was causing +# SQLite to return spurious SQLITE_CORRUPT errors and arguably incorrect +# query results. +# +do_test delete-9.1 { + sqlite3 db test.db + execsql { + CREATE TABLE t5(a, b); + CREATE TABLE t6(c, d); + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + INSERT INTO t6 VALUES('a', 'b'); + INSERT INTO t6 VALUES('c', 'd'); + CREATE INDEX i5 ON t5(a); + CREATE INDEX i6 ON t6(c); + } +} {} +do_test delete-9.2 { + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b {} c d} +do_test delete-9.3 { + execsql { + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 2 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b {} c d 3 a b 3 c d} +do_test delete-9.4 { + execsql { + DELETE FROM t5; + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 1 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b 2 c d 3 a b 3 c d} +do_test delete-9.5 { + execsql { + DELETE FROM t5; + INSERT INTO t5 VALUES(1, 2); + INSERT INTO t5 VALUES(3, 4); + INSERT INTO t5 VALUES(5, 6); + } + set res [list] + db eval { SELECT t5.rowid AS r, c, d FROM t5, t6 ORDER BY a } { + if {$r==2} { db eval { DELETE FROM t5 WHERE rowid = 3 } } + lappend res $r $c $d + } + set res +} {1 a b 1 c d 2 a b 2 c d} + +do_execsql_test delete-10.0 { + CREATE TABLE t1(a INT UNIQUE, b INT); + INSERT INTO t1(a,b) VALUES('1','2'); + SELECT * FROM t1 WHERE a='1' AND b='2'; +} {1 2} + +do_execsql_test delete-10.1 { + DELETE FROM t1 WHERE a='1' AND b='2'; +} + +do_execsql_test delete-10.2 { + SELECT * FROM t1 WHERE a='1' AND b='2'; +} + +do_execsql_test delete-11.0 { + CREATE TABLE t11(a INTEGER PRIMARY KEY, b INT); + WITH RECURSIVE cnt(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM cnt WHERE x<20) + INSERT INTO t11(a,b) SELECT x, (x*17)%100 FROM cnt; + SELECT * FROM t11; +} {1 17 2 34 3 51 4 68 5 85 6 2 7 19 8 36 9 53 10 70 11 87 12 4 13 21 14 38 15 55 16 72 17 89 18 6 19 23 20 40} +do_execsql_test delete-11.1 { + DELETE FROM t11 AS xyz + WHERE EXISTS(SELECT 1 FROM t11 WHERE t11.a>xyz.a AND t11.b<=xyz.b); + SELECT * FROM t11; +} {6 2 12 4 18 6 19 23 20 40} + + +# 2023-03-15 +# https://sqlite.org/forum/forumpost/e61252062c9d286d +# +# When the WHERE clause of a DELETE statement contains a subquery +# which uses the table that is being deleted from and there is a +# short-circuit operator of some kind in the WHERE clause such that +# the subquery might not run right away, then the subquery might +# run after one or more rows have been deleted, which can change +# the result of the subquery, and result in the wrong answer. +# +# Similar problem for UPDATE tested by update-21.4 +# https://sqlite.org/forum/forumpost/0007d1fdb1 +# +reset_db +do_execsql_test delete-12.0 { + CREATE TABLE t0(vkey INTEGER, pkey INTEGER,c1 INTEGER); + INSERT INTO t0 VALUES(2,1,-20),(2,2,NULL),(2,3,0),(8,4,95); + DELETE FROM t0 WHERE NOT ( + (t0.vkey <= t0.c1) AND + (t0.vkey <> (SELECT vkey FROM t0 ORDER BY vkey LIMIT 1 OFFSET 2)) + ); + SELECT * FROM t0; +} {8 4 95} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/delete3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete3.test new file mode 100644 index 0000000000000000000000000000000000000000..a31f6ec39e49eed7fb0b2445822466457c696774 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete3.test @@ -0,0 +1,57 @@ +# 2005 August 24 +# +# 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. The +# focus of this script is a test of the DELETE command where a +# large number of rows are deleted. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table that contains a large number of rows. +# +do_test delete3-1.1 { + execsql { + CREATE TABLE t1(x integer primary key); + BEGIN; + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 SELECT x+2 FROM t1; + INSERT INTO t1 SELECT x+4 FROM t1; + INSERT INTO t1 SELECT x+8 FROM t1; + INSERT INTO t1 SELECT x+16 FROM t1; + INSERT INTO t1 SELECT x+32 FROM t1; + INSERT INTO t1 SELECT x+64 FROM t1; + INSERT INTO t1 SELECT x+128 FROM t1; + INSERT INTO t1 SELECT x+256 FROM t1; + INSERT INTO t1 SELECT x+512 FROM t1; + INSERT INTO t1 SELECT x+1024 FROM t1; + INSERT INTO t1 SELECT x+2048 FROM t1; + INSERT INTO t1 SELECT x+4096 FROM t1; + INSERT INTO t1 SELECT x+8192 FROM t1; + INSERT INTO t1 SELECT x+16384 FROM t1; + INSERT INTO t1 SELECT x+32768 FROM t1; + INSERT INTO t1 SELECT x+65536 FROM t1; + INSERT INTO t1 SELECT x+131072 FROM t1; + INSERT INTO t1 SELECT x+262144 FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {524288} +do_test delete3-1.2 { + execsql { + DELETE FROM t1 WHERE x%2==0; + SELECT count(*) FROM t1; + } +} {262144} +integrity_check delete3-1.3 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/delete4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete4.test new file mode 100644 index 0000000000000000000000000000000000000000..8d6a1b8c7cacf6189d49f0d473c176053c0f845a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete4.test @@ -0,0 +1,272 @@ +# 2005 August 24 +# +# 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. The +# focus of this script is a test of the DELETE command. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix delete4 + +do_execsql_test 1.1 { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y); + INSERT INTO t1 VALUES(1, 0); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 0); + INSERT INTO t1 VALUES(4, 1); + INSERT INTO t1 VALUES(5, 0); + INSERT INTO t1 VALUES(6, 1); + INSERT INTO t1 VALUES(7, 0); + INSERT INTO t1 VALUES(8, 1); +} +do_execsql_test 1.2 { + DELETE FROM t1 WHERE y=1; +} +do_execsql_test 1.3 { + SELECT x FROM t1; +} {1 3 5 7} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 2.1 { + CREATE TABLE t1(x INTEGER PRIMARY KEY, y, z); + INSERT INTO t1 VALUES(1, 0, randomblob(200)); + INSERT INTO t1 VALUES(2, 1, randomblob(200)); + INSERT INTO t1 VALUES(3, 0, randomblob(200)); + INSERT INTO t1 VALUES(4, 1, randomblob(200)); + INSERT INTO t1 VALUES(5, 0, randomblob(200)); + INSERT INTO t1 VALUES(6, 1, randomblob(200)); + INSERT INTO t1 VALUES(7, 0, randomblob(200)); + INSERT INTO t1 VALUES(8, 1, randomblob(200)); +} +do_execsql_test 2.2 { + DELETE FROM t1 WHERE y=1; +} +do_execsql_test 2.3 { + SELECT x FROM t1; +} {1 3 5 7} + + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3.0.1 { + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)) WITHOUT ROWID; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(2, 4); + INSERT INTO t1 VALUES(1, 5); + DELETE FROM t1 WHERE a=1; + SELECT printf('(%d)',changes()); + SELECT * FROM t1; +} {(2) 2 4} +do_execsql_test 3.0.2 { + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b) SELECT x, x+1 FROM c; + SELECT printf('(%d)',changes()); + DELETE FROM t1; + SELECT printf('(%d)',changes()); +} {(100) (101)} + +#------------------------------------------------------------------------- +# DELETE statement that uses the OR optimization +# +reset_db +do_execsql_test 3.1 { + CREATE TABLE t1(i INTEGER PRIMARY KEY, a, b); + CREATE INDEX i1a ON t1(a); + CREATE INDEX i1b ON t1(b); + INSERT INTO t1 VALUES(1, 'one', 'i'); + INSERT INTO t1 VALUES(2, 'two', 'ii'); + INSERT INTO t1 VALUES(3, 'three', 'iii'); + INSERT INTO t1 VALUES(4, 'four', 'iv'); + INSERT INTO t1 VALUES(5, 'one', 'i'); + INSERT INTO t1 VALUES(6, 'two', 'ii'); + INSERT INTO t1 VALUES(7, 'three', 'iii'); + INSERT INTO t1 VALUES(8, 'four', 'iv'); +} {} + +do_execsql_test 3.2 { + DELETE FROM t1 WHERE a='two' OR b='iv'; +} + +do_execsql_test 3.3 { + SELECT i FROM t1 ORDER BY i; +} {1 3 5 7} + +do_execsql_test 3.4 { + PRAGMA integrity_check; +} {ok} + +# Between 2015-09-14 and 2015-09-28, the following test cases would result +# in corruption (wrong # of entries in index) due to a bug in the ONEPASS +# optimization. +# +do_execsql_test 4.1 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1); + INSERT INTO "t4" VALUES(14, 'abcde'); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + CREATE INDEX idx_t4_3 ON t4 (col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.2 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1); + INSERT INTO "t4" VALUES(14, 'abcde'); + CREATE INDEX idx_t4_3 ON t4 (col0); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.11 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1, pk PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t4 VALUES(14, 'abcde','xyzzy'); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + CREATE INDEX idx_t4_3 ON t4 (col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} +do_execsql_test 4.12 { + DROP TABLE IF EXISTS t4; + CREATE TABLE t4(col0, col1, pk PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t4 VALUES(14, 'abcde','xyzzy'); + CREATE INDEX idx_t4_3 ON t4 (col0); + CREATE INDEX idx_t4_0 ON t4 (col1, col0); + DELETE FROM t4 WHERE col0=69 OR col0>7; + PRAGMA integrity_check; +} {ok} + +# 2016-04-09 +# Ticket https://sqlite.org/src/info/a306e56ff68b8fa5 +# Failure to completely delete when reverse_unordered_selects is +# engaged. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 5.0 { + PRAGMA page_size=1024; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c); + CREATE INDEX x1 ON t1(b, c); + INSERT INTO t1(a,b,c) VALUES(1, 1, zeroblob(80)); + INSERT INTO t1(a,b,c) SELECT a+1, 1, c FROM t1; + INSERT INTO t1(a,b,c) SELECT a+2, 1, c FROM t1; + INSERT INTO t1(a,b,c) SELECT a+10, 2, c FROM t1 WHERE b=1; + INSERT INTO t1(a,b,c) SELECT a+20, 3, c FROM t1 WHERE b=1; + PRAGMA reverse_unordered_selects = ON; + DELETE FROM t1 WHERE b=2; + SELECT a FROM t1 WHERE b=2; +} {} + +# 2016-05-02 +# Ticket https://www.sqlite.org/src/tktview/dc6ebeda93960877 +# A subquery in the WHERE clause of a one-pass DELETE can cause an +# incorrect answer. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 6.0 { + CREATE TABLE t2(x INT); + INSERT INTO t2(x) VALUES(1),(2),(3),(4),(5); + DELETE FROM t2 WHERE EXISTS(SELECT 1 FROM t2 AS v WHERE v.x=t2.x-1); + SELECT x FROM t2; +} {1} +do_execsql_test 6.1 { + DROP TABLE IF EXISTS t2; + CREATE TABLE t2(x INT); + INSERT INTO t2(x) VALUES(1),(2),(3),(4),(5); + DELETE FROM t2 WHERE EXISTS(SELECT 1 FROM t2 AS v WHERE v.x=t2.x+1); + SELECT x FROM t2; +} {5} + +#------------------------------------------------------------------------- +# Test the effect of failing to find a table row based on an index key +# within a DELETE. Either because the db is corrupt, or a trigger on another +# row already deleted the entry, or because a BEFORE trigger on the current +# row has already deleted it. +# +do_execsql_test 7.1.0 { + CREATE TABLE t3(id INT PRIMARY KEY, a, b) WITHOUT ROWID; + CREATE INDEX t3a ON t3(a); + CREATE INDEX t3b ON t3(b); + + INSERT INTO t3 VALUES(1, 1, 1); + INSERT INTO t3 VALUES(2, 2, 2); + INSERT INTO t3 VALUES(3, 3, 3); + INSERT INTO t3 VALUES(4, 4, 1); +} +do_execsql_test 7.1.1 { + DELETE FROM t3 WHERE a=4 OR b=1; +} +do_execsql_test 7.1.2 { + SELECT * FROM t3; +} { 2 2 2 3 3 3 } + +do_execsql_test 7.2.0 { + CREATE TABLE t4(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE INDEX t4i ON t4(b); + INSERT INTO t4 VALUES(1, 'hello'); + INSERT INTO t4 VALUES(2, 'world'); + + CREATE TABLE t5(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE INDEX t5i ON t5(b); + INSERT INTO t5 VALUES(1, 'hello'); + INSERT INTO t5 VALUES(3, 'world'); + + PRAGMA writable_schema = 1; + UPDATE sqlite_master SET rootpage = ( + SELECT rootpage FROM sqlite_master WHERE name = 't5' + ) WHERE name = 't4'; +} + +db close +sqlite3 db test.db +do_execsql_test 7.2.1 { + DELETE FROM t4 WHERE b='world' +} +reset_db + +do_execsql_test 7.3.0 { + CREATE TABLE t3(id INT PRIMARY KEY, a, b) WITHOUT ROWID; + INSERT INTO t3 VALUES(1, 2, 3); + INSERT INTO t3 VALUES(4, 5, 6); + INSERT INTO t3 VALUES(7, 8, 9); + CREATE TRIGGER t3t BEFORE DELETE ON t3 BEGIN + DELETE FROM t3 WHERE id=old.id+3; + END; +} + +do_execsql_test 7.3.1 { + DELETE FROM t3 WHERE a IN(2, 5, 8); + SELECT * FROM t3; +} {} + +do_execsql_test 7.3.2 { + DROP TRIGGER t3t; + INSERT INTO t3 VALUES(1, 2, 3); + INSERT INTO t3 VALUES(4, 5, 6); + INSERT INTO t3 VALUES(7, 8, 9); + CREATE TRIGGER t3t BEFORE DELETE ON t3 BEGIN + DELETE FROM t3 WHERE id=old.id; + END; +} + +do_execsql_test 7.3.3 { + DELETE FROM t3 WHERE a IN(2, 5, 8); + SELECT * FROM t3; +} {} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/delete_db.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete_db.test new file mode 100644 index 0000000000000000000000000000000000000000..6edd9c242e01d5502d16200eba95b1a59a52dd3b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/delete_db.test @@ -0,0 +1,222 @@ +# 2016 September 10 +# +# 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. The +# focus of this file is testing the code in test_delete.c (the +# sqlite3_delete_database() API). +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix delete_db + +if {[atomic_batch_write test.db]} { + finish_test + return +} + +proc delete_all {} { + foreach f [glob -nocomplain test2*] { file delete $f } + foreach f [glob -nocomplain test3*] { file delete $f } +} + +proc copydb {} { + foreach f [glob -nocomplain test3*] { file delete $f } + foreach f [glob -nocomplain test2*] { + set p [string range $f 5 end] + file copy "test2$p" "test3$p" + } +} + +proc files {} { + lsort [glob -nocomplain test3*] +} + +db close +delete_all +sqlite3 db test2.database + +#------------------------------------------------------------------------- +# +# 1.1: Journal files. +# 1.2: Wal files. +# 1.3: Multiplexor with journal file. +# 1.4: Multiplexor with wal file. +# +# 2.* are a copy of 1.* with the multiplexor enabled. +# +# 3.* tests errors. +# + +do_test 1.1.0 { + execsql { + CREATE TABLE t1(x, y); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + } + copydb + files +} {test3.database test3.database-journal} + +do_test 1.1.1 { + sqlite3_delete_database test3.database + files +} {} + +do_test 1.2.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(3, 4); + } + copydb + files +} {test3.database test3.database-shm test3.database-wal} +do_test 1.2.1 { + sqlite3_delete_database test3.database + files +} {} + +db close +delete_all +sqlite3_multiplex_initialize "" 0 +sqlite3 db test2.database -vfs multiplex +sqlite3_multiplex_control db "main" chunk_size 32768 + +do_test 1.3.0 { + execsql { PRAGMA auto_vacuum = 0; } + execsql { + CREATE TABLE x1(a, b); + WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) + INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; + BEGIN; + UPDATE x1 SET a=randomblob(101) + } + copydb + files +} [list {*}{ + test3.database test3.database-journal test3.database001 + test3.database002 test3.database003 +}] +do_test 1.3.1 { + sqlite3_delete_database test3.database + files +} {} + + +do_test 1.4.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + UPDATE x1 SET a=randomblob(102) + } + copydb + files +} [list {*}{ + test3.database test3.database-shm test3.database-wal test3.database001 + test3.database002 test3.database003 +}] +do_test 1.4.1 { + sqlite3_delete_database test3.database + files +} {} + + +ifcapable 8_3_names { + db close + delete_all + sqlite3 db file:test2.db?8_3_names=1 -uri 1 + + do_test 2.1.0 { + execsql { + CREATE TABLE t1(x, y); + BEGIN; + INSERT INTO t1 VALUES(1, 2); + } + copydb + files + } {test3.db test3.nal} + + do_test 2.1.1 { + sqlite3_delete_database test3.db + files + } {} + + do_test 2.2.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(3, 4); + } + copydb + files + } {test3.db test3.shm test3.wal} + do_test 2.2.1 { + sqlite3_delete_database test3.db + files + } {} + + + db close + delete_all + sqlite3_multiplex_initialize "" 0 + sqlite3 db file:test2.db?8_3_names=1 -uri 1 -vfs multiplex + sqlite3_multiplex_control db "main" chunk_size 32768 + + do_test 2.3.0 { + execsql { PRAGMA auto_vacuum = 0; } + execsql { + CREATE TABLE x1(a, b); + WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000 ) + INSERT INTO x1 SELECT randomblob(100), randomblob(100) FROM s; + BEGIN; + UPDATE x1 SET a=randomblob(101) + } + copydb + files + } [list {*}{ + test3.001 test3.002 test3.003 test3.db test3.nal + }] + do_test 2.3.1 { + sqlite3_delete_database test3.db + files + } {} + + + do_test 2.4.0 { + execsql { + COMMIT; + PRAGMA journal_mode = wal; + UPDATE x1 SET a=randomblob(102) + } + copydb + files + } [list {*}{ + test3.001 test3.002 test3.003 test3.db test3.db-shm test3.wal + }] + do_test 2.4.1 { + sqlite3_delete_database test3.db + files + } {} +} + +db close +delete_all +sqlite3_multiplex_shutdown + +do_test 3.0 { + file mkdir dir2.db + sqlite3_delete_database dir2.db +} {SQLITE_ERROR} +do_test 3.1 { + sqlite3_delete_database dir2.db/test.db +} {SQLITE_OK} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx1.test new file mode 100644 index 0000000000000000000000000000000000000000..14be6f84e85e9dde176a050ef226ad2cfadc384a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx1.test @@ -0,0 +1,365 @@ +# 2005 December 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 implements regression tests for SQLite library. The +# focus of this script is descending indices. +# +# $Id: descidx1.test,v 1.10 2008/03/19 00:21:31 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + + +# Verify that the file format starts as 4. +# +do_test descidx1-1.1 { + execsql { + CREATE TABLE t1(a,b); + CREATE INDEX i1 ON t1(b ASC); + } + get_file_format +} {4} +do_test descidx1-1.2 { + execsql { + CREATE INDEX i2 ON t1(a DESC); + } + get_file_format +} {4} + +# Put some information in the table and verify that the descending +# index actually works. +# +do_test descidx1-2.1 { + execsql { + INSERT INTO t1 VALUES(1,1); + INSERT INTO t1 VALUES(2,2); + INSERT INTO t1 SELECT a+2, a+2 FROM t1; + INSERT INTO t1 SELECT a+4, a+4 FROM t1; + SELECT b FROM t1 WHERE a>3 AND a<7; + } +} {6 5 4} +do_test descidx1-2.2 { + execsql { + SELECT a FROM t1 WHERE b>3 AND b<7; + } +} {4 5 6} +do_test descidx1-2.3 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<7; + } +} {6 5 4 3} +do_test descidx1-2.4 { + execsql { + SELECT b FROM t1 WHERE a>3 AND a<=7; + } +} {7 6 5 4} +do_test descidx1-2.5 { + execsql { + SELECT b FROM t1 WHERE a>=3 AND a<=7; + } +} {7 6 5 4 3} +do_test descidx1-2.6 { + execsql { + SELECT a FROM t1 WHERE b>=3 AND b<=7; + } +} {3 4 5 6 7} + +# This procedure executes the SQL. Then it checks to see if the OP_Sort +# opcode was executed. If an OP_Sort did occur, then "sort" is appended +# to the result. If no OP_Sort happened, then "nosort" is appended. +# +# This procedure is used to check to make sure sorting is or is not +# occurring as expected. +# +proc cksort {sql} { + set ::sqlite_sort_count 0 + set data [execsql $sql] + if {$::sqlite_sort_count} {set x sort} {set x nosort} + lappend data $x + return $data +} + +# Test sorting using a descending index. +# +do_test descidx1-3.1 { + cksort {SELECT a FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.2 { + cksort {SELECT a FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.3 { + cksort {SELECT a FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.4 { + cksort {SELECT b FROM t1 ORDER BY a} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.5 { + cksort {SELECT b FROM t1 ORDER BY a ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.6 { + cksort {SELECT b FROM t1 ORDER BY a DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.7 { + cksort {SELECT a FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.8 { + cksort {SELECT a FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.9 { + cksort {SELECT a FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} +do_test descidx1-3.10 { + cksort {SELECT b FROM t1 ORDER BY b} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.11 { + cksort {SELECT b FROM t1 ORDER BY b ASC} +} {1 2 3 4 5 6 7 8 nosort} +do_test descidx1-3.12 { + cksort {SELECT b FROM t1 ORDER BY b DESC} +} {8 7 6 5 4 3 2 1 nosort} + +do_test descidx1-3.21 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx1-3.22 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx1-3.23 { + cksort {SELECT a FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} +do_test descidx1-3.24 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a} +} {4 5 6 7 nosort} +do_test descidx1-3.25 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a ASC} +} {4 5 6 7 nosort} +do_test descidx1-3.26 { + cksort {SELECT b FROM t1 WHERE a>3 AND a<8 ORDER BY a DESC} +} {7 6 5 4 nosort} + +# Create a table with indices that are descending on some terms and +# ascending on others. +# +ifcapable bloblit { + do_test descidx1-4.1 { + execsql { + CREATE TABLE t2(a INT, b TEXT, c BLOB, d REAL); + CREATE INDEX i3 ON t2(a ASC, b DESC, c ASC); + CREATE INDEX i4 ON t2(b DESC, a ASC, d DESC); + INSERT INTO t2 VALUES(1,'one',x'31',1.0); + INSERT INTO t2 VALUES(2,'two',x'3232',2.0); + INSERT INTO t2 VALUES(3,'three',x'333333',3.0); + INSERT INTO t2 VALUES(4,'four',x'34343434',4.0); + INSERT INTO t2 VALUES(5,'five',x'3535353535',5.0); + INSERT INTO t2 VALUES(6,'six',x'363636363636',6.0); + INSERT INTO t2 VALUES(2,'two',x'323232',2.1); + INSERT INTO t2 VALUES(2,'zwei',x'3232',2.2); + INSERT INTO t2 VALUES(2,NULL,NULL,2.3); + SELECT count(*) FROM t2; + } + } {9} + do_test descidx1-4.2 { + execsql { + SELECT d FROM t2 ORDER BY a; + } + } {1.0 2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0} + do_test descidx1-4.3 { + execsql { + SELECT d FROM t2 WHERE a>=2 ORDER BY a; + } + } {2.2 2.0 2.1 2.3 3.0 4.0 5.0 6.0} + do_test descidx1-4.4 { + execsql { + SELECT d FROM t2 WHERE a>2 ORDER BY a; + } + } {3.0 4.0 5.0 6.0} + do_test descidx1-4.5 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b>'two'; + } + } {2.2} + do_test descidx1-4.6 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b>='two'; + } + } {2.2 2.0 2.1} + do_test descidx1-4.7 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b<'two'; + } + } {} + do_test descidx1-4.8 { + execsql { + SELECT d FROM t2 WHERE a=2 AND b<='two'; + } + } {2.0 2.1} +} + +do_test descidx1-5.1 { + execsql { + CREATE TABLE t3(a,b,c,d); + CREATE INDEX t3i1 ON t3(a DESC, b ASC, c DESC, d ASC); + INSERT INTO t3 VALUES(0,0,0,0); + INSERT INTO t3 VALUES(0,0,0,1); + INSERT INTO t3 VALUES(0,0,1,0); + INSERT INTO t3 VALUES(0,0,1,1); + INSERT INTO t3 VALUES(0,1,0,0); + INSERT INTO t3 VALUES(0,1,0,1); + INSERT INTO t3 VALUES(0,1,1,0); + INSERT INTO t3 VALUES(0,1,1,1); + INSERT INTO t3 VALUES(1,0,0,0); + INSERT INTO t3 VALUES(1,0,0,1); + INSERT INTO t3 VALUES(1,0,1,0); + INSERT INTO t3 VALUES(1,0,1,1); + INSERT INTO t3 VALUES(1,1,0,0); + INSERT INTO t3 VALUES(1,1,0,1); + INSERT INTO t3 VALUES(1,1,1,0); + INSERT INTO t3 VALUES(1,1,1,1); + SELECT count(*) FROM t3; + } +} {16} +do_test descidx1-5.2 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a,b,c,d; + } +} {0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 sort} +do_test descidx1-5.3 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a DESC, b ASC, c DESC, d ASC; + } +} {1010 1011 1000 1001 1110 1111 1100 1101 0010 0011 0000 0001 0110 0111 0100 0101 nosort} +do_test descidx1-5.4 { + cksort { + SELECT a||b||c||d FROM t3 ORDER BY a ASC, b DESC, c ASC, d DESC; + } +} {0101 0100 0111 0110 0001 0000 0011 0010 1101 1100 1111 1110 1001 1000 1011 1010 nosort} +do_test descidx1-5.5 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b ASC, c DESC + } +} {101 100 111 110 001 000 011 010 nosort} +do_test descidx1-5.6 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c ASC + } +} {010 011 000 001 110 111 100 101 nosort} +do_test descidx1-5.7 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b DESC, c DESC + } +} {011 010 001 000 111 110 101 100 sort} +do_test descidx1-5.8 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a ASC, b ASC, c ASC + } +} {000 001 010 011 100 101 110 111 sort} +do_test descidx1-5.9 { + cksort { + SELECT a||b||c FROM t3 WHERE d=0 ORDER BY a DESC, b DESC, c ASC + } +} {110 111 100 101 010 011 000 001 sort} + +# Test the legacy_file_format pragma here because we have access to +# the get_file_format command. +# +ifcapable legacyformat { + do_test descidx1-6.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT + } {1} +} else { + do_test descidx1-6.1 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT + } {0} +} +do_test descidx1-6.2 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + sqlite3_db_config db LEGACY_FILE_FORMAT +} {1} +do_test descidx1-6.3 { + execsql { + CREATE TABLE t1(a,b,c); + } + get_file_format +} {1} +ifcapable vacuum { + # Verify that the file format is preserved across a vacuum. + do_test descidx1-6.3.1 { + execsql {VACUUM} + get_file_format + } {1} +} +do_test descidx1-6.4 { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + sqlite3_db_config db LEGACY_FILE_FORMAT 0 + sqlite3_db_config db LEGACY_FILE_FORMAT +} {0} +do_test descidx1-6.5 { + execsql { + CREATE TABLE t1(a,b,c); + CREATE INDEX i1 ON t1(a ASC, b DESC, c ASC); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(1,1,0); + INSERT INTO t1 VALUES(1,2,1); + INSERT INTO t1 VALUES(1,3,4); + } + get_file_format +} {4} +ifcapable vacuum { + # Verify that the file format is preserved across a vacuum. + do_test descidx1-6.6 { + execsql {VACUUM} + get_file_format + } {4} + do_test descidx1-6.7 { + sqlite3_db_config db LEGACY_FILE_FORMAT 1 + execsql { + VACUUM; + } + get_file_format + } {4} +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx3.test new file mode 100644 index 0000000000000000000000000000000000000000..30dd8f895cd5b188e883e0262bed1bb878e13e39 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/descidx3.test @@ -0,0 +1,155 @@ +# 2006 January 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is descending indices. +# +# $Id: descidx3.test,v 1.6 2008/03/19 00:21:31 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +ifcapable !bloblit { + finish_test + return +} +#db eval {PRAGMA legacy_file_format=OFF} +sqlite3_db_config db LEGACY_FILE_FORMAT 0 + +# This procedure sets the value of the file-format in file 'test.db' +# to $newval. Also, the schema cookie is incremented. +# +proc set_file_format {newval} { + hexio_write test.db 44 [hexio_render_int32 $newval] + set schemacookie [hexio_get_int [hexio_read test.db 40 4]] + incr schemacookie + hexio_write test.db 40 [hexio_render_int32 $schemacookie] + return {} +} + +# This procedure returns the value of the file-format in file 'test.db'. +# +proc get_file_format {{fname test.db}} { + return [hexio_get_int [hexio_read $fname 44 4]] +} + +# Verify that the file format starts as 4. +# +do_test descidx3-1.1 { + execsql { + CREATE TABLE t1(i INTEGER PRIMARY KEY,a,b,c,d); + CREATE INDEX t1i1 ON t1(a DESC, b ASC, c DESC); + CREATE INDEX t1i2 ON t1(b DESC, c ASC, d DESC); + } + get_file_format +} {4} + +# Put some information in the table and verify that the descending +# index actually works. +# +do_test descidx3-2.1 { + execsql { + INSERT INTO t1 VALUES(1, NULL, NULL, NULL, NULL); + INSERT INTO t1 VALUES(2, 2, 2, 2, 2); + INSERT INTO t1 VALUES(3, 3, 3, 3, 3); + INSERT INTO t1 VALUES(4, 2.5, 2.5, 2.5, 2.5); + INSERT INTO t1 VALUES(5, -5, -5, -5, -5); + INSERT INTO t1 VALUES(6, 'six', 'six', 'six', 'six'); + INSERT INTO t1 VALUES(7, x'77', x'77', x'77', x'77'); + INSERT INTO t1 VALUES(8, 'eight', 'eight', 'eight', 'eight'); + INSERT INTO t1 VALUES(9, x'7979', x'7979', x'7979', x'7979'); + SELECT count(*) FROM t1; + } +} 9 +do_test descidx3-2.2 { + execsql { + SELECT i FROM t1 ORDER BY a; + } +} {1 5 2 4 3 8 6 7 9} +do_test descidx3-2.3 { + execsql { + SELECT i FROM t1 ORDER BY a DESC; + } +} {9 7 6 8 3 4 2 5 1} + +# The "natural" order for the index is decreasing +do_test descidx3-2.4 { + execsql { + SELECT i FROM t1 WHERE a<=x'7979'; + } +} {9 7 6 8 3 4 2 5} +do_test descidx3-2.5 { + execsql { + SELECT i FROM t1 WHERE a>-99; + } +} {9 7 6 8 3 4 2 5} + +# Even when all values of t1.a are the same, sorting by A returns +# the rows in reverse order because this the natural order of the +# index. +# +do_test descidx3-3.1 { + execsql { + UPDATE t1 SET a=1; + SELECT i FROM t1 ORDER BY a; + } +} {9 7 6 8 3 4 2 5 1} +do_test descidx3-3.2 { + execsql { + SELECT i FROM t1 WHERE a=1 AND b>0 AND b<'zzz' + } +} {2 4 3 8 6} +do_test descidx3-3.3 { + execsql { + SELECT i FROM t1 WHERE b>0 AND b<'zzz' + } +} {6 8 3 4 2} +do_test descidx3-3.4 { + execsql { + SELECT i FROM t1 WHERE a=1 AND b>-9999 AND b-9999 AND b0 AND b<'zzz'; + }] + } {2 3 4 6 8} + do_test descidx3-4.2 { + execsql { + UPDATE t1 SET a=1; + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz'; + } + } {2 4 3 8 6} + do_test descidx3-4.3 { + execsql { + UPDATE t1 SET b=2; + SELECT i FROM t1 WHERE a IN (1,2) AND b>0 AND b<'zzz'; + } + } {9 7 6 8 3 4 2 5 1} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/diskfull.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/diskfull.test new file mode 100644 index 0000000000000000000000000000000000000000..391dfb4fcf440f7515f1dbb1f3f812737408f561 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/diskfull.test @@ -0,0 +1,115 @@ +# 2001 October 12 +# +# 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. The +# focus of this file is testing for correct handling of disk full +# errors. +# +# $Id: diskfull.test,v 1.8 2008/07/12 14:52:20 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set sqlite_io_error_persist 0 +set sqlite_io_error_hit 0 +set sqlite_io_error_pending 0 +do_test diskfull-1.1 { + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(randstr(1000,1000)); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + CREATE INDEX t1i1 ON t1(x); + CREATE TABLE t2 AS SELECT x AS a, x AS b FROM t1; + CREATE INDEX t2i1 ON t2(b); + } +} {} +set sqlite_diskfull_pending 0 +integrity_check diskfull-1.2 +do_test diskfull-1.3 { + set sqlite_diskfull_pending 1 + catchsql { + INSERT INTO t1 SELECT * FROM t1; + } +} {1 {database or disk is full}} +set sqlite_diskfull_pending 0 +integrity_check diskfull-1.4 +do_test diskfull-1.5 { + set sqlite_diskfull_pending 1 + catchsql { + DELETE FROM t1; + } +} {1 {database or disk is full}} +set sqlite_diskfull_pending 0 +set sqlite_io_error_hit 0 +integrity_check diskfull-1.6 + +proc do_diskfull_test {prefix sql} { + set ::go 1 + set ::sql $sql + set ::i 1 + while {$::go} { + incr ::i + do_test ${prefix}.$::i.1 { + set ::sqlite_diskfull_pending $::i + set ::sqlite_diskfull 0 + set r [catchsql $::sql] + if {!$::sqlite_diskfull} { + set r {1 {database or disk is full}} + set ::go 0 + } + if {$r=="1 {disk I/O error}"} { + set r {1 {database or disk is full}} + } + set r + } {1 {database or disk is full}} + set ::sqlite_diskfull_pending 0 + db close + sqlite3 db test.db + integrity_check ${prefix}.$::i.2 + } +} + +do_diskfull_test diskfull-2 VACUUM + +# db close +# forcedelete test.db +# forcedelete test.db-journal +# sqlite3 db test.db +# +# do_test diskfull-3.1 { +# execsql { +# PRAGMA default_cache_size = 10; +# CREATE TABLE t3(a, b, UNIQUE(a, b)); +# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# INSERT INTO t3 SELECT randstr(100, 100), randstr(100, 100) FROM t3; +# UPDATE t3 +# SET b = (SELECT a FROM t3 WHERE rowid = (SELECT max(rowid)-1 FROM t3)) +# WHERE rowid = (SELECT max(rowid) FROM t3); +# PRAGMA cache_size; +# } +# } {10} +# +# do_diskfull_test diskfull-3.2 { +# BEGIN; +# INSERT INTO t3 VALUES( randstr(100, 100), randstr(100, 100) ); +# UPDATE t3 SET a = b; +# COMMIT; +# } + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/distinct2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/distinct2.test new file mode 100644 index 0000000000000000000000000000000000000000..980b0b1e3a8ebd0edf1ff60f812783695af169ac --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/distinct2.test @@ -0,0 +1,383 @@ +# 2016-04-15 +# +# 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. The +# focus of this script is DISTINCT queries using the skip-ahead +# optimization. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix distinct2 + +do_execsql_test 100 { + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(0),(1),(2); + CREATE TABLE t2 AS + SELECT DISTINCT a.x AS aa, b.x AS bb + FROM t1 a, t1 b; + SELECT *, '|' FROM t2 ORDER BY aa, bb; +} {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |} +do_execsql_test 110 { + DROP TABLE t2; + CREATE TABLE t2 AS + SELECT DISTINCT a.x AS aa, b.x AS bb + FROM t1 a, t1 b + WHERE a.x IN t1 AND b.x IN t1; + SELECT *, '|' FROM t2 ORDER BY aa, bb; +} {0 0 | 0 1 | 0 2 | 1 0 | 1 1 | 1 2 | 2 0 | 2 1 | 2 2 |} +do_execsql_test 120 { + CREATE TABLE t102 (i0 TEXT UNIQUE NOT NULL); + INSERT INTO t102 VALUES ('0'),('1'),('2'); + DROP TABLE t2; + CREATE TABLE t2 AS + SELECT DISTINCT * + FROM t102 AS t0 + JOIN t102 AS t4 ON (t2.i0 IN t102) + NATURAL JOIN t102 AS t3 + JOIN t102 AS t1 ON (t0.i0 IN t102) + JOIN t102 AS t2 ON (t2.i0=+t0.i0 OR (t0.i0<>500 AND t2.i0=t1.i0)); + SELECT *, '|' FROM t2 ORDER BY 1, 2, 3, 4, 5; +} {0 0 0 0 | 0 0 1 0 | 0 0 1 1 | 0 0 2 0 | 0 0 2 2 | 0 1 0 0 | 0 1 1 0 | 0 1 1 1 | 0 1 2 0 | 0 1 2 2 | 0 2 0 0 | 0 2 1 0 | 0 2 1 1 | 0 2 2 0 | 0 2 2 2 | 1 0 0 0 | 1 0 0 1 | 1 0 1 1 | 1 0 2 1 | 1 0 2 2 | 1 1 0 0 | 1 1 0 1 | 1 1 1 1 | 1 1 2 1 | 1 1 2 2 | 1 2 0 0 | 1 2 0 1 | 1 2 1 1 | 1 2 2 1 | 1 2 2 2 | 2 0 0 0 | 2 0 0 2 | 2 0 1 1 | 2 0 1 2 | 2 0 2 2 | 2 1 0 0 | 2 1 0 2 | 2 1 1 1 | 2 1 1 2 | 2 1 2 2 | 2 2 0 0 | 2 2 0 2 | 2 2 1 1 | 2 2 1 2 | 2 2 2 2 |} + +do_execsql_test 400 { + CREATE TABLE t4(a,b,c,d,e,f,g,h,i,j); + INSERT INTO t4 VALUES(0,1,2,3,4,5,6,7,8,9); + INSERT INTO t4 SELECT * FROM t4; + INSERT INTO t4 SELECT * FROM t4; + CREATE INDEX t4x ON t4(c,d,e); + SELECT DISTINCT a,b,c FROM t4 WHERE a=0 AND b=1; +} {0 1 2} +do_execsql_test 410 { + SELECT DISTINCT a,b,c,d FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3} +do_execsql_test 411 { + SELECT DISTINCT d,a,b,c FROM t4 WHERE a=0 AND b=1; +} {3 0 1 2} +do_execsql_test 420 { + SELECT DISTINCT a,b,c,d,e FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3 4} +do_execsql_test 430 { + SELECT DISTINCT a,b,c,d,e,f FROM t4 WHERE a=0 AND b=1; +} {0 1 2 3 4 5} + +do_execsql_test 500 { + CREATE TABLE t5(a INT, b INT); + CREATE UNIQUE INDEX t5x ON t5(a+b); + INSERT INTO t5(a,b) VALUES(0,0),(1,0),(1,1),(0,3); + CREATE TEMP TABLE out AS SELECT DISTINCT a+b FROM t5; + SELECT * FROM out ORDER BY 1; +} {0 1 2 3} + +do_execsql_test 600 { + CREATE TABLE t6a(x INTEGER PRIMARY KEY); + INSERT INTO t6a VALUES(1); + CREATE TABLE t6b(y INTEGER PRIMARY KEY); + INSERT INTO t6b VALUES(2),(3); + SELECT DISTINCT x, x FROM t6a, t6b; +} {1 1} + +do_execsql_test 700 { + CREATE TABLE t7(a, b, c); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<200 + ) + INSERT INTO t7 SELECT i/100, i/50, i FROM s; +} +do_execsql_test 710 { + SELECT DISTINCT a, b FROM t7; +} { + 0 0 0 1 + 1 2 1 3 +} +do_execsql_test 720 { + SELECT DISTINCT a, b+1 FROM t7; +} { + 0 1 0 2 + 1 3 1 4 +} +do_execsql_test 730 { + CREATE INDEX i7 ON t7(a, b+1); + ANALYZE; + SELECT DISTINCT a, b+1 FROM t7; +} { + 0 1 0 2 + 1 3 1 4 +} + +do_execsql_test 800 { + CREATE TABLE t8(a, b, c); + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE (i+1)<100 + ) + INSERT INTO t8 SELECT i/40, i/20, i/40 FROM s; +} + +do_execsql_test 820 { + SELECT DISTINCT a, b, c FROM t8; +} { + 0 0 0 0 1 0 + 1 2 1 1 3 1 + 2 4 2 +} + +do_execsql_test 820 { + SELECT DISTINCT a, b, c FROM t8 WHERE b=3; +} {1 3 1} + +do_execsql_test 830 { + CREATE INDEX i8 ON t8(a, c); + ANALYZE; + SELECT DISTINCT a, b, c FROM t8 WHERE b=3; +} {1 3 1} + +do_execsql_test 900 { + CREATE TABLE t9(v); + INSERT INTO t9 VALUES + ('abcd'), ('Abcd'), ('aBcd'), ('ABcd'), ('abCd'), ('AbCd'), ('aBCd'), + ('ABCd'), ('abcD'), ('AbcD'), ('aBcD'), ('ABcD'), ('abCD'), ('AbCD'), + ('aBCD'), ('ABCD'), + ('wxyz'), ('Wxyz'), ('wXyz'), ('WXyz'), ('wxYz'), ('WxYz'), ('wXYz'), + ('WXYz'), ('wxyZ'), ('WxyZ'), ('wXyZ'), ('WXyZ'), ('wxYZ'), ('WxYZ'), + ('wXYZ'), ('WXYZ'); +} + +do_execsql_test 910 { + SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v; +} { + ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD + AbCD AbCd AbCd AbcD AbcD Abcd Abcd + WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ + WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz + aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD + abCD abCd abCd abcD abcD abcd abcd + wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ + wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz +} + +do_execsql_test 920 { + CREATE INDEX i9 ON t9(v COLLATE NOCASE, v); + ANALYZE; + + SELECT DISTINCT v COLLATE NOCASE, v FROM t9 ORDER BY +v; +} { + ABCD ABCD ABCd ABCd ABcD ABcD ABcd ABcd AbCD + AbCD AbCd AbCd AbcD AbcD Abcd Abcd + WXYZ WXYZ WXYz WXYz WXyZ WXyZ WXyz WXyz WxYZ + WxYZ WxYz WxYz WxyZ WxyZ Wxyz Wxyz + aBCD aBCD aBCd aBCd aBcD aBcD aBcd aBcd abCD + abCD abCd abCd abcD abcD abcd abcd + wXYZ wXYZ wXYz wXYz wXyZ wXyZ wXyz wXyz wxYZ + wxYZ wxYz wxYz wxyZ wxyZ wxyz wxyz +} + +# Ticket https://sqlite.org/src/info/ef9318757b152e3a on 2017-11-21 +# Incorrect result due to a skip-ahead-distinct optimization on a +# join where no rows of the inner loop appear in the result set. +# +db close +sqlite3 db :memory: +do_execsql_test 1000 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + CREATE INDEX t1b ON t1(b); + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + CREATE INDEX t2y ON t2(y); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<49) + INSERT INTO t1(b) SELECT x/10 - 1 FROM c; + WITH RECURSIVE c(x) AS (VALUES(-1) UNION ALL SELECT x+1 FROM c WHERE x<19) + INSERT INTO t2(x,y) SELECT x, 1 FROM c; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>-1; + ANALYZE; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>-1; +} {1 1} +db close +sqlite3 db :memory: +do_execsql_test 1010 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + CREATE INDEX t1b ON t1(b); + CREATE TABLE t2(x INTEGER PRIMARY KEY, y INTEGER); + CREATE INDEX t2y ON t2(y); + WITH RECURSIVE c(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM c WHERE x<49) + INSERT INTO t1(b) SELECT -(x/10 - 1) FROM c; + WITH RECURSIVE c(x) AS (VALUES(-1) UNION ALL SELECT x+1 FROM c WHERE x<19) + INSERT INTO t2(x,y) SELECT -x, 1 FROM c; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>1 ORDER BY y DESC; + ANALYZE; + SELECT DISTINCT y FROM t1, t2 WHERE b=x AND b<>1 ORDER BY y DESC; +} {1 1} +db close +sqlite3 db :memory: +do_execsql_test 1020 { + CREATE TABLE t1(a, b); + CREATE INDEX t1a ON t1(a, b); + -- Lots of rows of (1, 'no'), followed by a single (1, 'yes'). + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a, b) SELECT 1, 'no' FROM c; + INSERT INTO t1(a, b) VALUES(1, 'yes'); + CREATE TABLE t2(x PRIMARY KEY); + INSERT INTO t2 VALUES('yes'); + SELECT DISTINCT a FROM t1, t2 WHERE x=b; + ANALYZE; + SELECT DISTINCT a FROM t1, t2 WHERE x=b; +} {1 1} + +#------------------------------------------------------------------------- +reset_db + +do_execsql_test 2000 { + CREATE TABLE t0 (c0, c1, c2, PRIMARY KEY (c0, c1)); + CREATE TABLE t1 (c2); + INSERT INTO t0(c2) VALUES (0),(1),(3),(4),(5),(6),(7),(8),(9),(10),(11); + INSERT INTO t0(c1) VALUES ('a'); + INSERT INTO t1(c2) VALUES (0); +} +do_execsql_test 2010 { + SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0; +} {{} 1 {} {} 1 a} +do_execsql_test 1.2 { + ANALYZE; +} +do_execsql_test 2020 { + SELECT DISTINCT t0.c0, t1._rowid_, t0.c1 FROM t1 CROSS JOIN t0 ORDER BY t0.c0; +} {{} 1 {} {} 1 a} + + +do_execsql_test 2030 { + CREATE TABLE t2(a, b, c); + CREATE INDEX t2ab ON t2(a, b); + + WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64) + INSERT INTO t2 SELECT 'one', i%2, 'one' FROM c; + + WITH c(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM c WHERE i<64) + INSERT INTO t2 SELECT 'two', i%2, 'two' FROM c; + + CREATE TABLE t3(x INTEGER PRIMARY KEY); + INSERT INTO t3 VALUES(1); + + ANALYZE; +} +do_execsql_test 2040 { + SELECT DISTINCT a, b, x FROM t3 CROSS JOIN t2 ORDER BY a, +b; +} { + one 0 1 + one 1 1 + two 0 1 + two 1 1 +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 3000 { + CREATE TABLE t0 (c0, c1 NOT NULL DEFAULT 1, c2, PRIMARY KEY (c0, c1)); + INSERT INTO t0(c2) VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); + INSERT INTO t0(c2) VALUES('a'); +} + +do_execsql_test 3010 { + SELECT DISTINCT * FROM t0 WHERE NULL IS t0.c0; +} { + {} 1 {} + {} 1 a +} + +do_execsql_test 3020 { + ANALYZE; +} + +do_execsql_test 3030 { + SELECT DISTINCT * FROM t0 WHERE NULL IS c0; +} { + {} 1 {} + {} 1 a +} + +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 4010 { + CREATE TABLE t1(a, b COLLATE RTRIM); + INSERT INTO t1 VALUES(1, ''), (2, ' '), (3, ' '); +} +do_execsql_test 4020 { + SELECT b FROM t1 UNION SELECT 1; +} {1 { }} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5010 { + CREATE TABLE cnt(a); + WITH RECURSIVE cnt2(x) AS ( + VALUES(1) UNION ALL SELECT x+1 FROM cnt2 WHERE x<50 + ) + INSERT INTO cnt SELECT x FROM cnt2; +} + +do_execsql_test 5020 { + SELECT DISTINCT abs(random())%5 AS r FROM cnt ORDER BY r; +} {0 1 2 3 4} + +do_execsql_test 5030 { + SELECT abs(random())%5 AS r FROM cnt GROUP BY 1 ORDER BY 1; +} {0 1 2 3 4} + +do_execsql_test 5040 { + SELECT a FROM cnt WHERE a>45 GROUP BY 1; +} {46 47 48 49 50} + + +# 2024-06-03 dbsqlfuzz 8a44f675401a8b1f68a43bf813c4f4f72ad8f0ea +# Use of uninitialized bytecode register due to the call-function-once +# optimization at check-in 663f5dd32d9db832 +# +db null NULL +do_execsql_test 5050 { + CREATE TABLE t0(a TEXT); INSERT INTO t0 VALUES('abcd'); + CREATE TABLE t1(b TEXT); + CREATE TABLE t2(c TEXT); + CREATE TABLE t3(d TEXT); INSERT INTO t3 VALUES('wxyz'); + CREATE VIEW v4(e) AS SELECT (SELECT t2.c FROM t0, t1 GROUP BY 1) FROM t2; + SELECT v4.e FROM t3 LEFT JOIN v4 ON true GROUP BY 1; +} NULL +do_execsql_test 5060 { + DROP VIEW v4; + CREATE VIEW v4(e) AS SELECT (SELECT t2.c COLLATE nocase FROM t0, t1 GROUP BY 1) FROM t2; + SELECT v4.e FROM t3 LEFT JOIN v4 ON true GROUP BY 1; +} NULL + +do_execsql_test 5070 { + DROP VIEW v4; + CREATE VIEW v4(e) AS SELECT (SELECT unlikely(t2.c COLLATE nocase) FROM t0, t1 GROUP BY 1) FROM t2; + SELECT v4.e FROM t3 LEFT JOIN v4 ON true GROUP BY 1; +} NULL + +# 2024-06-28 dbsqlfuzz 46343912848a603e32c6072cae792eb056bac897 +# Do not call sqlite3ExprToRegister() on an expression that is already +# a register. +# +do_execsql_test 5080 { + CREATE TABLE dual(dummy TEXT); + INSERT INTO dual VALUES('X'); + SELECT 11 = ( + SELECT b + FROM ( + SELECT a AS b + FROM dual + LEFT JOIN (SELECT 22 AS a FROM dual) + ) + GROUP BY b, b + ); +} 0 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/distinctagg.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/distinctagg.test new file mode 100644 index 0000000000000000000000000000000000000000..9eedd35bd2cf34dea7d29da97123f0fea5c18ea6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/distinctagg.test @@ -0,0 +1,224 @@ +# 2005 September 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this script is the DISTINCT modifier on aggregate functions. +# +# $Id: distinctagg.test,v 1.3 2009/02/09 13:19:28 drh Exp $ + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix distinctagg + +do_test distinctagg-1.1 { + execsql { + CREATE TABLE t1(a,b,c); + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(1,3,4); + INSERT INTO t1 VALUES(1,3,5); + SELECT count(distinct a), + count(distinct b), + count(distinct c), + count(all a) FROM t1; + } +} {1 2 3 3} +do_test distinctagg-1.2 { + execsql { + SELECT b, count(distinct c) FROM t1 GROUP BY b + } +} {2 1 3 2} +do_test distinctagg-1.3 { + execsql { + INSERT INTO t1 SELECT a+1, b+3, c+5 FROM t1; + INSERT INTO t1 SELECT a+2, b+6, c+10 FROM t1; + INSERT INTO t1 SELECT a+4, b+12, c+20 FROM t1; + SELECT count(*), count(distinct a), count(distinct b) FROM t1 + } +} {24 8 16} +do_test distinctagg-1.4 { + execsql { + SELECT a, count(distinct c) FROM t1 GROUP BY a ORDER BY a + } +} {1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3} + +do_test distinctagg-2.1 { + catchsql { + SELECT count(distinct) FROM t1; + } +} {1 {DISTINCT aggregates must have exactly one argument}} +do_test distinctagg-2.2 { + catchsql { + SELECT string_agg(distinct a,b) FROM t1; + } +} {1 {DISTINCT aggregates must have exactly one argument}} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + + INSERT INTO t1 VALUES (1, 1, 1); + INSERT INTO t1 VALUES (2, 2, 2); + INSERT INTO t1 VALUES (3, 3, 3); + INSERT INTO t1 VALUES (4, 1, 4); + INSERT INTO t1 VALUES (5, 2, 1); + INSERT INTO t1 VALUES (5, 3, 2); + INSERT INTO t1 VALUES (4, 1, 3); + INSERT INTO t1 VALUES (3, 2, 4); + INSERT INTO t1 VALUES (2, 3, 1); + INSERT INTO t1 VALUES (1, 1, 2); + + INSERT INTO t2 VALUES('a', 'a', 'a'); + INSERT INTO t2 VALUES('b', 'b', 'b'); + INSERT INTO t2 VALUES('c', 'c', 'c'); + + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b, c); +} + +foreach {tn use_eph sql res} { + 1 0 "SELECT count(DISTINCT a) FROM t1" 5 + 2 0 "SELECT count(DISTINCT b) FROM t1" 3 + 3 1 "SELECT count(DISTINCT c) FROM t1" 4 + 4 0 "SELECT count(DISTINCT c) FROM t1 WHERE b=3" 3 + 5 0 "SELECT count(DISTINCT rowid) FROM t1" 10 + 6 0 "SELECT count(DISTINCT a) FROM t1, t2" 5 + 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 0 "SELECT count(DISTINCT t1.rowid) FROM t1, t2" 10 +} { + do_test 3.$tn.1 { + set prg [db eval "EXPLAIN $sql"] + set idx [lsearch $prg OpenEphemeral] + expr {$idx>=0} + } $use_eph + + do_execsql_test 3.$tn.2 $sql $res +} + +do_execsql_test 3.10 { + SELECT a, count(DISTINCT b) FROM t1 GROUP BY a; +} { + 1 1 2 2 3 2 4 1 5 2 +} + +#-------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a, b, c); + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b, c); + + INSERT INTO t1 VALUES(1, 'A', 1); + INSERT INTO t1 VALUES(1, 'A', 1); + INSERT INTO t1 VALUES(2, 'A', 2); + INSERT INTO t1 VALUES(2, 'A', 2); + INSERT INTO t1 VALUES(1, 'B', 1); + INSERT INTO t1 VALUES(2, 'B', 2); + INSERT INTO t1 VALUES(3, 'B', 3); + INSERT INTO t1 VALUES(NULL, 'B', NULL); + INSERT INTO t1 VALUES(NULL, 'C', NULL); + INSERT INTO t1 VALUES('d', 'D', 'd'); + + CREATE TABLE t2(d, e, f); + CREATE INDEX t2def ON t2(d, e, f); + + INSERT INTO t2 VALUES(1, 1, 'a'); + INSERT INTO t2 VALUES(1, 1, 'a'); + INSERT INTO t2 VALUES(1, 2, 'a'); + INSERT INTO t2 VALUES(1, 2, 'a'); + INSERT INTO t2 VALUES(1, 2, 'b'); + INSERT INTO t2 VALUES(1, 3, 'b'); + INSERT INTO t2 VALUES(1, 3, 'a'); + INSERT INTO t2 VALUES(1, 3, 'b'); + INSERT INTO t2 VALUES(2, 3, 'x'); + INSERT INTO t2 VALUES(2, 3, 'y'); + INSERT INTO t2 VALUES(2, 3, 'z'); + + 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} { + 1 0 "SELECT count(DISTINCT c) FROM t1 GROUP BY b" {2 3 0 1} + 2 1 "SELECT count(DISTINCT a) FROM t1 GROUP BY b" {2 3 0 1} + 3 1 "SELECT count(DISTINCT a) FROM t1 GROUP BY b+c" {0 1 1 1 1} + + 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"] + set idx [lsearch $prg OpenEphemeral] + expr {$idx>=0} + } $use_eph + + do_execsql_test 4.$tn.2 $sql $res +} + + +set t3root [db one {SELECT rootpage FROM sqlite_schema WHERE name='t3'}] +foreach {tn use_t3 sql res} { + 1 1 "SELECT count(*) FROM t3" 2 + 2 0 "SELECT count(*) FROM t1" 10 + 2 1 "SELECT count(DISTINCT a) FROM t1, t3" 4 + 3 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3" 4 + 4 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 WHERE t3.x=1" 4 + 5 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 WHERE t3.x=0" 0 + 6 1 "SELECT count(DISTINCT a) FROM t1 LEFT JOIN t3 ON (t3.x=0)" 4 + 7 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3" 2 + 8 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 WHERE t3.x=1" 1 + 9 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 WHERE t3.x=0" 0 + 10 1 "SELECT count(DISTINCT x) FROM t1 LEFT JOIN t3 ON (t3.x=0)" 0 + +} { + unset -nocomplain a + do_test 5.$tn.1 { + set bUse 0 + db eval "EXPLAIN $sql" a { + if {$a(opcode)=="OpenRead" && $a(p2)==$t3root} {set bUse 1} + } + set bUse + } $use_t3 + + do_execsql_test 5.$tn.2 $sql $res +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d); + INSERT INTO t1 VALUES(123,456); + INSERT INTO t2 VALUES(123,456); +} +do_execsql_test 6.1 { + SELECT count(DISTINCT c) FROM t1 LEFT JOIN t2; +} {1} + +do_execsql_test 7.0 { + CREATE TABLE v1 ( v2 UNIQUE, v3 AS( TYPEOF ( NULL ) ) UNIQUE ); + SELECT COUNT ( DISTINCT TRUE ) FROM v1 GROUP BY likelihood ( v3 , 0.100000 ); +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobbytes.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobbytes.test new file mode 100644 index 0000000000000000000000000000000000000000..c24318c565aceed3ff4efc60fe1089372cc45927 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobbytes.test @@ -0,0 +1,79 @@ +# 2014 October 30 +# +# 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 e_blobbytes + +ifcapable !incrblob { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE q1(r INTEGER PRIMARY KEY, s TEXT); + WITH d(a, b) AS ( + SELECT 0, '' + UNION ALL + SELECT a+1, b||'.' FROM d WHERE a<10000 + ) + INSERT INTO q1 SELECT * FROM d; +} + + +# EVIDENCE-OF: R-07796-55423 Returns the size in bytes of the BLOB +# accessible via the successfully opened BLOB handle in its only +# argument. +# +proc check_blob_size {tn rowid bytes} { + uplevel [list do_test $tn [subst -nocommands { + sqlite3_blob_open db main q1 s $rowid 0 B + set res [sqlite3_blob_bytes [set B]] + sqlite3_blob_close [set B] + set res + }] $bytes] +} +check_blob_size 1.1 43 43 +check_blob_size 1.2 391 391 +check_blob_size 1.3 6349 6349 +check_blob_size 1.4 2621 2621 +check_blob_size 1.5 7771 7771 +check_blob_size 1.6 7949 7949 +check_blob_size 1.7 4374 4374 +check_blob_size 1.8 2578 2578 +check_blob_size 1.9 7004 7004 +check_blob_size 1.10 2180 2180 +check_blob_size 1.11 3796 3796 +check_blob_size 1.12 7101 7101 +check_blob_size 1.13 7449 7449 +check_blob_size 1.14 7224 7224 +check_blob_size 1.15 3038 3038 +check_blob_size 1.16 1083 1083 +check_blob_size 1.17 5157 5157 +check_blob_size 1.18 6686 6686 +check_blob_size 1.19 6592 6592 +check_blob_size 1.20 0 0 + + +# EVIDENCE-OF: R-53088-19343 The incremental blob I/O routines can only +# read or overwriting existing blob content; they cannot change the size +# of a blob. +# +# Also demonstrated in other e_blobXXX.test files. +# +do_test 2.1 { + sqlite3_blob_open db main q1 s 86 1 B + list [catch { sqlite3_blob_write $B 86 "1" 1 } msg] $msg +} {1 SQLITE_ERROR} +sqlite3_blob_close $B + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobclose.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobclose.test new file mode 100644 index 0000000000000000000000000000000000000000..40291cf03677a656960ec7e5ccbc1f9550522405 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobclose.test @@ -0,0 +1,175 @@ +# 2014 October 30 +# +# 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 e_blobclose + +ifcapable !incrblob { + finish_test + return +} + +set dots [string repeat . 40] +do_execsql_test 1.0 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b DOTS); + INSERT INTO x1 VALUES(-1, $dots); + INSERT INTO x1 VALUES(-10, $dots); + INSERT INTO x1 VALUES(-100, $dots); + INSERT INTO x1 VALUES(-1000, $dots); + INSERT INTO x1 VALUES(-10000, $dots); +} + +# EVIDENCE-OF: R-03145-46390 This function closes an open BLOB handle. +# +# It's not clear how to test that a blob handle really is closed. +# Attempting to use a closed blob handle will likely crash the process. +# Assume here that if the SHARED lock on the db file is released, +# the blob handle has been closed. +# +do_execsql_test 1.1 { PRAGMA lock_status } {main unlocked temp closed} +sqlite3_blob_open db main x1 b -1 0 B +do_execsql_test 1.2 { PRAGMA lock_status } {main shared temp closed} +sqlite3_blob_close $B +do_execsql_test 1.3 { PRAGMA lock_status } {main unlocked temp closed} + + +# EVIDENCE-OF: R-34027-00617 If the blob handle being closed was opened +# for read-write access, and if the database is in auto-commit mode and +# there are no other open read-write blob handles or active write +# statements, the current transaction is committed. +# +# 2.1.*: Transaction is not committed if there are other open +# read-write blob handles. +# +# 2.2.*: Transaction is not committed if not in auto-commit mode. +# +# 2.3.*: Active write statements. +# +do_test 2.1.1 { + sqlite3_blob_open db main x1 b -100 1 B1 + sqlite3_blob_open db main x1 b -1000 1 B2 + sqlite3_blob_open db main x1 b -10000 1 B3 + sqlite3_blob_open db main x1 b -10000 0 B4 ;# B4 is read-only! + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.2 { + sqlite3_blob_close $B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.3 { + sqlite3_blob_close $B2 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.1.4 { + sqlite3_blob_close $B3 + execsql { PRAGMA lock_status } +} {main shared temp closed} +do_test 2.1.5 { + sqlite3_blob_close $B4 + execsql { PRAGMA lock_status } +} {main unlocked temp closed} + +do_test 2.2.1 { + sqlite3_blob_open db main x1 b -100 1 B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.2.2 { + execsql { BEGIN } + sqlite3_blob_close $B1 + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.2.3 { + execsql { COMMIT } + execsql { PRAGMA lock_status } +} {main unlocked temp closed} + +proc val {} { + sqlite3_blob_close $::B + db eval { PRAGMA lock_status } +} +db func val val +do_test 2.3.1 { + sqlite3_blob_open db main x1 b -100 1 B + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.3.2 { + execsql { INSERT INTO x1 VALUES(15, val()) } + execsql { PRAGMA lock_status } +} {main unlocked temp closed} +do_test 2.3.3 { + execsql { SELECT * FROM x1 WHERE a = 15 } +} {15 {main reserved temp closed}} + +# A reader does not inhibit commit. +do_test 2.3.4 { + sqlite3_blob_open db main x1 b -100 1 B + execsql { PRAGMA lock_status } +} {main reserved temp closed} +do_test 2.3.5 { + execsql { SELECT a, val() FROM x1 LIMIT 1 } +} {-10000 {main shared temp closed}} + + +do_test 3.1 { + sqlite3_blob_open db main x1 b -10 1 B + execsql { + INSERT INTO x1 VALUES(1, 'abc'); + SELECT * FROM x1 WHERE a=1; + } +} {1 abc} +do_test 3.2 { + sqlite3_blob_write $B 0 "abcdefghij" 10 + execsql { SELECT * FROM x1 WHERE a=-10 } +} {-10 abcdefghij..............................} + +do_test 3.3 { + sqlite3 db2 test.db + execsql { BEGIN ; SELECT * FROM x1 } db2 + sqlite3_blob_close $B +} {SQLITE_BUSY} + +# EVIDENCE-OF: R-41959-38737 Otherwise, if this function is passed a +# valid open blob handle, the values returned by the sqlite3_errcode() +# and sqlite3_errmsg() functions are set before returning. +# +do_test 3.4 { + list [sqlite3_errcode db] [sqlite3_errmsg db] +} {SQLITE_BUSY {database is locked}} + +# EVIDENCE-OF: R-37801-37633 The BLOB handle is closed unconditionally. +# Even if this routine returns an error code, the handle is still +# closed. +# +# Test that the lock has been released. Assume this means the handle +# is closed, even though blob_close() returned SQLITE_BUSY. +# +do_execsql_test 3.4 { PRAGMA lock_status } {main unlocked temp closed} + +# EVIDENCE-OF: R-35111-05628 If an error occurs while committing the +# transaction, an error code is returned and the transaction rolled +# back. +# +# Row 1 is removed (it was inserted this transaction) and row -10 +# is restored to its original state. Transaction has been rolled back. +# +do_execsql_test 3.5 { + SELECT * FROM x1 WHERE a IN (1, -10); +} {-10 ........................................} + +# EVIDENCE-OF: R-25894-51060 Calling this routine with a null pointer +# (such as would be returned by a failed call to sqlite3_blob_open()) is +# a harmless no-op. +# +do_test 4.0 { sqlite3_blob_close 0 } {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobopen.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobopen.test new file mode 100644 index 0000000000000000000000000000000000000000..41fd13c674c52279ea4bf5ff72fc4bf6b974ecf7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobopen.test @@ -0,0 +1,553 @@ +# 2014 October 30 +# +# 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 e_blobopen + +ifcapable !incrblob { + finish_test + return +} + +forcedelete test.db2 + +do_execsql_test 1.0 { + ATTACH 'test.db2' AS aux; + + CREATE TABLE main.t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TEMP TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + + CREATE TABLE main.x1(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TEMP TABLE x2(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + CREATE TABLE aux.x3(a INTEGER PRIMARY KEY, b TEXT, c BLOB); + + INSERT INTO main.t1 VALUES(1, 'main one', X'0101'); + INSERT INTO main.t1 VALUES(2, 'main two', X'0102'); + INSERT INTO main.t1 VALUES(3, 'main three', X'0103'); + INSERT INTO main.t1 VALUES(4, 'main four', X'0104'); + INSERT INTO main.t1 VALUES(5, 'main five', X'0105'); + + INSERT INTO main.x1 VALUES(1, 'x main one', X'000101'); + INSERT INTO main.x1 VALUES(2, 'x main two', X'000102'); + INSERT INTO main.x1 VALUES(3, 'x main three', X'000103'); + INSERT INTO main.x1 VALUES(4, 'x main four', X'000104'); + INSERT INTO main.x1 VALUES(5, 'x main five', X'000105'); + + INSERT INTO temp.t1 VALUES(1, 'temp one', X'0201'); + INSERT INTO temp.t1 VALUES(2, 'temp two', X'0202'); + INSERT INTO temp.t1 VALUES(3, 'temp three', X'0203'); + INSERT INTO temp.t1 VALUES(4, 'temp four', X'0204'); + INSERT INTO temp.t1 VALUES(5, 'temp five', X'0205'); + + INSERT INTO temp.x2 VALUES(1, 'x temp one', X'000201'); + INSERT INTO temp.x2 VALUES(2, 'x temp two', X'000202'); + INSERT INTO temp.x2 VALUES(3, 'x temp three', X'000203'); + INSERT INTO temp.x2 VALUES(4, 'x temp four', X'000204'); + INSERT INTO temp.x2 VALUES(5, 'x temp five', X'000205'); + + INSERT INTO aux.t1 VALUES(1, 'aux one', X'0301'); + INSERT INTO aux.t1 VALUES(2, 'aux two', X'0302'); + INSERT INTO aux.t1 VALUES(3, 'aux three', X'0303'); + INSERT INTO aux.t1 VALUES(4, 'aux four', X'0304'); + INSERT INTO aux.t1 VALUES(5, 'aux five', X'0305'); + + INSERT INTO aux.x3 VALUES(1, 'x aux one', X'000301'); + INSERT INTO aux.x3 VALUES(2, 'x aux two', X'000302'); + INSERT INTO aux.x3 VALUES(3, 'x aux three', X'000303'); + INSERT INTO aux.x3 VALUES(4, 'x aux four', X'000304'); + INSERT INTO aux.x3 VALUES(5, 'x aux five', X'000305'); +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-37639-55938 This interfaces opens a handle to the BLOB +# located in row iRow, column zColumn, table zTable in database zDb; in +# other words, the same BLOB that would be selected by: SELECT zColumn +# FROM zDb.zTable WHERE rowid = iRow; +# +proc read_blob {zDb zTab zCol iRow} { + sqlite3_blob_open db $zDb $zTab $zCol $iRow 0 B + set nByte [sqlite3_blob_bytes $B] + set data [sqlite3_blob_read $B 0 $nByte] + sqlite3_blob_close $B + return $data +} + +do_test 1.1.1 { read_blob main t1 b 1 } "main one" +do_test 1.1.2 { read_blob main t1 c 1 } "\01\01" +do_test 1.1.3 { read_blob temp t1 b 1 } "temp one" +do_test 1.1.4 { read_blob temp t1 c 1 } "\02\01" +do_test 1.1.6 { read_blob aux t1 b 1 } "aux one" +do_test 1.1.7 { read_blob aux t1 c 1 } "\03\01" + +do_test 1.2.1 { read_blob main t1 b 4 } "main four" +do_test 1.2.2 { read_blob main t1 c 4 } "\01\04" +do_test 1.2.3 { read_blob temp t1 b 4 } "temp four" +do_test 1.2.4 { read_blob temp t1 c 4 } "\02\04" +do_test 1.2.6 { read_blob aux t1 b 4 } "aux four" +do_test 1.2.7 { read_blob aux t1 c 4 } "\03\04" + +do_test 1.3.1 { read_blob main x1 b 2 } "x main two" +do_test 1.3.2 { read_blob main x1 c 2 } "\00\01\02" +do_test 1.3.3 { read_blob temp x2 b 2 } "x temp two" +do_test 1.3.4 { read_blob temp x2 c 2 } "\00\02\02" +do_test 1.3.6 { read_blob aux x3 b 2 } "x aux two" +do_test 1.3.7 { read_blob aux x3 c 2 } "\00\03\02" + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-27234-05761 Parameter zDb is not the filename that +# contains the database, but rather the symbolic name of the database. +# For attached databases, this is the name that appears after the AS +# keyword in the ATTACH statement. For the main database file, the +# database name is "main". For TEMP tables, the database name is "temp". +# +# The test cases immediately above demonstrate that the database name +# for the main db, for TEMP tables and for those in attached databases +# is correct. The following tests check that filenames cannot be +# used as well. +# +do_test 2.1 { + list [catch { sqlite3_blob_open db "test.db" t1 b 1 0 B } msg] $msg +} {1 SQLITE_ERROR} +do_test 2.2 { + list [catch { sqlite3_blob_open db "test.db2" t1 b 1 0 B } msg] $msg +} {1 SQLITE_ERROR} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-50854-53979 If the flags parameter is non-zero, then +# the BLOB is opened for read and write access. +# +# EVIDENCE-OF: R-03922-41160 If the flags parameter is zero, the BLOB is +# opened for read-only access. +# +foreach {tn iRow flags} { + 1 1 0 + 2 2 1 + 3 3 -1 + 4 4 2147483647 + 5 5 -2147483648 +} { + do_test 3.$tn.1 { + sqlite3_blob_open db main x1 c $iRow $flags B + set n [sqlite3_blob_bytes $B] + sqlite3_blob_read $B 0 $n + } [binary format ccc 0 1 $iRow] + + if {$flags==0} { + # Blob was opened for read-only access - writing returns an error. + do_test 3.$tn.2 { + list [catch { sqlite3_blob_write $B 0 xxx 3 } msg] $msg + } {1 SQLITE_READONLY} + + do_execsql_test 3.$tn.3 { + SELECT c FROM x1 WHERE a=$iRow; + } [binary format ccc 0 1 $iRow] + } else { + # Blob was opened for read/write access - writing succeeds + do_test 3.$tn.4 { + list [catch { sqlite3_blob_write $B 0 xxx 3 } msg] $msg + } {0 {}} + + do_execsql_test 3.$tn.5 { + SELECT c FROM x1 WHERE a=$iRow; + } {xxx} + } + + sqlite3_blob_close $B +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('abcd', 152); + INSERT INTO t1 VALUES(NULL, X'00010203'); + INSERT INTO t1 VALUES('', 154.2); + + CREATE TABLE t2(x PRIMARY KEY, y) WITHOUT ROWID; + INSERT INTO t2 VALUES(1, 'blob'); + + CREATE TABLE t3(a PRIMARY KEY, b, c, d, e, f, UNIQUE(e, f)); + INSERT INTO t3 VALUES('aaaa', 'bbbb', 'cccc', 'dddd', 'eeee', 'ffff'); + CREATE INDEX t3b ON t3(b); + + CREATE TABLE p1(x PRIMARY KEY); + INSERT INTO p1 VALUES('abc'); + + CREATE TABLE c1(a INTEGER PRIMARY KEY, b REFERENCES p1); + INSERT INTO c1 VALUES(45, 'abc'); +} + +proc test_blob_open {tn zDb zTab zCol iRow flags errcode errmsg} { + global B + set B "0x1234" + + if {$errcode=="SQLITE_OK"} { + set expected "0 {}" + } else { + set expected "1 $errcode" + } + + set ::res [list [ + catch { sqlite3_blob_open db $zDb $zTab $zCol $iRow $flags B } msg + ] $msg] + do_test 4.$tn.1 { set ::res } $expected + + # EVIDENCE-OF: R-08940-21305 Unless it returns SQLITE_MISUSE, this + # function sets the database connection error code and message + # accessible via sqlite3_errcode() and sqlite3_errmsg() and related + # functions. + # + # This proc (test_blob_open) is used below to test various error and + # non-error conditions. But never SQLITE_MISUSE conditions. So these + # test cases are considered as partly verifying the requirement above. + # See below for a test of the SQLITE_MISUSE case. + # + do_test 4.$tn.2 { + sqlite3_errcode db + } $errcode + do_test 4.$tn.3 { + sqlite3_errmsg db + } $errmsg + + # EVIDENCE-OF: R-31086-35521 On success, SQLITE_OK is returned and the + # new BLOB handle is stored in *ppBlob. Otherwise an error code is + # returned and, unless the error code is SQLITE_MISUSE, *ppBlob is set + # to NULL. + # + do_test 4.$tn.4 { + expr {$B == "0"} + } [expr {$errcode != "SQLITE_OK"}] + + # EVIDENCE-OF: R-63421-15521 This means that, provided the API is not + # misused, it is always safe to call sqlite3_blob_close() on *ppBlob + # after this function it returns. + do_test 4.$tn.5 { + sqlite3_blob_close $B + } {} +} + +# EVIDENCE-OF: R-31204-44780 Database zDb does not exist +test_blob_open 1 nosuchdb t1 x 1 0 SQLITE_ERROR "no such table: nosuchdb.t1" + +# EVIDENCE-OF: R-28676-08005 Table zTable does not exist within database zDb +test_blob_open 2 main tt1 x 1 0 SQLITE_ERROR "no such table: main.tt1" + +# EVIDENCE-OF: R-40134-30296 Table zTable is a WITHOUT ROWID table +test_blob_open 3 main t2 y 1 0 SQLITE_ERROR \ + "cannot open table without rowid: t2" + +# EVIDENCE-OF: R-56376-21261 Column zColumn does not exist +test_blob_open 4 main t1 z 2 0 SQLITE_ERROR "no such column: \"z\"" + +# EVIDENCE-OF: R-28258-23166 Row iRow is not present in the table +test_blob_open 5 main t1 y 6 0 SQLITE_ERROR "no such rowid: 6" + +# EVIDENCE-OF: R-11683-62380 The specified column of row iRow contains a +# value that is not a TEXT or BLOB value +test_blob_open 6 main t1 x 2 0 SQLITE_ERROR "cannot open value of type null" +test_blob_open 7 main t1 y 1 0 SQLITE_ERROR "cannot open value of type integer" +test_blob_open 8 main t1 y 3 0 SQLITE_ERROR "cannot open value of type real" + +# EVIDENCE-OF: R-34146-30782 Column zColumn is part of an index, PRIMARY +# KEY or UNIQUE constraint and the blob is being opened for read/write +# access +# +# Test cases 8.1.* show that such columns can be opened for read-access. +# Tests 8.2.* show that read-write access is different. Columns "c" and "c" +# are not part of an index, PK or UNIQUE constraint, so they work in both +# cases. +# +test_blob_open 8.1.1 main t3 a 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.2 main t3 b 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.3 main t3 c 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.4 main t3 d 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.5 main t3 e 1 0 SQLITE_OK "not an error" +test_blob_open 8.1.6 main t3 f 1 0 SQLITE_OK "not an error" + +set cannot "cannot open indexed column for writing" +test_blob_open 8.2.1 main t3 a 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.2 main t3 b 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.3 main t3 c 1 8 SQLITE_OK "not an error" +test_blob_open 8.2.4 main t3 d 1 8 SQLITE_OK "not an error" +test_blob_open 8.2.5 main t3 e 1 8 SQLITE_ERROR $cannot +test_blob_open 8.2.6 main t3 f 1 8 SQLITE_ERROR $cannot + +# EVIDENCE-OF: R-50117-55204 Foreign key constraints are enabled, column +# zColumn is part of a child key definition and the blob is being opened +# for read/write access +# +# 9.1: FK disabled, read-only access. +# 9.2: FK disabled, read-only access. +# 9.3: FK enabled, read/write access. +# 9.4: FK enabled, read/write access. +# +test_blob_open 9.1 main c1 b 45 0 SQLITE_OK "not an error" +test_blob_open 9.2 main c1 b 45 1 SQLITE_OK "not an error" +execsql { PRAGMA foreign_keys = ON } +test_blob_open 9.3 main c1 b 45 0 SQLITE_OK "not an error" +test_blob_open 9.4 main c1 b 45 1 SQLITE_ERROR \ + "cannot open foreign key column for writing" + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-08940-21305 Unless it returns SQLITE_MISUSE, this +# function sets the database connection error code and message +# accessible via sqlite3_errcode() and sqlite3_errmsg() and related +# functions. +# +# This requirement is partially verified by the many uses of test +# command [test_blob_open] above. All that is left is to verify the +# SQLITE_MISUSE case. +# +# SQLITE_MISUSE is only returned if SQLITE_ENABLE_API_ARMOR is defined +# during compilation. +# +ifcapable api_armor { + sqlite3_blob_open db main t1 x 1 0 B + + do_test 10.1.1 { + list [catch {sqlite3_blob_open $B main t1 x 1 0 B2} msg] $msg + } {1 SQLITE_MISUSE} + do_test 10.1.2 { + list [sqlite3_errcode db] [sqlite3_errmsg db] + } {SQLITE_OK {not an error}} + sqlite3_blob_close $B + + do_test 10.2.1 { + list [catch {sqlite3_blob_open db main {} x 1 0 B} msg] $msg + } {1 SQLITE_MISUSE} + do_test 10.2.2 { + list [sqlite3_errcode db] [sqlite3_errmsg db] + } {SQLITE_OK {not an error}} +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-50542-62589 If the row that a BLOB handle points to is +# modified by an UPDATE, DELETE, or by ON CONFLICT side-effects then the +# BLOB handle is marked as "expired". This is true if any column of the +# row is changed, even a column other than the one the BLOB handle is +# open on. +# +# EVIDENCE-OF: R-48367-20048 Calls to sqlite3_blob_read() and +# sqlite3_blob_write() for an expired BLOB handle fail with a return +# code of SQLITE_ABORT. +# +# 11.2: read-only handle, DELETE. +# 11.3: read-only handle, UPDATE. +# 11.4: read-only handle, REPLACE. +# 11.5: read/write handle, DELETE. +# 11.6: read/write handle, UPDATE. +# 11.7: read/write handle, REPLACE. +# +do_execsql_test 11.1 { + CREATE TABLE b1(a INTEGER PRIMARY KEY, b, c UNIQUE); + INSERT INTO b1 VALUES(1, '1234567890', 1); + INSERT INTO b1 VALUES(2, '1234567890', 2); + INSERT INTO b1 VALUES(3, '1234567890', 3); + INSERT INTO b1 VALUES(4, '1234567890', 4); + INSERT INTO b1 VALUES(5, '1234567890', 5); + INSERT INTO b1 VALUES(6, '1234567890', 6); + + CREATE TABLE b2(a INTEGER PRIMARY KEY, b, c UNIQUE); + INSERT INTO b2 VALUES(1, '1234567890', 1); + INSERT INTO b2 VALUES(2, '1234567890', 2); + INSERT INTO b2 VALUES(3, '1234567890', 3); + INSERT INTO b2 VALUES(4, '1234567890', 4); + INSERT INTO b2 VALUES(5, '1234567890', 5); + INSERT INTO b2 VALUES(6, '1234567890', 6); +} + +do_test 11.2.1 { + sqlite3_blob_open db main b1 b 2 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.2.2 { + # Deleting a different row does not invalidate the blob handle. + execsql { DELETE FROM b1 WHERE a = 1 } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.2.3 { + execsql { DELETE FROM b1 WHERE a = 2 } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.2.4 { + sqlite3_blob_close $B +} {} + +do_test 11.3.1 { + sqlite3_blob_open db main b1 b 3 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.3.2 { + # Updating a different row + execsql { UPDATE b1 SET c = 42 WHERE a=4 } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.3.3 { + execsql { UPDATE b1 SET c = 43 WHERE a=3 } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.3.4 { + sqlite3_blob_close $B +} {} + +do_test 11.4.1 { + sqlite3_blob_open db main b1 b 6 0 B + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.4.2 { + # Replace a different row + execsql { INSERT OR REPLACE INTO b1 VALUES(10, 'abcdefghij', 5) } + sqlite3_blob_read $B 0 10 +} {1234567890} +do_test 11.4.3 { + execsql { INSERT OR REPLACE INTO b1 VALUES(11, 'abcdefghij', 6) } + list [catch { sqlite3_blob_read $B 0 10 } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.4.4 { + sqlite3_blob_close $B +} {} + +do_test 11.4.1 { + sqlite3_blob_open db main b2 b 2 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.4.2 { + # Deleting a different row does not invalidate the blob handle. + execsql { DELETE FROM b2 WHERE a = 1 } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.4.3 { + execsql { DELETE FROM b2 WHERE a = 2 } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.4.4 { + sqlite3_blob_close $B +} {} + +do_test 11.5.1 { + sqlite3_blob_open db main b2 b 3 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.5.2 { + # Updating a different row + execsql { UPDATE b2 SET c = 42 WHERE a=4 } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.5.3 { + execsql { UPDATE b2 SET c = 43 WHERE a=3 } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.5.4 { + sqlite3_blob_close $B +} {} + +do_test 11.6.1 { + sqlite3_blob_open db main b2 b 6 1 B + sqlite3_blob_write $B 0 "abcdefghij" +} {} +do_test 11.6.2 { + # Replace a different row + execsql { INSERT OR REPLACE INTO b2 VALUES(10, 'abcdefghij', 5) } + sqlite3_blob_write $B 0 "ABCDEFGHIJ" +} {} +do_test 11.6.3 { + execsql { INSERT OR REPLACE INTO b2 VALUES(11, 'abcdefghij', 6) } + list [catch { sqlite3_blob_write $B 0 "0987654321" } msg] $msg +} {1 SQLITE_ABORT} +do_test 11.6.4 { + sqlite3_blob_close $B +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-45408-40694 Changes written into a BLOB prior to the +# BLOB expiring are not rolled back by the expiration of the BLOB. Such +# changes will eventually commit if the transaction continues to +# completion. +# +do_execsql_test 12.1 { + CREATE TABLE b3(x INTEGER PRIMARY KEY, y TEXT, z INTEGER); + INSERT INTO b3 VALUES(22, '..........', NULL); +} +do_test 12.2 { + sqlite3_blob_open db main b3 y 22 1 B + sqlite3_blob_write $B 0 "xxxxx" 5 +} {} +do_execsql_test 12.3 { + UPDATE b3 SET z = 'not null'; +} +do_test 12.4 { + list [catch {sqlite3_blob_write $B 5 "xxxxx" 5} msg] $msg +} {1 SQLITE_ABORT} +do_execsql_test 12.5 { + SELECT * FROM b3; +} {22 xxxxx..... {not null}} +do_test 12.5 { + sqlite3_blob_close $B +} {} +do_execsql_test 12.6 { + SELECT * FROM b3; +} {22 xxxxx..... {not null}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-58813-55036 The sqlite3_bind_zeroblob() and +# sqlite3_result_zeroblob() interfaces and the built-in zeroblob SQL +# function may be used to create a zero-filled blob to read or write +# using the incremental-blob interface. +# +do_execsql_test 13.1 { + CREATE TABLE c2(i INTEGER PRIMARY KEY, j); + INSERT INTO c2 VALUES(10, zeroblob(24)); +} + +do_test 13.2 { + set stmt [sqlite3_prepare_v2 db "INSERT INTO c2 VALUES(11, ?)" -1] + sqlite3_bind_zeroblob $stmt 1 45 + sqlite3_step $stmt + sqlite3_finalize $stmt +} {SQLITE_OK} + +# The blobs can be read: +# +do_test 13.3.1 { + sqlite3_blob_open db main c2 j 10 1 B + sqlite3_blob_open db main c2 j 11 1 B2 + list [sqlite3_blob_bytes $B] [sqlite3_blob_bytes $B2] +} {24 45} +do_test 13.3.2 { + sqlite3_blob_read $B 0 24 +} [string repeat [binary format c 0] 24] +do_test 13.3.3 { + sqlite3_blob_read $B2 0 45 +} [string repeat [binary format c 0] 45] + +# And also written: +# +do_test 13.4.1 { + sqlite3_blob_write $B 0 [string repeat [binary format c 1] 24] +} {} +do_test 13.4.2 { + sqlite3_blob_write $B2 0 [string repeat [binary format c 1] 45] +} {} +do_test 13.5 { + sqlite3_blob_close $B + sqlite3_blob_close $B2 + execsql { SELECT j FROM c2 } +} [list \ + [string repeat [binary format c 1] 24] \ + [string repeat [binary format c 1] 45] \ +] + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobwrite.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobwrite.test new file mode 100644 index 0000000000000000000000000000000000000000..8d8588e6aa88b9393d0cacac20b27492c9d78c2e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_blobwrite.test @@ -0,0 +1,208 @@ +# 2014 October 30 +# +# 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 e_blobwrite + +ifcapable !incrblob { + finish_test + return +} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-62898-22698 This function is used to write data into an +# open BLOB handle from a caller-supplied buffer. N bytes of data are +# copied from the buffer Z into the open BLOB, starting at offset +# iOffset. +# +set dots [string repeat . 40] +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, t TEXT); + INSERT INTO t1 VALUES(-1, $dots); + INSERT INTO t1 VALUES(-2, $dots); + INSERT INTO t1 VALUES(-3, $dots); + INSERT INTO t1 VALUES(-4, $dots); + INSERT INTO t1 VALUES(-5, $dots); + INSERT INTO t1 VALUES(-6, $dots); +} + +proc blob_write_test {tn id iOffset blob nData final} { + sqlite3_blob_open db main t1 t $id 1 B + + # EVIDENCE-OF: R-45864-01884 On success, sqlite3_blob_write() returns + # SQLITE_OK. Otherwise, an error code or an extended error code is + # returned. + # + # This block tests the SQLITE_OK case in the requirement above (the + # Tcl sqlite3_blob_write() wrapper uses an empty string in place of + # "SQLITE_OK"). The error cases are tested by the "blob_write_error_test" + # tests below. + # + set res [sqlite3_blob_write $B $iOffset $blob $nData] + uplevel [list do_test $tn.1 [list set {} $res] {}] + + sqlite3_blob_close $B + uplevel [list do_execsql_test $tn.3 "SELECT t FROM t1 WHERE a=$id" $final] +} + +set blob "0123456789012345678901234567890123456789" +blob_write_test 1.1 -1 0 $blob 10 { 0123456789.............................. } +blob_write_test 1.2 -2 8 $blob 10 { ........0123456789...................... } +blob_write_test 1.3 -3 8 $blob 1 { ........0............................... } +blob_write_test 1.4 -4 18 $blob 22 { ..................0123456789012345678901 } +blob_write_test 1.5 -5 18 $blob 0 { ........................................ } +blob_write_test 1.6 -6 0 $blob 40 { 0123456789012345678901234567890123456789 } + + +proc blob_write_error_test {tn B iOffset blob nData errcode errmsg} { + + # In cases where the underlying sqlite3_blob_write() function returns + # SQLITE_OK, the Tcl wrapper returns an empty string. If the underlying + # function returns an error, the Tcl wrapper throws an exception with + # the error code as the Tcl exception message. + # + if {$errcode=="SQLITE_OK"} { + set ret "" + set isError 0 + } else { + set ret $errcode + set isError 1 + } + + set cmd [list sqlite3_blob_write $B $iOffset $blob $nData] + uplevel [list do_test $tn.1 [subst -nocommands { + list [catch {$cmd} msg] [set msg] + }] [list $isError $ret]] + + # EVIDENCE-OF: R-34782-18311 Unless SQLITE_MISUSE is returned, this + # function sets the database connection error code and message + # accessible via sqlite3_errcode() and sqlite3_errmsg() and related + # functions. + # + if {$errcode == "SQLITE_MISUSE"} { error "test proc misuse!" } + uplevel [list do_test $tn.2 [list sqlite3_errcode db] $errcode] + uplevel [list do_test $tn.3 [list sqlite3_errmsg db] $errmsg] +} + +do_execsql_test 2.0 { + CREATE TABLE t2(a TEXT, b INTEGER PRIMARY KEY); + INSERT INTO t2 VALUES($dots, 43); + INSERT INTO t2 VALUES($dots, 44); + INSERT INTO t2 VALUES($dots, 45); +} + +# EVIDENCE-OF: R-63341-57517 If the BLOB handle passed as the first +# argument was not opened for writing (the flags parameter to +# sqlite3_blob_open() was zero), this function returns SQLITE_READONLY. +# +sqlite3_blob_open db main t2 a 43 0 B +blob_write_error_test 2.1 $B 0 $blob 10 \ + SQLITE_READONLY {attempt to write a readonly database} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-29804-27366 If offset iOffset is less than N bytes from +# the end of the BLOB, SQLITE_ERROR is returned and no data is written. +# +sqlite3_blob_open db main t2 a 44 3 B +blob_write_error_test 2.2.1 $B 31 $blob 10 \ + SQLITE_ERROR {SQL logic error} + +# Make a successful write to the blob handle. This shows that the +# sqlite3_errcode() and sqlite3_errmsg() values are set even if the +# blob_write() call succeeds (see requirement in the [blob_write_error_test] +# proc). +blob_write_error_test 2.2.1 $B 30 $blob 10 SQLITE_OK {not an error} + +# EVIDENCE-OF: R-58570-38916 If N or iOffset are less than zero +# SQLITE_ERROR is returned and no data is written. +# +blob_write_error_test 2.2.2 $B 31 $blob -1 \ + SQLITE_ERROR {SQL logic error} +blob_write_error_test 2.2.3 $B 20 $blob 10 SQLITE_OK {not an error} +blob_write_error_test 2.2.4 $B -1 $blob 10 \ + SQLITE_ERROR {SQL logic error} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-20958-54138 An attempt to write to an expired BLOB +# handle fails with an error code of SQLITE_ABORT. +# +do_test 2.3 { + sqlite3_blob_open db main t2 a 43 0 B + execsql { DELETE FROM t2 WHERE b=43 } +} {} +blob_write_error_test 2.3.1 $B 5 $blob 5 \ + SQLITE_ABORT {query aborted} +do_test 2.3.2 { + execsql { SELECT 1, 2, 3 } + sqlite3_errcode db +} {SQLITE_OK} +blob_write_error_test 2.3.3 $B 5 $blob 5 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B + +# EVIDENCE-OF: R-08382-59936 Writes to the BLOB that occurred before the +# BLOB handle expired are not rolled back by the expiration of the +# handle, though of course those changes might have been overwritten by +# the statement that expired the BLOB handle or by other independent +# statements. +# +# 3.1.*: not rolled back, +# 3.2.*: overwritten. +# +do_execsql_test 3.0 { + CREATE TABLE t3(i INTEGER PRIMARY KEY, j TEXT, k TEXT); + INSERT INTO t3 VALUES(1, $dots, $dots); + INSERT INTO t3 VALUES(2, $dots, $dots); + SELECT * FROM t3 WHERE i=1; +} { + 1 + ........................................ + ........................................ +} +sqlite3_blob_open db main t3 j 1 1 B +blob_write_error_test 3.1.1 $B 5 $blob 10 SQLITE_OK {not an error} +do_execsql_test 3.1.2 { + UPDATE t3 SET k = 'xyz' WHERE i=1; + SELECT * FROM t3 WHERE i=1; +} { + 1 .....0123456789......................... xyz +} +blob_write_error_test 3.1.3 $B 15 $blob 10 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B +do_execsql_test 3.1.4 { + SELECT * FROM t3 WHERE i=1; +} { + 1 .....0123456789......................... xyz +} + +sqlite3_blob_open db main t3 j 2 1 B +blob_write_error_test 3.2.1 $B 5 $blob 10 SQLITE_OK {not an error} +do_execsql_test 3.2.2 { + UPDATE t3 SET j = 'xyz' WHERE i=2; + SELECT * FROM t3 WHERE i=2; +} { + 2 xyz ........................................ +} +blob_write_error_test 3.2.3 $B 15 $blob 10 \ + SQLITE_ABORT {query aborted} +sqlite3_blob_close $B +do_execsql_test 3.2.4 { + SELECT * FROM t3 WHERE i=2; +} { + 2 xyz ........................................ +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_changes.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_changes.test new file mode 100644 index 0000000000000000000000000000000000000000..2eb77d3130eb36d78757560e7b003e70051e7688 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_changes.test @@ -0,0 +1,443 @@ +# 2011 October 28 +# +# 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 e_changes + +# Like [do_execsql_test], except it appends the value returned by +# [db changes] to the result of executing the SQL script. +# +proc do_changes_test {tn sql res} { + uplevel [list \ + do_test $tn "concat \[execsql {$sql}\] \[db changes\]" $res + ] +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-58361-29089 The changes() function returns the number +# of database rows that were changed or inserted or deleted by the most +# recently completed INSERT, DELETE, or UPDATE statement, exclusive of +# statements in lower-level triggers. +# +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)) WITHOUT ROWID; + CREATE INDEX i1 ON t1(a); + CREATE INDEX i2 ON t2(y); +} +foreach {tn schema} { + 1 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(b); + } + 2 { + CREATE TABLE t1(a, b, PRIMARY KEY(a, b)) WITHOUT ROWID; + CREATE INDEX i1 ON t1(b); + } +} { + reset_db + execsql $schema + + # Insert 1 row. + do_changes_test 1.$tn.1 { INSERT INTO t1 VALUES(0, 0) } 1 + + # Insert 10 rows. + do_changes_test 1.$tn.2 { + WITH rows(i, j) AS ( + SELECT 1, 1 UNION ALL SELECT i+1, j+i FROM rows WHERE i<10 + ) + INSERT INTO t1 SELECT * FROM rows + } 10 + + # Modify 5 rows. + do_changes_test 1.$tn.3 { + UPDATE t1 SET b=b+1 WHERE a<5; + } 5 + + # Delete 4 rows + do_changes_test 1.$tn.4 { + DELETE FROM t1 WHERE a>6 + } 4 + + # Check the "on the database connecton specified" part of hte + # requirement - changes made by other connections do not show up in + # the return value of sqlite3_changes(). + do_test 1.$tn.5 { + sqlite3 db2 test.db + execsql { INSERT INTO t1 VALUES(-1, -1) } db2 + db2 changes + } 1 + do_test 1.$tn.6 { + db changes + } 4 + db2 close + + # Test that statements that modify no rows because they hit UNIQUE + # constraints set the sqlite3_changes() value to 0. Regardless of + # whether or not they are executed inside an explicit transaction. + # + # 1.$tn.8-9: outside of a transaction + # 1.$tn.10-12: inside a transaction + # + do_changes_test 1.$tn.7 { + CREATE UNIQUE INDEX i2 ON t1(a); + } 4 + do_catchsql_test 1.$tn.8 { + INSERT INTO t1 VALUES('a', 0), ('b', 0), ('c', 0), (0, 11); + } {1 {UNIQUE constraint failed: t1.a}} + do_test 1.$tn.9 { db changes } 0 + do_catchsql_test 1.$tn.10 { + BEGIN; + INSERT INTO t1 VALUES('a', 0), ('b', 0), ('c', 0), (0, 11); + } {1 {UNIQUE constraint failed: t1.a}} + do_test 1.$tn.11 { db changes } 0 + do_changes_test 1.$tn.12 COMMIT 0 + +} + + +#-------------------------------------------------------------------------- +# X-EVIDENCE-OF: R-44877-05564 Executing any other type of SQL statement +# does not modify the value returned by this function. +# +reset_db +do_changes_test 2.1 { CREATE TABLE t1(x) } 0 +do_changes_test 2.2 { + WITH d(y) AS (SELECT 1 UNION ALL SELECT y+1 FROM d WHERE y<47) + INSERT INTO t1 SELECT y FROM d; +} 47 + +# The statement above set changes() to 47. Check that none of the following +# modify this. +do_changes_test 2.3 { SELECT count(x) FROM t1 } {47 47} +do_changes_test 2.4 { DROP TABLE t1 } 47 +do_changes_test 2.5 { CREATE TABLE t1(x) } 47 +ifcapable altertable { + do_changes_test 2.6 { ALTER TABLE t1 ADD COLUMN b } 47 +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-53938-27527 Only changes made directly by the INSERT, +# UPDATE or DELETE statement are considered - auxiliary changes caused +# by triggers, foreign key actions or REPLACE constraint resolution are +# not counted. +# +# 3.1.*: triggers +# 3.2.*: foreign key actions +# 3.3.*: replace constraints +# +reset_db +do_execsql_test 3.1.0 { + CREATE TABLE log(x); + CREATE TABLE p1(one PRIMARY KEY, two); + + CREATE TRIGGER tr_ai AFTER INSERT ON p1 BEGIN + INSERT INTO log VALUES('insert'); + END; + CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN + INSERT INTO log VALUES('delete'); + END; + CREATE TRIGGER tr_au AFTER UPDATE ON p1 BEGIN + INSERT INTO log VALUES('update'); + END; + +} + +do_changes_test 3.1.1 { + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); +} 3 +do_changes_test 3.1.2 { + UPDATE p1 SET two = two||two; +} 3 +do_changes_test 3.1.3 { + DELETE FROM p1 WHERE one IN ('a', 'c'); +} 2 +do_execsql_test 3.1.4 { + -- None of the inserts on table log were counted. + SELECT count(*) FROM log +} 8 + +do_execsql_test 3.2.0 { + DELETE FROM p1; + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); + + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET DEFAULT); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE CASCADE); + INSERT INTO c1 VALUES('a', 'aaa'); + INSERT INTO c2 VALUES('b', 'bbb'); + INSERT INTO c3 VALUES('c', 'ccc'); + + INSERT INTO p1 VALUES('d', 'D'), ('e', 'E'), ('f', 'F'); + CREATE TABLE c4(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET NULL); + CREATE TABLE c5(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET DEFAULT); + CREATE TABLE c6(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE CASCADE); + INSERT INTO c4 VALUES('d', 'aaa'); + INSERT INTO c5 VALUES('e', 'bbb'); + INSERT INTO c6 VALUES('f', 'ccc'); + + PRAGMA foreign_keys = ON; +} + +do_changes_test 3.2.1 { DELETE FROM p1 WHERE one = 'a' } 1 +do_changes_test 3.2.2 { DELETE FROM p1 WHERE one = 'b' } 1 +do_changes_test 3.2.3 { DELETE FROM p1 WHERE one = 'c' } 1 +do_execsql_test 3.2.4 { + SELECT * FROM c1; + SELECT * FROM c2; + SELECT * FROM c3; +} {{} aaa {} bbb} + +do_changes_test 3.2.5 { UPDATE p1 SET one = 'g' WHERE one = 'd' } 1 +do_changes_test 3.2.6 { UPDATE p1 SET one = 'h' WHERE one = 'e' } 1 +do_changes_test 3.2.7 { UPDATE p1 SET one = 'i' WHERE one = 'f' } 1 +do_execsql_test 3.2.8 { + SELECT * FROM c4; + SELECT * FROM c5; + SELECT * FROM c6; +} {{} aaa {} bbb i ccc} + +do_execsql_test 3.3.0 { + CREATE TABLE r1(a UNIQUE, b UNIQUE); + INSERT INTO r1 VALUES('i', 'i'); + INSERT INTO r1 VALUES('ii', 'ii'); + INSERT INTO r1 VALUES('iii', 'iii'); + INSERT INTO r1 VALUES('iv', 'iv'); + INSERT INTO r1 VALUES('v', 'v'); + INSERT INTO r1 VALUES('vi', 'vi'); + INSERT INTO r1 VALUES('vii', 'vii'); +} + +do_changes_test 3.3.1 { INSERT OR REPLACE INTO r1 VALUES('i', 1) } 1 +do_changes_test 3.3.2 { INSERT OR REPLACE INTO r1 VALUES('iv', 'v') } 1 +do_changes_test 3.3.3 { UPDATE OR REPLACE r1 SET b='v' WHERE a='iii' } 1 +do_changes_test 3.3.4 { UPDATE OR REPLACE r1 SET b='vi',a='vii' WHERE a='ii' } 1 +do_execsql_test 3.3.5 { + SELECT * FROM r1 ORDER BY a; +} {i 1 iii v vii vi} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-09813-48563 The value returned by sqlite3_changes() +# immediately after an INSERT, UPDATE or DELETE statement run on a view +# is always zero. +# +reset_db +do_execsql_test 4.1 { + CREATE TABLE log(log); + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TRIGGER v1_i INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO log VALUES('insert'); + END; + CREATE TRIGGER v1_u INSTEAD OF UPDATE ON v1 BEGIN + INSERT INTO log VALUES('update'), ('update'); + END; + CREATE TRIGGER v1_d INSTEAD OF DELETE ON v1 BEGIN + INSERT INTO log VALUES('delete'), ('delete'), ('delete'); + END; +} + +do_changes_test 4.2.1 { INSERT INTO t1 SELECT * FROM t1 } 3 +do_changes_test 4.2.2 { INSERT INTO v1 VALUES(1, 2) } 0 + +do_changes_test 4.3.1 { INSERT INTO t1 SELECT * FROM t1 } 6 +do_changes_test 4.3.2 { UPDATE v1 SET y='xyz' WHERE x=1 } 0 + +do_changes_test 4.4.1 { INSERT INTO t1 SELECT * FROM t1 } 12 +do_changes_test 4.4.2 { DELETE FROM v1 WHERE x=5 } 0 + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-32918-61474 Before entering a trigger program the value +# returned by sqlite3_changes() function is saved. After the trigger +# program has finished, the original value is restored. +# +reset_db +db func my_changes my_changes +set ::changes [list] +proc my_changes {x} { + set res [db changes] + lappend ::changes $x $res + return $res +} + +do_execsql_test 5.1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2(x); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, NULL); + INSERT INTO t1 VALUES(3, NULL); + CREATE TRIGGER AFTER UPDATE ON t1 BEGIN + INSERT INTO t2 VALUES('a'), ('b'), ('c'); + SELECT my_changes('trigger'); + END; +} + +do_execsql_test 5.1.1 { + INSERT INTO t2 VALUES('a'), ('b'); + UPDATE t1 SET b = my_changes('update'); + SELECT * FROM t1; +} {1 2 2 2 3 2} + +# Value is being restored to "2" when the trigger program exits. +do_test 5.1.2 { + set ::changes +} {update 2 trigger 3 update 2 trigger 3 update 2 trigger 3} + + +reset_db +do_execsql_test 5.2.0 { + CREATE TABLE t1(a, b); + CREATE TABLE log(x); + INSERT INTO t1 VALUES(1, 0); + INSERT INTO t1 VALUES(2, 0); + INSERT INTO t1 VALUES(3, 0); + CREATE TRIGGER t1_a_u AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES(old.b || ' -> ' || new.b || ' c = ' || changes() ); + END; + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1), (2), (3); + UPDATE t1 SET b = changes(); +} +do_execsql_test 5.2.1 { + SELECT * FROM t1; +} {1 3 2 3 3 3} +do_execsql_test 5.2.2 { + SELECT * FROM log; +} {{0 -> 3 c = 3} {0 -> 3 c = 3} {0 -> 3 c = 3}} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-17146-37073 Within a trigger program each INSERT, +# UPDATE and DELETE statement sets the value returned by +# sqlite3_changes() upon completion as normal. Of course, this value +# will not include any changes performed by sub-triggers, as the +# sqlite3_changes() value will be saved and restored after each +# sub-trigger has run. +reset_db +do_execsql_test 6.0 { + + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE t3(a, b); + CREATE TABLE log(x); + + CREATE TRIGGER t1_i BEFORE INSERT ON t1 BEGIN + INSERT INTO t2 VALUES(new.a, new.b), (new.a, new.b); + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_i AFTER INSERT ON t2 BEGIN + INSERT INTO t3 VALUES(new.a, new.b), (new.a, new.b), (new.a, new.b); + INSERT INTO log VALUES('t3->' || changes()); + END; + + CREATE TRIGGER t1_u AFTER UPDATE ON t1 BEGIN + UPDATE t2 SET b=new.b WHERE a=old.a; + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_u BEFORE UPDATE ON t2 BEGIN + UPDATE t3 SET b=new.b WHERE a=old.a; + INSERT INTO log VALUES('t3->' || changes()); + END; + + CREATE TRIGGER t1_d AFTER DELETE ON t1 BEGIN + DELETE FROM t2 WHERE a=old.a AND b=old.b; + INSERT INTO log VALUES('t2->' || changes()); + END; + + CREATE TRIGGER t2_d BEFORE DELETE ON t2 BEGIN + DELETE FROM t3 WHERE a=old.a AND b=old.b; + INSERT INTO log VALUES('t3->' || changes()); + END; +} + +do_changes_test 6.1 { + INSERT INTO t1 VALUES('+', 'o'); + SELECT * FROM log; +} {t3->3 t3->3 t2->2 1} + +do_changes_test 6.2 { + DELETE FROM log; + UPDATE t1 SET b='*'; + SELECT * FROM log; +} {t3->6 t3->6 t2->2 1} + +do_changes_test 6.3 { + DELETE FROM log; + DELETE FROM t1; + SELECT * FROM log; +} {t3->6 t3->0 t2->2 1} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-43399-09409 This means that if the changes() SQL +# function (or similar) is used by the first INSERT, UPDATE or DELETE +# statement within a trigger, it returns the value as set when the +# calling statement began executing. +# +# EVIDENCE-OF: R-53215-27584 If it is used by the second or subsequent +# such statement within a trigger program, the value returned reflects +# the number of rows modified by the previous INSERT, UPDATE or DELETE +# statement within the same trigger. +# +reset_db +do_execsql_test 7.1 { + CREATE TABLE q1(t); + CREATE TABLE q2(u, v); + CREATE TABLE q3(w); + + CREATE TRIGGER q2_insert BEFORE INSERT ON q2 BEGIN + + /* changes() returns value from previous I/U/D in callers context */ + INSERT INTO q1 VALUES('1:' || changes()); + + /* changes() returns value of previous I/U/D in this context */ + INSERT INTO q3 VALUES(changes()), (2), (3); + INSERT INTO q1 VALUES('2:' || changes()); + INSERT INTO q3 VALUES(changes() + 3), (changes()+4); + SELECT 'this does not affect things!'; + INSERT INTO q1 VALUES('3:' || changes()); + UPDATE q3 SET w = w+10 WHERE w%2; + INSERT INTO q1 VALUES('4:' || changes()); + DELETE FROM q3; + INSERT INTO q1 VALUES('5:' || changes()); + END; +} + +do_execsql_test 7.2 { + INSERT INTO q2 VALUES('x', 'y'); + SELECT * FROM q1; +} { + 1:0 2:3 3:2 4:3 5:5 +} + +do_execsql_test 7.3 { + DELETE FROM q1; + INSERT INTO q2 VALUES('x', 'y'); + SELECT * FROM q1; +} { + 1:5 2:3 3:2 4:3 5:5 +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_createtable.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_createtable.test new file mode 100644 index 0000000000000000000000000000000000000000..92ccc803237e1de42d29582f5a625dd07ddade21 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_createtable.test @@ -0,0 +1,1970 @@ +# 2010 September 25 +# +# 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 to verify that the "testable statements" in +# the lang_createtable.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix e_createtable + +# Test organization: +# +# e_createtable-0.*: Test that the syntax diagrams are correct. +# +# e_createtable-1.*: Test statements related to table and database names, +# the TEMP and TEMPORARY keywords, and the IF NOT EXISTS clause. +# +# e_createtable-2.*: Test "CREATE TABLE AS" statements. +# + +proc do_createtable_tests {nm args} { + uplevel do_select_tests [list e_createtable-$nm] $args +} + + +#------------------------------------------------------------------------- +# This command returns a serialized tcl array mapping from the name of +# each attached database to a list of tables in that database. For example, +# if the database schema is created with: +# +# CREATE TABLE t1(x); +# CREATE TEMP TABLE t2(x); +# CREATE TEMP TABLE t3(x); +# +# Then this command returns "main t1 temp {t2 t3}". +# +proc table_list {} { + set res [list] + db eval { pragma database_list } a { + set dbname $a(name) + set master $a(name).sqlite_master + if {$dbname == "temp"} { set master sqlite_temp_master } + lappend res $dbname [ + db eval "SELECT DISTINCT tbl_name FROM $master ORDER BY tbl_name" + ] + } + set res +} + + +do_createtable_tests 0.1.1 -repair { + drop_all_tables +} { + 1 "CREATE TABLE t1(c1 one)" {} + 2 "CREATE TABLE t1(c1 one two)" {} + 3 "CREATE TABLE t1(c1 one two three)" {} + 4 "CREATE TABLE t1(c1 one two three four)" {} + 5 "CREATE TABLE t1(c1 one two three four(14))" {} + 6 "CREATE TABLE t1(c1 one two three four(14, 22))" {} + 7 "CREATE TABLE t1(c1 var(+14, -22.3))" {} + 8 "CREATE TABLE t1(c1 var(1.0e10))" {} +} +do_createtable_tests 0.1.2 -error { + near "%s": syntax error +} { + 1 "CREATE TABLE t1(c1 one(number))" {number} +} + + +# syntax diagram column-constraint +# +do_createtable_tests 0.2.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY) } +} { + 1.1 "CREATE TABLE t1(c1 text PRIMARY KEY)" {} + 1.2 "CREATE TABLE t1(c1 text PRIMARY KEY ASC)" {} + 1.3 "CREATE TABLE t1(c1 text PRIMARY KEY DESC)" {} + 1.4 "CREATE TABLE t1(c1 text CONSTRAINT cons PRIMARY KEY DESC)" {} + + 2.1 "CREATE TABLE t1(c1 text NOT NULL)" {} + 2.2 "CREATE TABLE t1(c1 text CONSTRAINT nm NOT NULL)" {} + 2.3 "CREATE TABLE t1(c1 text NULL)" {} + 2.4 "CREATE TABLE t1(c1 text CONSTRAINT nm NULL)" {} + + 3.1 "CREATE TABLE t1(c1 text UNIQUE)" {} + 3.2 "CREATE TABLE t1(c1 text CONSTRAINT un UNIQUE)" {} + + 4.1 "CREATE TABLE t1(c1 text CHECK(c1!=0))" {} + 4.2 "CREATE TABLE t1(c1 text CONSTRAINT chk CHECK(c1!=0))" {} + + 5.1 "CREATE TABLE t1(c1 text DEFAULT 1)" {} + 5.2 "CREATE TABLE t1(c1 text DEFAULT -1)" {} + 5.3 "CREATE TABLE t1(c1 text DEFAULT +1)" {} + 5.4 "CREATE TABLE t1(c1 text DEFAULT -45.8e22)" {} + 5.5 "CREATE TABLE t1(c1 text DEFAULT (1+1))" {} + 5.6 "CREATE TABLE t1(c1 text CONSTRAINT \"1 2\" DEFAULT (1+1))" {} + + 6.1 "CREATE TABLE t1(c1 text COLLATE nocase)" {} + 6.2 "CREATE TABLE t1(c1 text CONSTRAINT 'a x' COLLATE nocase)" {} + + 7.1 "CREATE TABLE t1(c1 REFERENCES t2)" {} + 7.2 "CREATE TABLE t1(c1 CONSTRAINT abc REFERENCES t2)" {} + + 8.1 { + CREATE TABLE t1(c1 + PRIMARY KEY NOT NULL UNIQUE CHECK(c1 IS 'ten') DEFAULT 123 REFERENCES t1 + ); + } {} + 8.2 { + CREATE TABLE t1(c1 + REFERENCES t1 DEFAULT 123 CHECK(c1 IS 'ten') UNIQUE NOT NULL PRIMARY KEY + ); + } {} +} + +# -- syntax diagram table-constraint +# +do_createtable_tests 0.3.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY) } +} { + 1.1 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1))" {} + 1.2 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2))" {} + 1.3 "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2) ON CONFLICT IGNORE)" {} + + 2.1 "CREATE TABLE t1(c1, c2, UNIQUE(c1))" {} + 2.2 "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2))" {} + 2.3 "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2) ON CONFLICT IGNORE)" {} + + 3.1 "CREATE TABLE t1(c1, c2, CHECK(c1 IS NOT c2))" {} + + 4.1 "CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2)" {} +} + +# -- syntax diagram column-def +# +do_createtable_tests 0.4.1 -repair { + drop_all_tables +} { + 1 {CREATE TABLE t1( + col1, + col2 TEXT, + col3 INTEGER UNIQUE, + col4 VARCHAR(10, 10) PRIMARY KEY, + "name with spaces" REFERENCES t1 + ); + } {} +} + +# -- syntax diagram create-table-stmt +# +do_createtable_tests 0.5.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(a, b, c) } +} { + 1 "CREATE TABLE t1(a, b, c)" {} + 2 "CREATE TEMP TABLE t1(a, b, c)" {} + 3 "CREATE TEMPORARY TABLE t1(a, b, c)" {} + 4 "CREATE TABLE IF NOT EXISTS t1(a, b, c)" {} + 5 "CREATE TEMP TABLE IF NOT EXISTS t1(a, b, c)" {} + 6 "CREATE TEMPORARY TABLE IF NOT EXISTS t1(a, b, c)" {} + + 7 "CREATE TABLE main.t1(a, b, c)" {} + 8 "CREATE TEMP TABLE temp.t1(a, b, c)" {} + 9 "CREATE TEMPORARY TABLE temp.t1(a, b, c)" {} + 10 "CREATE TABLE IF NOT EXISTS main.t1(a, b, c)" {} + 11 "CREATE TEMP TABLE IF NOT EXISTS temp.t1(a, b, c)" {} + 12 "CREATE TEMPORARY TABLE IF NOT EXISTS temp.t1(a, b, c)" {} + + 13 "CREATE TABLE t1 AS SELECT * FROM t2" {} + 14 "CREATE TEMP TABLE t1 AS SELECT c, b, a FROM t2" {} + 15 "CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2" {} +} + +# +# 1: Explicit parent-key columns. +# 2: Implicit child-key columns. +# +# 1: MATCH FULL +# 2: MATCH PARTIAL +# 3: MATCH SIMPLE +# 4: MATCH STICK +# 5: +# +# 1: ON DELETE SET NULL +# 2: ON DELETE SET DEFAULT +# 3: ON DELETE CASCADE +# 4: ON DELETE RESTRICT +# 5: ON DELETE NO ACTION +# 6: +# +# 1: ON UPDATE SET NULL +# 2: ON UPDATE SET DEFAULT +# 3: ON UPDATE CASCADE +# 4: ON UPDATE RESTRICT +# 5: ON UPDATE NO ACTION +# 6: +# +# 1: NOT DEFERRABLE INITIALLY DEFERRED +# 2: NOT DEFERRABLE INITIALLY IMMEDIATE +# 3: NOT DEFERRABLE +# 4: DEFERRABLE INITIALLY DEFERRED +# 5: DEFERRABLE INITIALLY IMMEDIATE +# 6: DEFERRABLE +# 7: +# +do_createtable_tests 0.6.1 -repair { + drop_all_tables + execsql { CREATE TABLE t2(x PRIMARY KEY, y) } + execsql { CREATE TABLE t3(i, j, UNIQUE(i, j) ) } +} { + 11146 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH FULL + ON DELETE SET NULL ON UPDATE RESTRICT DEFERRABLE + )} {} + 11412 { CREATE TABLE t1(a + REFERENCES t2(x) + ON DELETE RESTRICT ON UPDATE SET NULL MATCH FULL + NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 12135 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE SET NULL ON UPDATE CASCADE DEFERRABLE INITIALLY IMMEDIATE + )} {} + 12427 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE RESTRICT ON UPDATE SET DEFAULT + )} {} + 12446 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE RESTRICT ON UPDATE RESTRICT DEFERRABLE + )} {} + 12522 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH PARTIAL + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 13133 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET NULL ON UPDATE CASCADE NOT DEFERRABLE + )} {} + 13216 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET DEFAULT ON UPDATE SET NULL DEFERRABLE + )} {} + 13263 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE SET DEFAULT NOT DEFERRABLE + )} {} + 13421 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE RESTRICT ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 13432 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE RESTRICT ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 13523 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH SIMPLE + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE + )} {} + 14336 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH STICK + ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE + )} {} + 14611 { CREATE TABLE t1(a + REFERENCES t2(x) MATCH STICK + ON UPDATE SET NULL NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 15155 { CREATE TABLE t1(a + REFERENCES t2(x) + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE + )} {} + 15453 { CREATE TABLE t1(a + REFERENCES t2(x) ON DELETE RESTRICT ON UPDATE NO ACTION NOT DEFERRABLE + )} {} + 15661 { CREATE TABLE t1(a + REFERENCES t2(x) NOT DEFERRABLE INITIALLY DEFERRED + )} {} + 21115 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE SET NULL ON UPDATE SET NULL DEFERRABLE INITIALLY IMMEDIATE + )} {} + 21123 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE SET NULL ON UPDATE SET DEFAULT NOT DEFERRABLE + )} {} + 21217 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL ON DELETE SET DEFAULT ON UPDATE SET NULL + )} {} + 21362 { CREATE TABLE t1(a + REFERENCES t2 MATCH FULL + ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 22143 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL + ON DELETE SET NULL ON UPDATE RESTRICT NOT DEFERRABLE + )} {} + 22156 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE + )} {} + 22327 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL ON DELETE CASCADE ON UPDATE SET DEFAULT + )} {} + 22663 { CREATE TABLE t1(a + REFERENCES t2 MATCH PARTIAL NOT DEFERRABLE + )} {} + 23236 { CREATE TABLE t1(a + REFERENCES t2 MATCH SIMPLE + ON DELETE SET DEFAULT ON UPDATE CASCADE DEFERRABLE + )} {} + 24155 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE + )} {} + 24522 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 24625 { CREATE TABLE t1(a + REFERENCES t2 MATCH STICK + ON UPDATE SET DEFAULT DEFERRABLE INITIALLY IMMEDIATE + )} {} + 25454 { CREATE TABLE t1(a + REFERENCES t2 + ON DELETE RESTRICT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED + )} {} +} + +#------------------------------------------------------------------------- +# Test cases e_createtable-1.* - test statements related to table and +# database names, the TEMP and TEMPORARY keywords, and the IF NOT EXISTS +# clause. +# +drop_all_tables +forcedelete test.db2 test.db3 + +do_execsql_test e_createtable-1.0 { + ATTACH 'test.db2' AS auxa; + ATTACH 'test.db3' AS auxb; +} {} + +# EVIDENCE-OF: R-17899-04554 Table names that begin with "sqlite_" are +# reserved for internal use. It is an error to attempt to create a table +# with a name that starts with "sqlite_". +# +do_createtable_tests 1.1.1 -error { + object name reserved for internal use: %s +} { + 1 "CREATE TABLE sqlite_abc(a, b, c)" sqlite_abc + 2 "CREATE TABLE temp.sqlite_helloworld(x)" sqlite_helloworld + 3 {CREATE TABLE auxa."sqlite__"(x, y)} sqlite__ + 4 {CREATE TABLE auxb."sqlite_"(z)} sqlite_ + 5 {CREATE TABLE "SQLITE_TBL"(z)} SQLITE_TBL +} +do_createtable_tests 1.1.2 { + 1 "CREATE TABLE sqlit_abc(a, b, c)" {} + 2 "CREATE TABLE temp.sqlitehelloworld(x)" {} + 3 {CREATE TABLE auxa."sqlite"(x, y)} {} + 4 {CREATE TABLE auxb."sqlite-"(z)} {} + 5 {CREATE TABLE "SQLITE-TBL"(z)} {} +} + + +# EVIDENCE-OF: R-18448-33677 If a schema-name is specified, it must be +# either "main", "temp", or the name of an attached database. +# +# EVIDENCE-OF: R-39822-07822 In this case the new table is created in +# the named database. +# +# Test cases 1.2.* test the first of the two requirements above. The +# second is verified by cases 1.3.*. +# +do_createtable_tests 1.2.1 -error { + unknown database %s +} { + 1 "CREATE TABLE george.t1(a, b)" george + 2 "CREATE TABLE _.t1(a, b)" _ +} +do_createtable_tests 1.2.2 { + 1 "CREATE TABLE main.abc(a, b, c)" {} + 2 "CREATE TABLE temp.helloworld(x)" {} + 3 {CREATE TABLE auxa."t 1"(x, y)} {} + 4 {CREATE TABLE auxb.xyz(z)} {} +} +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.3 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TABLE main.abc(a, b, c)" {abc {} {} {}} + 2 "CREATE TABLE main.t1(a, b, c)" {{abc t1} {} {} {}} + 3 "CREATE TABLE temp.tmp(a, b, c)" {{abc t1} tmp {} {}} + 4 "CREATE TABLE auxb.tbl(x, y)" {{abc t1} tmp {} tbl} + 5 "CREATE TABLE auxb.t1(k, v)" {{abc t1} tmp {} {t1 tbl}} + 6 "CREATE TABLE auxa.next(c, d)" {{abc t1} tmp next {t1 tbl}} + } +} + +# EVIDENCE-OF: R-18895-27365 If the "TEMP" or "TEMPORARY" keyword occurs +# between the "CREATE" and "TABLE" then the new table is created in the +# temp database. +# +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.4 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TEMP TABLE t1(a, b)" {{} t1 {} {}} + 2 "CREATE TEMPORARY TABLE t2(a, b)" {{} {t1 t2} {} {}} + } +} + +# EVIDENCE-OF: R-23976-43329 It is an error to specify both a +# schema-name and the TEMP or TEMPORARY keyword, unless the schema-name +# is "temp". +# +drop_all_tables +do_createtable_tests 1.5.1 -error { + temporary table name must be unqualified +} { + 1 "CREATE TEMP TABLE main.t1(a, b)" {} + 2 "CREATE TEMPORARY TABLE auxa.t2(a, b)" {} + 3 "CREATE TEMP TABLE auxb.t3(a, b)" {} + 4 "CREATE TEMPORARY TABLE main.xxx(x)" {} +} +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.5.2 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TEMP TABLE temp.t1(a, b)" {{} t1 {} {}} + 2 "CREATE TEMPORARY TABLE temp.t2(a, b)" {{} {t1 t2} {} {}} + 3 "CREATE TEMP TABLE TEMP.t3(a, b)" {{} {t1 t2 t3} {} {}} + 4 "CREATE TEMPORARY TABLE TEMP.xxx(x)" {{} {t1 t2 t3 xxx} {} {}} + } +} + +# EVIDENCE-OF: R-31997-24564 If no schema name is specified and the TEMP +# keyword is not present then the table is created in the main database. +# +drop_all_tables +if {[permutation]!="maindbname"} { + do_createtable_tests 1.6 -tclquery { + unset -nocomplain X + array set X [table_list] + list $X(main) $X(temp) $X(auxa) $X(auxb) + } { + 1 "CREATE TABLE t1(a, b)" {t1 {} {} {}} + 2 "CREATE TABLE t2(a, b)" {{t1 t2} {} {} {}} + 3 "CREATE TABLE t3(a, b)" {{t1 t2 t3} {} {} {}} + 4 "CREATE TABLE xxx(x)" {{t1 t2 t3 xxx} {} {} {}} + } +} + +drop_all_tables +do_execsql_test e_createtable-1.7.0 { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x); + CREATE VIEW v1 AS SELECT * FROM t1; + + CREATE TABLE auxa.tbl1(x, y); + CREATE INDEX auxa.idx1 ON tbl1(x); + CREATE VIEW auxa.view1 AS SELECT * FROM tbl1; +} {} + +# EVIDENCE-OF: R-01232-54838 It is usually an error to attempt to create +# a new table in a database that already contains a table, index or view +# of the same name. +# +# Test cases 1.7.1.* verify that creating a table in a database with a +# table/index/view of the same name does fail. 1.7.2.* tests that creating +# a table with the same name as a table/index/view in a different database +# is Ok. +# +do_createtable_tests 1.7.1 -error { %s } { + 1 "CREATE TABLE t1(a, b)" {{table t1 already exists}} + 2 "CREATE TABLE i1(a, b)" {{there is already an index named i1}} + 3 "CREATE TABLE v1(a, b)" {{view v1 already exists}} + 4 "CREATE TABLE auxa.tbl1(a, b)" {{table tbl1 already exists}} + 5 "CREATE TABLE auxa.idx1(a, b)" {{there is already an index named idx1}} + 6 "CREATE TABLE auxa.view1(a, b)" {{view view1 already exists}} +} +do_createtable_tests 1.7.2 { + 1 "CREATE TABLE auxa.t1(a, b)" {} + 2 "CREATE TABLE auxa.i1(a, b)" {} + 3 "CREATE TABLE auxa.v1(a, b)" {} + 4 "CREATE TABLE tbl1(a, b)" {} + 5 "CREATE TABLE idx1(a, b)" {} + 6 "CREATE TABLE view1(a, b)" {} +} + +# EVIDENCE-OF: R-33917-24086 However, if the "IF NOT EXISTS" clause is +# specified as part of the CREATE TABLE statement and a table or view of +# the same name already exists, the CREATE TABLE command simply has no +# effect (and no error message is returned). +# +drop_all_tables +do_execsql_test e_createtable-1.8.0 { + CREATE TABLE t1(x, y); + CREATE INDEX i1 ON t1(x); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE TABLE auxa.tbl1(x, y); + CREATE INDEX auxa.idx1 ON tbl1(x); + CREATE VIEW auxa.view1 AS SELECT * FROM tbl1; +} {} +do_createtable_tests 1.8 { + 1 "CREATE TABLE IF NOT EXISTS t1(a, b)" {} + 2 "CREATE TABLE IF NOT EXISTS auxa.tbl1(a, b)" {} + 3 "CREATE TABLE IF NOT EXISTS v1(a, b)" {} + 4 "CREATE TABLE IF NOT EXISTS auxa.view1(a, b)" {} +} + +# EVIDENCE-OF: R-16465-40078 An error is still returned if the table +# cannot be created because of an existing index, even if the "IF NOT +# EXISTS" clause is specified. +# +do_createtable_tests 1.9 -error { %s } { + 1 "CREATE TABLE IF NOT EXISTS i1(a, b)" + {{there is already an index named i1}} + 2 "CREATE TABLE IF NOT EXISTS auxa.idx1(a, b)" + {{there is already an index named idx1}} +} + +# EVIDENCE-OF: R-05513-33819 It is not an error to create a table that +# has the same name as an existing trigger. +# +drop_all_tables +do_execsql_test e_createtable-1.10.0 { + CREATE TABLE t1(x, y); + CREATE TABLE auxb.t2(x, y); + + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + SELECT 1; + END; + CREATE TRIGGER auxb.tr2 AFTER INSERT ON t2 BEGIN + SELECT 1; + END; +} {} +do_createtable_tests 1.10 { + 1 "CREATE TABLE tr1(a, b)" {} + 2 "CREATE TABLE tr2(a, b)" {} + 3 "CREATE TABLE auxb.tr1(a, b)" {} + 4 "CREATE TABLE auxb.tr2(a, b)" {} +} + +# EVIDENCE-OF: R-22283-14179 Tables are removed using the DROP TABLE +# statement. +# +drop_all_tables +do_execsql_test e_createtable-1.11.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE auxa.t3(a, b); + CREATE TABLE auxa.t4(a, b); +} {} + +do_execsql_test e_createtable-1.11.1.1 { + SELECT * FROM t1; + SELECT * FROM t2; + SELECT * FROM t3; + SELECT * FROM t4; +} {} +do_execsql_test e_createtable-1.11.1.2 { DROP TABLE t1 } {} +do_catchsql_test e_createtable-1.11.1.3 { + SELECT * FROM t1 +} {1 {no such table: t1}} +do_execsql_test e_createtable-1.11.1.4 { DROP TABLE t3 } {} +do_catchsql_test e_createtable-1.11.1.5 { + SELECT * FROM t3 +} {1 {no such table: t3}} + +do_execsql_test e_createtable-1.11.2.1 { + SELECT name FROM sqlite_master; + SELECT name FROM auxa.sqlite_master; +} {t2 t4} +do_execsql_test e_createtable-1.11.2.2 { DROP TABLE t2 } {} +do_execsql_test e_createtable-1.11.2.3 { DROP TABLE t4 } {} +do_execsql_test e_createtable-1.11.2.4 { + SELECT name FROM sqlite_master; + SELECT name FROM auxa.sqlite_master; +} {} + +#------------------------------------------------------------------------- +# Test cases e_createtable-2.* - test statements related to the CREATE +# TABLE AS ... SELECT statement. +# + +# Three Tcl commands: +# +# select_column_names SQL +# The argument must be a SELECT statement. Return a list of the names +# of the columns of the result-set that would be returned by executing +# the SELECT. +# +# table_column_names TBL +# The argument must be a table name. Return a list of column names, from +# left to right, for the table. +# +# table_column_decltypes TBL +# The argument must be a table name. Return a list of column declared +# types, from left to right, for the table. +# +proc sci {select cmd} { + set res [list] + set STMT [sqlite3_prepare_v2 db $select -1 dummy] + for {set i 0} {$i < [sqlite3_column_count $STMT]} {incr i} { + lappend res [$cmd $STMT $i] + } + sqlite3_finalize $STMT + set res +} +proc tci {tbl cmd} { sci "SELECT * FROM $tbl" $cmd } +proc select_column_names {sql} { sci $sql sqlite3_column_name } +proc table_column_names {tbl} { tci $tbl sqlite3_column_name } +proc table_column_decltypes {tbl} { tci $tbl sqlite3_column_decltype } + +# Create a database schema. This schema is used by tests 2.1.* through 2.3.*. +# +drop_all_tables +do_execsql_test e_createtable-2.0 { + CREATE TABLE t1(a, b, c); + CREATE TABLE t2(d, e, f); + CREATE TABLE t3(g BIGINT, h VARCHAR(10)); + CREATE TABLE t4(i BLOB, j ANYOLDATA); + CREATE TABLE t5(k FLOAT, l INTEGER); + CREATE TABLE t6(m DEFAULT 10, n DEFAULT 5, PRIMARY KEY(m, n)); + CREATE TABLE t7(x INTEGER PRIMARY KEY); + CREATE TABLE t8(o COLLATE nocase DEFAULT 'abc'); + CREATE TABLE t9(p NOT NULL, q DOUBLE CHECK (q!=0), r STRING UNIQUE); +} {} + +# EVIDENCE-OF: R-64828-59568 The table has the same number of columns as +# the rows returned by the SELECT statement. The name of each column is +# the same as the name of the corresponding column in the result set of +# the SELECT statement. +# +do_createtable_tests 2.1 -tclquery { + table_column_names x1 +} -repair { + catchsql { DROP TABLE x1 } +} { + 1 "CREATE TABLE x1 AS SELECT * FROM t1" {a b c} + 2 "CREATE TABLE x1 AS SELECT c, b, a FROM t1" {c b a} + 3 "CREATE TABLE x1 AS SELECT * FROM t1, t2" {a b c d e f} + 4 "CREATE TABLE x1 AS SELECT count(*) FROM t1" {count(*)} + 5 "CREATE TABLE x1 AS SELECT count(a) AS a, max(b) FROM t1" {a max(b)} +} + +# EVIDENCE-OF: R-55407-45319 The declared type of each column is +# determined by the expression affinity of the corresponding expression +# in the result set of the SELECT statement, as follows: Expression +# Affinity Column Declared Type TEXT "TEXT" NUMERIC "NUM" INTEGER "INT" +# REAL "REAL" BLOB (a.k.a "NONE") "" (empty string) +# +do_createtable_tests 2.2 -tclquery { + table_column_decltypes x1 +} -repair { + catchsql { DROP TABLE x1 } +} { + 1 "CREATE TABLE x1 AS SELECT a FROM t1" {""} + 2 "CREATE TABLE x1 AS SELECT * FROM t3" {INT TEXT} + 3 "CREATE TABLE x1 AS SELECT * FROM t4" {"" NUM} + 4 "CREATE TABLE x1 AS SELECT * FROM t5" {REAL INT} +} + +# EVIDENCE-OF: R-16667-09772 A table created using CREATE TABLE AS has +# no PRIMARY KEY and no constraints of any kind. The default value of +# each column is NULL. The default collation sequence for each column of +# the new table is BINARY. +# +# The following tests create tables based on SELECT statements that read +# from tables that have primary keys, constraints and explicit default +# collation sequences. None of this is transfered to the definition of +# the new table as stored in the sqlite_master table. +# +# Tests 2.3.2.* show that the default value of each column is NULL. +# +do_createtable_tests 2.3.1 -query { + SELECT sql FROM sqlite_master ORDER BY rowid DESC LIMIT 1 +} { + 1 "CREATE TABLE x1 AS SELECT * FROM t6" {{CREATE TABLE x1(m,n)}} + 2 "CREATE TABLE x2 AS SELECT * FROM t7" {{CREATE TABLE x2(x INT)}} + 3 "CREATE TABLE x3 AS SELECT * FROM t8" {{CREATE TABLE x3(o)}} + 4 "CREATE TABLE x4 AS SELECT * FROM t9" {{CREATE TABLE x4(p,q REAL,r NUM)}} +} +do_execsql_test e_createtable-2.3.2.1 { + INSERT INTO x1 DEFAULT VALUES; + INSERT INTO x2 DEFAULT VALUES; + INSERT INTO x3 DEFAULT VALUES; + INSERT INTO x4 DEFAULT VALUES; +} {} +db nullvalue null +do_execsql_test e_createtable-2.3.2.2 { SELECT * FROM x1 } {null null} +do_execsql_test e_createtable-2.3.2.3 { SELECT * FROM x2 } {null} +do_execsql_test e_createtable-2.3.2.4 { SELECT * FROM x3 } {null} +do_execsql_test e_createtable-2.3.2.5 { SELECT * FROM x4 } {null null null} +db nullvalue {} + +drop_all_tables +do_execsql_test e_createtable-2.4.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('i', 'one'); + INSERT INTO t1 VALUES('ii', 'two'); + INSERT INTO t1 VALUES('iii', 'three'); +} {} + +# EVIDENCE-OF: R-24153-28352 Tables created using CREATE TABLE AS are +# initially populated with the rows of data returned by the SELECT +# statement. +# +# EVIDENCE-OF: R-08224-30249 Rows are assigned contiguously ascending +# rowid values, starting with 1, in the order that they are returned by +# the SELECT statement. +# +# Each test case below is specified as the name of a table to create +# using "CREATE TABLE ... AS SELECT ..." and a SELECT statement to use in +# creating it. The table is created. +# +# Test cases 2.4.*.1 check that after it has been created, the data in the +# table is the same as the data returned by the SELECT statement executed as +# a standalone command, verifying the first testable statement above. +# +# Test cases 2.4.*.2 check that the rowids were allocated contiguously +# as required by the second testable statement above. That the rowids +# from the contiguous block were allocated to rows in the order rows are +# returned by the SELECT statement is verified by 2.4.*.1. +# +# EVIDENCE-OF: R-32365-09043 A "CREATE TABLE ... AS SELECT" statement +# creates and populates a database table based on the results of a +# SELECT statement. +# +# The above is also considered to be tested by the following. It is +# clear that tables are being created and populated by the command in +# question. +# +foreach {tn tbl select} { + 1 x1 "SELECT * FROM t1" + 2 x2 "SELECT * FROM t1 ORDER BY x DESC" + 3 x3 "SELECT * FROM t1 ORDER BY x ASC" +} { + # Create the table using a "CREATE TABLE ... AS SELECT ..." command. + execsql [subst {CREATE TABLE $tbl AS $select}] + + # Check that the rows inserted into the table, sorted in ascending rowid + # order, match those returned by executing the SELECT statement as a + # standalone command. + do_execsql_test e_createtable-2.4.$tn.1 [subst { + SELECT * FROM $tbl ORDER BY rowid; + }] [execsql $select] + + # Check that the rowids in the new table are a contiguous block starting + # with rowid 1. Note that this will fail if SELECT statement $select + # returns 0 rows (as max(rowid) will be NULL). + do_execsql_test e_createtable-2.4.$tn.2 [subst { + SELECT min(rowid), count(rowid)==max(rowid) FROM $tbl + }] {1 1} +} + +#-------------------------------------------------------------------------- +# Test cases for column defintions in CREATE TABLE statements that do not +# use a SELECT statement. Not including data constraints. In other words, +# tests for the specification of: +# +# * declared types, +# * default values, and +# * default collation sequences. +# + +# EVIDENCE-OF: R-27219-49057 Unlike most SQL databases, SQLite does not +# restrict the type of data that may be inserted into a column based on +# the columns declared type. +# +# Test this by creating a few tables with varied declared types, then +# inserting various different types of values into them. +# +drop_all_tables +do_execsql_test e_createtable-3.1.0 { + CREATE TABLE t1(x VARCHAR(10), y INTEGER, z DOUBLE); + CREATE TABLE t2(a DATETIME, b STRING, c REAL); + CREATE TABLE t3(o, t); +} {} + +# value type -> declared column type +# ---------------------------------- +# integer -> VARCHAR(10) +# string -> INTEGER +# blob -> DOUBLE +# +do_execsql_test e_createtable-3.1.1 { + INSERT INTO t1 VALUES(14, 'quite a lengthy string', X'555655'); + SELECT * FROM t1; +} {14 {quite a lengthy string} UVU} + +# string -> DATETIME +# integer -> STRING +# time -> REAL +# +do_execsql_test e_createtable-3.1.2 { + INSERT INTO t2 VALUES('not a datetime', 13, '12:41:59'); + SELECT * FROM t2; +} {{not a datetime} 13 12:41:59} + +# EVIDENCE-OF: R-10565-09557 The declared type of a column is used to +# determine the affinity of the column only. +# +# Affinities are tested in more detail elsewhere (see document +# datatype3.html). Here, just test that affinity transformations +# consistent with the expected affinity of each column (based on +# the declared type) appear to take place. +# +# Affinities of t1 (test cases 3.2.1.*): TEXT, INTEGER, REAL +# Affinities of t2 (test cases 3.2.2.*): NUMERIC, NUMERIC, REAL +# Affinities of t3 (test cases 3.2.3.*): NONE, NONE +# +do_execsql_test e_createtable-3.2.0 { DELETE FROM t1; DELETE FROM t2; } {} + +do_createtable_tests 3.2.1 -query { + SELECT quote(x), quote(y), quote(z) FROM t1 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t1 VALUES(15, '22.0', '14')" {'15' 22 14.0} + 2 "INSERT INTO t1 VALUES(22.0, 22.0, 22.0)" {'22.0' 22 22.0} +} +do_createtable_tests 3.2.2 -query { + SELECT quote(a), quote(b), quote(c) FROM t2 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t2 VALUES(15, '22.0', '14')" {15 22 14.0} + 2 "INSERT INTO t2 VALUES(22.0, 22.0, 22.0)" {22 22 22.0} +} +do_createtable_tests 3.2.3 -query { + SELECT quote(o), quote(t) FROM t3 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t3 VALUES('15', '22.0')" {'15' '22.0'} + 2 "INSERT INTO t3 VALUES(15, 22.0)" {15 22.0} +} + +# EVIDENCE-OF: R-42316-09582 If there is no explicit DEFAULT clause +# attached to a column definition, then the default value of the column +# is NULL. +# +# None of the columns in table t1 have an explicit DEFAULT clause. +# So testing that the default value of all columns in table t1 is +# NULL serves to verify the above. +# +do_createtable_tests 3.2.3 -query { + SELECT quote(x), quote(y), quote(z) FROM t1 +} -repair { + execsql { DELETE FROM t1 } +} { + 1 "INSERT INTO t1(x, y) VALUES('abc', 'xyz')" {'abc' 'xyz' NULL} + 2 "INSERT INTO t1(x, z) VALUES('abc', 'xyz')" {'abc' NULL 'xyz'} + 3 "INSERT INTO t1 DEFAULT VALUES" {NULL NULL NULL} +} + +# EVIDENCE-OF: R-07343-35026 An explicit DEFAULT clause may specify that +# the default value is NULL, a string constant, a blob constant, a +# signed-number, or any constant expression enclosed in parentheses. A +# default value may also be one of the special case-independent keywords +# CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP. +# +do_execsql_test e_createtable-3.3.1 { + CREATE TABLE t4( + a DEFAULT NULL, + b DEFAULT 'string constant', + c DEFAULT X'424C4F42', + d DEFAULT 1, + e DEFAULT -1, + f DEFAULT 3.14, + g DEFAULT -3.14, + h DEFAULT ( substr('abcd', 0, 2) || 'cd' ), + i DEFAULT CURRENT_TIME, + j DEFAULT CURRENT_DATE, + k DEFAULT CURRENT_TIMESTAMP + ); +} {} + +# EVIDENCE-OF: R-33440-07331 For the purposes of the DEFAULT clause, an +# expression is considered constant if it contains no sub-queries, +# column or table references, bound parameters, or string literals +# enclosed in double-quotes instead of single-quotes. +# +do_createtable_tests 3.4.1 -error { + default value of column [x] is not constant +} { + 1 {CREATE TABLE t5(x DEFAULT ( (SELECT 1) ))} {} + 2 {CREATE TABLE t5(x DEFAULT ( "abc" ))} {} + 3 {CREATE TABLE t5(x DEFAULT ( 1 IN (SELECT 1) ))} {} + 4 {CREATE TABLE t5(x DEFAULT ( EXISTS (SELECT 1) ))} {} + 5 {CREATE TABLE t5(x DEFAULT ( x!=?1 ))} {} +} +do_createtable_tests 3.4.2 -repair { + catchsql { DROP TABLE t5 } +} { + 1 {CREATE TABLE t5(x DEFAULT ( 'abc' ))} {} + 2 {CREATE TABLE t5(x DEFAULT ( 1 IN (1, 2, 3) ))} {} +} + +# EVIDENCE-OF: R-18814-23501 Each time a row is inserted into the table +# by an INSERT statement that does not provide explicit values for all +# table columns the values stored in the new row are determined by their +# default values +# +# Verify this with some assert statements for which all, some and no +# columns lack explicit values. +# +set sqlite_current_time 1000000000 +do_createtable_tests 3.5 -query { + SELECT quote(a), quote(b), quote(c), quote(d), quote(e), quote(f), + quote(g), quote(h), quote(i), quote(j), quote(k) + FROM t4 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t4 DEFAULT VALUES" { + NULL {'string constant'} X'424C4F42' 1 -1 3.14 -3.14 + 'acd' '01:46:40' '2001-09-09' {'2001-09-09 01:46:40'} + } + + 2 "INSERT INTO t4(a, b, c) VALUES(1, 2, 3)" { + 1 2 3 1 -1 3.14 -3.14 'acd' '01:46:40' '2001-09-09' {'2001-09-09 01:46:40'} + } + + 3 "INSERT INTO t4(k, j, i) VALUES(1, 2, 3)" { + NULL {'string constant'} X'424C4F42' 1 -1 3.14 -3.14 'acd' 3 2 1 + } + + 4 "INSERT INTO t4(a,b,c,d,e,f,g,h,i,j,k) VALUES(1,2,3,4,5,6,7,8,9,10,11)" { + 1 2 3 4 5 6 7 8 9 10 11 + } +} + +# EVIDENCE-OF: R-12572-62501 If the default value of the column is a +# constant NULL, text, blob or signed-number value, then that value is +# used directly in the new row. +# +do_execsql_test e_createtable-3.6.1 { + CREATE TABLE t5( + a DEFAULT NULL, + b DEFAULT 'text value', + c DEFAULT X'424C4F42', + d DEFAULT -45678.6, + e DEFAULT 394507 + ); +} {} +do_execsql_test e_createtable-3.6.2 { + INSERT INTO t5 DEFAULT VALUES; + SELECT quote(a), quote(b), quote(c), quote(d), quote(e) FROM t5; +} {NULL {'text value'} X'424C4F42' -45678.6 394507} + +# EVIDENCE-OF: R-60616-50251 If the default value of a column is an +# expression in parentheses, then the expression is evaluated once for +# each row inserted and the results used in the new row. +# +# Test case 3.6.4 demonstrates that the expression is evaluated +# separately for each row if the INSERT is an "INSERT INTO ... SELECT ..." +# command. +# +set ::nextint 0 +proc nextint {} { incr ::nextint } +db func nextint nextint + +do_execsql_test e_createtable-3.7.1 { + CREATE TABLE t6(a DEFAULT ( nextint() ), b DEFAULT ( nextint() )); +} {} +do_execsql_test e_createtable-3.7.2 { + INSERT INTO t6 DEFAULT VALUES; + SELECT quote(a), quote(b) FROM t6; +} {1 2} +do_execsql_test e_createtable-3.7.3 { + INSERT INTO t6(a) VALUES('X'); + SELECT quote(a), quote(b) FROM t6; +} {1 2 'X' 3} +do_execsql_test e_createtable-3.7.4 { + INSERT INTO t6(a) SELECT a FROM t6; + SELECT quote(a), quote(b) FROM t6; +} {1 2 'X' 3 1 4 'X' 5} + +# EVIDENCE-OF: R-15363-55230 If the default value of a column is +# CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP, then the value used +# in the new row is a text representation of the current UTC date and/or +# time. +# +# This is difficult to test literally without knowing what time the +# user will run the tests. Instead, we test that the three cases +# above set the value to the current date and/or time according to +# the xCurrentTime() method of the VFS. Which is usually the same +# as UTC. In this case, however, we instrument it to always return +# a time equivalent to "2001-09-09 01:46:40 UTC". +# +set sqlite_current_time 1000000000 +do_execsql_test e_createtable-3.8.1 { + CREATE TABLE t7( + a DEFAULT CURRENT_TIME, + b DEFAULT CURRENT_DATE, + c DEFAULT CURRENT_TIMESTAMP + ); +} {} +do_execsql_test e_createtable-3.8.2 { + INSERT INTO t7 DEFAULT VALUES; + SELECT quote(a), quote(b), quote(c) FROM t7; +} {'01:46:40' '2001-09-09' {'2001-09-09 01:46:40'}} + + +# EVIDENCE-OF: R-62327-53843 For CURRENT_TIME, the format of the value +# is "HH:MM:SS". +# +# EVIDENCE-OF: R-03775-43471 For CURRENT_DATE, "YYYY-MM-DD". +# +# EVIDENCE-OF: R-07677-44926 The format for CURRENT_TIMESTAMP is +# "YYYY-MM-DD HH:MM:SS". +# +# The three above are demonstrated by tests 1, 2 and 3 below. +# Respectively. +# +do_createtable_tests 3.8.3 -query { + SELECT a, b, c FROM t7 ORDER BY rowid DESC LIMIT 1; +} { + 1 "INSERT INTO t7(b, c) VALUES('x', 'y')" {01:46:40 x y} + 2 "INSERT INTO t7(c, a) VALUES('x', 'y')" {y 2001-09-09 x} + 3 "INSERT INTO t7(a, b) VALUES('x', 'y')" {x y {2001-09-09 01:46:40}} +} + +# EVIDENCE-OF: R-55061-47754 The COLLATE clause specifies the name of a +# collating sequence to use as the default collation sequence for the +# column. +# +# EVIDENCE-OF: R-40275-54363 If no COLLATE clause is specified, the +# default collation sequence is BINARY. +# +do_execsql_test e_createtable-3-9.1 { + CREATE TABLE t8(a COLLATE nocase, b COLLATE rtrim, c COLLATE binary, d); + INSERT INTO t8 VALUES('abc', 'abc', 'abc', 'abc'); + INSERT INTO t8 VALUES('abc ', 'abc ', 'abc ', 'abc '); + INSERT INTO t8 VALUES('ABC ', 'ABC ', 'ABC ', 'ABC '); + INSERT INTO t8 VALUES('ABC', 'ABC', 'ABC', 'ABC'); +} {} +do_createtable_tests 3.9 { + 2 "SELECT a FROM t8 ORDER BY a, rowid" {abc ABC {abc } {ABC }} + 3 "SELECT b FROM t8 ORDER BY b, rowid" {{ABC } ABC abc {abc }} + 4 "SELECT c FROM t8 ORDER BY c, rowid" {ABC {ABC } abc {abc }} + 5 "SELECT d FROM t8 ORDER BY d, rowid" {ABC {ABC } abc {abc }} +} + +# EVIDENCE-OF: R-25473-20557 The number of columns in a table is limited +# by the SQLITE_MAX_COLUMN compile-time parameter. +# +proc columns {n} { + set res [list] + for {set i 0} {$i < $n} {incr i} { lappend res "c$i" } + join $res ", " +} +do_execsql_test e_createtable-3.10.1 [subst { + CREATE TABLE t9([columns $::SQLITE_MAX_COLUMN]); +}] {} +do_catchsql_test e_createtable-3.10.2 [subst { + CREATE TABLE t10([columns [expr $::SQLITE_MAX_COLUMN+1]]); +}] {1 {too many columns on t10}} + +# EVIDENCE-OF: R-27775-64721 Both of these limits can be lowered at +# runtime using the sqlite3_limit() C/C++ interface. +# +# A 30,000 byte blob consumes 30,003 bytes of record space. A record +# that contains 3 such blobs consumes (30,000*3)+1 bytes of space. Tests +# 3.11.4 and 3.11.5, which verify that SQLITE_MAX_LENGTH may be lowered +# at runtime, are based on this calculation. +# +sqlite3_limit db SQLITE_LIMIT_COLUMN 500 +do_execsql_test e_createtable-3.11.1 [subst { + CREATE TABLE t10([columns 500]); +}] {} +do_catchsql_test e_createtable-3.11.2 [subst { + CREATE TABLE t11([columns 501]); +}] {1 {too many columns on t11}} + +# Check that it is not possible to raise the column limit above its +# default compile time value. +# +sqlite3_limit db SQLITE_LIMIT_COLUMN [expr $::SQLITE_MAX_COLUMN+2] +do_catchsql_test e_createtable-3.11.3 [subst { + CREATE TABLE t11([columns [expr $::SQLITE_MAX_COLUMN+1]]); +}] {1 {too many columns on t11}} + +sqlite3_limit db SQLITE_LIMIT_LENGTH 90010 +do_execsql_test e_createtable-3.11.4 { + CREATE TABLE t12(a, b, c); + INSERT INTO t12 VALUES(randomblob(30000),randomblob(30000),randomblob(30000)); +} {} +do_catchsql_test e_createtable-3.11.5 { + INSERT INTO t12 VALUES(randomblob(30001),randomblob(30000),randomblob(30000)); +} {1 {string or blob too big}} + +#------------------------------------------------------------------------- +# Tests for statements regarding constraints (PRIMARY KEY, UNIQUE, NOT +# NULL and CHECK constraints). +# + +# EVIDENCE-OF: R-52382-54248 Each table in SQLite may have at most one +# PRIMARY KEY. +# +# EVIDENCE-OF: R-31826-01813 An error is raised if more than one PRIMARY +# KEY clause appears in a CREATE TABLE statement. +# +# To test the two above, show that zero primary keys is Ok, one primary +# key is Ok, and two or more primary keys is an error. +# +drop_all_tables +do_createtable_tests 4.1.1 { + 1 "CREATE TABLE t1(a, b, c)" {} + 2 "CREATE TABLE t2(a PRIMARY KEY, b, c)" {} + 3 "CREATE TABLE t3(a, b, c, PRIMARY KEY(a))" {} + 4 "CREATE TABLE t4(a, b, c, PRIMARY KEY(c,b,a))" {} +} +do_createtable_tests 4.1.2 -error { + table "t5" has more than one primary key +} { + 1 "CREATE TABLE t5(a PRIMARY KEY, b PRIMARY KEY, c)" {} + 2 "CREATE TABLE t5(a, b PRIMARY KEY, c, PRIMARY KEY(a))" {} + 3 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b PRIMARY KEY, c)" {} + 4 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b, c, PRIMARY KEY(b, c))" {} + 5 "CREATE TABLE t5(a PRIMARY KEY, b, c, PRIMARY KEY(a))" {} + 6 "CREATE TABLE t5(a INTEGER PRIMARY KEY, b, c, PRIMARY KEY(a))" {} +} + +# EVIDENCE-OF: R-54755-39291 The PRIMARY KEY is optional for ordinary +# tables but is required for WITHOUT ROWID tables. +# +do_catchsql_test 4.1.3 { + CREATE TABLE t6(a, b); --ok +} {0 {}} +do_catchsql_test 4.1.4 { + CREATE TABLE t7(a, b) WITHOUT ROWID; --Error, no PRIMARY KEY +} {1 {PRIMARY KEY missing on table t7}} + + +proc table_pk {tbl} { + set pk [list] + db eval "pragma table_info($tbl)" a { + if {$a(pk)} { lappend pk $a(name) } + } + set pk +} + +# EVIDENCE-OF: R-41411-18837 If the keywords PRIMARY KEY are added to a +# column definition, then the primary key for the table consists of that +# single column. +# +# The above is tested by 4.2.1.* +# +# EVIDENCE-OF: R-31775-48204 Or, if a PRIMARY KEY clause is specified as +# a table-constraint, then the primary key of the table consists of the +# list of columns specified as part of the PRIMARY KEY clause. +# +# The above is tested by 4.2.2.* +# +do_createtable_tests 4.2 -repair { + catchsql { DROP TABLE t5 } +} -tclquery { + table_pk t5 +} { + 1.1 "CREATE TABLE t5(a, b INTEGER PRIMARY KEY, c)" {b} + 1.2 "CREATE TABLE t5(a PRIMARY KEY, b, c)" {a} + + 2.1 "CREATE TABLE t5(a, b, c, PRIMARY KEY(a))" {a} + 2.2 "CREATE TABLE t5(a, b, c, PRIMARY KEY(c,b,a))" {a b c} + 2.3 "CREATE TABLE t5(a, b INTEGER PRIMARY KEY, c)" {b} +} + +# EVIDENCE-OF: R-59124-61339 Each row in a table with a primary key must +# have a unique combination of values in its primary key columns. +# +# EVIDENCE-OF: R-06471-16287 If an INSERT or UPDATE statement attempts +# to modify the table content so that two or more rows have identical +# primary key values, that is a constraint violation. +# +drop_all_tables +do_execsql_test 4.3.0 { + CREATE TABLE t1(x PRIMARY KEY, y); + INSERT INTO t1 VALUES(0, 'zero'); + INSERT INTO t1 VALUES(45.5, 'one'); + INSERT INTO t1 VALUES('brambles', 'two'); + INSERT INTO t1 VALUES(X'ABCDEF', 'three'); + + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)); + INSERT INTO t2 VALUES(0, 'zero'); + INSERT INTO t2 VALUES(45.5, 'one'); + INSERT INTO t2 VALUES('brambles', 'two'); + INSERT INTO t2 VALUES(X'ABCDEF', 'three'); +} {} + +do_createtable_tests 4.3.1 -error {UNIQUE constraint failed: t1.x} { + 1 "INSERT INTO t1 VALUES(0, 0)" {"column x is"} + 2 "INSERT INTO t1 VALUES(45.5, 'abc')" {"column x is"} + 3 "INSERT INTO t1 VALUES(0.0, 'abc')" {"column x is"} + 4 "INSERT INTO t1 VALUES('brambles', 'abc')" {"column x is"} + 5 "INSERT INTO t1 VALUES(X'ABCDEF', 'abc')" {"column x is"} +} +do_createtable_tests 4.3.1 -error {UNIQUE constraint failed: t2.x, t2.y} { + 6 "INSERT INTO t2 VALUES(0, 'zero')" {"columns x, y are"} + 7 "INSERT INTO t2 VALUES(45.5, 'one')" {"columns x, y are"} + 8 "INSERT INTO t2 VALUES(0.0, 'zero')" {"columns x, y are"} + 9 "INSERT INTO t2 VALUES('brambles', 'two')" {"columns x, y are"} + 10 "INSERT INTO t2 VALUES(X'ABCDEF', 'three')" {"columns x, y are"} +} +do_createtable_tests 4.3.2 { + 1 "INSERT INTO t1 VALUES(-1, 0)" {} + 2 "INSERT INTO t1 VALUES(45.2, 'abc')" {} + 3 "INSERT INTO t1 VALUES(0.01, 'abc')" {} + 4 "INSERT INTO t1 VALUES('bramble', 'abc')" {} + 5 "INSERT INTO t1 VALUES(X'ABCDEE', 'abc')" {} + + 6 "INSERT INTO t2 VALUES(0, 0)" {} + 7 "INSERT INTO t2 VALUES(45.5, 'abc')" {} + 8 "INSERT INTO t2 VALUES(0.0, 'abc')" {} + 9 "INSERT INTO t2 VALUES('brambles', 'abc')" {} + 10 "INSERT INTO t2 VALUES(X'ABCDEF', 'abc')" {} +} +do_createtable_tests 4.3.3 -error {UNIQUE constraint failed: t1.x} { + 1 "UPDATE t1 SET x=0 WHERE y='two'" {"column x is"} + 2 "UPDATE t1 SET x='brambles' WHERE y='three'" {"column x is"} + 3 "UPDATE t1 SET x=45.5 WHERE y='zero'" {"column x is"} + 4 "UPDATE t1 SET x=X'ABCDEF' WHERE y='one'" {"column x is"} + 5 "UPDATE t1 SET x=0.0 WHERE y='three'" {"column x is"} +} +do_createtable_tests 4.3.3 -error {UNIQUE constraint failed: t2.x, t2.y} { + 6 "UPDATE t2 SET x=0, y='zero' WHERE y='two'" {"columns x, y are"} + 7 "UPDATE t2 SET x='brambles', y='two' WHERE y='three'" + {"columns x, y are"} + 8 "UPDATE t2 SET x=45.5, y='one' WHERE y='zero'" {"columns x, y are"} + 9 "UPDATE t2 SET x=X'ABCDEF', y='three' WHERE y='one'" + {"columns x, y are"} + 10 "UPDATE t2 SET x=0.0, y='zero' WHERE y='three'" + {"columns x, y are"} +} + + +# EVIDENCE-OF: R-52572-02078 For the purposes of determining the +# uniqueness of primary key values, NULL values are considered distinct +# from all other values, including other NULLs. +# +do_createtable_tests 4.4 { + 1 "INSERT INTO t1 VALUES(NULL, 0)" {} + 2 "INSERT INTO t1 VALUES(NULL, 0)" {} + 3 "INSERT INTO t1 VALUES(NULL, 0)" {} + + 4 "INSERT INTO t2 VALUES(NULL, 'zero')" {} + 5 "INSERT INTO t2 VALUES(NULL, 'one')" {} + 6 "INSERT INTO t2 VALUES(NULL, 'two')" {} + 7 "INSERT INTO t2 VALUES(NULL, 'three')" {} + + 8 "INSERT INTO t2 VALUES(0, NULL)" {} + 9 "INSERT INTO t2 VALUES(45.5, NULL)" {} + 10 "INSERT INTO t2 VALUES(0.0, NULL)" {} + 11 "INSERT INTO t2 VALUES('brambles', NULL)" {} + 12 "INSERT INTO t2 VALUES(X'ABCDEF', NULL)" {} + + 13 "INSERT INTO t2 VALUES(NULL, NULL)" {} + 14 "INSERT INTO t2 VALUES(NULL, NULL)" {} +} + +# EVIDENCE-OF: R-40010-16873 Unless the column is an INTEGER PRIMARY KEY +# or the table is a WITHOUT ROWID table or a STRICT table or the column +# is declared NOT NULL, SQLite allows NULL values in a PRIMARY KEY +# column. +# +# If the column is an integer primary key, attempting to insert a NULL +# into the column triggers the auto-increment behavior. Attempting +# to use UPDATE to set an ipk column to a NULL value is an error. +# +do_createtable_tests 4.5.1 { + 1 "SELECT count(*) FROM t1 WHERE x IS NULL" 3 + 2 "SELECT count(*) FROM t2 WHERE x IS NULL" 6 + 3 "SELECT count(*) FROM t2 WHERE y IS NULL" 7 + 4 "SELECT count(*) FROM t2 WHERE x IS NULL AND y IS NULL" 2 +} +do_execsql_test 4.5.2 { + CREATE TABLE t3(s, u INTEGER PRIMARY KEY, v); + INSERT INTO t3 VALUES(1, NULL, 2); + INSERT INTO t3 VALUES('x', NULL, 'y'); + SELECT u FROM t3; +} {1 2} +do_catchsql_test 4.5.3 { + INSERT INTO t3 VALUES(2, 5, 3); + UPDATE t3 SET u = NULL WHERE s = 2; +} {1 {datatype mismatch}} +do_catchsql_test 4.5.4 { + CREATE TABLE t4(s, u INT PRIMARY KEY, v) WITHOUT ROWID; + INSERT INTO t4 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t4.u}} +do_catchsql_test 4.5.5 { + CREATE TABLE t5(s, u INT PRIMARY KEY NOT NULL, v); + INSERT INTO t5 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t5.u}} +do_catchsql_test 4.5.6 { + CREATE TABLE t6(s INT, u INT PRIMARY KEY, v INT) STRICT; + INSERT INTO t6 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t6.u}} +do_catchsql_test 4.5.7 { + CREATE TABLE t7(s INT, u INT PRIMARY KEY NOT NULL, v INT) STRICT; + INSERT INTO t7 VALUES(1, NULL, 2); +} {1 {NOT NULL constraint failed: t7.u}} + +# EVIDENCE-OF: R-00227-21080 A UNIQUE constraint is similar to a PRIMARY +# KEY constraint, except that a single table may have any number of +# UNIQUE constraints. +# +drop_all_tables +do_createtable_tests 4.6 { + 1 "CREATE TABLE t1(a UNIQUE, b UNIQUE)" {} + 2 "CREATE TABLE t2(a UNIQUE, b, c, UNIQUE(c, b))" {} + 3 "CREATE TABLE t3(a, b, c, UNIQUE(a), UNIQUE(b), UNIQUE(c))" {} + 4 "CREATE TABLE t4(a, b, c, UNIQUE(a, b, c))" {} +} + +# EVIDENCE-OF: R-30981-64168 For each UNIQUE constraint on the table, +# each row must contain a unique combination of values in the columns +# identified by the UNIQUE constraint. +# +# EVIDENCE-OF: R-59124-61339 Each row in a table with a primary key must +# have a unique combination of values in its primary key columns. +# +do_execsql_test 4.7.0 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(4.3, 5.5); + INSERT INTO t1 VALUES('reveal', 'variableness'); + INSERT INTO t1 VALUES(X'123456', X'654321'); + + INSERT INTO t4 VALUES('xyx', 1, 1); + INSERT INTO t4 VALUES('xyx', 2, 1); + INSERT INTO t4 VALUES('uvw', 1, 1); +} +do_createtable_tests 4.7.1 -error {UNIQUE constraint failed: %s} { + 1 "INSERT INTO t1 VALUES(1, 'one')" {{t1.a}} + 2 "INSERT INTO t1 VALUES(4.3, 'two')" {{t1.a}} + 3 "INSERT INTO t1 VALUES('reveal', 'three')" {{t1.a}} + 4 "INSERT INTO t1 VALUES(X'123456', 'four')" {{t1.a}} + + 5 "UPDATE t1 SET a = 1 WHERE rowid=2" {{t1.a}} + 6 "UPDATE t1 SET a = 4.3 WHERE rowid=3" {{t1.a}} + 7 "UPDATE t1 SET a = 'reveal' WHERE rowid=4" {{t1.a}} + 8 "UPDATE t1 SET a = X'123456' WHERE rowid=1" {{t1.a}} + + 9 "INSERT INTO t4 VALUES('xyx', 1, 1)" {{t4.a, t4.b, t4.c}} + 10 "INSERT INTO t4 VALUES('xyx', 2, 1)" {{t4.a, t4.b, t4.c}} + 11 "INSERT INTO t4 VALUES('uvw', 1, 1)" {{t4.a, t4.b, t4.c}} + + 12 "UPDATE t4 SET a='xyx' WHERE rowid=3" {{t4.a, t4.b, t4.c}} + 13 "UPDATE t4 SET b=1 WHERE rowid=2" {{t4.a, t4.b, t4.c}} + 14 "UPDATE t4 SET a=0, b=0, c=0" {{t4.a, t4.b, t4.c}} +} + +# EVIDENCE-OF: R-00404-17670 For the purposes of UNIQUE constraints, +# NULL values are considered distinct from all other values, including +# other NULLs. +# +do_createtable_tests 4.8 { + 1 "INSERT INTO t1 VALUES(NULL, NULL)" {} + 2 "INSERT INTO t1 VALUES(NULL, NULL)" {} + 3 "UPDATE t1 SET a = NULL" {} + 4 "UPDATE t1 SET b = NULL" {} + + 5 "INSERT INTO t4 VALUES(NULL, NULL, NULL)" {} + 6 "INSERT INTO t4 VALUES(NULL, NULL, NULL)" {} + 7 "UPDATE t4 SET a = NULL" {} + 8 "UPDATE t4 SET b = NULL" {} + 9 "UPDATE t4 SET c = NULL" {} +} + +# EVIDENCE-OF: R-55820-29984 In most cases, UNIQUE and PRIMARY KEY +# constraints are implemented by creating a unique index in the +# database. +do_createtable_tests 4.9 -repair drop_all_tables -query { + SELECT count(*) FROM sqlite_master WHERE type='index' +} { + 1 "CREATE TABLE t1(a TEXT PRIMARY KEY, b)" 1 + 2 "CREATE TABLE t1(a INTEGER PRIMARY KEY, b)" 0 + 3 "CREATE TABLE t1(a TEXT UNIQUE, b)" 1 + 4 "CREATE TABLE t1(a PRIMARY KEY, b TEXT UNIQUE)" 2 + 5 "CREATE TABLE t1(a PRIMARY KEY, b, c, UNIQUE(c, b))" 2 +} + +# Obsolete: R-02252-33116 Such an index is used like any other index +# in the database to optimize queries. +# +do_execsql_test 4.10.0 { + CREATE TABLE t1(a, b PRIMARY KEY); + CREATE TABLE t2(a, b, c, UNIQUE(b, c)); +} +do_createtable_tests 4.10 { + 1 "EXPLAIN QUERY PLAN SELECT * FROM t1 WHERE b = 5" + {/*SEARCH t1 USING INDEX sqlite_autoindex_t1_1 (b=?)*/} + + 2 "EXPLAIN QUERY PLAN SELECT * FROM t2 ORDER BY b, c" + {/*SCAN t2 USING INDEX sqlite_autoindex_t2_1*/} + + 3 "EXPLAIN QUERY PLAN SELECT * FROM t2 WHERE b=10 AND c>10" + {/*SEARCH t2 USING INDEX sqlite_autoindex_t2_1 (b=? AND c>?)*/} +} + +# EVIDENCE-OF: R-45493-35653 A CHECK constraint may be attached to a +# column definition or specified as a table constraint. In practice it +# makes no difference. +# +# All the tests that deal with CHECK constraints below (4.11.* and +# 4.12.*) are run once for a table with the check constraint attached +# to a column definition, and once with a table where the check +# condition is specified as a table constraint. +# +# EVIDENCE-OF: R-55435-14303 Each time a new row is inserted into the +# table or an existing row is updated, the expression associated with +# each CHECK constraint is evaluated and cast to a NUMERIC value in the +# same way as a CAST expression. If the result is zero (integer value 0 +# or real value 0.0), then a constraint violation has occurred. +# +drop_all_tables +do_execsql_test 4.11 { + CREATE TABLE x1(a TEXT, b INTEGER CHECK( b>0 )); + CREATE TABLE t1(a TEXT, b INTEGER, CHECK( b>0 )); + INSERT INTO x1 VALUES('x', 'xx'); + INSERT INTO x1 VALUES('y', 'yy'); + INSERT INTO t1 SELECT * FROM x1; + + CREATE TABLE x2(a CHECK( a||b ), b); + CREATE TABLE t2(a, b, CHECK( a||b )); + INSERT INTO x2 VALUES(1, 'xx'); + INSERT INTO x2 VALUES(1, 'yy'); + INSERT INTO t2 SELECT * FROM x2; +} + +do_createtable_tests 4.11 -error {CHECK constraint failed: %s} { + 1a "INSERT INTO x1 VALUES('one', 0)" {b>0} + 1b "INSERT INTO t1 VALUES('one', -4.0)" {b>0} + + 2a "INSERT INTO x2 VALUES('abc', 1)" {a||b} + 2b "INSERT INTO t2 VALUES('abc', 1)" {a||b} + + 3a "INSERT INTO x2 VALUES(0, 'abc')" {a||b} + 3b "INSERT INTO t2 VALUES(0, 'abc')" {a||b} + + 4a "UPDATE t1 SET b=-1 WHERE rowid=1" {b>0} + 4b "UPDATE x1 SET b=-1 WHERE rowid=1" {b>0} + + 4a "UPDATE x2 SET a='' WHERE rowid=1" {a||b} + 4b "UPDATE t2 SET a='' WHERE rowid=1" {a||b} +} + +# EVIDENCE-OF: R-34109-39108 If the CHECK expression evaluates to NULL, +# or any other non-zero value, it is not a constraint violation. +# +do_createtable_tests 4.12 { + 1a "INSERT INTO x1 VALUES('one', NULL)" {} + 1b "INSERT INTO t1 VALUES('one', NULL)" {} + + 2a "INSERT INTO x1 VALUES('one', 2)" {} + 2b "INSERT INTO t1 VALUES('one', 2)" {} + + 3a "INSERT INTO x2 VALUES(1, 'abc')" {} + 3b "INSERT INTO t2 VALUES(1, 'abc')" {} +} + +# EVIDENCE-OF: R-02060-64547 A NOT NULL constraint may only be attached +# to a column definition, not specified as a table constraint. +# +drop_all_tables +do_createtable_tests 4.13.1 { + 1 "CREATE TABLE t1(a NOT NULL, b)" {} + 2 "CREATE TABLE t2(a PRIMARY KEY NOT NULL, b)" {} + 3 "CREATE TABLE t3(a NOT NULL, b NOT NULL, c NOT NULL UNIQUE)" {} +} +do_createtable_tests 4.13.2 -error { + near "NOT": syntax error +} { + 1 "CREATE TABLE t4(a, b, NOT NULL(a))" {} + 2 "CREATE TABLE t4(a PRIMARY KEY, b, NOT NULL(a))" {} + 3 "CREATE TABLE t4(a, b, c UNIQUE, NOT NULL(a, b, c))" {} +} + +# EVIDENCE-OF: R-31795-57643 a NOT NULL constraint dictates that the +# associated column may not contain a NULL value. Attempting to set the +# column value to NULL when inserting a new row or updating an existing +# one causes a constraint violation. +# +# These tests use the tables created by 4.13. +# +do_execsql_test 4.14.0 { + INSERT INTO t1 VALUES('x', 'y'); + INSERT INTO t1 VALUES('z', NULL); + + INSERT INTO t2 VALUES('x', 'y'); + INSERT INTO t2 VALUES('z', NULL); + + INSERT INTO t3 VALUES('x', 'y', 'z'); + INSERT INTO t3 VALUES(1, 2, 3); +} +do_createtable_tests 4.14 -error {NOT NULL constraint failed: %s} { + 1 "INSERT INTO t1 VALUES(NULL, 'a')" {t1.a} + 2 "INSERT INTO t2 VALUES(NULL, 'b')" {t2.a} + 3 "INSERT INTO t3 VALUES('c', 'd', NULL)" {t3.c} + 4 "INSERT INTO t3 VALUES('e', NULL, 'f')" {t3.b} + 5 "INSERT INTO t3 VALUES(NULL, 'g', 'h')" {t3.a} +} + +# EVIDENCE-OF: R-34093-09213 PRIMARY KEY, UNIQUE and NOT NULL +# constraints may be explicitly assigned another default conflict +# resolution algorithm by including a conflict-clause in their +# definitions. +# +# Conflict clauses: ABORT, ROLLBACK, IGNORE, FAIL, REPLACE +# +# Test cases 4.15.*, 4.16.* and 4.17.* focus on PRIMARY KEY, NOT NULL +# and UNIQUE constraints, respectively. +# +drop_all_tables +do_execsql_test 4.15.0 { + CREATE TABLE t1_ab(a PRIMARY KEY ON CONFLICT ABORT, b); + CREATE TABLE t1_ro(a PRIMARY KEY ON CONFLICT ROLLBACK, b); + CREATE TABLE t1_ig(a PRIMARY KEY ON CONFLICT IGNORE, b); + CREATE TABLE t1_fa(a PRIMARY KEY ON CONFLICT FAIL, b); + CREATE TABLE t1_re(a PRIMARY KEY ON CONFLICT REPLACE, b); + CREATE TABLE t1_xx(a PRIMARY KEY, b); + + INSERT INTO t1_ab VALUES(1, 'one'); + INSERT INTO t1_ab VALUES(2, 'two'); + INSERT INTO t1_ro SELECT * FROM t1_ab; + INSERT INTO t1_ig SELECT * FROM t1_ab; + INSERT INTO t1_fa SELECT * FROM t1_ab; + INSERT INTO t1_re SELECT * FROM t1_ab; + INSERT INTO t1_xx SELECT * FROM t1_ab; + + CREATE TABLE t2_ab(a, b NOT NULL ON CONFLICT ABORT); + CREATE TABLE t2_ro(a, b NOT NULL ON CONFLICT ROLLBACK); + CREATE TABLE t2_ig(a, b NOT NULL ON CONFLICT IGNORE); + CREATE TABLE t2_fa(a, b NOT NULL ON CONFLICT FAIL); + CREATE TABLE t2_re(a, b NOT NULL ON CONFLICT REPLACE); + CREATE TABLE t2_xx(a, b NOT NULL); + + INSERT INTO t2_ab VALUES(1, 'one'); + INSERT INTO t2_ab VALUES(2, 'two'); + INSERT INTO t2_ro SELECT * FROM t2_ab; + INSERT INTO t2_ig SELECT * FROM t2_ab; + INSERT INTO t2_fa SELECT * FROM t2_ab; + INSERT INTO t2_re SELECT * FROM t2_ab; + INSERT INTO t2_xx SELECT * FROM t2_ab; + + CREATE TABLE t3_ab(a, b, UNIQUE(a, b) ON CONFLICT ABORT); + CREATE TABLE t3_ro(a, b, UNIQUE(a, b) ON CONFLICT ROLLBACK); + CREATE TABLE t3_ig(a, b, UNIQUE(a, b) ON CONFLICT IGNORE); + CREATE TABLE t3_fa(a, b, UNIQUE(a, b) ON CONFLICT FAIL); + CREATE TABLE t3_re(a, b, UNIQUE(a, b) ON CONFLICT REPLACE); + CREATE TABLE t3_xx(a, b, UNIQUE(a, b)); + + INSERT INTO t3_ab VALUES(1, 'one'); + INSERT INTO t3_ab VALUES(2, 'two'); + INSERT INTO t3_ro SELECT * FROM t3_ab; + INSERT INTO t3_ig SELECT * FROM t3_ab; + INSERT INTO t3_fa SELECT * FROM t3_ab; + INSERT INTO t3_re SELECT * FROM t3_ab; + INSERT INTO t3_xx SELECT * FROM t3_ab; +} + +foreach {tn tbl res ac data} { + 1 t1_ab {1 {UNIQUE constraint failed: t1_ab.a}} 0 {1 one 2 two 3 three} + 2 t1_ro {1 {UNIQUE constraint failed: t1_ro.a}} 1 {1 one 2 two} + 3 t1_fa {1 {UNIQUE constraint failed: t1_fa.a}} 0 {1 one 2 two 3 three 4 string} + 4 t1_ig {0 {}} 0 {1 one 2 two 3 three 4 string 6 string} + 5 t1_re {0 {}} 0 {1 one 2 two 4 string 3 string 6 string} + 6 t1_xx {1 {UNIQUE constraint failed: t1_xx.a}} 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.15.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.15.$tn.2 " + INSERT INTO $tbl SELECT ((a%2)*a+3), 'string' FROM $tbl; + " $res + + do_test e_createtable-4.15.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.15.$tn.4 "SELECT * FROM $tbl" $data +} +foreach {tn tbl res ac data} { + 1 t2_ab {1 {NOT NULL constraint failed: t2_ab.b}} 0 {1 one 2 two 3 three} + 2 t2_ro {1 {NOT NULL constraint failed: t2_ro.b}} 1 {1 one 2 two} + 3 t2_fa {1 {NOT NULL constraint failed: t2_fa.b}} 0 {1 one 2 two 3 three 4 xx} + 4 t2_ig {0 {}} 0 {1 one 2 two 3 three 4 xx 6 xx} + 5 t2_re {1 {NOT NULL constraint failed: t2_re.b}} 0 {1 one 2 two 3 three} + 6 t2_xx {1 {NOT NULL constraint failed: t2_xx.b}} 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.16.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.16.$tn.2 " + INSERT INTO $tbl SELECT a+3, CASE a WHEN 2 THEN NULL ELSE 'xx' END FROM $tbl + " $res + + do_test e_createtable-4.16.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.16.$tn.4 "SELECT * FROM $tbl" $data +} +foreach {tn tbl res ac data} { + 1 t3_ab {1 {UNIQUE constraint failed: t3_ab.a, t3_ab.b}} + 0 {1 one 2 two 3 three} + 2 t3_ro {1 {UNIQUE constraint failed: t3_ro.a, t3_ro.b}} + 1 {1 one 2 two} + 3 t3_fa {1 {UNIQUE constraint failed: t3_fa.a, t3_fa.b}} + 0 {1 one 2 two 3 three 4 three} + 4 t3_ig {0 {}} 0 {1 one 2 two 3 three 4 three 6 three} + 5 t3_re {0 {}} 0 {1 one 2 two 4 three 3 three 6 three} + 6 t3_xx {1 {UNIQUE constraint failed: t3_xx.a, t3_xx.b}} + 0 {1 one 2 two 3 three} +} { + catchsql COMMIT + do_execsql_test 4.17.$tn.1 "BEGIN; INSERT INTO $tbl VALUES(3, 'three')" + + do_catchsql_test 4.17.$tn.2 " + INSERT INTO $tbl SELECT ((a%2)*a+3), 'three' FROM $tbl + " $res + + do_test e_createtable-4.17.$tn.3 { sqlite3_get_autocommit db } $ac + do_execsql_test 4.17.$tn.4 "SELECT * FROM $tbl ORDER BY rowid" $data +} +catchsql COMMIT + +# EVIDENCE-OF: R-17539-59899 Or, if a constraint definition does not +# include a conflict-clause, the default conflict resolution algorithm +# is ABORT. +# +# The first half of the above is tested along with explicit ON +# CONFLICT clauses above (specifically, the tests involving t1_xx, t2_xx +# and t3_xx). The following just tests that the default conflict +# handling for CHECK constraints is ABORT. +# +do_execsql_test 4.18.1 { + CREATE TABLE t4(a, b CHECK (b!=10)); + INSERT INTO t4 VALUES(1, 2); + INSERT INTO t4 VALUES(3, 4); +} +do_execsql_test 4.18.2 { BEGIN; INSERT INTO t4 VALUES(5, 6) } +do_catchsql_test 4.18.3 { + INSERT INTO t4 SELECT a+4, b+4 FROM t4 +} {1 {CHECK constraint failed: b!=10}} +do_test e_createtable-4.18.4 { sqlite3_get_autocommit db } 0 +do_execsql_test 4.18.5 { SELECT * FROM t4 } {1 2 3 4 5 6} + +# EVIDENCE-OF: R-19114-56113 Different constraints within the same table +# may have different default conflict resolution algorithms. +# +do_execsql_test 4.19.0 { + CREATE TABLE t5(a NOT NULL ON CONFLICT IGNORE, b NOT NULL ON CONFLICT ABORT); +} +do_catchsql_test 4.19.1 { INSERT INTO t5 VALUES(NULL, 'not null') } {0 {}} +do_execsql_test 4.19.2 { SELECT * FROM t5 } {} +do_catchsql_test 4.19.3 { INSERT INTO t5 VALUES('not null', NULL) } \ + {1 {NOT NULL constraint failed: t5.b}} +do_execsql_test 4.19.4 { SELECT * FROM t5 } {} + +#------------------------------------------------------------------------ +# Tests for INTEGER PRIMARY KEY and rowid related statements. +# + +# EVIDENCE-OF: R-52584-04009 The rowid value can be accessed using one +# of the special case-independent names "rowid", "oid", or "_rowid_" in +# place of a column name. +# +# EVIDENCE-OF: R-06726-07466 A column name can be any of the names +# defined in the CREATE TABLE statement or one of the following special +# identifiers: "ROWID", "OID", or "_ROWID_". +# +drop_all_tables +do_execsql_test 5.1.0 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES('one', 'first'); + INSERT INTO t1 VALUES('two', 'second'); + INSERT INTO t1 VALUES('three', 'third'); +} +do_createtable_tests 5.1 { + 1 "SELECT rowid FROM t1" {1 2 3} + 2 "SELECT oid FROM t1" {1 2 3} + 3 "SELECT _rowid_ FROM t1" {1 2 3} + 4 "SELECT ROWID FROM t1" {1 2 3} + 5 "SELECT OID FROM t1" {1 2 3} + 6 "SELECT _ROWID_ FROM t1" {1 2 3} + 7 "SELECT RoWiD FROM t1" {1 2 3} + 8 "SELECT OiD FROM t1" {1 2 3} + 9 "SELECT _RoWiD_ FROM t1" {1 2 3} +} + +# EVIDENCE-OF: R-26501-17306 If a table contains a user defined column +# named "rowid", "oid" or "_rowid_", then that name always refers the +# explicitly declared column and cannot be used to retrieve the integer +# rowid value. +# +# EVIDENCE-OF: R-44615-33286 The special identifiers only refer to the +# row key if the CREATE TABLE statement does not define a real column +# with the same name. +# +do_execsql_test 5.2.0 { + CREATE TABLE t2(oid, b); + CREATE TABLE t3(a, _rowid_); + CREATE TABLE t4(a, b, rowid); + + INSERT INTO t2 VALUES('one', 'two'); + INSERT INTO t2 VALUES('three', 'four'); + + INSERT INTO t3 VALUES('five', 'six'); + INSERT INTO t3 VALUES('seven', 'eight'); + + INSERT INTO t4 VALUES('nine', 'ten', 'eleven'); + INSERT INTO t4 VALUES('twelve', 'thirteen', 'fourteen'); +} +do_createtable_tests 5.2 { + 1 "SELECT oid, rowid, _rowid_ FROM t2" {one 1 1 three 2 2} + 2 "SELECT oid, rowid, _rowid_ FROM t3" {1 1 six 2 2 eight} + 3 "SELECT oid, rowid, _rowid_ FROM t4" {1 eleven 1 2 fourteen 2} +} + + +# Argument $tbl is the name of a table in the database. Argument $col is +# the name of one of the tables columns. Return 1 if $col is an alias for +# the rowid, or 0 otherwise. +# +proc is_integer_primary_key {tbl col} { + lindex [db eval [subst { + DELETE FROM $tbl; + INSERT INTO $tbl ($col) VALUES(0); + SELECT (rowid==$col) FROM $tbl; + DELETE FROM $tbl; + }]] 0 +} + +# EVIDENCE-OF: R-47901-33947 With one exception noted below, if a rowid +# table has a primary key that consists of a single column and the +# declared type of that column is "INTEGER" in any mixture of upper and +# lower case, then the column becomes an alias for the rowid. +# +# EVIDENCE-OF: R-45951-08347 if the declaration of a column with +# declared type "INTEGER" includes an "PRIMARY KEY DESC" clause, it does +# not become an alias for the rowid and is not classified as an integer +# primary key. +# +do_createtable_tests 5.3 -tclquery { + is_integer_primary_key t5 pk +} -repair { + catchsql { DROP TABLE t5 } +} { + 1 "CREATE TABLE t5(pk integer primary key)" 1 + 2 "CREATE TABLE t5(pk integer, primary key(pk))" 1 + 3 "CREATE TABLE t5(pk integer, v integer, primary key(pk))" 1 + 4 "CREATE TABLE t5(pk integer, v integer, primary key(pk, v))" 0 + 5 "CREATE TABLE t5(pk int, v integer, primary key(pk, v))" 0 + 6 "CREATE TABLE t5(pk int, v integer, primary key(pk))" 0 + 7 "CREATE TABLE t5(pk int primary key, v integer)" 0 + 8 "CREATE TABLE t5(pk inTEger primary key)" 1 + 9 "CREATE TABLE t5(pk inteGEr, primary key(pk))" 1 + 10 "CREATE TABLE t5(pk INTEGER, v integer, primary key(pk))" 1 +} + +# EVIDENCE-OF: R-41444-49665 Other integer type names like "INT" or +# "BIGINT" or "SHORT INTEGER" or "UNSIGNED INTEGER" causes the primary +# key column to behave as an ordinary table column with integer affinity +# and a unique index, not as an alias for the rowid. +# +do_execsql_test 5.4.1 { + CREATE TABLE t6(pk INT primary key); + CREATE TABLE t7(pk BIGINT primary key); + CREATE TABLE t8(pk SHORT INTEGER primary key); + CREATE TABLE t9(pk UNSIGNED INTEGER primary key); +} +do_test e_createtable-5.4.2.1 { is_integer_primary_key t6 pk } 0 +do_test e_createtable-5.4.2.2 { is_integer_primary_key t7 pk } 0 +do_test e_createtable-5.4.2.3 { is_integer_primary_key t8 pk } 0 +do_test e_createtable-5.4.2.4 { is_integer_primary_key t9 pk } 0 + +do_execsql_test 5.4.3 { + INSERT INTO t6 VALUES('2.0'); + INSERT INTO t7 VALUES('2.0'); + INSERT INTO t8 VALUES('2.0'); + INSERT INTO t9 VALUES('2.0'); + SELECT typeof(pk), pk FROM t6; + SELECT typeof(pk), pk FROM t7; + SELECT typeof(pk), pk FROM t8; + SELECT typeof(pk), pk FROM t9; +} {integer 2 integer 2 integer 2 integer 2} + +do_catchsql_test 5.4.4.1 { + INSERT INTO t6 VALUES(2) +} {1 {UNIQUE constraint failed: t6.pk}} +do_catchsql_test 5.4.4.2 { + INSERT INTO t7 VALUES(2) +} {1 {UNIQUE constraint failed: t7.pk}} +do_catchsql_test 5.4.4.3 { + INSERT INTO t8 VALUES(2) +} {1 {UNIQUE constraint failed: t8.pk}} +do_catchsql_test 5.4.4.4 { + INSERT INTO t9 VALUES(2) +} {1 {UNIQUE constraint failed: t9.pk}} + +# EVIDENCE-OF: R-56094-57830 the following three table declarations all +# cause the column "x" to be an alias for the rowid (an integer primary +# key): CREATE TABLE t(x INTEGER PRIMARY KEY ASC, y, z); CREATE TABLE +# t(x INTEGER, y, z, PRIMARY KEY(x ASC)); CREATE TABLE t(x INTEGER, y, +# z, PRIMARY KEY(x DESC)); +# +# EVIDENCE-OF: R-20149-25884 the following declaration does not result +# in "x" being an alias for the rowid: CREATE TABLE t(x INTEGER PRIMARY +# KEY DESC, y, z); +# +do_createtable_tests 5 -tclquery { + is_integer_primary_key t x +} -repair { + catchsql { DROP TABLE t } +} { + 5.1 "CREATE TABLE t(x INTEGER PRIMARY KEY ASC, y, z)" 1 + 5.2 "CREATE TABLE t(x INTEGER, y, z, PRIMARY KEY(x ASC))" 1 + 5.3 "CREATE TABLE t(x INTEGER, y, z, PRIMARY KEY(x DESC))" 1 + 6.1 "CREATE TABLE t(x INTEGER PRIMARY KEY DESC, y, z)" 0 +} + +# EVIDENCE-OF: R-03733-29734 Rowid values may be modified using an +# UPDATE statement in the same way as any other column value can, either +# using one of the built-in aliases ("rowid", "oid" or "_rowid_") or by +# using an alias created by an integer primary key. +# +do_execsql_test 5.7.0 { + CREATE TABLE t10(a, b); + INSERT INTO t10 VALUES('ten', 10); + + CREATE TABLE t11(a, b INTEGER PRIMARY KEY); + INSERT INTO t11 VALUES('ten', 10); +} +do_createtable_tests 5.7.1 -query { + SELECT rowid, _rowid_, oid FROM t10; +} { + 1 "UPDATE t10 SET rowid = 5" {5 5 5} + 2 "UPDATE t10 SET _rowid_ = 6" {6 6 6} + 3 "UPDATE t10 SET oid = 7" {7 7 7} +} +do_createtable_tests 5.7.2 -query { + SELECT rowid, _rowid_, oid, b FROM t11; +} { + 1 "UPDATE t11 SET rowid = 5" {5 5 5 5} + 2 "UPDATE t11 SET _rowid_ = 6" {6 6 6 6} + 3 "UPDATE t11 SET oid = 7" {7 7 7 7} + 4 "UPDATE t11 SET b = 8" {8 8 8 8} +} + +# EVIDENCE-OF: R-58706-14229 Similarly, an INSERT statement may provide +# a value to use as the rowid for each row inserted. +# +do_createtable_tests 5.8.1 -query { + SELECT rowid, _rowid_, oid FROM t10; +} -repair { + execsql { DELETE FROM t10 } +} { + 1 "INSERT INTO t10(oid) VALUES(15)" {15 15 15} + 2 "INSERT INTO t10(rowid) VALUES(16)" {16 16 16} + 3 "INSERT INTO t10(_rowid_) VALUES(17)" {17 17 17} + 4 "INSERT INTO t10(a, b, oid) VALUES(1,2,3)" {3 3 3} +} +do_createtable_tests 5.8.2 -query { + SELECT rowid, _rowid_, oid, b FROM t11; +} -repair { + execsql { DELETE FROM t11 } +} { + 1 "INSERT INTO t11(oid) VALUES(15)" {15 15 15 15} + 2 "INSERT INTO t11(rowid) VALUES(16)" {16 16 16 16} + 3 "INSERT INTO t11(_rowid_) VALUES(17)" {17 17 17 17} + 4 "INSERT INTO t11(a, b) VALUES(1,2)" {2 2 2 2} +} + +# EVIDENCE-OF: R-32326-44592 Unlike normal SQLite columns, an integer +# primary key or rowid column must contain integer values. Integer +# primary key or rowid columns are not able to hold floating point +# values, strings, BLOBs, or NULLs. +# +# This is considered by the tests for the following 3 statements, +# which show that: +# +# 1. Attempts to UPDATE a rowid column to a non-integer value fail, +# 2. Attempts to INSERT a real, string or blob value into a rowid +# column fail, and +# 3. Attempting to INSERT a NULL value into a rowid column causes the +# system to automatically select an integer value to use. +# + + +# EVIDENCE-OF: R-64224-62578 If an UPDATE statement attempts to set an +# integer primary key or rowid column to a NULL or blob value, or to a +# string or real value that cannot be losslessly converted to an +# integer, a "datatype mismatch" error occurs and the statement is +# aborted. +# +drop_all_tables +do_execsql_test 5.9.0 { + CREATE TABLE t12(x INTEGER PRIMARY KEY, y); + INSERT INTO t12 VALUES(5, 'five'); +} +do_createtable_tests 5.9.1 -query { SELECT typeof(x), x FROM t12 } { + 1 "UPDATE t12 SET x = 4" {integer 4} + 2 "UPDATE t12 SET x = 10.0" {integer 10} + 3 "UPDATE t12 SET x = '12.0'" {integer 12} + 4 "UPDATE t12 SET x = '-15.0'" {integer -15} +} +do_createtable_tests 5.9.2 -error { + datatype mismatch +} { + 1 "UPDATE t12 SET x = 4.1" {} + 2 "UPDATE t12 SET x = 'hello'" {} + 3 "UPDATE t12 SET x = NULL" {} + 4 "UPDATE t12 SET x = X'ABCD'" {} + 5 "UPDATE t12 SET x = X'3900'" {} + 6 "UPDATE t12 SET x = X'39'" {} +} + +# EVIDENCE-OF: R-05734-13629 If an INSERT statement attempts to insert a +# blob value, or a string or real value that cannot be losslessly +# converted to an integer into an integer primary key or rowid column, a +# "datatype mismatch" error occurs and the statement is aborted. +# +do_execsql_test 5.10.0 { DELETE FROM t12 } +do_createtable_tests 5.10.1 -error { + datatype mismatch +} { + 1 "INSERT INTO t12(x) VALUES(4.1)" {} + 2 "INSERT INTO t12(x) VALUES('hello')" {} + 3 "INSERT INTO t12(x) VALUES(X'ABCD')" {} + 4 "INSERT INTO t12(x) VALUES(X'3900')" {} + 5 "INSERT INTO t12(x) VALUES(X'39')" {} +} +do_createtable_tests 5.10.2 -query { + SELECT typeof(x), x FROM t12 +} -repair { + execsql { DELETE FROM t12 } +} { + 1 "INSERT INTO t12(x) VALUES(4)" {integer 4} + 2 "INSERT INTO t12(x) VALUES(10.0)" {integer 10} + 3 "INSERT INTO t12(x) VALUES('12.0')" {integer 12} + 4 "INSERT INTO t12(x) VALUES('4e3')" {integer 4000} + 5 "INSERT INTO t12(x) VALUES('-14.0')" {integer -14} +} + +# EVIDENCE-OF: R-07986-46024 If an INSERT statement attempts to insert a +# NULL value into a rowid or integer primary key column, the system +# chooses an integer value to use as the rowid automatically. +# +do_execsql_test 5.11.0 { DELETE FROM t12 } +do_createtable_tests 5.11 -query { + SELECT typeof(x), x FROM t12 WHERE y IS (SELECT max(y) FROM t12) +} { + 1 "INSERT INTO t12 DEFAULT VALUES" {integer 1} + 2 "INSERT INTO t12(y) VALUES(5)" {integer 2} + 3 "INSERT INTO t12(x,y) VALUES(NULL, 10)" {integer 3} + 4 "INSERT INTO t12(x,y) SELECT NULL, 15 FROM t12" + {integer 4 integer 5 integer 6} + 5 "INSERT INTO t12(y) SELECT 20 FROM t12 LIMIT 3" + {integer 7 integer 8 integer 9} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_droptrigger.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_droptrigger.test new file mode 100644 index 0000000000000000000000000000000000000000..5cd5d0a07bafa67a17cbba54babbe8879859603f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_droptrigger.test @@ -0,0 +1,218 @@ +# 2010 November 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. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_droptrigger.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix e_droptrigger + +ifcapable !trigger { finish_test ; return } + +proc do_droptrigger_tests {nm args} { + uplevel do_select_tests [list e_createtable-$nm] $args +} + +proc list_all_triggers {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + if {$name == "temp"} { + set tbl sqlite_temp_master + } else { + set tbl "$name.sqlite_master" + } + lappend res {*}[ + db eval "SELECT '$name.' || name FROM $tbl WHERE type = 'trigger'" + ] + } + set res +} + + +proc droptrigger_reopen_db {{event INSERT}} { + db close + forcedelete test.db test.db2 + sqlite3 db test.db + + set ::triggers_fired [list] + proc r {x} { lappend ::triggers_fired $x } + db func r r + + db eval " + ATTACH 'test.db2' AS aux; + + CREATE TEMP TABLE t1(a, b); + INSERT INTO t1 VALUES('a', 'b'); + CREATE TRIGGER tr1 AFTER $event ON t1 BEGIN SELECT r('temp.tr1') ; END; + + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('a', 'b'); + CREATE TRIGGER tr1 BEFORE $event ON t2 BEGIN SELECT r('main.tr1') ; END; + CREATE TRIGGER tr2 AFTER $event ON t2 BEGIN SELECT r('main.tr2') ; END; + + CREATE TABLE aux.t3(a, b); + INSERT INTO t3 VALUES('a', 'b'); + CREATE TRIGGER aux.tr1 BEFORE $event ON t3 BEGIN SELECT r('aux.tr1') ; END; + CREATE TRIGGER aux.tr2 AFTER $event ON t3 BEGIN SELECT r('aux.tr2') ; END; + CREATE TRIGGER aux.tr3 AFTER $event ON t3 BEGIN SELECT r('aux.tr3') ; END; + " +} + + +# -- syntax diagram drop-trigger-stmt +# +do_droptrigger_tests 1.1 -repair { + droptrigger_reopen_db +} -tclquery { + list_all_triggers +} { + 1 "DROP TRIGGER main.tr1" + {main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 2 "DROP TRIGGER IF EXISTS main.tr1" + {main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 3 "DROP TRIGGER tr1" + {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + 4 "DROP TRIGGER IF EXISTS tr1" + {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + + 5 "DROP TRIGGER aux.tr1" + {main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3} + 6 "DROP TRIGGER IF EXISTS aux.tr1" + {main.tr1 main.tr2 temp.tr1 aux.tr2 aux.tr3} + + 7 "DROP TRIGGER IF EXISTS aux.xxx" + {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} + 8 "DROP TRIGGER IF EXISTS aux.xxx" + {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} +} + +# EVIDENCE-OF: R-61172-15671 The DROP TRIGGER statement removes a +# trigger created by the CREATE TRIGGER statement. +# +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 2.$tn.1 { + droptrigger_reopen_db + execsql " INSERT INTO $tbl VALUES('1', '2') " + set ::triggers_fired + } $before + + do_test 2.$tn.2 { + droptrigger_reopen_db + execsql $droptrigger + execsql " INSERT INTO $tbl VALUES('1', '2') " + set ::triggers_fired + } $after +} + +# EVIDENCE-OF: R-04950-25529 Once removed, the trigger definition is no +# longer present in the sqlite_schema (or sqlite_temp_schema) table and +# is not fired by any subsequent INSERT, UPDATE or DELETE statements. +# +# Test cases e_droptrigger-1.* test the first part of this statement +# (that dropped triggers do not appear in the schema table), and tests +# droptrigger-2.* test that dropped triggers are not fired by INSERT +# statements. The following tests verify that they are not fired by +# UPDATE or DELETE statements. +# +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 3.1.$tn.1 { + droptrigger_reopen_db UPDATE + execsql "UPDATE $tbl SET a = 'abc'" + set ::triggers_fired + } $before + + do_test 3.1.$tn.2 { + droptrigger_reopen_db UPDATE + execsql $droptrigger + execsql "UPDATE $tbl SET a = 'abc'" + set ::triggers_fired + } $after +} +foreach {tn tbl droptrigger before after} { + 1 t1 "DROP TRIGGER tr1" {temp.tr1} {} + 2 t2 "DROP TRIGGER tr1" {main.tr1 main.tr2} {main.tr1 main.tr2} + 3 t3 "DROP TRIGGER tr1" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 4 t1 "DROP TRIGGER tr2" {temp.tr1} {temp.tr1} + 5 t2 "DROP TRIGGER tr2" {main.tr1 main.tr2} {main.tr1} + 6 t3 "DROP TRIGGER tr2" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr3 aux.tr2} + + 7 t1 "DROP TRIGGER tr3" {temp.tr1} {temp.tr1} + 8 t2 "DROP TRIGGER tr3" {main.tr1 main.tr2} {main.tr1 main.tr2} + 9 t3 "DROP TRIGGER tr3" {aux.tr1 aux.tr3 aux.tr2} {aux.tr1 aux.tr2} +} { + + do_test 3.2.$tn.1 { + droptrigger_reopen_db DELETE + execsql "DELETE FROM $tbl" + set ::triggers_fired + } $before + + do_test 3.2.$tn.2 { + droptrigger_reopen_db DELETE + execsql $droptrigger + execsql "DELETE FROM $tbl" + set ::triggers_fired + } $after +} + +# EVIDENCE-OF: R-37808-62273 Note that triggers are automatically +# dropped when the associated table is dropped. +# +do_test 4.1 { + droptrigger_reopen_db + list_all_triggers +} {main.tr1 main.tr2 temp.tr1 aux.tr1 aux.tr2 aux.tr3} +do_test 4.2 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} +do_test 4.3 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} +do_test 4.4 { + droptrigger_reopen_db + execsql "DROP TABLE t1" + list_all_triggers +} {main.tr1 main.tr2 aux.tr1 aux.tr2 aux.tr3} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_dropview.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_dropview.test new file mode 100644 index 0000000000000000000000000000000000000000..00f59ddc4f853323f8047cc7d67cd7540c11db11 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_dropview.test @@ -0,0 +1,192 @@ +# 2010 November 30 +# +# 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 to verify that the "testable statements" in +# the lang_dropview.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix e_dropview + +proc dropview_reopen_db {} { + db close + forcedelete test.db test.db2 + sqlite3 db test.db + + db eval { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES('a main', 'b main'); + CREATE VIEW v1 AS SELECT * FROM t1; + CREATE VIEW v2 AS SELECT * FROM t1; + + CREATE TEMP TABLE t1(a, b); + INSERT INTO temp.t1 VALUES('a temp', 'b temp'); + CREATE VIEW temp.v1 AS SELECT * FROM t1; + + CREATE TABLE aux.t1(a, b); + INSERT INTO aux.t1 VALUES('a aux', 'b aux'); + CREATE VIEW aux.v1 AS SELECT * FROM t1; + CREATE VIEW aux.v2 AS SELECT * FROM t1; + CREATE VIEW aux.v3 AS SELECT * FROM t1; + } +} + +proc list_all_views {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + set tbl "$name.sqlite_master" + if {$name == "temp"} { set tbl temp.sqlite_master } + + set sql "SELECT '$name.' || name FROM $tbl WHERE type = 'view'" + lappend res {*}[$db eval $sql] + } + set res +} + +proc list_all_data {{db db}} { + set res [list] + $db eval { PRAGMA database_list } { + set tbl "$name.sqlite_master" + if {$name == "temp"} { set tbl sqlite_temp_master } + + db eval "SELECT '$name.' || name AS x FROM $tbl WHERE type = 'table'" { + lappend res [list $x [db eval "SELECT * FROM $x"]] + } + } + set res +} + +proc do_dropview_tests {nm args} { + uplevel do_select_tests $nm $args +} + +# -- syntax diagram drop-view-stmt +# +# All paths in the syntax diagram for DROP VIEW are tested by tests 1.*. +# +do_dropview_tests 1 -repair { + dropview_reopen_db +} -tclquery { + list_all_views +} { + 1 "DROP VIEW v1" {main.v1 main.v2 aux.v1 aux.v2 aux.v3} + 2 "DROP VIEW v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 3 "DROP VIEW main.v1" {main.v2 temp.v1 aux.v1 aux.v2 aux.v3} + 4 "DROP VIEW main.v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 5 "DROP VIEW IF EXISTS v1" {main.v1 main.v2 aux.v1 aux.v2 aux.v3} + 6 "DROP VIEW IF EXISTS v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} + 7 "DROP VIEW IF EXISTS main.v1" {main.v2 temp.v1 aux.v1 aux.v2 aux.v3} + 8 "DROP VIEW IF EXISTS main.v2" {main.v1 temp.v1 aux.v1 aux.v2 aux.v3} +} + +# EVIDENCE-OF: R-27002-52307 The DROP VIEW statement removes a view +# created by the CREATE VIEW statement. +# +dropview_reopen_db +do_execsql_test 2.1 { + CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y; + SELECT * FROM "new view"; +} {{a main} {b main} {a main} {b main}} +do_execsql_test 2.2 {; + SELECT * FROM sqlite_master WHERE name = 'new view'; +} { + view {new view} {new view} 0 + {CREATE VIEW "new view" AS SELECT * FROM t1 AS x, t1 AS y} +} +do_execsql_test 2.3 { + DROP VIEW "new view"; + SELECT * FROM sqlite_master WHERE name = 'new view'; +} {} +do_catchsql_test 2.4 { + SELECT * FROM "new view" +} {1 {no such table: new view}} + +# EVIDENCE-OF: R-00359-41639 The view definition is removed from the +# database schema, but no actual data in the underlying base tables is +# modified. +# +# For each view in the database, check that it can be queried. Then drop +# it. Check that it can no longer be queried and is no longer listed +# in any schema table. Then check that the contents of the db tables have +# not changed +# +set databasedata [list_all_data] + +do_execsql_test 3.1.0 { SELECT * FROM temp.v1 } {{a temp} {b temp}} +do_execsql_test 3.1.1 { DROP VIEW temp.v1 } {} +do_catchsql_test 3.1.2 { SELECT * FROM temp.v1 } {1 {no such table: temp.v1}} +do_test 3.1.3 { list_all_views } {main.v1 main.v2 aux.v1 aux.v2 aux.v3} +do_test 3.1.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.2.0 { SELECT * FROM v1 } {{a main} {b main}} +do_execsql_test 3.2.1 { DROP VIEW v1 } {} +do_catchsql_test 3.2.2 { SELECT * FROM main.v1 } {1 {no such table: main.v1}} +do_test 3.2.3 { list_all_views } {main.v2 aux.v1 aux.v2 aux.v3} +do_test 3.2.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.3.0 { SELECT * FROM v2 } {{a main} {b main}} +do_execsql_test 3.3.1 { DROP VIEW v2 } {} +do_catchsql_test 3.3.2 { SELECT * FROM main.v2 } {1 {no such table: main.v2}} +do_test 3.3.3 { list_all_views } {aux.v1 aux.v2 aux.v3} +do_test 3.3.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.4.0 { SELECT * FROM v1 } {{a aux} {b aux}} +do_execsql_test 3.4.1 { DROP VIEW v1 } {} +do_catchsql_test 3.4.2 { SELECT * FROM v1 } {1 {no such table: v1}} +do_test 3.4.3 { list_all_views } {aux.v2 aux.v3} +do_test 3.4.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.5.0 { SELECT * FROM aux.v2 } {{a aux} {b aux}} +do_execsql_test 3.5.1 { DROP VIEW aux.v2 } {} +do_catchsql_test 3.5.2 { SELECT * FROM aux.v2 } {1 {no such table: aux.v2}} +do_test 3.5.3 { list_all_views } {aux.v3} +do_test 3.5.4 { string compare [list_all_data] $databasedata } 0 + +do_execsql_test 3.6.0 { SELECT * FROM v3 } {{a aux} {b aux}} +do_execsql_test 3.6.1 { DROP VIEW v3 } {} +do_catchsql_test 3.6.2 { SELECT * FROM v3 } {1 {no such table: v3}} +do_test 3.6.3 { list_all_views } {} +do_test 3.6.4 { string compare [list_all_data] $databasedata } 0 + +# EVIDENCE-OF: R-25558-37487 If the specified view cannot be found and +# the IF EXISTS clause is not present, it is an error. +# +do_dropview_tests 4 -repair { + dropview_reopen_db +} -errorformat { + no such view: %s +} { + 1 "DROP VIEW xx" xx + 2 "DROP VIEW main.xx" main.xx + 3 "DROP VIEW temp.v2" temp.v2 +} + +# EVIDENCE-OF: R-07490-32536 If the specified view cannot be found and +# an IF EXISTS clause is present in the DROP VIEW statement, then the +# statement is a no-op. +# +do_dropview_tests 5 -repair { + dropview_reopen_db +} -tclquery { + list_all_views + #expr {[list_all_views] == "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3"} +} { + 1 "DROP VIEW IF EXISTS xx" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" + 2 "DROP VIEW IF EXISTS main.xx" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" + 3 "DROP VIEW IF EXISTS temp.v2" "main.v1 main.v2 temp.v1 aux.v1 aux.v2 aux.v3" +} + + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_expr.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_expr.test new file mode 100644 index 0000000000000000000000000000000000000000..0db63a8ac4602c7945edb0bc2438f1d83d100d0e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_expr.test @@ -0,0 +1,1989 @@ +# 2010 July 16 +# +# 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 to verify that the "testable statements" in +# the lang_expr.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl + +ifcapable !compound { + finish_test + return +} + +proc do_expr_test {tn expr type value} { + uplevel do_execsql_test $tn [list "SELECT typeof($expr), $expr"] [ + list [list $type $value] + ] +} + +proc do_qexpr_test {tn expr value} { + uplevel do_execsql_test $tn [list "SELECT quote($expr)"] [list $value] +} + +# Set up three global variables: +# +# ::opname An array mapping from SQL operator to an easy to parse +# name. The names are used as part of test case names. +# +# ::opprec An array mapping from SQL operator to a numeric +# precedence value. Operators that group more tightly +# have lower numeric precedences. +# +# ::oplist A list of all SQL operators supported by SQLite. +# +foreach {op opn} { + || cat * mul / div % mod + add + - sub << lshift >> rshift & bitand | bitor + < less <= lesseq > more >= moreeq = eq1 + == eq2 <> ne1 != ne2 IS is LIKE like + GLOB glob AND and OR or MATCH match REGEXP regexp + {IS NOT} isnt +} { + set ::opname($op) $opn +} +set oplist [list] +foreach {prec opl} { + 1 || + 2 {* / %} + 3 {+ -} + 4 {<< >> & |} + 5 {< <= > >=} + 6 {= == != <> IS {IS NOT} LIKE GLOB MATCH REGEXP} + 7 AND + 8 OR +} { + foreach op $opl { + set ::opprec($op) $prec + lappend oplist $op + } +} + + +# Hook in definitions of MATCH and REGEX. The following implementations +# cause MATCH and REGEX to behave similarly to the == operator. +# +proc matchfunc {a b} { return [expr {$a==$b}] } +proc regexfunc {a b} { return [expr {$a==$b}] } +db func match -argcount 2 matchfunc +db func regexp -argcount 2 regexfunc + +#------------------------------------------------------------------------- +# Test cases e_expr-1.* attempt to verify that all binary operators listed +# in the documentation exist and that the relative precedences of the +# operators are also as the documentation suggests. +# +# X-EVIDENCE-OF: R-15514-65163 SQLite understands the following binary +# operators, in order from highest to lowest precedence: || * / % + - +# << >> & | < <= > >= = == != <> IS IS +# NOT IN LIKE GLOB MATCH REGEXP AND OR +# +# X-EVIDENCE-OF: R-38759-38789 Operators IS and IS NOT have the same +# precedence as =. +# + +unset -nocomplain untested +foreach op1 $oplist { + foreach op2 $oplist { + set untested($op1,$op2) 1 + foreach {tn A B C} { + 1 22 45 66 + 2 0 0 0 + 3 0 0 1 + 4 0 1 0 + 5 0 1 1 + 6 1 0 0 + 7 1 0 1 + 8 1 1 0 + 9 1 1 1 + 10 5 6 1 + 11 1 5 6 + 12 1 5 5 + 13 5 5 1 + + 14 5 2 1 + 15 1 4 1 + 16 -1 0 1 + 17 0 1 -1 + + } { + set testname "e_expr-1.$opname($op1).$opname($op2).$tn" + + # If $op2 groups more tightly than $op1, then the result + # of executing $sql1 whould be the same as executing $sql3. + # If $op1 groups more tightly, or if $op1 and $op2 have + # the same precedence, then executing $sql1 should return + # the same value as $sql2. + # + set sql1 "SELECT $A $op1 $B $op2 $C" + set sql2 "SELECT ($A $op1 $B) $op2 $C" + set sql3 "SELECT $A $op1 ($B $op2 $C)" + + set a2 [db one $sql2] + set a3 [db one $sql3] + + do_execsql_test $testname $sql1 [list [ + if {$opprec($op2) < $opprec($op1)} {set a3} {set a2} + ]] + if {$a2 != $a3} { unset -nocomplain untested($op1,$op2) } + } + } +} + +foreach op {* AND OR + || & |} { unset untested($op,$op) } +unset untested(+,-) ;# Since (a+b)-c == a+(b-c) +unset untested(*,<<) ;# Since (a*b)< work as the not-equals operator. +# +# EVIDENCE-OF: R-03679-60639 Equals can be either = or ==. +# +# EVIDENCE-OF: R-49372-18364 The not-equal operator can be either != or +# <>. +# +foreach {tn literal different} { + 1 'helloworld' '12345' + 2 22 23 + 3 'xyz' X'78797A' + 4 X'78797A00' 'xyz' +} { + do_execsql_test e_expr-4.$tn " + SELECT $literal = $literal, $literal == $literal, + $literal = $different, $literal == $different, + $literal = NULL, $literal == NULL, + $literal != $literal, $literal <> $literal, + $literal != $different, $literal <> $different, + $literal != NULL, $literal != NULL + + " {1 1 0 0 {} {} 0 0 1 1 {} {}} +} + +#------------------------------------------------------------------------- +# Test the || operator. +# +# EVIDENCE-OF: R-44409-62641 The || operator is "concatenate" - it joins +# together the two strings of its operands. +# +foreach {tn a b} { + 1 'helloworld' '12345' + 2 22 23 +} { + set as [db one "SELECT $a"] + set bs [db one "SELECT $b"] + + do_execsql_test e_expr-5.$tn "SELECT $a || $b" [list "${as}${bs}"] +} + +#------------------------------------------------------------------------- +# Test the % operator. +# +# EVIDENCE-OF: R-53431-59159 The % operator casts both of its operands +# to type INTEGER and then computes the remainder after dividing the +# left integer by the right integer. +# +do_execsql_test e_expr-6.1 {SELECT 72%5} {2} +do_execsql_test e_expr-6.2 {SELECT 72%-5} {2} +do_execsql_test e_expr-6.3 {SELECT -72%-5} {-2} +do_execsql_test e_expr-6.4 {SELECT -72%5} {-2} +do_execsql_test e_expr-6.5 {SELECT 72.35%5} {2.0} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-15904-00746 The result of any binary operator is either +# a numeric value or NULL, except for the || concatenation operator, and +# the -> and ->> extract operators which evaluate to either +# NULL or a text value. +# +set literals { + 1 'abc' 2 'hexadecimal' 3 '' + 4 123 5 -123 6 0 + 7 123.4 8 0.0 9 -123.4 + 10 X'ABCDEF' 11 X'' 12 X'0000' + 13 NULL +} +foreach op $oplist { + foreach {n1 rhs} $literals { + foreach {n2 lhs} $literals { + + set t [db one " SELECT typeof($lhs $op $rhs) "] + do_test e_expr-7.$opname($op).$n1.$n2 { + expr { + ($op=="||" && ($t == "text" || $t == "null")) + || ($op!="||" && ($t == "integer" || $t == "real" || $t == "null")) + } + } 1 + + }} +} + +#------------------------------------------------------------------------- +# Test the IS and IS NOT operators. +# +# EVIDENCE-OF: R-24731-45773 The IS and IS NOT operators work like = and +# != except when one or both of the operands are NULL. +# +# EVIDENCE-OF: R-06325-15315 In this case, if both operands are NULL, +# then the IS operator evaluates to 1 (true) and the IS NOT operator +# evaluates to 0 (false). +# +# EVIDENCE-OF: R-19812-36779 If one operand is NULL and the other is +# not, then the IS operator evaluates to 0 (false) and the IS NOT +# operator is 1 (true). +# +# EVIDENCE-OF: R-61975-13410 It is not possible for an IS or IS NOT +# expression to evaluate to NULL. +# +do_execsql_test e_expr-8.1.1 { SELECT NULL IS NULL } {1} +do_execsql_test e_expr-8.1.2 { SELECT 'ab' IS NULL } {0} +do_execsql_test e_expr-8.1.3 { SELECT NULL IS 'ab' } {0} +do_execsql_test e_expr-8.1.4 { SELECT 'ab' IS 'ab' } {1} +do_execsql_test e_expr-8.1.5 { SELECT NULL == NULL } {{}} +do_execsql_test e_expr-8.1.6 { SELECT 'ab' == NULL } {{}} +do_execsql_test e_expr-8.1.7 { SELECT NULL == 'ab' } {{}} +do_execsql_test e_expr-8.1.8 { SELECT 'ab' == 'ab' } {1} +do_execsql_test e_expr-8.1.9 { SELECT NULL IS NOT NULL } {0} +do_execsql_test e_expr-8.1.10 { SELECT 'ab' IS NOT NULL } {1} +do_execsql_test e_expr-8.1.11 { SELECT NULL IS NOT 'ab' } {1} +do_execsql_test e_expr-8.1.12 { SELECT 'ab' IS NOT 'ab' } {0} +do_execsql_test e_expr-8.1.13 { SELECT NULL != NULL } {{}} +do_execsql_test e_expr-8.1.14 { SELECT 'ab' != NULL } {{}} +do_execsql_test e_expr-8.1.15 { SELECT NULL != 'ab' } {{}} +do_execsql_test e_expr-8.1.16 { SELECT 'ab' != 'ab' } {0} + +foreach {n1 rhs} $literals { + foreach {n2 lhs} $literals { + if {$rhs!="NULL" && $lhs!="NULL"} { + set eq [execsql "SELECT $lhs = $rhs, $lhs != $rhs"] + } else { + set eq [list [expr {$lhs=="NULL" && $rhs=="NULL"}] \ + [expr {$lhs!="NULL" || $rhs!="NULL"}] + ] + } + set test e_expr-8.2.$n1.$n2 + do_execsql_test $test.1 "SELECT $lhs IS $rhs, $lhs IS NOT $rhs" $eq + do_execsql_test $test.2 " + SELECT ($lhs IS $rhs) IS NULL, ($lhs IS NOT $rhs) IS NULL + " {0 0} + } +} + +#------------------------------------------------------------------------- +# Run some tests on the COLLATE "unary postfix operator". +# +# This collation sequence reverses both arguments before using +# [string compare] to compare them. For example, when comparing the +# strings 'one' and 'four', return the result of: +# +# string compare eno ruof +# +proc reverse_str {zStr} { + set out "" + foreach c [split $zStr {}] { set out "${c}${out}" } + set out +} +proc reverse_collate {zLeft zRight} { + string compare [reverse_str $zLeft] [reverse_str $zRight] +} +db collate reverse reverse_collate + +# EVIDENCE-OF: R-59577-33471 The COLLATE operator is a unary postfix +# operator that assigns a collating sequence to an expression. +# +# X-EVIDENCE-OF: R-36231-30731 The COLLATE operator has a higher +# precedence (binds more tightly) than any binary operator and any unary +# prefix operator except "~". +# +do_execsql_test e_expr-9.1 { SELECT 'abcd' < 'bbbb' COLLATE reverse } 0 +do_execsql_test e_expr-9.2 { SELECT ('abcd' < 'bbbb') COLLATE reverse } 1 +do_execsql_test e_expr-9.3 { SELECT 'abcd' <= 'bbbb' COLLATE reverse } 0 +do_execsql_test e_expr-9.4 { SELECT ('abcd' <= 'bbbb') COLLATE reverse } 1 + +do_execsql_test e_expr-9.5 { SELECT 'abcd' > 'bbbb' COLLATE reverse } 1 +do_execsql_test e_expr-9.6 { SELECT ('abcd' > 'bbbb') COLLATE reverse } 0 +do_execsql_test e_expr-9.7 { SELECT 'abcd' >= 'bbbb' COLLATE reverse } 1 +do_execsql_test e_expr-9.8 { SELECT ('abcd' >= 'bbbb') COLLATE reverse } 0 + +do_execsql_test e_expr-9.10 { SELECT 'abcd' = 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.11 { SELECT ('abcd' = 'ABCD') COLLATE nocase } 0 +do_execsql_test e_expr-9.12 { SELECT 'abcd' == 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.13 { SELECT ('abcd' == 'ABCD') COLLATE nocase } 0 +do_execsql_test e_expr-9.14 { SELECT 'abcd' IS 'ABCD' COLLATE nocase } 1 +do_execsql_test e_expr-9.15 { SELECT ('abcd' IS 'ABCD') COLLATE nocase } 0 + +do_execsql_test e_expr-9.16 { SELECT 'abcd' != 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.17 { SELECT ('abcd' != 'ABCD') COLLATE nocase } 1 +do_execsql_test e_expr-9.18 { SELECT 'abcd' <> 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.19 { SELECT ('abcd' <> 'ABCD') COLLATE nocase } 1 +do_execsql_test e_expr-9.20 { SELECT 'abcd' IS NOT 'ABCD' COLLATE nocase } 0 +do_execsql_test e_expr-9.21 { SELECT ('abcd' IS NOT 'ABCD') COLLATE nocase } 1 + +do_execsql_test e_expr-9.22 { + SELECT 'bbb' BETWEEN 'AAA' AND 'CCC' COLLATE nocase +} 1 +do_execsql_test e_expr-9.23 { + SELECT ('bbb' BETWEEN 'AAA' AND 'CCC') COLLATE nocase +} 0 + +# EVIDENCE-OF: R-58731-25439 The collating sequence set by the COLLATE +# operator overrides the collating sequence determined by the COLLATE +# clause in a table column definition. +# +do_execsql_test e_expr-9.24 { + CREATE TABLE t24(a COLLATE NOCASE, b); + INSERT INTO t24 VALUES('aaa', 1); + INSERT INTO t24 VALUES('bbb', 2); + INSERT INTO t24 VALUES('ccc', 3); +} {} +do_execsql_test e_expr-9.25 { SELECT 'BBB' = a FROM t24 } {0 1 0} +do_execsql_test e_expr-9.25 { SELECT a = 'BBB' FROM t24 } {0 1 0} +do_execsql_test e_expr-9.25 { SELECT 'BBB' = a COLLATE binary FROM t24 } {0 0 0} +do_execsql_test e_expr-9.25 { SELECT a COLLATE binary = 'BBB' FROM t24 } {0 0 0} + +#------------------------------------------------------------------------- +# Test statements related to literal values. +# +# EVIDENCE-OF: R-31536-32008 Literal values may be integers, floating +# point numbers, strings, BLOBs, or NULLs. +# +do_execsql_test e_expr-10.1.1 { SELECT typeof(5) } {integer} +do_execsql_test e_expr-10.1.2 { SELECT typeof(5.1) } {real} +do_execsql_test e_expr-10.1.3 { SELECT typeof('5.1') } {text} +do_execsql_test e_expr-10.1.4 { SELECT typeof(X'ABCD') } {blob} +do_execsql_test e_expr-10.1.5 { SELECT typeof(NULL) } {null} + +# "Scientific notation is supported for point literal values." +# +do_execsql_test e_expr-10.2.1 { SELECT typeof(3.4e-02) } {real} +do_execsql_test e_expr-10.2.2 { SELECT typeof(3e+5) } {real} +do_execsql_test e_expr-10.2.3 { SELECT 3.4e-02 } {0.034} +do_execsql_test e_expr-10.2.4 { SELECT 3e+4 } {30000.0} + +# EVIDENCE-OF: R-35229-17830 A string constant is formed by enclosing +# the string in single quotes ('). +# +# EVIDENCE-OF: R-07100-06606 A single quote within the string can be +# encoded by putting two single quotes in a row - as in Pascal. +# +do_execsql_test e_expr-10.3.1 { SELECT 'is not' } {{is not}} +do_execsql_test e_expr-10.3.2 { SELECT typeof('is not') } {text} +do_execsql_test e_expr-10.3.3 { SELECT 'isn''t' } {isn't} +do_execsql_test e_expr-10.3.4 { SELECT typeof('isn''t') } {text} + +# EVIDENCE-OF: R-09593-03321 BLOB literals are string literals +# containing hexadecimal data and preceded by a single "x" or "X" +# character. +# +# EVIDENCE-OF: R-19836-11244 Example: X'53514C697465' +# +do_execsql_test e_expr-10.4.1 { SELECT typeof(X'0123456789ABCDEF') } blob +do_execsql_test e_expr-10.4.2 { SELECT typeof(x'0123456789ABCDEF') } blob +do_execsql_test e_expr-10.4.3 { SELECT typeof(X'0123456789abcdef') } blob +do_execsql_test e_expr-10.4.4 { SELECT typeof(x'0123456789abcdef') } blob +do_execsql_test e_expr-10.4.5 { SELECT typeof(X'53514C697465') } blob + +# EVIDENCE-OF: R-23914-51476 A literal value can also be the token +# "NULL". +# +do_execsql_test e_expr-10.5.1 { SELECT NULL } {{}} +do_execsql_test e_expr-10.5.2 { SELECT typeof(NULL) } {null} + +#------------------------------------------------------------------------- +# Test statements related to bound parameters +# + +proc parameter_test {tn sql params result} { + set stmt [sqlite3_prepare_v2 db $sql -1] + + foreach {number name} $params { + set nm [sqlite3_bind_parameter_name $stmt $number] + do_test $tn.name.$number [list set {} $nm] $name + sqlite3_bind_int $stmt $number [expr -1 * $number] + } + + sqlite3_step $stmt + + set res [list] + for {set i 0} {$i < [sqlite3_column_count $stmt]} {incr i} { + lappend res [sqlite3_column_text $stmt $i] + } + + set rc [sqlite3_finalize $stmt] + do_test $tn.rc [list set {} $rc] SQLITE_OK + do_test $tn.res [list set {} $res] $result +} + +# EVIDENCE-OF: R-33509-39458 A question mark followed by a number NNN +# holds a spot for the NNN-th parameter. NNN must be between 1 and +# SQLITE_MAX_VARIABLE_NUMBER. +# +set mvn $SQLITE_MAX_VARIABLE_NUMBER +parameter_test e_expr-11.1 " + SELECT ?1, ?123, ?$SQLITE_MAX_VARIABLE_NUMBER, ?123, ?4 +" "1 ?1 123 ?123 $mvn ?$mvn 4 ?4" "-1 -123 -$mvn -123 -4" + +set errmsg "variable number must be between ?1 and ?$SQLITE_MAX_VARIABLE_NUMBER" +foreach {tn param_number} [list \ + 2 0 \ + 3 [expr $SQLITE_MAX_VARIABLE_NUMBER+1] \ + 4 [expr $SQLITE_MAX_VARIABLE_NUMBER+2] \ + 5 12345678903456789034567890234567890 \ + 6 2147483648 \ + 7 2147483649 \ + 8 4294967296 \ + 9 4294967297 \ + 10 9223372036854775808 \ + 11 9223372036854775809 \ + 12 18446744073709551616 \ + 13 18446744073709551617 \ +] { + do_catchsql_test e_expr-11.1.$tn "SELECT ?$param_number" [list 1 $errmsg] +} + +# EVIDENCE-OF: R-33670-36097 A question mark that is not followed by a +# number creates a parameter with a number one greater than the largest +# parameter number already assigned. +# +# EVIDENCE-OF: R-42938-07030 If this means the parameter number is +# greater than SQLITE_MAX_VARIABLE_NUMBER, it is an error. +# +parameter_test e_expr-11.2.1 "SELECT ?" {1 {}} -1 +parameter_test e_expr-11.2.2 "SELECT ?, ?" {1 {} 2 {}} {-1 -2} +parameter_test e_expr-11.2.3 "SELECT ?5, ?" {5 ?5 6 {}} {-5 -6} +parameter_test e_expr-11.2.4 "SELECT ?, ?5" {1 {} 5 ?5} {-1 -5} +parameter_test e_expr-11.2.5 "SELECT ?, ?456, ?" { + 1 {} 456 ?456 457 {} +} {-1 -456 -457} +parameter_test e_expr-11.2.5 "SELECT ?, ?456, ?4, ?" { + 1 {} 456 ?456 4 ?4 457 {} +} {-1 -456 -4 -457} +foreach {tn sql} [list \ + 1 "SELECT ?$mvn, ?" \ + 2 "SELECT ?[expr $mvn-5], ?, ?, ?, ?, ?, ?" \ + 3 "SELECT ?[expr $mvn], ?5, ?6, ?" \ +] { + do_catchsql_test e_expr-11.3.$tn $sql [list 1 {too many SQL variables}] +} + +# EVIDENCE-OF: R-11620-22743 A colon followed by an identifier name +# holds a spot for a named parameter with the name :AAAA. +# +# Identifiers in SQLite consist of alphanumeric, '_' and '$' characters, +# and any UTF characters with codepoints larger than 127 (non-ASCII +# characters). +# +parameter_test e_expr-11.2.1 {SELECT :AAAA} {1 :AAAA} -1 +parameter_test e_expr-11.2.2 {SELECT :123} {1 :123} -1 +parameter_test e_expr-11.2.3 {SELECT :__} {1 :__} -1 +parameter_test e_expr-11.2.4 {SELECT :_$_} {1 :_$_} -1 +parameter_test e_expr-11.2.5 " + SELECT :\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 :\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.2.6 "SELECT :\u0080" "1 :\u0080" -1 + +# EVIDENCE-OF: R-49783-61279 An "at" sign works exactly like a colon, +# except that the name of the parameter created is @AAAA. +# +parameter_test e_expr-11.3.1 {SELECT @AAAA} {1 @AAAA} -1 +parameter_test e_expr-11.3.2 {SELECT @123} {1 @123} -1 +parameter_test e_expr-11.3.3 {SELECT @__} {1 @__} -1 +parameter_test e_expr-11.3.4 {SELECT @_$_} {1 @_$_} -1 +parameter_test e_expr-11.3.5 " + SELECT @\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 @\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.3.6 "SELECT @\u0080" "1 @\u0080" -1 + +# EVIDENCE-OF: R-62610-51329 A dollar-sign followed by an identifier +# name also holds a spot for a named parameter with the name $AAAA. +# +# EVIDENCE-OF: R-55025-21042 The identifier name in this case can +# include one or more occurrences of "::" and a suffix enclosed in +# "(...)" containing any text at all. +# +# Note: Looks like an identifier cannot consist entirely of "::" +# characters or just a suffix. Also, the other named variable characters +# (: and @) work the same way internally. Why not just document it that way? +# +parameter_test e_expr-11.4.1 {SELECT $AAAA} {1 $AAAA} -1 +parameter_test e_expr-11.4.2 {SELECT $123} {1 $123} -1 +parameter_test e_expr-11.4.3 {SELECT $__} {1 $__} -1 +parameter_test e_expr-11.4.4 {SELECT $_$_} {1 $_$_} -1 +parameter_test e_expr-11.4.5 " + SELECT \$\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25 +" "1 \$\u0e40\u0e2d\u0e28\u0e02\u0e39\u0e40\u0e2d\u0e25" -1 +parameter_test e_expr-11.4.6 "SELECT \$\u0080" "1 \$\u0080" -1 + +parameter_test e_expr-11.5.1 {SELECT $::::a(++--++)} {1 $::::a(++--++)} -1 +parameter_test e_expr-11.5.2 {SELECT $::a()} {1 $::a()} -1 +parameter_test e_expr-11.5.3 {SELECT $::1(::#$)} {1 $::1(::#$)} -1 + +# EVIDENCE-OF: R-11370-04520 Named parameters are also numbered. The +# number assigned is one greater than the largest parameter number +# already assigned. +# +# EVIDENCE-OF: R-42620-22184 If this means the parameter would be +# assigned a number greater than SQLITE_MAX_VARIABLE_NUMBER, it is an +# error. +# +parameter_test e_expr-11.6.1 "SELECT ?, @abc" {1 {} 2 @abc} {-1 -2} +parameter_test e_expr-11.6.2 "SELECT ?123, :a1" {123 ?123 124 :a1} {-123 -124} +parameter_test e_expr-11.6.3 {SELECT $a, ?8, ?, $b, ?2, $c} { + 1 $a 8 ?8 9 {} 10 $b 2 ?2 11 $c +} {-1 -8 -9 -10 -2 -11} +foreach {tn sql} [list \ + 1 "SELECT ?$mvn, \$::a" \ + 2 "SELECT ?$mvn, ?4, @a1" \ + 3 "SELECT ?[expr $mvn-2], :bag, @123, \$x" \ +] { + do_catchsql_test e_expr-11.7.$tn $sql [list 1 {too many SQL variables}] +} + +# EVIDENCE-OF: R-14068-49671 Parameters that are not assigned values +# using sqlite3_bind() are treated as NULL. +# +do_test e_expr-11.7.1 { + set stmt [sqlite3_prepare_v2 db { SELECT ?, :a, @b, $d } -1] + sqlite3_step $stmt + + list [sqlite3_column_type $stmt 0] \ + [sqlite3_column_type $stmt 1] \ + [sqlite3_column_type $stmt 2] \ + [sqlite3_column_type $stmt 3] +} {NULL NULL NULL NULL} +do_test e_expr-11.7.1 { sqlite3_finalize $stmt } SQLITE_OK + +#------------------------------------------------------------------------- +# "Test" the syntax diagrams in lang_expr.html. +# +# -- syntax diagram signed-number +# +do_execsql_test e_expr-12.1.1 { SELECT 0, +0, -0 } {0 0 0} +do_execsql_test e_expr-12.1.2 { SELECT 1, +1, -1 } {1 1 -1} +do_execsql_test e_expr-12.1.3 { SELECT 2, +2, -2 } {2 2 -2} +do_execsql_test e_expr-12.1.4 { + SELECT 1.4, +1.4, -1.4 +} {1.4 1.4 -1.4} +do_execsql_test e_expr-12.1.5 { + SELECT 1.5e+5, +1.5e+5, -1.5e+5 +} {150000.0 150000.0 -150000.0} +do_execsql_test e_expr-12.1.6 { + SELECT 0.0001, +0.0001, -0.0001 +} {0.0001 0.0001 -0.0001} + +# -- syntax diagram literal-value +# +set sqlite_current_time 1 +do_execsql_test e_expr-12.2.1 {SELECT 123} {123} +do_execsql_test e_expr-12.2.2 {SELECT 123.4e05} {12340000.0} +do_execsql_test e_expr-12.2.3 {SELECT 'abcde'} {abcde} +do_execsql_test e_expr-12.2.4 {SELECT X'414243'} {ABC} +do_execsql_test e_expr-12.2.5 {SELECT NULL} {{}} +do_execsql_test e_expr-12.2.6 {SELECT CURRENT_TIME} {00:00:01} +do_execsql_test e_expr-12.2.7 {SELECT CURRENT_DATE} {1970-01-01} +do_execsql_test e_expr-12.2.8 {SELECT CURRENT_TIMESTAMP} {{1970-01-01 00:00:01}} +set sqlite_current_time 0 + +# -- syntax diagram expr +# +forcedelete test.db2 +execsql { + ATTACH 'test.db2' AS dbname; + CREATE TABLE dbname.tblname(cname); +} + +proc glob {args} {return 1} +db function glob glob +db function match glob +db function regexp glob + +foreach {tn expr} { + 1 123 + 2 123.4e05 + 3 'abcde' + 4 X'414243' + 5 NULL + 6 CURRENT_TIME + 7 CURRENT_DATE + 8 CURRENT_TIMESTAMP + + 9 ? + 10 ?123 + 11 @hello + 12 :world + 13 $tcl + 14 $tcl(array) + + 15 cname + 16 tblname.cname + 17 dbname.tblname.cname + + 18 "+ EXPR" + 19 "- EXPR" + 20 "NOT EXPR" + 21 "~ EXPR" + + 22 "EXPR1 || EXPR2" + 23 "EXPR1 * EXPR2" + 24 "EXPR1 / EXPR2" + 25 "EXPR1 % EXPR2" + 26 "EXPR1 + EXPR2" + 27 "EXPR1 - EXPR2" + 28 "EXPR1 << EXPR2" + 29 "EXPR1 >> EXPR2" + 30 "EXPR1 & EXPR2" + 31 "EXPR1 | EXPR2" + 32 "EXPR1 < EXPR2" + 33 "EXPR1 <= EXPR2" + 34 "EXPR1 > EXPR2" + 35 "EXPR1 >= EXPR2" + 36 "EXPR1 = EXPR2" + 37 "EXPR1 == EXPR2" + 38 "EXPR1 != EXPR2" + 39 "EXPR1 <> EXPR2" + 40 "EXPR1 IS EXPR2" + 41 "EXPR1 IS NOT EXPR2" + 42 "EXPR1 AND EXPR2" + 43 "EXPR1 OR EXPR2" + + 44 "count(*)" + 45 "count(DISTINCT EXPR)" + 46 "substr(EXPR, 10, 20)" + 47 "changes()" + + 48 "( EXPR )" + + 49 "CAST ( EXPR AS integer )" + 50 "CAST ( EXPR AS 'abcd' )" + 51 "CAST ( EXPR AS 'ab$ $cd' )" + + 52 "EXPR COLLATE nocase" + 53 "EXPR COLLATE binary" + + 54 "EXPR1 LIKE EXPR2" + 55 "EXPR1 LIKE EXPR2 ESCAPE EXPR" + 56 "EXPR1 GLOB EXPR2" + 57 "EXPR1 GLOB EXPR2 ESCAPE EXPR" + 58 "EXPR1 REGEXP EXPR2" + 59 "EXPR1 REGEXP EXPR2 ESCAPE EXPR" + 60 "EXPR1 MATCH EXPR2" + 61 "EXPR1 MATCH EXPR2 ESCAPE EXPR" + 62 "EXPR1 NOT LIKE EXPR2" + 63 "EXPR1 NOT LIKE EXPR2 ESCAPE EXPR" + 64 "EXPR1 NOT GLOB EXPR2" + 65 "EXPR1 NOT GLOB EXPR2 ESCAPE EXPR" + 66 "EXPR1 NOT REGEXP EXPR2" + 67 "EXPR1 NOT REGEXP EXPR2 ESCAPE EXPR" + 68 "EXPR1 NOT MATCH EXPR2" + 69 "EXPR1 NOT MATCH EXPR2 ESCAPE EXPR" + + 70 "EXPR ISNULL" + 71 "EXPR NOTNULL" + 72 "EXPR NOT NULL" + + 73 "EXPR1 IS EXPR2" + 74 "EXPR1 IS NOT EXPR2" + + 75 "EXPR NOT BETWEEN EXPR1 AND EXPR2" + 76 "EXPR BETWEEN EXPR1 AND EXPR2" + + 77 "EXPR NOT IN (SELECT cname FROM tblname)" + 78 "EXPR NOT IN (1)" + 79 "EXPR NOT IN (1, 2, 3)" + 80 "EXPR NOT IN tblname" + 81 "EXPR NOT IN dbname.tblname" + 82 "EXPR IN (SELECT cname FROM tblname)" + 83 "EXPR IN (1)" + 84 "EXPR IN (1, 2, 3)" + 85 "EXPR IN tblname" + 86 "EXPR IN dbname.tblname" + + 87 "EXISTS (SELECT cname FROM tblname)" + 88 "NOT EXISTS (SELECT cname FROM tblname)" + + 89 "CASE EXPR WHEN EXPR1 THEN EXPR2 ELSE EXPR END" + 90 "CASE EXPR WHEN EXPR1 THEN EXPR2 END" + 91 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END" + 92 "CASE EXPR WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END" + 93 "CASE WHEN EXPR1 THEN EXPR2 ELSE EXPR END" + 94 "CASE WHEN EXPR1 THEN EXPR2 END" + 95 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 ELSE EXPR2 END" + 96 "CASE WHEN EXPR1 THEN EXPR2 WHEN EXPR THEN EXPR1 END" +} { + + # If the expression string being parsed contains "EXPR2", then replace + # string "EXPR1" and "EXPR2" with arbitrary SQL expressions. If it + # contains "EXPR", then replace EXPR with an arbitrary SQL expression. + # + set elist [list $expr] + if {[string match *EXPR2* $expr]} { + set elist [list] + foreach {e1 e2} { cname "34+22" } { + lappend elist [string map [list EXPR1 $e1 EXPR2 $e2] $expr] + } + } + if {[string match *EXPR* $expr]} { + set elist2 [list] + foreach el $elist { + foreach e { cname "34+22" } { + lappend elist2 [string map [list EXPR $e] $el] + } + } + set elist $elist2 + } + + set x 0 + foreach e $elist { + incr x + do_test e_expr-12.3.$tn.$x { + set rc [catch { execsql "SELECT $e FROM tblname" } msg] + } {0} + } +} + +# -- syntax diagram raise-function +# +foreach {tn raiseexpr} { + 1 "RAISE(IGNORE)" + 2 "RAISE(ROLLBACK, 'error message')" + 3 "RAISE(ABORT, 'error message')" + 4 "RAISE(FAIL, 'error message')" +} { + do_execsql_test e_expr-12.4.$tn " + CREATE TRIGGER dbname.tr$tn BEFORE DELETE ON tblname BEGIN + SELECT $raiseexpr ; + END; + " {} +} + +#------------------------------------------------------------------------- +# Test the statements related to the BETWEEN operator. +# +# EVIDENCE-OF: R-40079-54503 The BETWEEN operator is logically +# equivalent to a pair of comparisons. "x BETWEEN y AND z" is equivalent +# to "x>=y AND x<=z" except that with BETWEEN, the x expression is +# only evaluated once. +# +db func x x +proc x {} { incr ::xcount ; return [expr $::x] } +foreach {tn x expr res nEval} { + 1 10 "x() >= 5 AND x() <= 15" 1 2 + 2 10 "x() BETWEEN 5 AND 15" 1 1 + + 3 5 "x() >= 5 AND x() <= 5" 1 2 + 4 5 "x() BETWEEN 5 AND 5" 1 1 + + 5 9 "(x(),8) >= (9,7) AND (x(),8)<=(9,10)" 1 2 + 6 9 "(x(),8) BETWEEN (9,7) AND (9,10)" 1 1 +} { + do_test e_expr-13.1.$tn { + set ::xcount 0 + set a [execsql "SELECT $expr"] + list $::xcount $a + } [list $nEval $res] +} + +# X-EVIDENCE-OF: R-05155-34454 The precedence of the BETWEEN operator is +# the same as the precedence as operators == and != and LIKE and groups +# left to right. +# +# Therefore, BETWEEN groups more tightly than operator "AND", but less +# so than "<". +# +do_execsql_test e_expr-13.2.1 { SELECT 1 == 10 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.2 { SELECT (1 == 10) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.3 { SELECT 1 == (10 BETWEEN 0 AND 2) } 0 +do_execsql_test e_expr-13.2.4 { SELECT 6 BETWEEN 4 AND 8 == 1 } 1 +do_execsql_test e_expr-13.2.5 { SELECT (6 BETWEEN 4 AND 8) == 1 } 1 +do_execsql_test e_expr-13.2.6 { SELECT 6 BETWEEN 4 AND (8 == 1) } 0 + +do_execsql_test e_expr-13.2.7 { SELECT 5 BETWEEN 0 AND 0 != 1 } 1 +do_execsql_test e_expr-13.2.8 { SELECT (5 BETWEEN 0 AND 0) != 1 } 1 +do_execsql_test e_expr-13.2.9 { SELECT 5 BETWEEN 0 AND (0 != 1) } 0 +do_execsql_test e_expr-13.2.10 { SELECT 1 != 0 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.11 { SELECT (1 != 0) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.12 { SELECT 1 != (0 BETWEEN 0 AND 2) } 0 + +do_execsql_test e_expr-13.2.13 { SELECT 1 LIKE 10 BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.14 { SELECT (1 LIKE 10) BETWEEN 0 AND 2 } 1 +do_execsql_test e_expr-13.2.15 { SELECT 1 LIKE (10 BETWEEN 0 AND 2) } 0 +do_execsql_test e_expr-13.2.16 { SELECT 6 BETWEEN 4 AND 8 LIKE 1 } 1 +do_execsql_test e_expr-13.2.17 { SELECT (6 BETWEEN 4 AND 8) LIKE 1 } 1 +do_execsql_test e_expr-13.2.18 { SELECT 6 BETWEEN 4 AND (8 LIKE 1) } 0 + +do_execsql_test e_expr-13.2.19 { SELECT 0 AND 0 BETWEEN 0 AND 1 } 0 +do_execsql_test e_expr-13.2.20 { SELECT 0 AND (0 BETWEEN 0 AND 1) } 0 +do_execsql_test e_expr-13.2.21 { SELECT (0 AND 0) BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.22 { SELECT 0 BETWEEN -1 AND 1 AND 0 } 0 +do_execsql_test e_expr-13.2.23 { SELECT (0 BETWEEN -1 AND 1) AND 0 } 0 +do_execsql_test e_expr-13.2.24 { SELECT 0 BETWEEN -1 AND (1 AND 0) } 1 + +do_execsql_test e_expr-13.2.25 { SELECT 2 < 3 BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.26 { SELECT (2 < 3) BETWEEN 0 AND 1 } 1 +do_execsql_test e_expr-13.2.27 { SELECT 2 < (3 BETWEEN 0 AND 1) } 0 +do_execsql_test e_expr-13.2.28 { SELECT 2 BETWEEN 1 AND 2 < 3 } 0 +do_execsql_test e_expr-13.2.29 { SELECT 2 BETWEEN 1 AND (2 < 3) } 0 +do_execsql_test e_expr-13.2.30 { SELECT (2 BETWEEN 1 AND 2) < 3 } 1 + +#------------------------------------------------------------------------- +# Test the statements related to the LIKE and GLOB operators. +# +# EVIDENCE-OF: R-16584-60189 The LIKE operator does a pattern matching +# comparison. +# +# EVIDENCE-OF: R-11295-04657 The operand to the right of the LIKE +# operator contains the pattern and the left hand operand contains the +# string to match against the pattern. +# +do_execsql_test e_expr-14.1.1 { SELECT 'abc%' LIKE 'abcde' } 0 +do_execsql_test e_expr-14.1.2 { SELECT 'abcde' LIKE 'abc%' } 1 + +# EVIDENCE-OF: R-55406-38524 A percent symbol ("%") in the LIKE pattern +# matches any sequence of zero or more characters in the string. +# +do_execsql_test e_expr-14.2.1 { SELECT 'abde' LIKE 'ab%de' } 1 +do_execsql_test e_expr-14.2.2 { SELECT 'abXde' LIKE 'ab%de' } 1 +do_execsql_test e_expr-14.2.3 { SELECT 'abABCde' LIKE 'ab%de' } 1 + +# EVIDENCE-OF: R-30433-25443 An underscore ("_") in the LIKE pattern +# matches any single character in the string. +# +do_execsql_test e_expr-14.3.1 { SELECT 'abde' LIKE 'ab_de' } 0 +do_execsql_test e_expr-14.3.2 { SELECT 'abXde' LIKE 'ab_de' } 1 +do_execsql_test e_expr-14.3.3 { SELECT 'abABCde' LIKE 'ab_de' } 0 + +# EVIDENCE-OF: R-59007-20454 Any other character matches itself or its +# lower/upper case equivalent (i.e. case-insensitive matching). +# +do_execsql_test e_expr-14.4.1 { SELECT 'abc' LIKE 'aBc' } 1 +do_execsql_test e_expr-14.4.2 { SELECT 'aBc' LIKE 'aBc' } 1 +do_execsql_test e_expr-14.4.3 { SELECT 'ac' LIKE 'aBc' } 0 + +# EVIDENCE-OF: R-23648-58527 SQLite only understands upper/lower case +# for ASCII characters by default. +# +# EVIDENCE-OF: R-04532-11527 The LIKE operator is case sensitive by +# default for unicode characters that are beyond the ASCII range. +# +# EVIDENCE-OF: R-44381-11669 the expression +# 'a' LIKE 'A' is TRUE but +# 'æ' LIKE 'Æ' is FALSE. +# +# The restriction to ASCII characters does not apply if the ICU +# library is compiled in. When ICU is enabled SQLite does not act +# as it does "by default". +# +do_execsql_test e_expr-14.5.1 { SELECT 'A' LIKE 'a' } 1 +ifcapable !icu { + do_execsql_test e_expr-14.5.2 "SELECT '\u00c6' LIKE '\u00e6'" 0 +} + +# EVIDENCE-OF: R-56683-13731 If the optional ESCAPE clause is present, +# then the expression following the ESCAPE keyword must evaluate to a +# string consisting of a single character. +# +do_catchsql_test e_expr-14.6.1 { + SELECT 'A' LIKE 'a' ESCAPE '12' +} {1 {ESCAPE expression must be a single character}} +do_catchsql_test e_expr-14.6.2 { + SELECT 'A' LIKE 'a' ESCAPE '' +} {1 {ESCAPE expression must be a single character}} +do_catchsql_test e_expr-14.6.3 { SELECT 'A' LIKE 'a' ESCAPE 'x' } {0 1} +do_catchsql_test e_expr-14.6.4 "SELECT 'A' LIKE 'a' ESCAPE '\u00e6'" {0 1} + +# EVIDENCE-OF: R-02045-23762 This character may be used in the LIKE +# pattern to include literal percent or underscore characters. +# +# EVIDENCE-OF: R-13345-31830 The escape character followed by a percent +# symbol (%), underscore (_), or a second instance of the escape +# character itself matches a literal percent symbol, underscore, or a +# single escape character, respectively. +# +do_execsql_test e_expr-14.7.1 { SELECT 'abc%' LIKE 'abcX%' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.2 { SELECT 'abc5' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.3 { SELECT 'abc' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.4 { SELECT 'abcX%' LIKE 'abcX%' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.5 { SELECT 'abc%%' LIKE 'abcX%' ESCAPE 'X' } 0 + +do_execsql_test e_expr-14.7.6 { SELECT 'abc_' LIKE 'abcX_' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.7 { SELECT 'abc5' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.8 { SELECT 'abc' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.9 { SELECT 'abcX_' LIKE 'abcX_' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.10 { SELECT 'abc__' LIKE 'abcX_' ESCAPE 'X' } 0 + +do_execsql_test e_expr-14.7.11 { SELECT 'abcX' LIKE 'abcXX' ESCAPE 'X' } 1 +do_execsql_test e_expr-14.7.12 { SELECT 'abc5' LIKE 'abcXX' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.13 { SELECT 'abc' LIKE 'abcXX' ESCAPE 'X' } 0 +do_execsql_test e_expr-14.7.14 { SELECT 'abcXX' LIKE 'abcXX' ESCAPE 'X' } 0 + +# EVIDENCE-OF: R-51359-17496 The infix LIKE operator is implemented by +# calling the application-defined SQL functions like(Y,X) or like(Y,X,Z). +# +proc likefunc {args} { + eval lappend ::likeargs $args + return 1 +} +db func like -argcount 2 likefunc +db func like -argcount 3 likefunc +set ::likeargs [list] +do_execsql_test e_expr-15.1.1 { SELECT 'abc' LIKE 'def' } 1 +do_test e_expr-15.1.2 { set likeargs } {def abc} +set ::likeargs [list] +do_execsql_test e_expr-15.1.3 { SELECT 'abc' LIKE 'def' ESCAPE 'X' } 1 +do_test e_expr-15.1.4 { set likeargs } {def abc X} +db close +sqlite3 db test.db + +# EVIDENCE-OF: R-22868-25880 The LIKE operator can be made case +# sensitive using the case_sensitive_like pragma. +# +do_execsql_test e_expr-16.1.1 { SELECT 'abcxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.1b { SELECT 'abc%xyz' LIKE 'ABC\%x%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.2 { PRAGMA case_sensitive_like = 1 } {} +do_execsql_test e_expr-16.1.3 { SELECT 'abcxyz' LIKE 'ABC%' } 0 +do_execsql_test e_expr-16.1.3b { SELECT 'abc%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 0 +do_execsql_test e_expr-16.1.4 { SELECT 'ABCxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.4b { SELECT 'ABC%xyz' LIKE 'ABC\%x%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.5 { PRAGMA case_sensitive_like = 0 } {} +do_execsql_test e_expr-16.1.6 { SELECT 'abcxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.6b { SELECT 'abc%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 1 +do_execsql_test e_expr-16.1.7 { SELECT 'ABCxyz' LIKE 'ABC%' } 1 +do_execsql_test e_expr-16.1.7b { SELECT 'ABC%xyz' LIKE 'ABC\%X%' ESCAPE '\' } 1 + +# EVIDENCE-OF: R-52087-12043 The GLOB operator is similar to LIKE but +# uses the Unix file globbing syntax for its wildcards. +# +# EVIDENCE-OF: R-09813-17279 Also, GLOB is case sensitive, unlike LIKE. +# +do_execsql_test e_expr-17.1.1 { SELECT 'abcxyz' GLOB 'abc%' } 0 +do_execsql_test e_expr-17.1.2 { SELECT 'abcxyz' GLOB 'abc*' } 1 +do_execsql_test e_expr-17.1.3 { SELECT 'abcxyz' GLOB 'abc___' } 0 +do_execsql_test e_expr-17.1.4 { SELECT 'abcxyz' GLOB 'abc???' } 1 + +do_execsql_test e_expr-17.1.5 { SELECT 'abcxyz' GLOB 'abc*' } 1 +do_execsql_test e_expr-17.1.6 { SELECT 'ABCxyz' GLOB 'abc*' } 0 +do_execsql_test e_expr-17.1.7 { SELECT 'abcxyz' GLOB 'ABC*' } 0 + +# EVIDENCE-OF: R-39616-20555 Both GLOB and LIKE may be preceded by the +# NOT keyword to invert the sense of the test. +# +do_execsql_test e_expr-17.2.1 { SELECT 'abcxyz' NOT GLOB 'ABC*' } 1 +do_execsql_test e_expr-17.2.2 { SELECT 'abcxyz' NOT GLOB 'abc*' } 0 +do_execsql_test e_expr-17.2.3 { SELECT 'abcxyz' NOT LIKE 'ABC%' } 0 +do_execsql_test e_expr-17.2.4 { SELECT 'abcxyz' NOT LIKE 'abc%' } 0 +do_execsql_test e_expr-17.2.5 { SELECT 'abdxyz' NOT LIKE 'abc%' } 1 + +db nullvalue null +do_execsql_test e_expr-17.2.6 { SELECT 'abcxyz' NOT GLOB NULL } null +do_execsql_test e_expr-17.2.7 { SELECT 'abcxyz' NOT LIKE NULL } null +do_execsql_test e_expr-17.2.8 { SELECT NULL NOT GLOB 'abc*' } null +do_execsql_test e_expr-17.2.9 { SELECT NULL NOT LIKE 'ABC%' } null +db nullvalue {} + +# EVIDENCE-OF: R-39414-35489 The infix GLOB operator is implemented by +# calling the function glob(Y,X) and can be modified by overriding that +# function. +proc globfunc {args} { + eval lappend ::globargs $args + return 1 +} +db func glob -argcount 2 globfunc +set ::globargs [list] +do_execsql_test e_expr-17.3.1 { SELECT 'abc' GLOB 'def' } 1 +do_test e_expr-17.3.2 { set globargs } {def abc} +set ::globargs [list] +do_execsql_test e_expr-17.3.3 { SELECT 'X' NOT GLOB 'Y' } 0 +do_test e_expr-17.3.4 { set globargs } {Y X} +sqlite3 db test.db + +# EVIDENCE-OF: R-41650-20872 No regexp() user function is defined by +# default and so use of the REGEXP operator will normally result in an +# error message. +# +# There is a regexp function if ICU is enabled though. +# +ifcapable !icu { + do_catchsql_test e_expr-18.1.1 { + SELECT regexp('abc', 'def') + } {1 {no such function: regexp}} + do_catchsql_test e_expr-18.1.2 { + SELECT 'abc' REGEXP 'def' + } {1 {no such function: REGEXP}} +} + +# EVIDENCE-OF: R-33693-50180 The REGEXP operator is a special syntax for +# the regexp() user function. +# +# EVIDENCE-OF: R-65524-61849 If an application-defined SQL function +# named "regexp" is added at run-time, then the "X REGEXP Y" operator +# will be implemented as a call to "regexp(Y,X)". +# +proc regexpfunc {args} { + eval lappend ::regexpargs $args + return 1 +} +db func regexp -argcount 2 regexpfunc +set ::regexpargs [list] +do_execsql_test e_expr-18.2.1 { SELECT 'abc' REGEXP 'def' } 1 +do_test e_expr-18.2.2 { set regexpargs } {def abc} +set ::regexpargs [list] +do_execsql_test e_expr-18.2.3 { SELECT 'X' NOT REGEXP 'Y' } 0 +do_test e_expr-18.2.4 { set regexpargs } {Y X} +sqlite3 db test.db + +# EVIDENCE-OF: R-42037-37826 The default match() function implementation +# raises an exception and is not really useful for anything. +# +do_catchsql_test e_expr-19.1.1 { + SELECT 'abc' MATCH 'def' +} {1 {unable to use function MATCH in the requested context}} +do_catchsql_test e_expr-19.1.2 { + SELECT match('abc', 'def') +} {1 {unable to use function MATCH in the requested context}} + +# EVIDENCE-OF: R-37916-47407 The MATCH operator is a special syntax for +# the match() application-defined function. +# +# EVIDENCE-OF: R-06021-09373 But extensions can override the match() +# function with more helpful logic. +# +proc matchfunc {args} { + eval lappend ::matchargs $args + return 1 +} +db func match -argcount 2 matchfunc +set ::matchargs [list] +do_execsql_test e_expr-19.2.1 { SELECT 'abc' MATCH 'def' } 1 +do_test e_expr-19.2.2 { set matchargs } {def abc} +set ::matchargs [list] +do_execsql_test e_expr-19.2.3 { SELECT 'X' NOT MATCH 'Y' } 0 +do_test e_expr-19.2.4 { set matchargs } {Y X} +sqlite3 db test.db + +#------------------------------------------------------------------------- +# Test cases for the testable statements related to the CASE expression. +# +# EVIDENCE-OF: R-57495-24088 There are two fundamental forms of the CASE +# expression: those with a base expression and those without. +# +do_execsql_test e_expr-20.1 { + SELECT CASE WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END; +} {true} +do_execsql_test e_expr-20.2 { + SELECT CASE 0 WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE 'else' END; +} {false} + +proc var {nm} { + lappend ::varlist $nm + return [set "::$nm"] +} +db func var var + +# EVIDENCE-OF: R-30638-59954 In a CASE without a base expression, each +# WHEN expression is evaluated and the result treated as a boolean, +# starting with the leftmost and continuing to the right. +# +foreach {a b c} {0 0 0} break +set varlist [list] +do_execsql_test e_expr-21.1.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' END +} {{}} +do_test e_expr-21.1.2 { set varlist } {a b c} +set varlist [list] +do_execsql_test e_expr-21.1.3 { + SELECT CASE WHEN var('c') THEN 'C' + WHEN var('b') THEN 'B' + WHEN var('a') THEN 'A' + ELSE 'no result' + END +} {{no result}} +do_test e_expr-21.1.4 { set varlist } {c b a} + +# EVIDENCE-OF: R-39009-25596 The result of the CASE expression is the +# evaluation of the THEN expression that corresponds to the first WHEN +# expression that evaluates to true. +# +foreach {a b c} {0 1 0} break +do_execsql_test e_expr-21.2.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {B} +foreach {a b c} {0 1 1} break +do_execsql_test e_expr-21.2.2 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {B} +foreach {a b c} {0 0 1} break +do_execsql_test e_expr-21.2.3 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {C} + +# EVIDENCE-OF: R-24227-04807 Or, if none of the WHEN expressions +# evaluate to true, the result of evaluating the ELSE expression, if +# any. +# +foreach {a b c} {0 0 0} break +do_execsql_test e_expr-21.3.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + ELSE 'no result' + END +} {{no result}} + +# EVIDENCE-OF: R-14168-07579 If there is no ELSE expression and none of +# the WHEN expressions are true, then the overall result is NULL. +# +db nullvalue null +do_execsql_test e_expr-21.3.2 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {null} +db nullvalue {} + +# EVIDENCE-OF: R-13943-13592 A NULL result is considered untrue when +# evaluating WHEN terms. +# +do_execsql_test e_expr-21.4.1 { + SELECT CASE WHEN NULL THEN 'A' WHEN 1 THEN 'B' END, iif(NULL,8,99); +} {B 99} +do_execsql_test e_expr-21.4.2 { + SELECT CASE WHEN 0 THEN 'A' WHEN NULL THEN 'B' ELSE 'C' END, iif(0,8,99); +} {C 99} + +# EVIDENCE-OF: R-38620-19499 In a CASE with a base expression, the base +# expression is evaluated just once and the result is compared against +# the evaluation of each WHEN expression from left to right. +# +# Note: This test case tests the "evaluated just once" part of the above +# statement. Tests associated with the next two statements test that the +# comparisons take place. +# +foreach {a b c} [list [expr 3] [expr 4] [expr 5]] break +set ::varlist [list] +do_execsql_test e_expr-22.1.1 { + SELECT CASE var('a') WHEN 1 THEN 'A' WHEN 2 THEN 'B' WHEN 3 THEN 'C' END +} {C} +do_test e_expr-22.1.2 { set ::varlist } {a} + +# EVIDENCE-OF: R-07667-49537 The result of the CASE expression is the +# evaluation of the THEN expression that corresponds to the first WHEN +# expression for which the comparison is true. +# +do_execsql_test e_expr-22.2.1 { + SELECT CASE 23 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {B} +do_execsql_test e_expr-22.2.2 { + SELECT CASE 1 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {A} + +# EVIDENCE-OF: R-47543-32145 Or, if none of the WHEN expressions +# evaluate to a value equal to the base expression, the result of +# evaluating the ELSE expression, if any. +# +do_execsql_test e_expr-22.3.1 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' ELSE 'D' END +} {D} + +# EVIDENCE-OF: R-54721-48557 If there is no ELSE expression and none of +# the WHEN expressions produce a result equal to the base expression, +# the overall result is NULL. +# +do_execsql_test e_expr-22.4.1 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {{}} +db nullvalue null +do_execsql_test e_expr-22.4.2 { + SELECT CASE 24 WHEN 1 THEN 'A' WHEN 23 THEN 'B' WHEN 23 THEN 'C' END +} {null} +db nullvalue {} + +# EVIDENCE-OF: R-11479-62774 When comparing a base expression against a +# WHEN expression, the same collating sequence, affinity, and +# NULL-handling rules apply as if the base expression and WHEN +# expression are respectively the left- and right-hand operands of an = +# operator. +# +proc rev {str} { + set ret "" + set chars [split $str] + for {set i [expr [llength $chars]-1]} {$i>=0} {incr i -1} { + append ret [lindex $chars $i] + } + set ret +} +proc reverse {lhs rhs} { + string compare [rev $lhs] [rev $rhs] +} +db collate reverse reverse +do_execsql_test e_expr-23.1.1 { + CREATE TABLE t1( + a TEXT COLLATE NOCASE, + b COLLATE REVERSE, + c INTEGER, + d BLOB + ); + INSERT INTO t1 VALUES('abc', 'cba', 55, 34.5); +} {} +do_execsql_test e_expr-23.1.2 { + SELECT CASE a WHEN 'xyz' THEN 'A' WHEN 'AbC' THEN 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.3 { + SELECT CASE 'AbC' WHEN 'abc' THEN 'A' WHEN a THEN 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.4 { + SELECT CASE a WHEN b THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.5 { + SELECT CASE b WHEN a THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.6 { + SELECT CASE 55 WHEN '55' THEN 'A' ELSE 'B' END +} {B} +do_execsql_test e_expr-23.1.7 { + SELECT CASE c WHEN '55' THEN 'A' ELSE 'B' END FROM t1 +} {A} +do_execsql_test e_expr-23.1.8 { + SELECT CASE '34.5' WHEN d THEN 'A' ELSE 'B' END FROM t1 +} {B} +do_execsql_test e_expr-23.1.9 { + SELECT CASE NULL WHEN NULL THEN 'A' ELSE 'B' END +} {B} + +# EVIDENCE-OF: R-37304-39405 If the base expression is NULL then the +# result of the CASE is always the result of evaluating the ELSE +# expression if it exists, or NULL if it does not. +# +do_execsql_test e_expr-24.1.1 { + SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' END; +} {{}} +do_execsql_test e_expr-24.1.2 { + SELECT CASE NULL WHEN 'abc' THEN 'A' WHEN 'def' THEN 'B' ELSE 'C' END; +} {C} + +# EVIDENCE-OF: R-56280-17369 Both forms of the CASE expression use lazy, +# or short-circuit, evaluation. +# +set varlist [list] +foreach {a b c} {0 1 0} break +do_execsql_test e_expr-25.1.1 { + SELECT CASE WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {B} +do_test e_expr-25.1.2 { set ::varlist } {a b} +set varlist [list] +do_execsql_test e_expr-25.1.3 { + SELECT CASE '0' WHEN var('a') THEN 'A' + WHEN var('b') THEN 'B' + WHEN var('c') THEN 'C' + END +} {A} +do_test e_expr-25.1.4 { set ::varlist } {a} + +# EVIDENCE-OF: R-34773-62253 The only difference between the following +# two CASE expressions is that the x expression is evaluated exactly +# once in the first example but might be evaluated multiple times in the +# second: CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END CASE WHEN +# x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END +# +proc ceval {x} { + incr ::evalcount + return $x +} +db func ceval ceval +set ::evalcount 0 + +do_execsql_test e_expr-26.1.1 { + CREATE TABLE t2(x, w1, r1, w2, r2, r3); + INSERT INTO t2 VALUES(1, 1, 'R1', 2, 'R2', 'R3'); + INSERT INTO t2 VALUES(2, 1, 'R1', 2, 'R2', 'R3'); + INSERT INTO t2 VALUES(3, 1, 'R1', 2, 'R2', 'R3'); +} {} +do_execsql_test e_expr-26.1.2 { + SELECT CASE x WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} +do_execsql_test e_expr-26.1.3 { + SELECT CASE WHEN x=w1 THEN r1 WHEN x=w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} + +do_execsql_test e_expr-26.1.4 { + SELECT CASE ceval(x) WHEN w1 THEN r1 WHEN w2 THEN r2 ELSE r3 END FROM t2 +} {R1 R2 R3} +do_test e_expr-26.1.5 { set ::evalcount } {3} +set ::evalcount 0 +do_execsql_test e_expr-26.1.6 { + SELECT CASE + WHEN ceval(x)=w1 THEN r1 + WHEN ceval(x)=w2 THEN r2 + ELSE r3 END + FROM t2 +} {R1 R2 R3} +do_test e_expr-26.1.6 { set ::evalcount } {5} + + +#------------------------------------------------------------------------- +# Test statements related to CAST expressions. +# +# EVIDENCE-OF: R-20854-17109 A CAST conversion is similar to the +# conversion that takes place when a column affinity is applied to a +# value except that with the CAST operator the conversion always takes +# place even if the conversion lossy and irreversible, whereas column +# affinity only changes the data type of a value if the change is +# lossless and reversible. +# +do_execsql_test e_expr-27.1.1 { + CREATE TABLE t3(a TEXT, b REAL, c INTEGER); + INSERT INTO t3 VALUES(X'555655', '1.23abc', 4.5); + SELECT typeof(a), a, typeof(b), b, typeof(c), c FROM t3; +} {blob UVU text 1.23abc real 4.5} +do_execsql_test e_expr-27.1.2 { + SELECT + typeof(CAST(X'555655' as TEXT)), CAST(X'555655' as TEXT), + typeof(CAST('1.23abc' as REAL)), CAST('1.23abc' as REAL), + typeof(CAST(4.5 as INTEGER)), CAST(4.5 as INTEGER) +} {text UVU real 1.23 integer 4} + +# EVIDENCE-OF: R-32434-09092 If the value of expr is NULL, then the +# result of the CAST expression is also NULL. +# +do_expr_test e_expr-27.2.1 { CAST(NULL AS integer) } null {} +do_expr_test e_expr-27.2.2 { CAST(NULL AS text) } null {} +do_expr_test e_expr-27.2.3 { CAST(NULL AS blob) } null {} +do_expr_test e_expr-27.2.4 { CAST(NULL AS number) } null {} + +# EVIDENCE-OF: R-29283-15561 Otherwise, the storage class of the result +# is determined by applying the rules for determining column affinity to +# the type-name. +# +# The R-29283-15561 requirement above is demonstrated by all of the +# subsequent e_expr-26 tests. +# +# EVIDENCE-OF: R-43522-35548 Casting a value to a type-name with no +# affinity causes the value to be converted into a BLOB. +# +do_expr_test e_expr-27.3.1 { CAST('abc' AS blob) } blob abc +do_expr_test e_expr-27.3.2 { CAST('def' AS shobblob_x) } blob def +do_expr_test e_expr-27.3.3 { CAST('ghi' AS abbLOb10) } blob ghi + +# EVIDENCE-OF: R-22956-37754 Casting to a BLOB consists of first casting +# the value to TEXT in the encoding of the database connection, then +# interpreting the resulting byte sequence as a BLOB instead of as TEXT. +# +do_qexpr_test e_expr-27.4.1 { CAST('ghi' AS blob) } X'676869' +do_qexpr_test e_expr-27.4.2 { CAST(456 AS blob) } X'343536' +do_qexpr_test e_expr-27.4.3 { CAST(1.78 AS blob) } X'312E3738' +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +db eval { PRAGMA encoding = 'utf-16le' } +do_qexpr_test e_expr-27.4.4 { CAST('ghi' AS blob) } X'670068006900' +do_qexpr_test e_expr-27.4.5 { CAST(456 AS blob) } X'340035003600' +do_qexpr_test e_expr-27.4.6 { CAST(1.78 AS blob) } X'31002E0037003800' +} +db close +sqlite3 db :memory: +db eval { PRAGMA encoding = 'utf-16be' } +ifcapable {utf16} { +do_qexpr_test e_expr-27.4.7 { CAST('ghi' AS blob) } X'006700680069' +do_qexpr_test e_expr-27.4.8 { CAST(456 AS blob) } X'003400350036' +do_qexpr_test e_expr-27.4.9 { CAST(1.78 AS blob) } X'0031002E00370038' +} +db close +rename db2 db + +# EVIDENCE-OF: R-04207-37981 To cast a BLOB value to TEXT, the sequence +# of bytes that make up the BLOB is interpreted as text encoded using +# the database encoding. +# +do_expr_test e_expr-28.1.1 { CAST (X'676869' AS text) } text ghi +do_expr_test e_expr-28.1.2 { CAST (X'670068006900' AS text) } text g +rename db db2 +sqlite3 db :memory: +db eval { PRAGMA encoding = 'utf-16le' } +ifcapable {utf16} { +do_expr_test e_expr-28.1.3 { CAST (X'676869' AS text) == 'ghi' } integer 0 +do_expr_test e_expr-28.1.4 { CAST (X'670068006900' AS text) } text ghi +} +db close +rename db2 db + +# EVIDENCE-OF: R-22235-47006 Casting an INTEGER or REAL value into TEXT +# renders the value as if via sqlite3_snprintf() except that the +# resulting TEXT uses the encoding of the database connection. +# +do_expr_test e_expr-28.2.1 { CAST (1 AS text) } text 1 +do_expr_test e_expr-28.2.2 { CAST (45 AS text) } text 45 +do_expr_test e_expr-28.2.3 { CAST (-45 AS text) } text -45 +do_expr_test e_expr-28.2.4 { CAST (8.8 AS text) } text 8.8 +do_expr_test e_expr-28.2.5 { CAST (2.3e+5 AS text) } text 230000.0 +do_expr_test e_expr-28.2.6 { CAST (-2.3e-5 AS text) } text -2.3e-05 +do_expr_test e_expr-28.2.7 { CAST (0.0 AS text) } text 0.0 +do_expr_test e_expr-28.2.7 { CAST (0 AS text) } text 0 + +# EVIDENCE-OF: R-26346-36443 When casting a BLOB value to a REAL, the +# value is first converted to TEXT. +# +do_expr_test e_expr-29.1.1 { CAST (X'312E3233' AS REAL) } real 1.23 +do_expr_test e_expr-29.1.2 { CAST (X'3233302E30' AS REAL) } real 230.0 +do_expr_test e_expr-29.1.3 { CAST (X'2D392E3837' AS REAL) } real -9.87 +do_expr_test e_expr-29.1.4 { CAST (X'302E30303031' AS REAL) } real 0.0001 +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +db eval { PRAGMA encoding = 'utf-16le' } +do_expr_test e_expr-29.1.5 { + CAST (X'31002E0032003300' AS REAL) } real 1.23 +do_expr_test e_expr-29.1.6 { + CAST (X'3200330030002E003000' AS REAL) } real 230.0 +do_expr_test e_expr-29.1.7 { + CAST (X'2D0039002E0038003700' AS REAL) } real -9.87 +do_expr_test e_expr-29.1.8 { + CAST (X'30002E003000300030003100' AS REAL) } real 0.0001 +} +db close +rename db2 db + +# EVIDENCE-OF: R-54898-34554 When casting a TEXT value to REAL, the +# longest possible prefix of the value that can be interpreted as a real +# number is extracted from the TEXT value and the remainder ignored. +# +do_expr_test e_expr-29.2.1 { CAST('1.23abcd' AS REAL) } real 1.23 +do_expr_test e_expr-29.2.2 { CAST('1.45.23abcd' AS REAL) } real 1.45 +do_expr_test e_expr-29.2.3 { CAST('-2.12e-01ABC' AS REAL) } real -0.212 +do_expr_test e_expr-29.2.4 { CAST('1 2 3 4' AS REAL) } real 1.0 + +# EVIDENCE-OF: R-11321-47427 Any leading spaces in the TEXT value are +# ignored when converging from TEXT to REAL. +# +do_expr_test e_expr-29.3.1 { CAST(' 1.23abcd' AS REAL) } real 1.23 +do_expr_test e_expr-29.3.2 { CAST(' 1.45.23abcd' AS REAL) } real 1.45 +do_expr_test e_expr-29.3.3 { CAST(' -2.12e-01ABC' AS REAL) } real -0.212 +do_expr_test e_expr-29.3.4 { CAST(' 1 2 3 4' AS REAL) } real 1.0 + +# EVIDENCE-OF: R-22662-28218 If there is no prefix that can be +# interpreted as a real number, the result of the conversion is 0.0. +# +do_expr_test e_expr-29.4.1 { CAST('' AS REAL) } real 0.0 +do_expr_test e_expr-29.4.2 { CAST('not a number' AS REAL) } real 0.0 +do_expr_test e_expr-29.4.3 { CAST('XXI' AS REAL) } real 0.0 + +# EVIDENCE-OF: R-21829-14563 When casting a BLOB value to INTEGER, the +# value is first converted to TEXT. +# +do_expr_test e_expr-30.1.1 { CAST(X'313233' AS INTEGER) } integer 123 +do_expr_test e_expr-30.1.2 { CAST(X'2D363738' AS INTEGER) } integer -678 +do_expr_test e_expr-30.1.3 { + CAST(X'31303030303030' AS INTEGER) +} integer 1000000 +do_expr_test e_expr-30.1.4 { + CAST(X'2D31313235383939393036383432363234' AS INTEGER) +} integer -1125899906842624 + +rename db db2 +sqlite3 db :memory: +ifcapable {utf16} { +execsql { PRAGMA encoding = 'utf-16be' } +do_expr_test e_expr-30.1.5 { CAST(X'003100320033' AS INTEGER) } integer 123 +do_expr_test e_expr-30.1.6 { CAST(X'002D003600370038' AS INTEGER) } integer -678 +do_expr_test e_expr-30.1.7 { + CAST(X'0031003000300030003000300030' AS INTEGER) +} integer 1000000 +do_expr_test e_expr-30.1.8 { + CAST(X'002D0031003100320035003800390039003900300036003800340032003600320034' AS INTEGER) +} integer -1125899906842624 +} +db close +rename db2 db + +# EVIDENCE-OF: R-47612-45842 When casting a TEXT value to INTEGER, the +# longest possible prefix of the value that can be interpreted as an +# integer number is extracted from the TEXT value and the remainder +# ignored. +# +do_expr_test e_expr-30.2.1 { CAST('123abcd' AS INT) } integer 123 +do_expr_test e_expr-30.2.2 { CAST('14523abcd' AS INT) } integer 14523 +do_expr_test e_expr-30.2.3 { CAST('-2.12e-01ABC' AS INT) } integer -2 +do_expr_test e_expr-30.2.4 { CAST('1 2 3 4' AS INT) } integer 1 + +# EVIDENCE-OF: R-34400-33772 Any leading spaces in the TEXT value when +# converting from TEXT to INTEGER are ignored. +# +do_expr_test e_expr-30.3.1 { CAST(' 123abcd' AS INT) } integer 123 +do_expr_test e_expr-30.3.2 { CAST(' 14523abcd' AS INT) } integer 14523 +do_expr_test e_expr-30.3.3 { CAST(' -2.12e-01ABC' AS INT) } integer -2 +do_expr_test e_expr-30.3.4 { CAST(' 1 2 3 4' AS INT) } integer 1 + +# EVIDENCE-OF: R-43164-44276 If there is no prefix that can be +# interpreted as an integer number, the result of the conversion is 0. +# +do_expr_test e_expr-30.4.1 { CAST('' AS INTEGER) } integer 0 +do_expr_test e_expr-30.4.2 { CAST('not a number' AS INTEGER) } integer 0 +do_expr_test e_expr-30.4.3 { CAST('XXI' AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-08980-53124 The CAST operator understands decimal +# integers only — conversion of hexadecimal integers stops at +# the "x" in the "0x" prefix of the hexadecimal integer string and thus +# result of the CAST is always zero. +do_expr_test e_expr-30.5.1 { CAST('0x1234' AS INTEGER) } integer 0 +do_expr_test e_expr-30.5.2 { CAST('0X1234' AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-02752-50091 A cast of a REAL value into an INTEGER +# results in the integer between the REAL value and zero that is closest +# to the REAL value. +# +do_expr_test e_expr-31.1.1 { CAST(3.14159 AS INTEGER) } integer 3 +do_expr_test e_expr-31.1.2 { CAST(1.99999 AS INTEGER) } integer 1 +do_expr_test e_expr-31.1.3 { CAST(-1.99999 AS INTEGER) } integer -1 +do_expr_test e_expr-31.1.4 { CAST(-0.99999 AS INTEGER) } integer 0 + +# EVIDENCE-OF: R-51517-40824 If a REAL is greater than the greatest +# possible signed integer (+9223372036854775807) then the result is the +# greatest possible signed integer and if the REAL is less than the +# least possible signed integer (-9223372036854775808) then the result +# is the least possible signed integer. +# +do_expr_test e_expr-31.2.1 { CAST(2e+50 AS INT) } integer 9223372036854775807 +do_expr_test e_expr-31.2.2 { CAST(-2e+50 AS INT) } integer -9223372036854775808 +do_expr_test e_expr-31.2.3 { + CAST(-9223372036854775809.0 AS INT) +} integer -9223372036854775808 +do_expr_test e_expr-31.2.4 { + CAST(9223372036854775809.0 AS INT) +} integer 9223372036854775807 + + +# EVIDENCE-OF: R-55084-10555 Casting a TEXT or BLOB value into NUMERIC +# yields either an INTEGER or a REAL result. +# +# EVIDENCE-OF: R-48945-04866 If the input text looks like an integer +# (there is no decimal point nor exponent) and the value is small enough +# to fit in a 64-bit signed integer, then the result will be INTEGER. +# +# EVIDENCE-OF: R-47045-23194 Input text that looks like floating point +# (there is a decimal point and/or an exponent) and the text describes a +# value that can be losslessly converted back and forth between IEEE 754 +# 64-bit float and a 51-bit signed integer, then the result is INTEGER. +# +do_expr_test e_expr-32.1.1 { CAST('45' AS NUMERIC) } integer 45 +do_expr_test e_expr-32.1.2 { CAST('45.0' AS NUMERIC) } integer 45 +do_expr_test e_expr-32.1.3 { CAST('45.2' AS NUMERIC) } real 45.2 +do_expr_test e_expr-32.1.4 { CAST('11abc' AS NUMERIC) } integer 11 +do_expr_test e_expr-32.1.5 { CAST('11.1abc' AS NUMERIC) } real 11.1 +do_expr_test e_expr-32.1.6 {CAST( '9.223372036e14' AS NUMERIC)} integer 922337203600000 +do_expr_test e_expr-32.1.7 {CAST('-9.223372036e14' AS NUMERIC)} integer -922337203600000 +do_test e_expr-32.1.8 { + set expr {CAST( '9.223372036e15' AS NUMERIC)} + db eval "SELECT typeof($expr) AS type, printf('%.5e',$expr) AS value" break; + list $type $value +} {real 9.22337e+15} +do_test e_expr-32.1.9 { + set expr {CAST('-9.223372036e15' AS NUMERIC)} + db eval "SELECT typeof($expr) AS type, printf('%.5e',$expr) AS value" break; + list $type $value +} {real -9.22337e+15} + +# EVIDENCE-OF: R-50300-26941 Any text input that describes a value +# outside the range of a 64-bit signed integer yields a REAL result. +# +do_expr_test e_expr-32.1.20 { CAST('9223372036854775807' AS numeric) } \ + integer 9223372036854775807 +do_expr_test e_expr-32.1.21 { CAST('9223372036854775808' AS numeric) } \ + real 9.22337203685478e+18 +do_expr_test e_expr-32.1.22 { CAST('-9223372036854775808' AS numeric) } \ + integer -9223372036854775808 +do_expr_test e_expr-32.1.23 { CAST('-9223372036854775809' AS numeric) } \ + real -9.22337203685478e+18 + +# EVIDENCE-OF: R-30347-18702 Casting a REAL or INTEGER value to NUMERIC +# is a no-op, even if a real value could be losslessly converted to an +# integer. +# +do_expr_test e_expr-32.2.1 { CAST(13.0 AS NUMERIC) } real 13.0 +do_expr_test e_expr-32.2.2 { CAST(13.5 AS NUMERIC) } real 13.5 + +do_expr_test e_expr-32.2.3 { + CAST(-9223372036854775808 AS NUMERIC) +} integer -9223372036854775808 +do_expr_test e_expr-32.2.4 { + CAST(9223372036854775807 AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.5 { + CAST('9223372036854775807 ' AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.6 { + CAST(' 9223372036854775807 ' AS NUMERIC) +} integer 9223372036854775807 +do_expr_test e_expr-32.2.7 { + CAST(' ' AS NUMERIC) +} integer 0 +do_execsql_test e_expr-32.2.8 { + WITH t1(x) AS (VALUES + ('9000000000000000001'), + ('9000000000000000001x'), + ('9000000000000000001 '), + (' 9000000000000000001 '), + (' 9000000000000000001'), + (' 9000000000000000001.'), + ('9223372036854775807'), + ('9223372036854775807 '), + (' 9223372036854775807 '), + ('9223372036854775808'), + (' 9223372036854775808 '), + ('9223372036854775807.0'), + ('9223372036854775807e+0'), + ('-5.0'), + ('-5e+0')) + SELECT typeof(CAST(x AS NUMERIC)), CAST(x AS NUMERIC)||'' FROM t1; +} [list \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + integer 9000000000000000001 \ + real 9.0e+18 \ + integer 9223372036854775807 \ + integer 9223372036854775807 \ + integer 9223372036854775807 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + real 9.22337203685478e+18 \ + integer -5 \ + integer -5 \ +] + +# EVIDENCE-OF: R-64550-29191 Note that the result from casting any +# non-BLOB value into a BLOB and the result from casting any BLOB value +# into a non-BLOB value may be different depending on whether the +# database encoding is UTF-8, UTF-16be, or UTF-16le. +# +ifcapable {utf16} { +sqlite3 db1 :memory: ; db1 eval { PRAGMA encoding = 'utf-8' } +sqlite3 db2 :memory: ; db2 eval { PRAGMA encoding = 'utf-16le' } +sqlite3 db3 :memory: ; db3 eval { PRAGMA encoding = 'utf-16be' } +foreach {tn castexpr differs} { + 1 { CAST(123 AS BLOB) } 1 + 2 { CAST('' AS BLOB) } 0 + 3 { CAST('abcd' AS BLOB) } 1 + + 4 { CAST(X'abcd' AS TEXT) } 1 + 5 { CAST(X'' AS TEXT) } 0 +} { + set r1 [db1 eval "SELECT typeof($castexpr), quote($castexpr)"] + set r2 [db2 eval "SELECT typeof($castexpr), quote($castexpr)"] + set r3 [db3 eval "SELECT typeof($castexpr), quote($castexpr)"] + + if {$differs} { + set res [expr {$r1!=$r2 && $r2!=$r3}] + } else { + set res [expr {$r1==$r2 && $r2==$r3}] + } + + do_test e_expr-33.1.$tn {set res} 1 +} +db1 close +db2 close +db3 close +} + +#------------------------------------------------------------------------- +# Test statements related to the EXISTS and NOT EXISTS operators. +# +catch { db close } +forcedelete test.db +sqlite3 db test.db + +do_execsql_test e_expr-34.1 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(NULL, 2); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(NULL, NULL); +} {} + +# EVIDENCE-OF: R-25588-27181 The EXISTS operator always evaluates to one +# of the integer values 0 and 1. +# +# This statement is not tested by itself. Instead, all e_expr-34.* tests +# following this point explicitly test that specific invocations of EXISTS +# return either integer 0 or integer 1. +# + +# EVIDENCE-OF: R-58553-63740 If executing the SELECT statement specified +# as the right-hand operand of the EXISTS operator would return one or +# more rows, then the EXISTS operator evaluates to 1. +# +foreach {tn expr} { + 1 { EXISTS ( SELECT a FROM t1 ) } + 2 { EXISTS ( SELECT b FROM t1 ) } + 3 { EXISTS ( SELECT 24 ) } + 4 { EXISTS ( SELECT NULL ) } + 5 { EXISTS ( SELECT a FROM t1 WHERE a IS NULL ) } +} { + do_expr_test e_expr-34.2.$tn $expr integer 1 +} + +# EVIDENCE-OF: R-19673-40972 If executing the SELECT would return no +# rows at all, then the EXISTS operator evaluates to 0. +# +foreach {tn expr} { + 1 { EXISTS ( SELECT a FROM t1 WHERE 0) } + 2 { EXISTS ( SELECT b FROM t1 WHERE a = 5) } + 3 { EXISTS ( SELECT 24 WHERE 0) } + 4 { EXISTS ( SELECT NULL WHERE 1=2) } +} { + do_expr_test e_expr-34.3.$tn $expr integer 0 +} + +# EVIDENCE-OF: R-35109-49139 The number of columns in each row returned +# by the SELECT statement (if any) and the specific values returned have +# no effect on the results of the EXISTS operator. +# +foreach {tn expr res} { + 1 { EXISTS ( SELECT * FROM t1 ) } 1 + 2 { EXISTS ( SELECT *, *, * FROM t1 ) } 1 + 3 { EXISTS ( SELECT 24, 25 ) } 1 + 4 { EXISTS ( SELECT NULL, NULL, NULL ) } 1 + 5 { EXISTS ( SELECT a,b,a||b FROM t1 WHERE a IS NULL ) } 1 + + 6 { EXISTS ( SELECT a, a FROM t1 WHERE 0) } 0 + 7 { EXISTS ( SELECT b, b, a FROM t1 WHERE a = 5) } 0 + 8 { EXISTS ( SELECT 24, 46, 89 WHERE 0) } 0 + 9 { EXISTS ( SELECT NULL, NULL WHERE 1=2) } 0 +} { + do_expr_test e_expr-34.4.$tn $expr integer $res +} + +# EVIDENCE-OF: R-10645-12439 In particular, rows containing NULL values +# are not handled any differently from rows without NULL values. +# +foreach {tn e1 e2} { + 1 { EXISTS (SELECT 'not null') } { EXISTS (SELECT NULL) } + 2 { EXISTS (SELECT NULL FROM t1) } { EXISTS (SELECT 'bread' FROM t1) } +} { + set res [db one "SELECT $e1"] + do_expr_test e_expr-34.5.${tn}a $e1 integer $res + do_expr_test e_expr-34.5.${tn}b $e2 integer $res +} + +#------------------------------------------------------------------------- +# Test statements related to scalar sub-queries. +# + +catch { db close } +forcedelete test.db +sqlite3 db test.db +do_test e_expr-35.0 { + execsql { + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('one', 'two'); + INSERT INTO t2 VALUES('three', NULL); + INSERT INTO t2 VALUES(4, 5.0); + } +} {} + +# EVIDENCE-OF: R-43573-23448 A SELECT statement enclosed in parentheses +# is a subquery. +# +# EVIDENCE-OF: R-56294-03966 All types of SELECT statement, including +# aggregate and compound SELECT queries (queries with keywords like +# UNION or EXCEPT) are allowed as scalar subqueries. +# +do_expr_test e_expr-35.1.1 { (SELECT 35) } integer 35 +do_expr_test e_expr-35.1.2 { (SELECT NULL) } null {} + +do_expr_test e_expr-35.1.3 { (SELECT count(*) FROM t2) } integer 3 +do_expr_test e_expr-35.1.4 { (SELECT 4 FROM t2) } integer 4 + +do_expr_test e_expr-35.1.5 { + (SELECT b FROM t2 UNION SELECT a+1 FROM t2) +} null {} +do_expr_test e_expr-35.1.6 { + (SELECT a FROM t2 UNION SELECT COALESCE(b, 55) FROM t2 ORDER BY 1) +} integer 4 + +# EVIDENCE-OF: R-43101-20178 A subquery that returns two or more columns +# is a row value subquery and can only be used as an operand of a +# comparison operator or as the value in an UPDATE SET clause whose +# column name list has the same size. +# +# The following block tests that errors are returned in a bunch of cases +# where a subquery returns more than one column. +# +set M {/1 {sub-select returns [23] columns - expected 1}/} +foreach {tn sql} { + 1 { SELECT (SELECT * FROM t2 UNION SELECT a+1, b+1 FROM t2) } + 2 { SELECT (SELECT * FROM t2 UNION SELECT a+1, b+1 FROM t2 ORDER BY 1) } + 3 { SELECT (SELECT 1, 2) } + 4 { SELECT (SELECT NULL, NULL, NULL) } + 5 { SELECT (SELECT * FROM t2) } + 6 { SELECT (SELECT * FROM (SELECT 1, 2, 3)) } +} { + do_catchsql_test e_expr-35.2.$tn $sql $M +} + +# EVIDENCE-OF: R-18318-14995 The value of a subquery expression is the +# first row of the result from the enclosed SELECT statement. +# +do_execsql_test e_expr-36.3.1 { + CREATE TABLE t4(x, y); + INSERT INTO t4 VALUES(1, 'one'); + INSERT INTO t4 VALUES(2, 'two'); + INSERT INTO t4 VALUES(3, 'three'); +} {} + +foreach {tn expr restype resval} { + 2 { ( SELECT x FROM t4 ORDER BY x ) } integer 1 + 3 { ( SELECT x FROM t4 ORDER BY y ) } integer 1 + 4 { ( SELECT x FROM t4 ORDER BY x DESC ) } integer 3 + 5 { ( SELECT x FROM t4 ORDER BY y DESC ) } integer 2 + 6 { ( SELECT y FROM t4 ORDER BY y DESC ) } text two + + 7 { ( SELECT sum(x) FROM t4 ) } integer 6 + 8 { ( SELECT string_agg(y,'') FROM t4 ) } text onetwothree + 9 { ( SELECT max(x) FROM t4 WHERE y LIKE '___') } integer 2 + +} { + do_expr_test e_expr-36.3.$tn $expr $restype $resval +} + +# EVIDENCE-OF: R-52325-25449 The value of a subquery expression is NULL +# if the enclosed SELECT statement returns no rows. +# +foreach {tn expr} { + 1 { ( SELECT x FROM t4 WHERE x>3 ORDER BY x ) } + 2 { ( SELECT x FROM t4 WHERE y<'one' ORDER BY y ) } +} { + do_expr_test e_expr-36.4.$tn $expr null {} +} + +# EVIDENCE-OF: R-62477-06476 For example, the values NULL, 0.0, 0, +# 'english' and '0' are all considered to be false. +# +do_execsql_test e_expr-37.1 { + SELECT CASE WHEN NULL THEN 'true' ELSE 'false' END, iif(NULL,'true','false'); +} {false false} +do_execsql_test e_expr-37.2 { + SELECT CASE WHEN 0.0 THEN 'true' ELSE 'false' END, iif(0.0,'true','false'); +} {false false} +do_execsql_test e_expr-37.3 { + SELECT CASE WHEN 0 THEN 'true' ELSE 'false' END, iif(0,'true','false'); +} {false false} +do_execsql_test e_expr-37.4 { + SELECT CASE WHEN 'engligh' THEN 'true' ELSE 'false' END, iif('engligh','true','false'); +} {false false} +do_execsql_test e_expr-37.5 { + SELECT CASE WHEN '0' THEN 'true' ELSE 'false' END, iif('0','true','false'); +} {false false} + +# EVIDENCE-OF: R-55532-10108 Values 1, 1.0, 0.1, -0.1 and '1english' are +# considered to be true. +# +do_execsql_test e_expr-37.6 { + SELECT CASE WHEN 1 THEN 'true' ELSE 'false' END, iif(1,'true','false'); +} {true true} +do_execsql_test e_expr-37.7 { + SELECT CASE WHEN 1.0 THEN 'true' ELSE 'false' END, iif(1.0,'true','false'); +} {true true} +do_execsql_test e_expr-37.8 { + SELECT CASE WHEN 0.1 THEN 'true' ELSE 'false' END, iif(0.1,'true','false'); +} {true true} +do_execsql_test e_expr-37.9 { + SELECT CASE WHEN -0.1 THEN 'true' ELSE 'false' END, iif(-0.1,'true','false'); +} {true true} +do_execsql_test e_expr-37.10 { + SELECT CASE WHEN '1english' THEN 'true' ELSE 'false' END, iif('1engl','true','false'); +} {true true} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fkey.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fkey.test new file mode 100644 index 0000000000000000000000000000000000000000..3662a39981844d96250a3f2360e0c0e8d80efab7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fkey.test @@ -0,0 +1,3047 @@ +# 2009 October 7 +# +# 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 to verify the "testable statements" in the +# foreignkeys.in document. +# +# The tests in this file are arranged to mirror the structure of +# foreignkey.in, with one exception: The statements in section 2, which +# deals with enabling/disabling foreign key support, is tested first, +# before section 1. This is because some statements in section 2 deal +# with builds that do not include complete foreign key support (because +# either SQLITE_OMIT_TRIGGER or SQLITE_OMIT_FOREIGN_KEY was defined +# at build time). +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc eqp {sql {db db}} { + uplevel [subst -nocommands { + set eqpres [list] + $db eval "$sql" { + lappend eqpres [set detail] + } + set eqpres + }] +} + +proc do_detail_test {tn sql res} { + set normalres [list {*}$res] + uplevel [subst -nocommands { + do_test $tn { + eqp { $sql } + } {$normalres} + }] +} + +########################################################################### +### SECTION 2: Enabling Foreign Key Support +########################################################################### + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-37672-59189 In order to use foreign key constraints in +# SQLite, the library must be compiled with neither +# SQLITE_OMIT_FOREIGN_KEY nor SQLITE_OMIT_TRIGGER defined. +# +ifcapable trigger&&foreignkey { + do_test e_fkey-1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } + } {world} +} + +#------------------------------------------------------------------------- +# Test the effects of defining OMIT_TRIGGER but not OMIT_FOREIGN_KEY. +# +# EVIDENCE-OF: R-10109-20452 If SQLITE_OMIT_TRIGGER is defined but +# SQLITE_OMIT_FOREIGN_KEY is not, then SQLite behaves as it did prior to +# version 3.6.19 (2009-10-14) - foreign key definitions are parsed and +# may be queried using PRAGMA foreign_key_list, but foreign key +# constraints are not enforced. +# +# Specifically, test that "PRAGMA foreign_keys" is a no-op in this case. +# When using the pragma to query the current setting, 0 rows are returned. +# +# EVIDENCE-OF: R-22567-44039 The PRAGMA foreign_keys command is a no-op +# in this configuration. +# +# EVIDENCE-OF: R-41784-13339 Tip: If the command "PRAGMA foreign_keys" +# returns no data instead of a single row containing "0" or "1", then +# the version of SQLite you are using does not support foreign keys +# (either because it is older than 3.6.19 or because it was compiled +# with SQLITE_OMIT_FOREIGN_KEY or SQLITE_OMIT_TRIGGER defined). +# +reset_db +ifcapable !trigger&&foreignkey { + do_test e_fkey-2.1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } + } {hello} + do_test e_fkey-2.2 { + execsql { PRAGMA foreign_key_list(c) } + } {0 0 p j {} CASCADE {NO ACTION} NONE} + do_test e_fkey-2.3 { + execsql { PRAGMA foreign_keys } + } {} +} + + +#------------------------------------------------------------------------- +# Test the effects of defining OMIT_FOREIGN_KEY. +# +# EVIDENCE-OF: R-58428-36660 If OMIT_FOREIGN_KEY is defined, then +# foreign key definitions cannot even be parsed (attempting to specify a +# foreign key definition is a syntax error). +# +# Specifically, test that foreign key constraints cannot even be parsed +# in such a build. +# +reset_db +ifcapable !foreignkey { + do_test e_fkey-3.1 { + execsql { CREATE TABLE p(i PRIMARY KEY) } + catchsql { CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE) } + } {1 {near "ON": syntax error}} + do_test e_fkey-3.2 { + # This is allowed, as in this build, "REFERENCES" is not a keyword. + # The declared datatype of column j is "REFERENCES p". + execsql { CREATE TABLE c(j REFERENCES p) } + } {} + do_test e_fkey-3.3 { + execsql { PRAGMA table_info(c) } + } {0 j {REFERENCES p} 0 {} 0} + do_test e_fkey-3.4 { + execsql { PRAGMA foreign_key_list(c) } + } {} + do_test e_fkey-3.5 { + execsql { PRAGMA foreign_keys } + } {} +} + +ifcapable !foreignkey||!trigger { finish_test ; return } +reset_db + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-07280-60510 Assuming the library is compiled with +# foreign key constraints enabled, it must still be enabled by the +# application at runtime, using the PRAGMA foreign_keys command. +# +# This also tests that foreign key constraints are disabled by default. +# +# EVIDENCE-OF: R-44261-39702 Foreign key constraints are disabled by +# default (for backwards compatibility), so must be enabled separately +# for each database connection. +# +drop_all_tables +do_test e_fkey-4.1 { + execsql { + CREATE TABLE p(i PRIMARY KEY); + CREATE TABLE c(j REFERENCES p ON UPDATE CASCADE); + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } +} {hello} +do_test e_fkey-4.2 { + execsql { + DELETE FROM c; + DELETE FROM p; + PRAGMA foreign_keys = ON; + INSERT INTO p VALUES('hello'); + INSERT INTO c VALUES('hello'); + UPDATE p SET i = 'world'; + SELECT * FROM c; + } +} {world} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-08013-37737 The application can also use a PRAGMA +# foreign_keys statement to determine if foreign keys are currently +# enabled. + +# +# This also tests the example code in section 2 of foreignkeys.in. +# +# EVIDENCE-OF: R-11255-19907 +# +reset_db +do_test e_fkey-5.1 { + execsql { PRAGMA foreign_keys } +} {0} +do_test e_fkey-5.2 { + execsql { + PRAGMA foreign_keys = ON; + PRAGMA foreign_keys; + } +} {1} +do_test e_fkey-5.3 { + execsql { + PRAGMA foreign_keys = OFF; + PRAGMA foreign_keys; + } +} {0} + +#------------------------------------------------------------------------- +# Test that it is not possible to enable or disable foreign key support +# while not in auto-commit mode. +# +# EVIDENCE-OF: R-46649-58537 It is not possible to enable or disable +# foreign key constraints in the middle of a multi-statement transaction +# (when SQLite is not in autocommit mode). Attempting to do so does not +# return an error; it simply has no effect. +# +reset_db +do_test e_fkey-6.1 { + execsql { + PRAGMA foreign_keys = ON; + CREATE TABLE t1(a UNIQUE, b); + CREATE TABLE t2(c, d REFERENCES t1(a)); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(2, 1); + BEGIN; + PRAGMA foreign_keys = OFF; + } + catchsql { + DELETE FROM t1 + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-6.2 { + execsql { PRAGMA foreign_keys } +} {1} +do_test e_fkey-6.3 { + execsql { + COMMIT; + PRAGMA foreign_keys = OFF; + BEGIN; + PRAGMA foreign_keys = ON; + DELETE FROM t1; + PRAGMA foreign_keys; + } +} {0} +do_test e_fkey-6.4 { + execsql COMMIT +} {} + +########################################################################### +### SECTION 1: Introduction to Foreign Key Constraints +########################################################################### +execsql "PRAGMA foreign_keys = ON" + +#------------------------------------------------------------------------- +# Verify that the syntax in the first example in section 1 is valid. +# +# EVIDENCE-OF: R-04042-24825 To do so, a foreign key definition may be +# added by modifying the declaration of the track table to the +# following: CREATE TABLE track( trackid INTEGER, trackname TEXT, +# trackartist INTEGER, FOREIGN KEY(trackartist) REFERENCES +# artist(artistid) ); +# +do_test e_fkey-7.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-61362-32087 Attempting to insert a row into the track +# table that does not correspond to any row in the artist table will +# fail, +# +do_test e_fkey-8.1 { + catchsql { INSERT INTO track VALUES(1, 'track 1', 1) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-8.2 { + execsql { INSERT INTO artist VALUES(2, 'artist 1') } + catchsql { INSERT INTO track VALUES(1, 'track 1', 1) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-8.2 { + execsql { INSERT INTO track VALUES(1, 'track 1', 2) } +} {} + +#------------------------------------------------------------------------- +# Attempting to delete a row from the 'artist' table while there are +# dependent rows in the track table also fails. +# +# EVIDENCE-OF: R-24401-52400 as will attempting to delete a row from the +# artist table when there exist dependent rows in the track table +# +do_test e_fkey-9.1 { + catchsql { DELETE FROM artist WHERE artistid = 2 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-9.2 { + execsql { + DELETE FROM track WHERE trackartist = 2; + DELETE FROM artist WHERE artistid = 2; + } +} {} + +#------------------------------------------------------------------------- +# If the foreign key column (trackartist) in table 'track' is set to NULL, +# there is no requirement for a matching row in the 'artist' table. +# +# EVIDENCE-OF: R-23980-48859 There is one exception: if the foreign key +# column in the track table is NULL, then no corresponding entry in the +# artist table is required. +# +do_test e_fkey-10.1 { + execsql { + INSERT INTO track VALUES(1, 'track 1', NULL); + INSERT INTO track VALUES(2, 'track 2', NULL); + } +} {} +do_test e_fkey-10.2 { + execsql { SELECT * FROM artist } +} {} +do_test e_fkey-10.3 { + # Setting the trackid to a non-NULL value fails, of course. + catchsql { UPDATE track SET trackartist = 5 WHERE trackid = 1 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-10.4 { + execsql { + INSERT INTO artist VALUES(5, 'artist 5'); + UPDATE track SET trackartist = 5 WHERE trackid = 1; + } + catchsql { DELETE FROM artist WHERE artistid = 5} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-10.5 { + execsql { + UPDATE track SET trackartist = NULL WHERE trackid = 1; + DELETE FROM artist WHERE artistid = 5; + } +} {} + +#------------------------------------------------------------------------- +# Test that the following is true fo all rows in the track table: +# +# trackartist IS NULL OR +# EXISTS(SELECT 1 FROM artist WHERE artistid=trackartist) +# +# EVIDENCE-OF: R-52486-21352 Expressed in SQL, this means that for every +# row in the track table, the following expression evaluates to true: +# trackartist IS NULL OR EXISTS(SELECT 1 FROM artist WHERE +# artistid=trackartist) + +# This procedure executes a test case to check that statement +# R-52486-21352 is true after executing the SQL statement passed. +# as the second argument. +proc test_r52486_21352 {tn sql} { + set res [catchsql $sql] + set results { + {0 {}} + {1 {UNIQUE constraint failed: artist.artistid}} + {1 {FOREIGN KEY constraint failed}} + } + if {[lsearch $results $res]<0} { + error $res + } + + do_test e_fkey-11.$tn { + execsql { + SELECT count(*) FROM track WHERE NOT ( + trackartist IS NULL OR + EXISTS(SELECT 1 FROM artist WHERE artistid=trackartist) + ) + } + } {0} +} + +# Execute a series of random INSERT, UPDATE and DELETE operations +# (some of which may fail due to FK or PK constraint violations) on +# the two tables in the example schema. Test that R-52486-21352 +# is true after executing each operation. +# +set Template { + {INSERT INTO track VALUES($t, 'track $t', $a)} + {DELETE FROM track WHERE trackid = $t} + {UPDATE track SET trackartist = $a WHERE trackid = $t} + {INSERT INTO artist VALUES($a, 'artist $a')} + {DELETE FROM artist WHERE artistid = $a} + {UPDATE artist SET artistid = $a2 WHERE artistid = $a} +} +for {set i 0} {$i < 500} {incr i} { + set a [expr int(rand()*10)] + set a2 [expr int(rand()*10)] + set t [expr int(rand()*50)] + set sql [subst [lindex $Template [expr int(rand()*6)]]] + + test_r52486_21352 $i $sql +} + +#------------------------------------------------------------------------- +# Check that a NOT NULL constraint can be added to the example schema +# to prohibit NULL child keys from being inserted. +# +# EVIDENCE-OF: R-42412-59321 Tip: If the application requires a stricter +# relationship between artist and track, where NULL values are not +# permitted in the trackartist column, simply add the appropriate "NOT +# NULL" constraint to the schema. +# +drop_all_tables +do_test e_fkey-12.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER NOT NULL, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} +do_test e_fkey-12.2 { + catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) } +} {1 {NOT NULL constraint failed: track.trackartist}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-16127-35442 +# +# Test an example from foreignkeys.html. +# +drop_all_tables +do_test e_fkey-13.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + INSERT INTO artist VALUES(1, 'Dean Martin'); + INSERT INTO artist VALUES(2, 'Frank Sinatra'); + INSERT INTO track VALUES(11, 'That''s Amore', 1); + INSERT INTO track VALUES(12, 'Christmas Blues', 1); + INSERT INTO track VALUES(13, 'My Way', 2); + } +} {} +do_test e_fkey-13.2 { + catchsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', 3) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-13.3 { + execsql { INSERT INTO track VALUES(14, 'Mr. Bojangles', NULL) } +} {} +do_test e_fkey-13.4 { + catchsql { + UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-13.5 { + execsql { + INSERT INTO artist VALUES(3, 'Sammy Davis Jr.'); + UPDATE track SET trackartist = 3 WHERE trackname = 'Mr. Bojangles'; + INSERT INTO track VALUES(15, 'Boogie Woogie', 3); + } +} {} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-15958-50233 +# +# Test the second example from the first section of foreignkeys.html. +# +do_test e_fkey-14.1 { + catchsql { + DELETE FROM artist WHERE artistname = 'Frank Sinatra'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-14.2 { + execsql { + DELETE FROM track WHERE trackname = 'My Way'; + DELETE FROM artist WHERE artistname = 'Frank Sinatra'; + } +} {} +do_test e_fkey-14.3 { + catchsql { + UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin'; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-14.4 { + execsql { + DELETE FROM track WHERE trackname IN('That''s Amore', 'Christmas Blues'); + UPDATE artist SET artistid=4 WHERE artistname = 'Dean Martin'; + } +} {} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-56032-24923 The foreign key constraint is satisfied if +# for each row in the child table either one or more of the child key +# columns are NULL, or there exists a row in the parent table for which +# each parent key column contains a value equal to the value in its +# associated child key column. +# +# Test also that the usual comparison rules are used when testing if there +# is a matching row in the parent table of a foreign key constraint. +# +# EVIDENCE-OF: R-57765-12380 In the above paragraph, the term "equal" +# means equal when values are compared using the rules specified here. +# +drop_all_tables +do_test e_fkey-15.1 { + execsql { + CREATE TABLE par(p PRIMARY KEY); + CREATE TABLE chi(c REFERENCES par); + + INSERT INTO par VALUES(1); + INSERT INTO par VALUES('1'); + INSERT INTO par VALUES(X'31'); + SELECT typeof(p) FROM par; + } +} {integer text blob} + +proc test_efkey_45 {tn isError sql} { + do_test e_fkey-15.$tn.1 " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] + + do_test e_fkey-15.$tn.2 { + execsql { + SELECT * FROM chi WHERE c IS NOT NULL AND c NOT IN (SELECT p FROM par) + } + } {} +} + +test_efkey_45 1 0 "INSERT INTO chi VALUES(1)" +test_efkey_45 2 1 "INSERT INTO chi VALUES('1.0')" +test_efkey_45 3 0 "INSERT INTO chi VALUES('1')" +test_efkey_45 4 1 "DELETE FROM par WHERE p = '1'" +test_efkey_45 5 0 "DELETE FROM chi WHERE c = '1'" +test_efkey_45 6 0 "DELETE FROM par WHERE p = '1'" +test_efkey_45 7 1 "INSERT INTO chi VALUES('1')" +test_efkey_45 8 0 "INSERT INTO chi VALUES(X'31')" +test_efkey_45 9 1 "INSERT INTO chi VALUES(X'32')" + +#------------------------------------------------------------------------- +# Specifically, test that when comparing child and parent key values the +# default collation sequence of the parent key column is used. +# +# EVIDENCE-OF: R-15796-47513 When comparing text values, the collating +# sequence associated with the parent key column is always used. +# +drop_all_tables +do_test e_fkey-16.1 { + execsql { + CREATE TABLE t1(a COLLATE nocase PRIMARY KEY); + CREATE TABLE t2(b REFERENCES t1); + } +} {} +do_test e_fkey-16.2 { + execsql { + INSERT INTO t1 VALUES('oNe'); + INSERT INTO t2 VALUES('one'); + INSERT INTO t2 VALUES('ONE'); + UPDATE t2 SET b = 'OnE'; + UPDATE t1 SET a = 'ONE'; + } +} {} +do_test e_fkey-16.3 { + catchsql { UPDATE t2 SET b = 'two' WHERE rowid = 1 } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-16.4 { + catchsql { DELETE FROM t1 WHERE rowid = 1 } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Specifically, test that when comparing child and parent key values the +# affinity of the parent key column is applied to the child key value +# before the comparison takes place. +# +# EVIDENCE-OF: R-04240-13860 When comparing values, if the parent key +# column has an affinity, then that affinity is applied to the child key +# value before the comparison is performed. +# +drop_all_tables +do_test e_fkey-17.1 { + execsql { + CREATE TABLE t1(a NUMERIC PRIMARY KEY); + CREATE TABLE t2(b TEXT REFERENCES t1); + } +} {} +do_test e_fkey-17.2 { + execsql { + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES('three'); + INSERT INTO t2 VALUES('2.0'); + SELECT b, typeof(b) FROM t2; + } +} {2.0 text} +do_test e_fkey-17.3 { + execsql { SELECT typeof(a) FROM t1 } +} {integer integer text} +do_test e_fkey-17.4 { + catchsql { DELETE FROM t1 WHERE rowid = 2 } +} {1 {FOREIGN KEY constraint failed}} + +########################################################################### +### SECTION 3: Required and Suggested Database Indexes +########################################################################### + +#------------------------------------------------------------------------- +# A parent key must be either a PRIMARY KEY, subject to a UNIQUE +# constraint, or have a UNIQUE index created on it. +# +# EVIDENCE-OF: R-13435-26311 Usually, the parent key of a foreign key +# constraint is the primary key of the parent table. If they are not the +# primary key, then the parent key columns must be collectively subject +# to a UNIQUE constraint or have a UNIQUE index. +# +# Also test that if a parent key is not subject to a PRIMARY KEY or UNIQUE +# constraint, but does have a UNIQUE index created on it, then the UNIQUE index +# must use the default collation sequences associated with the parent key +# columns. +# +# EVIDENCE-OF: R-00376-39212 If the parent key columns have a UNIQUE +# index, then that index must use the collation sequences that are +# specified in the CREATE TABLE statement for the parent table. +# +drop_all_tables +do_test e_fkey-18.1 { + execsql { + CREATE TABLE t2(a REFERENCES t1(x)); + } +} {} +proc test_efkey_57 {tn isError sql} { + catchsql { DROP TABLE t1 } + execsql $sql + do_test e_fkey-18.$tn { + catchsql { INSERT INTO t2 VALUES(NULL) } + } [lindex {{0 {}} {/1 {foreign key mismatch - ".*" referencing ".*"}/}} \ + $isError] +} +test_efkey_57 2 0 { CREATE TABLE t1(x PRIMARY KEY) } +test_efkey_57 3 0 { CREATE TABLE t1(x UNIQUE) } +test_efkey_57 4 0 { CREATE TABLE t1(x); CREATE UNIQUE INDEX t1i ON t1(x) } +test_efkey_57 5 1 { + CREATE TABLE t1(x); + CREATE UNIQUE INDEX t1i ON t1(x COLLATE nocase); +} +test_efkey_57 6 1 { CREATE TABLE t1(x) } +test_efkey_57 7 1 { CREATE TABLE t1(x, y, PRIMARY KEY(x, y)) } +test_efkey_57 8 1 { CREATE TABLE t1(x, y, UNIQUE(x, y)) } +test_efkey_57 9 1 { + CREATE TABLE t1(x, y); + CREATE UNIQUE INDEX t1i ON t1(x, y); +} + + +#------------------------------------------------------------------------- +# This block tests an example in foreignkeys.html. Several testable +# statements refer to this example, as follows +# +# EVIDENCE-OF: R-27484-01467 +# +# FK Constraints on child1, child2 and child3 are Ok. +# +# Problem with FK on child4: +# +# EVIDENCE-OF: R-51039-44840 The foreign key declared as part of table +# child4 is an error because even though the parent key column is +# indexed, the index is not UNIQUE. +# +# Problem with FK on child5: +# +# EVIDENCE-OF: R-01060-48788 The foreign key for table child5 is an +# error because even though the parent key column has a unique index, +# the index uses a different collating sequence. +# +# Problem with FK on child6 and child7: +# +# EVIDENCE-OF: R-63088-37469 Tables child6 and child7 are incorrect +# because while both have UNIQUE indices on their parent keys, the keys +# are not an exact match to the columns of a single UNIQUE index. +# +drop_all_tables +do_test e_fkey-19.1 { + execsql { + CREATE TABLE parent(a PRIMARY KEY, b UNIQUE, c, d, e, f); + CREATE UNIQUE INDEX i1 ON parent(c, d); + CREATE INDEX i2 ON parent(e); + CREATE UNIQUE INDEX i3 ON parent(f COLLATE nocase); + + CREATE TABLE child1(f, g REFERENCES parent(a)); -- Ok + CREATE TABLE child2(h, i REFERENCES parent(b)); -- Ok + CREATE TABLE child3(j, k, FOREIGN KEY(j, k) REFERENCES parent(c, d)); -- Ok + CREATE TABLE child4(l, m REFERENCES parent(e)); -- Err + CREATE TABLE child5(n, o REFERENCES parent(f)); -- Err + CREATE TABLE child6(p, q, FOREIGN KEY(p,q) REFERENCES parent(b, c)); -- Err + CREATE TABLE child7(r REFERENCES parent(c)); -- Err + } +} {} +do_test e_fkey-19.2 { + execsql { + INSERT INTO parent VALUES(1, 2, 3, 4, 5, 6); + INSERT INTO child1 VALUES('xxx', 1); + INSERT INTO child2 VALUES('xxx', 2); + INSERT INTO child3 VALUES(3, 4); + } +} {} +do_test e_fkey-19.2 { + catchsql { INSERT INTO child4 VALUES('xxx', 5) } +} {1 {foreign key mismatch - "child4" referencing "parent"}} +do_test e_fkey-19.3 { + catchsql { INSERT INTO child5 VALUES('xxx', 6) } +} {1 {foreign key mismatch - "child5" referencing "parent"}} +do_test e_fkey-19.4 { + catchsql { INSERT INTO child6 VALUES(2, 3) } +} {1 {foreign key mismatch - "child6" referencing "parent"}} +do_test e_fkey-19.5 { + catchsql { INSERT INTO child7 VALUES(3) } +} {1 {foreign key mismatch - "child7" referencing "parent"}} + +#------------------------------------------------------------------------- +# Test errors in the database schema that are detected while preparing +# DML statements. The error text for these messages always matches +# either "foreign key mismatch" or "no such table*" (using [string match]). +# +# EVIDENCE-OF: R-45488-08504 If the database schema contains foreign key +# errors that require looking at more than one table definition to +# identify, then those errors are not detected when the tables are +# created. +# +# EVIDENCE-OF: R-48391-38472 Instead, such errors prevent the +# application from preparing SQL statements that modify the content of +# the child or parent tables in ways that use the foreign keys. +# +# EVIDENCE-OF: R-03108-63659 The English language error message for +# foreign key DML errors is usually "foreign key mismatch" but can also +# be "no such table" if the parent table does not exist. +# +# EVIDENCE-OF: R-35763-48267 Foreign key DML errors are reported if: The +# parent table does not exist, or The parent key columns named in the +# foreign key constraint do not exist, or The parent key columns named +# in the foreign key constraint are not the primary key of the parent +# table and are not subject to a unique constraint using collating +# sequence specified in the CREATE TABLE, or The child table references +# the primary key of the parent without specifying the primary key +# columns and the number of primary key columns in the parent do not +# match the number of child key columns. +# +do_test e_fkey-20.1 { + execsql { + CREATE TABLE c1(c REFERENCES nosuchtable, d); + + CREATE TABLE p2(a, b, UNIQUE(a, b)); + CREATE TABLE c2(c, d, FOREIGN KEY(c, d) REFERENCES p2(a, x)); + + CREATE TABLE p3(a PRIMARY KEY, b); + CREATE TABLE c3(c REFERENCES p3(b), d); + + CREATE TABLE p4(a PRIMARY KEY, b); + CREATE UNIQUE INDEX p4i ON p4(b COLLATE nocase); + CREATE TABLE c4(c REFERENCES p4(b), d); + + CREATE TABLE p5(a PRIMARY KEY, b COLLATE nocase); + CREATE UNIQUE INDEX p5i ON p5(b COLLATE binary); + CREATE TABLE c5(c REFERENCES p5(b), d); + + CREATE TABLE p6(a PRIMARY KEY, b); + CREATE TABLE c6(c, d, FOREIGN KEY(c, d) REFERENCES p6); + + CREATE TABLE p7(a, b, PRIMARY KEY(a, b)); + CREATE TABLE c7(c, d REFERENCES p7); + } +} {} + +foreach {tn tbl ptbl err} { + 2 c1 {} "no such table: main.nosuchtable" + 3 c2 p2 "foreign key mismatch - \"c2\" referencing \"p2\"" + 4 c3 p3 "foreign key mismatch - \"c3\" referencing \"p3\"" + 5 c4 p4 "foreign key mismatch - \"c4\" referencing \"p4\"" + 6 c5 p5 "foreign key mismatch - \"c5\" referencing \"p5\"" + 7 c6 p6 "foreign key mismatch - \"c6\" referencing \"p6\"" + 8 c7 p7 "foreign key mismatch - \"c7\" referencing \"p7\"" +} { + do_test e_fkey-20.$tn.1 { + catchsql "INSERT INTO $tbl VALUES('a', 'b')" + } [list 1 $err] + do_test e_fkey-20.$tn.2 { + catchsql "UPDATE $tbl SET c = ?, d = ?" + } [list 1 $err] + do_test e_fkey-20.$tn.3 { + catchsql "INSERT INTO $tbl SELECT ?, ?" + } [list 1 $err] + + if {$ptbl ne ""} { + do_test e_fkey-20.$tn.4 { + catchsql "DELETE FROM $ptbl" + } [list 1 $err] + do_test e_fkey-20.$tn.5 { + catchsql "UPDATE $ptbl SET a = ?, b = ?" + } [list 1 $err] + do_test e_fkey-20.$tn.6 { + catchsql "INSERT INTO $ptbl SELECT ?, ?" + } [list 1 $err] + } +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-19353-43643 +# +# Test the example of foreign key mismatch errors caused by implicitly +# mapping a child key to the primary key of the parent table when the +# child key consists of a different number of columns to that primary key. +# +drop_all_tables +do_test e_fkey-21.1 { + execsql { + CREATE TABLE parent2(a, b, PRIMARY KEY(a,b)); + + CREATE TABLE child8(x, y, FOREIGN KEY(x,y) REFERENCES parent2); -- Ok + CREATE TABLE child9(x REFERENCES parent2); -- Err + CREATE TABLE child10(x,y,z, FOREIGN KEY(x,y,z) REFERENCES parent2); -- Err + } +} {} +do_test e_fkey-21.2 { + execsql { + INSERT INTO parent2 VALUES('I', 'II'); + INSERT INTO child8 VALUES('I', 'II'); + } +} {} +do_test e_fkey-21.3 { + catchsql { INSERT INTO child9 VALUES('I') } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.4 { + catchsql { INSERT INTO child9 VALUES('II') } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.5 { + catchsql { INSERT INTO child9 VALUES(NULL) } +} {1 {foreign key mismatch - "child9" referencing "parent2"}} +do_test e_fkey-21.6 { + catchsql { INSERT INTO child10 VALUES('I', 'II', 'III') } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} +do_test e_fkey-21.7 { + catchsql { INSERT INTO child10 VALUES(1, 2, 3) } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} +do_test e_fkey-21.8 { + catchsql { INSERT INTO child10 VALUES(NULL, NULL, NULL) } +} {1 {foreign key mismatch - "child10" referencing "parent2"}} + +#------------------------------------------------------------------------- +# Test errors that are reported when creating the child table. +# Specifically: +# +# * different number of child and parent key columns, and +# * child columns that do not exist. +# +# EVIDENCE-OF: R-23682-59820 By contrast, if foreign key errors can be +# recognized simply by looking at the definition of the child table and +# without having to consult the parent table definition, then the CREATE +# TABLE statement for the child table fails. +# +# These errors are reported whether or not FK support is enabled. +# +# EVIDENCE-OF: R-33883-28833 Foreign key DDL errors are reported +# regardless of whether or not foreign key constraints are enabled when +# the table is created. +# +drop_all_tables +foreach fk [list OFF ON] { + execsql "PRAGMA foreign_keys = $fk" + set i 0 + foreach {sql error} { + "CREATE TABLE child1(a, b, FOREIGN KEY(a, b) REFERENCES p(c))" + {number of columns in foreign key does not match the number of columns in the referenced table} + "CREATE TABLE child2(a, b, FOREIGN KEY(a, b) REFERENCES p(c, d, e))" + {number of columns in foreign key does not match the number of columns in the referenced table} + "CREATE TABLE child2(a, b, FOREIGN KEY(a, c) REFERENCES p(c, d))" + {unknown column "c" in foreign key definition} + "CREATE TABLE child2(a, b, FOREIGN KEY(c, b) REFERENCES p(c, d))" + {unknown column "c" in foreign key definition} + } { + do_test e_fkey-22.$fk.[incr i] { + catchsql $sql + } [list 1 $error] + } +} + +#------------------------------------------------------------------------- +# Test that a REFERENCING clause that does not specify parent key columns +# implicitly maps to the primary key of the parent table. +# +# EVIDENCE-OF: R-43879-08025 Attaching a "REFERENCES " +# clause to a column definition creates a foreign +# key constraint that maps the column to the primary key of +# . +# +do_test e_fkey-23.1 { + execsql { + CREATE TABLE p1(a, b, PRIMARY KEY(a, b)); + CREATE TABLE p2(a, b PRIMARY KEY); + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES p1); + CREATE TABLE c2(a, b REFERENCES p2); + } +} {} +proc test_efkey_60 {tn isError sql} { + do_test e_fkey-23.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} + +test_efkey_60 2 1 "INSERT INTO c1 VALUES(239, 231)" +test_efkey_60 3 0 "INSERT INTO p1 VALUES(239, 231)" +test_efkey_60 4 0 "INSERT INTO c1 VALUES(239, 231)" +test_efkey_60 5 1 "INSERT INTO c2 VALUES(239, 231)" +test_efkey_60 6 0 "INSERT INTO p2 VALUES(239, 231)" +test_efkey_60 7 0 "INSERT INTO c2 VALUES(239, 231)" + +#------------------------------------------------------------------------- +# Test that an index on on the child key columns of an FK constraint +# is optional. +# +# EVIDENCE-OF: R-15417-28014 Indices are not required for child key +# columns +# +# Also test that if an index is created on the child key columns, it does +# not make a difference whether or not it is a UNIQUE index. +# +# EVIDENCE-OF: R-15741-50893 The child key index does not have to be +# (and usually will not be) a UNIQUE index. +# +drop_all_tables +do_test e_fkey-24.1 { + execsql { + CREATE TABLE parent(x, y, UNIQUE(y, x)); + CREATE TABLE c1(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE TABLE c2(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE TABLE c3(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE INDEX c2i ON c2(a, b); + CREATE UNIQUE INDEX c3i ON c2(b, a); + } +} {} +proc test_efkey_61 {tn isError sql} { + do_test e_fkey-24.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +foreach {tn c} [list 2 c1 3 c2 4 c3] { + test_efkey_61 $tn.1 1 "INSERT INTO $c VALUES(1, 2)" + test_efkey_61 $tn.2 0 "INSERT INTO parent VALUES(1, 2)" + test_efkey_61 $tn.3 0 "INSERT INTO $c VALUES(1, 2)" + + execsql "DELETE FROM $c ; DELETE FROM parent" +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-00279-52283 +# +# Test an example showing that when a row is deleted from the parent +# table, the child table is queried for orphaned rows as follows: +# +# SELECT rowid FROM track WHERE trackartist = ? +# +# EVIDENCE-OF: R-23302-30956 If this SELECT returns any rows at all, +# then SQLite concludes that deleting the row from the parent table +# would violate the foreign key constraint and returns an error. +# +do_test e_fkey-25.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER, + FOREIGN KEY(trackartist) REFERENCES artist(artistid) + ); + } +} {} +do_detail_test e_fkey-25.2 { + PRAGMA foreign_keys = OFF; + EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1; + EXPLAIN QUERY PLAN SELECT rowid FROM track WHERE trackartist = ?; +} { + {SCAN artist} + {SCAN track} +} +do_detail_test e_fkey-25.3 { + PRAGMA foreign_keys = ON; + EXPLAIN QUERY PLAN DELETE FROM artist WHERE 1; +} { + {SCAN artist} + {SCAN track} +} +do_test e_fkey-25.4 { + execsql { + INSERT INTO artist VALUES(5, 'artist 5'); + INSERT INTO artist VALUES(6, 'artist 6'); + INSERT INTO artist VALUES(7, 'artist 7'); + INSERT INTO track VALUES(1, 'track 1', 5); + INSERT INTO track VALUES(2, 'track 2', 6); + } +} {} + +do_test e_fkey-25.5 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 5 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 5 }] +} {1 1 {FOREIGN KEY constraint failed}} + +do_test e_fkey-25.6 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 7 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 7 }] +} {0 {}} + +do_test e_fkey-25.7 { + concat \ + [execsql { SELECT rowid FROM track WHERE trackartist = 6 }] \ + [catchsql { DELETE FROM artist WHERE artistid = 6 }] +} {2 1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-47936-10044 Or, more generally: +# SELECT rowid FROM WHERE = :parent_key_value +# +# Test that when a row is deleted from the parent table of an FK +# constraint, the child table is queried for orphaned rows. The +# query is equivalent to: +# +# SELECT rowid FROM WHERE = :parent_key_value +# +# Also test that when a row is inserted into the parent table, or when the +# parent key values of an existing row are modified, a query equivalent +# to the following is planned. In some cases it is not executed, but it +# is always planned. +# +# SELECT rowid FROM WHERE = :parent_key_value +# +# EVIDENCE-OF: R-61616-46700 Similar queries may be run if the content +# of the parent key is modified or a new row is inserted into the parent +# table. +# +# +drop_all_tables +do_test e_fkey-26.1 { + execsql { CREATE TABLE parent(x, y, UNIQUE(y, x)) } +} {} +foreach {tn sql} { + 2 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)) + } + 3 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE INDEX childi ON child(a, b); + } + 4 { + CREATE TABLE child(a, b, FOREIGN KEY(a, b) REFERENCES parent(x, y)); + CREATE UNIQUE INDEX childi ON child(b, a); + } +} { + execsql $sql + + execsql {PRAGMA foreign_keys = OFF} + set delete [concat \ + [eqp "DELETE FROM parent WHERE 1"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] + ] + set update [concat \ + [eqp "UPDATE parent SET x=?, y=?"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] \ + [eqp "SELECT rowid FROM child WHERE a = ? AND b = ?"] + ] + execsql {PRAGMA foreign_keys = ON} + + do_test e_fkey-26.$tn.1 { eqp "DELETE FROM parent WHERE 1" } $delete + do_test e_fkey-26.$tn.2 { eqp "UPDATE parent set x=?, y=?" } $update + + execsql {DROP TABLE child} +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-14553-34013 +# +# Test the example schema at the end of section 3. Also test that is +# is "efficient". In this case "efficient" means that foreign key +# related operations on the parent table do not provoke linear scans. +# +drop_all_tables +do_test e_fkey-27.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist + ); + CREATE INDEX trackindex ON track(trackartist); + } +} {} +do_test e_fkey-27.2 { + eqp { INSERT INTO artist VALUES(?, ?) } +} {} +do_detail_test e_fkey-27.3 { + EXPLAIN QUERY PLAN UPDATE artist SET artistid = ?, artistname = ? +} { + {SCAN artist} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} +} +do_detail_test e_fkey-27.4 { + EXPLAIN QUERY PLAN DELETE FROM artist +} { + {SCAN artist} + {SEARCH track USING COVERING INDEX trackindex (trackartist=?)} +} + +########################################################################### +### SECTION 4.1: Composite Foreign Key Constraints +########################################################################### + +#------------------------------------------------------------------------- +# Check that parent and child keys must have the same number of columns. +# +# EVIDENCE-OF: R-41062-34431 Parent and child keys must have the same +# cardinality. +# +foreach {tn sql err} { + 1 "CREATE TABLE c(jj REFERENCES p(x, y))" + {foreign key on jj should reference only one column of table p} + + 2 "CREATE TABLE c(jj REFERENCES p())" {near ")": syntax error} + + 3 "CREATE TABLE c(jj, FOREIGN KEY(jj) REFERENCES p(x, y))" + {number of columns in foreign key does not match the number of columns in the referenced table} + + 4 "CREATE TABLE c(jj, FOREIGN KEY(jj) REFERENCES p())" + {near ")": syntax error} + + 5 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p())" + {near ")": syntax error} + + 6 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p(x))" + {number of columns in foreign key does not match the number of columns in the referenced table} + + 7 "CREATE TABLE c(ii, jj, FOREIGN KEY(jj, ii) REFERENCES p(x,y,z))" + {number of columns in foreign key does not match the number of columns in the referenced table} +} { + drop_all_tables + do_test e_fkey-28.$tn [list catchsql $sql] [list 1 $err] +} +do_test e_fkey-28.8 { + drop_all_tables + execsql { + CREATE TABLE p(x PRIMARY KEY); + CREATE TABLE c(a, b, FOREIGN KEY(a,b) REFERENCES p); + } + catchsql {DELETE FROM p} +} {1 {foreign key mismatch - "c" referencing "p"}} +do_test e_fkey-28.9 { + drop_all_tables + execsql { + CREATE TABLE p(x, y, PRIMARY KEY(x,y)); + CREATE TABLE c(a REFERENCES p); + } + catchsql {DELETE FROM p} +} {1 {foreign key mismatch - "c" referencing "p"}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-24676-09859 +# +# Test the example schema in the "Composite Foreign Key Constraints" +# section. +# +do_test e_fkey-29.1 { + execsql { + CREATE TABLE album( + albumartist TEXT, + albumname TEXT, + albumcover BINARY, + PRIMARY KEY(albumartist, albumname) + ); + CREATE TABLE song( + songid INTEGER, + songartist TEXT, + songalbum TEXT, + songname TEXT, + FOREIGN KEY(songartist, songalbum) REFERENCES album(albumartist,albumname) + ); + } +} {} + +do_test e_fkey-29.2 { + execsql { + INSERT INTO album VALUES('Elvis Presley', 'Elvis'' Christmas Album', NULL); + INSERT INTO song VALUES( + 1, 'Elvis Presley', 'Elvis'' Christmas Album', 'Here Comes Santa Clause' + ); + } +} {} +do_test e_fkey-29.3 { + catchsql { + INSERT INTO song VALUES(2, 'Elvis Presley', 'Elvis Is Back!', 'Fever'); + } +} {1 {FOREIGN KEY constraint failed}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-33626-48418 In SQLite, if any of the child key columns +# (in this case songartist and songalbum) are NULL, then there is no +# requirement for a corresponding row in the parent table. +# +do_test e_fkey-30.1 { + execsql { + INSERT INTO song VALUES(2, 'Elvis Presley', NULL, 'Fever'); + INSERT INTO song VALUES(3, NULL, 'Elvis Is Back', 'Soldier Boy'); + } +} {} + +########################################################################### +### SECTION 4.2: Deferred Foreign Key Constraints +########################################################################### + +#------------------------------------------------------------------------- +# Test that if a statement violates an immediate FK constraint, and the +# database does not satisfy the FK constraint once all effects of the +# statement have been applied, an error is reported and the effects of +# the statement rolled back. +# +# EVIDENCE-OF: R-09323-30470 If a statement modifies the contents of the +# database so that an immediate foreign key constraint is in violation +# at the conclusion the statement, an exception is thrown and the +# effects of the statement are reverted. +# +drop_all_tables +do_test e_fkey-31.1 { + execsql { + CREATE TABLE king(a, b, PRIMARY KEY(a)); + CREATE TABLE prince(c REFERENCES king, d); + } +} {} + +do_test e_fkey-31.2 { + # Execute a statement that violates the immediate FK constraint. + catchsql { INSERT INTO prince VALUES(1, 2) } +} {1 {FOREIGN KEY constraint failed}} + +do_test e_fkey-31.3 { + # This time, use a trigger to fix the constraint violation before the + # statement has finished executing. Then execute the same statement as + # in the previous test case. This time, no error. + execsql { + CREATE TRIGGER kt AFTER INSERT ON prince WHEN + NOT EXISTS (SELECT a FROM king WHERE a = new.c) + BEGIN + INSERT INTO king VALUES(new.c, NULL); + END + } + execsql { INSERT INTO prince VALUES(1, 2) } +} {} + +# Test that operating inside a transaction makes no difference to +# immediate constraint violation handling. +do_test e_fkey-31.4 { + execsql { + BEGIN; + INSERT INTO prince VALUES(2, 3); + DROP TRIGGER kt; + } + catchsql { INSERT INTO prince VALUES(3, 4) } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-31.5 { + execsql { + COMMIT; + SELECT * FROM king; + } +} {1 {} 2 {}} + +#------------------------------------------------------------------------- +# Test that if a deferred constraint is violated within a transaction, +# nothing happens immediately and the database is allowed to persist +# in a state that does not satisfy the FK constraint. However attempts +# to COMMIT the transaction fail until the FK constraint is satisfied. +# +# EVIDENCE-OF: R-49178-21358 By contrast, if a statement modifies the +# contents of the database such that a deferred foreign key constraint +# is violated, the violation is not reported immediately. +# +# EVIDENCE-OF: R-39692-12488 Deferred foreign key constraints are not +# checked until the transaction tries to COMMIT. +# +# EVIDENCE-OF: R-55147-47664 For as long as the user has an open +# transaction, the database is allowed to exist in a state that violates +# any number of deferred foreign key constraints. +# +# EVIDENCE-OF: R-29604-30395 However, COMMIT will fail as long as +# foreign key constraints remain in violation. +# +proc test_efkey_34 {tn isError sql} { + do_test e_fkey-32.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +drop_all_tables + +test_efkey_34 1 0 { + CREATE TABLE ll(k PRIMARY KEY); + CREATE TABLE kk(c REFERENCES ll DEFERRABLE INITIALLY DEFERRED); +} +test_efkey_34 2 0 "BEGIN" +test_efkey_34 3 0 "INSERT INTO kk VALUES(5)" +test_efkey_34 4 0 "INSERT INTO kk VALUES(10)" +test_efkey_34 5 1 "COMMIT" +test_efkey_34 6 0 "INSERT INTO ll VALUES(10)" +test_efkey_34 7 1 "COMMIT" +test_efkey_34 8 0 "INSERT INTO ll VALUES(5)" +test_efkey_34 9 0 "COMMIT" + +#------------------------------------------------------------------------- +# When not running inside a transaction, a deferred constraint is similar +# to an immediate constraint (violations are reported immediately). +# +# EVIDENCE-OF: R-56844-61705 If the current statement is not inside an +# explicit transaction (a BEGIN/COMMIT/ROLLBACK block), then an implicit +# transaction is committed as soon as the statement has finished +# executing. In this case deferred constraints behave the same as +# immediate constraints. +# +drop_all_tables +proc test_efkey_35 {tn isError sql} { + do_test e_fkey-33.$tn " + catchsql {$sql} + " [lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError] +} +do_test e_fkey-33.1 { + execsql { + CREATE TABLE parent(x, y); + CREATE UNIQUE INDEX pi ON parent(x, y); + CREATE TABLE child(a, b, + FOREIGN KEY(a, b) REFERENCES parent(x, y) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +test_efkey_35 2 1 "INSERT INTO child VALUES('x', 'y')" +test_efkey_35 3 0 "INSERT INTO parent VALUES('x', 'y')" +test_efkey_35 4 0 "INSERT INTO child VALUES('x', 'y')" + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-12782-61841 +# +# Test that an FK constraint is made deferred by adding the following +# to the definition: +# +# DEFERRABLE INITIALLY DEFERRED +# +# EVIDENCE-OF: R-09005-28791 +# +# Also test that adding any of the following to a foreign key definition +# makes the constraint IMMEDIATE: +# +# NOT DEFERRABLE INITIALLY DEFERRED +# NOT DEFERRABLE INITIALLY IMMEDIATE +# NOT DEFERRABLE +# DEFERRABLE INITIALLY IMMEDIATE +# DEFERRABLE +# +# Foreign keys are IMMEDIATE by default (if there is no DEFERRABLE or NOT +# DEFERRABLE clause). +# +# EVIDENCE-OF: R-35290-16460 Foreign key constraints are immediate by +# default. +# +# EVIDENCE-OF: R-30323-21917 Each foreign key constraint in SQLite is +# classified as either immediate or deferred. +# +drop_all_tables +do_test e_fkey-34.1 { + execsql { + CREATE TABLE parent(x, y, z, PRIMARY KEY(x,y,z)); + CREATE TABLE c1(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE c2(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE INITIALLY IMMEDIATE + ); + CREATE TABLE c3(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent NOT DEFERRABLE + ); + CREATE TABLE c4(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE INITIALLY IMMEDIATE + ); + CREATE TABLE c5(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE + ); + CREATE TABLE c6(a, b, c, FOREIGN KEY(a, b, c) REFERENCES parent); + + -- This FK constraint is the only deferrable one. + CREATE TABLE c7(a, b, c, + FOREIGN KEY(a, b, c) REFERENCES parent DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('a', 'b', 'c'); + INSERT INTO parent VALUES('d', 'e', 'f'); + INSERT INTO parent VALUES('g', 'h', 'i'); + INSERT INTO parent VALUES('j', 'k', 'l'); + INSERT INTO parent VALUES('m', 'n', 'o'); + INSERT INTO parent VALUES('p', 'q', 'r'); + INSERT INTO parent VALUES('s', 't', 'u'); + + INSERT INTO c1 VALUES('a', 'b', 'c'); + INSERT INTO c2 VALUES('d', 'e', 'f'); + INSERT INTO c3 VALUES('g', 'h', 'i'); + INSERT INTO c4 VALUES('j', 'k', 'l'); + INSERT INTO c5 VALUES('m', 'n', 'o'); + INSERT INTO c6 VALUES('p', 'q', 'r'); + INSERT INTO c7 VALUES('s', 't', 'u'); + } +} {} + +proc test_efkey_29 {tn sql isError} { + do_test e_fkey-34.$tn "catchsql {$sql}" [ + lindex {{0 {}} {1 {FOREIGN KEY constraint failed}}} $isError + ] +} +test_efkey_29 2 "BEGIN" 0 +test_efkey_29 3 "DELETE FROM parent WHERE x = 'a'" 1 +test_efkey_29 4 "DELETE FROM parent WHERE x = 'd'" 1 +test_efkey_29 5 "DELETE FROM parent WHERE x = 'g'" 1 +test_efkey_29 6 "DELETE FROM parent WHERE x = 'j'" 1 +test_efkey_29 7 "DELETE FROM parent WHERE x = 'm'" 1 +test_efkey_29 8 "DELETE FROM parent WHERE x = 'p'" 1 +test_efkey_29 9 "DELETE FROM parent WHERE x = 's'" 0 +test_efkey_29 10 "COMMIT" 1 +test_efkey_29 11 "ROLLBACK" 0 + +test_efkey_29 9 "BEGIN" 0 +test_efkey_29 10 "UPDATE parent SET z = 'z' WHERE z = 'c'" 1 +test_efkey_29 11 "UPDATE parent SET z = 'z' WHERE z = 'f'" 1 +test_efkey_29 12 "UPDATE parent SET z = 'z' WHERE z = 'i'" 1 +test_efkey_29 13 "UPDATE parent SET z = 'z' WHERE z = 'l'" 1 +test_efkey_29 14 "UPDATE parent SET z = 'z' WHERE z = 'o'" 1 +test_efkey_29 15 "UPDATE parent SET z = 'z' WHERE z = 'r'" 1 +test_efkey_29 16 "UPDATE parent SET z = 'z' WHERE z = 'u'" 0 +test_efkey_29 17 "COMMIT" 1 +test_efkey_29 18 "ROLLBACK" 0 + +test_efkey_29 17 "BEGIN" 0 +test_efkey_29 18 "INSERT INTO c1 VALUES(1, 2, 3)" 1 +test_efkey_29 19 "INSERT INTO c2 VALUES(1, 2, 3)" 1 +test_efkey_29 20 "INSERT INTO c3 VALUES(1, 2, 3)" 1 +test_efkey_29 21 "INSERT INTO c4 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c5 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c6 VALUES(1, 2, 3)" 1 +test_efkey_29 22 "INSERT INTO c7 VALUES(1, 2, 3)" 0 +test_efkey_29 23 "COMMIT" 1 +test_efkey_29 24 "INSERT INTO parent VALUES(1, 2, 3)" 0 +test_efkey_29 25 "COMMIT" 0 + +test_efkey_29 26 "BEGIN" 0 +test_efkey_29 27 "UPDATE c1 SET a = 10" 1 +test_efkey_29 28 "UPDATE c2 SET a = 10" 1 +test_efkey_29 29 "UPDATE c3 SET a = 10" 1 +test_efkey_29 30 "UPDATE c4 SET a = 10" 1 +test_efkey_29 31 "UPDATE c5 SET a = 10" 1 +test_efkey_29 31 "UPDATE c6 SET a = 10" 1 +test_efkey_29 31 "UPDATE c7 SET a = 10" 0 +test_efkey_29 32 "COMMIT" 1 +test_efkey_29 33 "ROLLBACK" 0 + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-24499-57071 +# +# Test an example from foreignkeys.html dealing with a deferred foreign +# key constraint. +# +do_test e_fkey-35.1 { + drop_all_tables + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist(artistid) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +do_test e_fkey-35.2 { + execsql { + BEGIN; + INSERT INTO track VALUES(1, 'White Christmas', 5); + } + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-35.3 { + execsql { + INSERT INTO artist VALUES(5, 'Bing Crosby'); + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Verify that a nested savepoint may be released without satisfying +# deferred foreign key constraints. +# +# EVIDENCE-OF: R-07223-48323 A nested savepoint transaction may be +# RELEASEd while the database is in a state that does not satisfy a +# deferred foreign key constraint. +# +drop_all_tables +do_test e_fkey-36.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, + b REFERENCES t1 DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO t1 VALUES(1, 1); + INSERT INTO t1 VALUES(2, 2); + INSERT INTO t1 VALUES(3, 3); + } +} {} +do_test e_fkey-36.2 { + execsql { + BEGIN; + SAVEPOINT one; + INSERT INTO t1 VALUES(4, 5); + RELEASE one; + } +} {} +do_test e_fkey-36.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-36.4 { + execsql { + UPDATE t1 SET a = 5 WHERE a = 4; + COMMIT; + } +} {} + + +#------------------------------------------------------------------------- +# Check that a transaction savepoint (an outermost savepoint opened when +# the database was in auto-commit mode) cannot be released without +# satisfying deferred foreign key constraints. It may be rolled back. +# +# EVIDENCE-OF: R-44295-13823 A transaction savepoint (a non-nested +# savepoint that was opened while there was not currently an open +# transaction), on the other hand, is subject to the same restrictions +# as a COMMIT - attempting to RELEASE it while the database is in such a +# state will fail. +# +do_test e_fkey-37.1 { + execsql { + SAVEPOINT one; + SAVEPOINT two; + INSERT INTO t1 VALUES(6, 7); + RELEASE two; + } +} {} +do_test e_fkey-37.2 { + catchsql {RELEASE one} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-37.3 { + execsql { + UPDATE t1 SET a = 7 WHERE a = 6; + RELEASE one; + } +} {} +do_test e_fkey-37.4 { + execsql { + SAVEPOINT one; + SAVEPOINT two; + INSERT INTO t1 VALUES(9, 10); + RELEASE two; + } +} {} +do_test e_fkey-37.5 { + catchsql {RELEASE one} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-37.6 { + execsql {ROLLBACK TO one ; RELEASE one} +} {} + +#------------------------------------------------------------------------- +# Test that if a COMMIT operation fails due to deferred foreign key +# constraints, any nested savepoints remain open. +# +# EVIDENCE-OF: R-37736-42616 If a COMMIT statement (or the RELEASE of a +# transaction SAVEPOINT) fails because the database is currently in a +# state that violates a deferred foreign key constraint and there are +# currently nested savepoints, the nested savepoints remain open. +# +do_test e_fkey-38.1 { + execsql { + DELETE FROM t1 WHERE a>3; + SELECT * FROM t1; + } +} {1 1 2 2 3 3} +do_test e_fkey-38.2 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(4, 4); + SAVEPOINT one; + INSERT INTO t1 VALUES(5, 6); + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4 5 6} +do_test e_fkey-38.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.4 { + execsql { + ROLLBACK TO one; + COMMIT; + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4} + +do_test e_fkey-38.5 { + execsql { + SAVEPOINT a; + INSERT INTO t1 VALUES(5, 5); + SAVEPOINT b; + INSERT INTO t1 VALUES(6, 7); + SAVEPOINT c; + INSERT INTO t1 VALUES(7, 8); + } +} {} +do_test e_fkey-38.6 { + catchsql {RELEASE a} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.7 { + execsql {ROLLBACK TO c} + catchsql {RELEASE a} +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-38.8 { + execsql { + ROLLBACK TO b; + RELEASE a; + SELECT * FROM t1; + } +} {1 1 2 2 3 3 4 4 5 5} + +########################################################################### +### SECTION 4.3: ON DELETE and ON UPDATE Actions +########################################################################### + +#------------------------------------------------------------------------- +# Test that configured ON DELETE and ON UPDATE actions take place when +# deleting or modifying rows of the parent table, respectively. +# +# EVIDENCE-OF: R-48270-44282 Foreign key ON DELETE and ON UPDATE clauses +# are used to configure actions that take place when deleting rows from +# the parent table (ON DELETE), or modifying the parent key values of +# existing rows (ON UPDATE). +# +# Test that a single FK constraint may have different actions configured +# for ON DELETE and ON UPDATE. +# +# EVIDENCE-OF: R-48124-63225 A single foreign key constraint may have +# different actions configured for ON DELETE and ON UPDATE. +# +do_test e_fkey-39.1 { + execsql { + CREATE TABLE p(a, b PRIMARY KEY, c); + CREATE TABLE c1(d, e, f DEFAULT 'k0' REFERENCES p + ON UPDATE SET DEFAULT + ON DELETE SET NULL + ); + + INSERT INTO p VALUES(0, 'k0', ''); + INSERT INTO p VALUES(1, 'k1', 'I'); + INSERT INTO p VALUES(2, 'k2', 'II'); + INSERT INTO p VALUES(3, 'k3', 'III'); + + INSERT INTO c1 VALUES(1, 'xx', 'k1'); + INSERT INTO c1 VALUES(2, 'xx', 'k2'); + INSERT INTO c1 VALUES(3, 'xx', 'k3'); + } +} {} +do_test e_fkey-39.2 { + execsql { + UPDATE p SET b = 'k4' WHERE a = 1; + SELECT * FROM c1; + } +} {1 xx k0 2 xx k2 3 xx k3} +do_test e_fkey-39.3 { + execsql { + DELETE FROM p WHERE a = 2; + SELECT * FROM c1; + } +} {1 xx k0 2 xx {} 3 xx k3} +do_test e_fkey-39.4 { + execsql { + CREATE UNIQUE INDEX pi ON p(c); + REPLACE INTO p VALUES(5, 'k5', 'III'); + SELECT * FROM c1; + } +} {1 xx k0 2 xx {} 3 xx {}} + +#------------------------------------------------------------------------- +# Each foreign key in the system has an ON UPDATE and ON DELETE action, +# either "NO ACTION", "RESTRICT", "SET NULL", "SET DEFAULT" or "CASCADE". +# +# EVIDENCE-OF: R-33326-45252 The ON DELETE and ON UPDATE action +# associated with each foreign key in an SQLite database is one of "NO +# ACTION", "RESTRICT", "SET NULL", "SET DEFAULT" or "CASCADE". +# +# If none is specified explicitly, "NO ACTION" is the default. +# +# EVIDENCE-OF: R-19803-45884 If an action is not explicitly specified, +# it defaults to "NO ACTION". +# +drop_all_tables +do_test e_fkey-40.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY, y); + CREATE TABLE child1(a, + b REFERENCES parent ON UPDATE NO ACTION ON DELETE RESTRICT + ); + CREATE TABLE child2(a, + b REFERENCES parent ON UPDATE RESTRICT ON DELETE SET NULL + ); + CREATE TABLE child3(a, + b REFERENCES parent ON UPDATE SET NULL ON DELETE SET DEFAULT + ); + CREATE TABLE child4(a, + b REFERENCES parent ON UPDATE SET DEFAULT ON DELETE CASCADE + ); + + -- Create some foreign keys that use the default action - "NO ACTION" + CREATE TABLE child5(a, b REFERENCES parent ON UPDATE CASCADE); + CREATE TABLE child6(a, b REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child7(a, b REFERENCES parent ON DELETE NO ACTION); + CREATE TABLE child8(a, b REFERENCES parent ON UPDATE NO ACTION); + } +} {} + +foreach {tn zTab lRes} { + 2 child1 {0 0 parent b {} {NO ACTION} RESTRICT NONE} + 3 child2 {0 0 parent b {} RESTRICT {SET NULL} NONE} + 4 child3 {0 0 parent b {} {SET NULL} {SET DEFAULT} NONE} + 5 child4 {0 0 parent b {} {SET DEFAULT} CASCADE NONE} + 6 child5 {0 0 parent b {} CASCADE {NO ACTION} NONE} + 7 child6 {0 0 parent b {} {NO ACTION} RESTRICT NONE} + 8 child7 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE} + 9 child8 {0 0 parent b {} {NO ACTION} {NO ACTION} NONE} +} { + do_test e_fkey-40.$tn { execsql "PRAGMA foreign_key_list($zTab)" } $lRes +} + +#------------------------------------------------------------------------- +# Test that "NO ACTION" means that nothing happens to a child row when +# it's parent row is updated or deleted. +# +# EVIDENCE-OF: R-19971-54976 Configuring "NO ACTION" means just that: +# when a parent key is modified or deleted from the database, no special +# action is taken. +# +drop_all_tables +do_test e_fkey-41.1 { + execsql { + CREATE TABLE parent(p1, p2, PRIMARY KEY(p1, p2)); + CREATE TABLE child(c1, c2, + FOREIGN KEY(c1, c2) REFERENCES parent + ON UPDATE NO ACTION + ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO parent VALUES('j', 'k'); + INSERT INTO parent VALUES('l', 'm'); + INSERT INTO child VALUES('j', 'k'); + INSERT INTO child VALUES('l', 'm'); + } +} {} +do_test e_fkey-41.2 { + execsql { + BEGIN; + UPDATE parent SET p1='k' WHERE p1='j'; + DELETE FROM parent WHERE p1='l'; + SELECT * FROM child; + } +} {j k l m} +do_test e_fkey-41.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-41.4 { + execsql ROLLBACK +} {} + +#------------------------------------------------------------------------- +# Test that "RESTRICT" means the application is prohibited from deleting +# or updating a parent table row when there exists one or more child keys +# mapped to it. +# +# EVIDENCE-OF: R-04272-38653 The "RESTRICT" action means that the +# application is prohibited from deleting (for ON DELETE RESTRICT) or +# modifying (for ON UPDATE RESTRICT) a parent key when there exists one +# or more child keys mapped to it. +# +drop_all_tables +do_test e_fkey-41.1 { + execsql { + CREATE TABLE parent(p1, p2); + CREATE UNIQUE INDEX parent_i ON parent(p1, p2); + CREATE TABLE child1(c1, c2, + FOREIGN KEY(c2, c1) REFERENCES parent(p1, p2) ON DELETE RESTRICT + ); + CREATE TABLE child2(c1, c2, + FOREIGN KEY(c2, c1) REFERENCES parent(p1, p2) ON UPDATE RESTRICT + ); + } +} {} +do_test e_fkey-41.2 { + execsql { + INSERT INTO parent VALUES('a', 'b'); + INSERT INTO parent VALUES('c', 'd'); + INSERT INTO child1 VALUES('b', 'a'); + INSERT INTO child2 VALUES('d', 'c'); + } +} {} +do_test e_fkey-41.3 { + catchsql { DELETE FROM parent WHERE p1 = 'a' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-41.4 { + catchsql { UPDATE parent SET p2 = 'e' WHERE p1 = 'c' } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Test that RESTRICT is slightly different from NO ACTION for IMMEDIATE +# constraints, in that it is enforced immediately, not at the end of the +# statement. +# +# EVIDENCE-OF: R-37997-42187 The difference between the effect of a +# RESTRICT action and normal foreign key constraint enforcement is that +# the RESTRICT action processing happens as soon as the field is updated +# - not at the end of the current statement as it would with an +# immediate constraint, or at the end of the current transaction as it +# would with a deferred constraint. +# +drop_all_tables +do_test e_fkey-42.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON UPDATE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + + CREATE TRIGGER parent_t AFTER UPDATE ON parent BEGIN + UPDATE child1 set c = new.x WHERE c = old.x; + UPDATE child2 set c = new.x WHERE c = old.x; + END; + } +} {} +do_test e_fkey-42.2 { + catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.3 { + execsql { + UPDATE parent SET x = 'key two' WHERE x = 'key2'; + SELECT * FROM child2; + } +} {{key two}} + +drop_all_tables +do_test e_fkey-42.4 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + + CREATE TRIGGER parent_t AFTER DELETE ON parent BEGIN + UPDATE child1 SET c = NULL WHERE c = old.x; + UPDATE child2 SET c = NULL WHERE c = old.x; + END; + } +} {} +do_test e_fkey-42.5 { + catchsql { DELETE FROM parent WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.6 { + execsql { + DELETE FROM parent WHERE x = 'key2'; + SELECT * FROM child2; + } +} {{}} + +drop_all_tables +do_test e_fkey-42.7 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + } +} {} +do_test e_fkey-42.8 { + catchsql { REPLACE INTO parent VALUES('key1') } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-42.9 { + execsql { + REPLACE INTO parent VALUES('key2'); + SELECT * FROM child2; + } +} {key2} + +#------------------------------------------------------------------------- +# Test that RESTRICT is enforced immediately, even for a DEFERRED constraint. +# +# EVIDENCE-OF: R-24179-60523 Even if the foreign key constraint it is +# attached to is deferred, configuring a RESTRICT action causes SQLite +# to return an error immediately if a parent key with dependent child +# keys is deleted or modified. +# +drop_all_tables +do_test e_fkey-43.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON UPDATE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE child2(c REFERENCES parent ON UPDATE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + BEGIN; + } +} {} +do_test e_fkey-43.2 { + catchsql { UPDATE parent SET x = 'key one' WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.3 { + execsql { UPDATE parent SET x = 'key two' WHERE x = 'key2' } +} {} +do_test e_fkey-43.4 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.5 { + execsql { + UPDATE child2 SET c = 'key two'; + COMMIT; + } +} {} + +drop_all_tables +do_test e_fkey-43.6 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child1(c REFERENCES parent ON DELETE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE child2(c REFERENCES parent ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + INSERT INTO parent VALUES('key1'); + INSERT INTO parent VALUES('key2'); + INSERT INTO child1 VALUES('key1'); + INSERT INTO child2 VALUES('key2'); + BEGIN; + } +} {} +do_test e_fkey-43.7 { + catchsql { DELETE FROM parent WHERE x = 'key1' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.8 { + execsql { DELETE FROM parent WHERE x = 'key2' } +} {} +do_test e_fkey-43.9 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-43.10 { + execsql { + UPDATE child2 SET c = NULL; + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Test SET NULL actions. +# +# EVIDENCE-OF: R-03353-05327 If the configured action is "SET NULL", +# then when a parent key is deleted (for ON DELETE SET NULL) or modified +# (for ON UPDATE SET NULL), the child key columns of all rows in the +# child table that mapped to the parent key are set to contain SQL NULL +# values. +# +drop_all_tables +do_test e_fkey-44.1 { + execsql { + CREATE TABLE pA(x PRIMARY KEY); + CREATE TABLE cA(c REFERENCES pA ON DELETE SET NULL); + CREATE TABLE cB(c REFERENCES pA ON UPDATE SET NULL); + + INSERT INTO pA VALUES(X'ABCD'); + INSERT INTO pA VALUES(X'1234'); + INSERT INTO cA VALUES(X'ABCD'); + INSERT INTO cB VALUES(X'1234'); + } +} {} +do_test e_fkey-44.2 { + execsql { + DELETE FROM pA WHERE rowid = 1; + SELECT quote(x) FROM pA; + } +} {X'1234'} +do_test e_fkey-44.3 { + execsql { + SELECT quote(c) FROM cA; + } +} {NULL} +do_test e_fkey-44.4 { + execsql { + UPDATE pA SET x = X'8765' WHERE rowid = 2; + SELECT quote(x) FROM pA; + } +} {X'8765'} +do_test e_fkey-44.5 { + execsql { SELECT quote(c) FROM cB } +} {NULL} + +#------------------------------------------------------------------------- +# Test SET DEFAULT actions. +# +# EVIDENCE-OF: R-55814-22637 The "SET DEFAULT" actions are similar to +# "SET NULL", except that each of the child key columns is set to +# contain the column's default value instead of NULL. +# +drop_all_tables +do_test e_fkey-45.1 { + execsql { + CREATE TABLE pA(x PRIMARY KEY); + CREATE TABLE cA(c DEFAULT X'0000' REFERENCES pA ON DELETE SET DEFAULT); + CREATE TABLE cB(c DEFAULT X'9999' REFERENCES pA ON UPDATE SET DEFAULT); + + INSERT INTO pA(rowid, x) VALUES(1, X'0000'); + INSERT INTO pA(rowid, x) VALUES(2, X'9999'); + INSERT INTO pA(rowid, x) VALUES(3, X'ABCD'); + INSERT INTO pA(rowid, x) VALUES(4, X'1234'); + + INSERT INTO cA VALUES(X'ABCD'); + INSERT INTO cB VALUES(X'1234'); + } +} {} +do_test e_fkey-45.2 { + execsql { + DELETE FROM pA WHERE rowid = 3; + SELECT quote(x) FROM pA ORDER BY rowid; + } +} {X'0000' X'9999' X'1234'} +do_test e_fkey-45.3 { + execsql { SELECT quote(c) FROM cA } +} {X'0000'} +do_test e_fkey-45.4 { + execsql { + UPDATE pA SET x = X'8765' WHERE rowid = 4; + SELECT quote(x) FROM pA ORDER BY rowid; + } +} {X'0000' X'9999' X'8765'} +do_test e_fkey-45.5 { + execsql { SELECT quote(c) FROM cB } +} {X'9999'} + +#------------------------------------------------------------------------- +# Test ON DELETE CASCADE actions. +# +# EVIDENCE-OF: R-61376-57267 A "CASCADE" action propagates the delete or +# update operation on the parent key to each dependent child key. +# +# EVIDENCE-OF: R-61809-62207 For an "ON DELETE CASCADE" action, this +# means that each row in the child table that was associated with the +# deleted parent row is also deleted. +# +drop_all_tables +do_test e_fkey-46.1 { + execsql { + CREATE TABLE p1(a, b UNIQUE); + CREATE TABLE c1(c REFERENCES p1(b) ON DELETE CASCADE, d); + INSERT INTO p1 VALUES(NULL, NULL); + INSERT INTO p1 VALUES(4, 4); + INSERT INTO p1 VALUES(5, 5); + INSERT INTO c1 VALUES(NULL, NULL); + INSERT INTO c1 VALUES(4, 4); + INSERT INTO c1 VALUES(5, 5); + SELECT count(*) FROM c1; + } +} {3} +do_test e_fkey-46.2 { + execsql { + DELETE FROM p1 WHERE a = 4; + SELECT d, c FROM c1; + } +} {{} {} 5 5} +do_test e_fkey-46.3 { + execsql { + DELETE FROM p1; + SELECT d, c FROM c1; + } +} {{} {}} +do_test e_fkey-46.4 { + execsql { SELECT * FROM p1 } +} {} + + +#------------------------------------------------------------------------- +# Test ON UPDATE CASCADE actions. +# +# EVIDENCE-OF: R-13877-64542 For an "ON UPDATE CASCADE" action, it means +# that the values stored in each dependent child key are modified to +# match the new parent key values. +# +# EVIDENCE-OF: R-61376-57267 A "CASCADE" action propagates the delete or +# update operation on the parent key to each dependent child key. +# +drop_all_tables +do_test e_fkey-47.1 { + execsql { + CREATE TABLE p1(a, b UNIQUE); + CREATE TABLE c1(c REFERENCES p1(b) ON UPDATE CASCADE, d); + INSERT INTO p1 VALUES(NULL, NULL); + INSERT INTO p1 VALUES(4, 4); + INSERT INTO p1 VALUES(5, 5); + INSERT INTO c1 VALUES(NULL, NULL); + INSERT INTO c1 VALUES(4, 4); + INSERT INTO c1 VALUES(5, 5); + SELECT count(*) FROM c1; + } +} {3} +do_test e_fkey-47.2 { + execsql { + UPDATE p1 SET b = 10 WHERE b = 5; + SELECT d, c FROM c1; + } +} {{} {} 4 4 5 10} +do_test e_fkey-47.3 { + execsql { + UPDATE p1 SET b = 11 WHERE b = 4; + SELECT d, c FROM c1; + } +} {{} {} 4 11 5 10} +do_test e_fkey-47.4 { + execsql { + UPDATE p1 SET b = 6 WHERE b IS NULL; + SELECT d, c FROM c1; + } +} {{} {} 4 11 5 10} +do_test e_fkey-46.5 { + execsql { SELECT * FROM p1 } +} {{} 6 4 11 5 10} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-65058-57158 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. +# +drop_all_tables +do_test e_fkey-48.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER REFERENCES artist(artistid) ON UPDATE CASCADE + ); + + INSERT INTO artist VALUES(1, 'Dean Martin'); + INSERT INTO artist VALUES(2, 'Frank Sinatra'); + INSERT INTO track VALUES(11, 'That''s Amore', 1); + INSERT INTO track VALUES(12, 'Christmas Blues', 1); + INSERT INTO track VALUES(13, 'My Way', 2); + } +} {} +do_test e_fkey-48.2 { + execsql { + UPDATE artist SET artistid = 100 WHERE artistname = 'Dean Martin'; + } +} {} +do_test e_fkey-48.3 { + execsql { SELECT * FROM artist } +} {2 {Frank Sinatra} 100 {Dean Martin}} +do_test e_fkey-48.4 { + execsql { SELECT * FROM track } +} {11 {That's Amore} 100 12 {Christmas Blues} 100 13 {My Way} 2} + + +#------------------------------------------------------------------------- +# Verify that adding an FK action does not absolve the user of the +# requirement not to violate the foreign key constraint. +# +# EVIDENCE-OF: R-53968-51642 Configuring an ON UPDATE or ON DELETE +# action does not mean that the foreign key constraint does not need to +# be satisfied. +# +drop_all_tables +do_test e_fkey-49.1 { + execsql { + CREATE TABLE parent(a COLLATE nocase, b, c, PRIMARY KEY(c, a)); + CREATE TABLE child(d DEFAULT 'a', e, f DEFAULT 'c', + FOREIGN KEY(f, d) REFERENCES parent ON UPDATE SET DEFAULT + ); + + INSERT INTO parent VALUES('A', 'b', 'c'); + INSERT INTO parent VALUES('ONE', 'two', 'three'); + INSERT INTO child VALUES('one', 'two', 'three'); + } +} {} +do_test e_fkey-49.2 { + execsql { + BEGIN; + UPDATE parent SET a = '' WHERE a = 'oNe'; + SELECT * FROM child; + } +} {a two c} +do_test e_fkey-49.3 { + execsql { + ROLLBACK; + DELETE FROM parent WHERE a = 'A'; + SELECT * FROM parent; + } +} {ONE two three} +do_test e_fkey-49.4 { + catchsql { UPDATE parent SET a = '' WHERE a = 'oNe' } +} {1 {FOREIGN KEY constraint failed}} + + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-11856-19836 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. This example shows that adding an "ON DELETE DEFAULT" +# clause does not abrogate the need to satisfy the foreign key constraint +# (R-28220-46694). +# +# EVIDENCE-OF: R-28220-46694 For example, if an "ON DELETE SET DEFAULT" +# action is configured, but there is no row in the parent table that +# corresponds to the default values of the child key columns, deleting a +# parent key while dependent child keys exist still causes a foreign key +# violation. +# +drop_all_tables +do_test e_fkey-50.1 { + execsql { + CREATE TABLE artist( + artistid INTEGER PRIMARY KEY, + artistname TEXT + ); + CREATE TABLE track( + trackid INTEGER, + trackname TEXT, + trackartist INTEGER DEFAULT 0 REFERENCES artist(artistid) ON DELETE SET DEFAULT + ); + INSERT INTO artist VALUES(3, 'Sammy Davis Jr.'); + INSERT INTO track VALUES(14, 'Mr. Bojangles', 3); + } +} {} +do_test e_fkey-50.2 { + catchsql { DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.' } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-50.3 { + execsql { + INSERT INTO artist VALUES(0, 'Unknown Artist'); + DELETE FROM artist WHERE artistname = 'Sammy Davis Jr.'; + } +} {} +do_test e_fkey-50.4 { + execsql { SELECT * FROM artist } +} {0 {Unknown Artist}} +do_test e_fkey-50.5 { + execsql { SELECT * FROM track } +} {14 {Mr. Bojangles} 0} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-09564-22170 +# +# Check that the order of steps in an UPDATE or DELETE on a parent +# table is as follows: +# +# 1. Execute applicable BEFORE trigger programs, +# 2. Check local (non foreign key) constraints, +# 3. Update or delete the row in the parent table, +# 4. Perform any required foreign key actions, +# 5. Execute applicable AFTER trigger programs. +# +drop_all_tables +do_test e_fkey-51.1 { + proc maxparent {args} { db one {SELECT max(x) FROM parent} } + db func maxparent maxparent + + execsql { + CREATE TABLE parent(x PRIMARY KEY); + + CREATE TRIGGER bu BEFORE UPDATE ON parent BEGIN + INSERT INTO parent VALUES(new.x-old.x); + END; + CREATE TABLE child( + a DEFAULT (maxparent()) REFERENCES parent ON UPDATE SET DEFAULT + ); + CREATE TRIGGER au AFTER UPDATE ON parent BEGIN + INSERT INTO parent VALUES(new.x+old.x); + END; + + INSERT INTO parent VALUES(1); + INSERT INTO child VALUES(1); + } +} {} +do_test e_fkey-51.2 { + execsql { + UPDATE parent SET x = 22; + SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child; + } +} {22 21 23 xxx 22} +do_test e_fkey-51.3 { + execsql { + DELETE FROM child; + DELETE FROM parent; + INSERT INTO parent VALUES(-1); + INSERT INTO child VALUES(-1); + UPDATE parent SET x = 22; + SELECT * FROM parent ORDER BY rowid; SELECT 'xxx' ; SELECT a FROM child; + } +} {22 23 21 xxx 23} + + +#------------------------------------------------------------------------- +# Verify that ON UPDATE actions only actually take place if the parent key +# is set to a new value that is distinct from the old value. The default +# collation sequence and affinity are used to determine if the new value +# is 'distinct' from the old or not. +# +# EVIDENCE-OF: R-27383-10246 An ON UPDATE action is only taken if the +# values of the parent key are modified so that the new parent key +# values are not equal to the old. +# +drop_all_tables +do_test e_fkey-52.1 { + execsql { + CREATE TABLE zeus(a INTEGER COLLATE NOCASE, b, PRIMARY KEY(a, b)); + CREATE TABLE apollo(c, d, + FOREIGN KEY(c, d) REFERENCES zeus ON UPDATE CASCADE + ); + INSERT INTO zeus VALUES('abc', 'xyz'); + INSERT INTO apollo VALUES('ABC', 'xyz'); + } + execsql { + UPDATE zeus SET a = 'aBc'; + SELECT * FROM apollo; + } +} {ABC xyz} +do_test e_fkey-52.2 { + execsql { + UPDATE zeus SET a = 1, b = 1; + SELECT * FROM apollo; + } +} {1 1} +do_test e_fkey-52.3 { + execsql { + UPDATE zeus SET a = 1, b = 1; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 integer 1} +do_test e_fkey-52.4 { + execsql { + UPDATE zeus SET a = '1'; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 integer 1} +do_test e_fkey-52.5 { + execsql { + UPDATE zeus SET b = '1'; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 text 1} +do_test e_fkey-52.6 { + execsql { + UPDATE zeus SET b = NULL; + SELECT typeof(c), c, typeof(d), d FROM apollo; + } +} {integer 1 null {}} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-35129-58141 +# +# Test an example from the "ON DELETE and ON UPDATE Actions" section +# of foreignkeys.html. This example demonstrates that ON UPDATE actions +# only take place if at least one parent key column is set to a value +# that is distinct from its previous value. +# +drop_all_tables +do_test e_fkey-53.1 { + execsql { + CREATE TABLE parent(x PRIMARY KEY); + CREATE TABLE child(y REFERENCES parent ON UPDATE SET NULL); + INSERT INTO parent VALUES('key'); + INSERT INTO child VALUES('key'); + } +} {} +do_test e_fkey-53.2 { + execsql { + UPDATE parent SET x = 'key'; + SELECT IFNULL(y, 'null') FROM child; + } +} {key} +do_test e_fkey-53.3 { + execsql { + UPDATE parent SET x = 'key2'; + SELECT IFNULL(y, 'null') FROM child; + } +} {null} + +########################################################################### +### SECTION 5: CREATE, ALTER and DROP TABLE commands +########################################################################### + +#------------------------------------------------------------------------- +# Test that parent keys are not checked when tables are created. +# +# EVIDENCE-OF: R-36018-21755 The parent key definitions of foreign key +# constraints are not checked when a table is created. +# +# EVIDENCE-OF: R-25384-39337 There is nothing stopping the user from +# creating a foreign key definition that refers to a parent table that +# does not exist, or to parent key columns that do not exist or are not +# collectively bound by a PRIMARY KEY or UNIQUE constraint. +# +# Child keys are checked to ensure all component columns exist. If parent +# key columns are explicitly specified, SQLite checks to make sure there +# are the same number of columns in the child and parent keys. (TODO: This +# is tested but does not correspond to any testable statement.) +# +# Also test that the above statements are true regardless of whether or not +# foreign keys are enabled: "A CREATE TABLE command operates the same whether +# or not foreign key constraints are enabled." +# +# EVIDENCE-OF: R-08908-23439 A CREATE TABLE command operates the same +# whether or not foreign key constraints are enabled. +# +foreach {tn zCreateTbl lRes} { + 1 "CREATE TABLE t1(a, b REFERENCES t1)" {0 {}} + 2 "CREATE TABLE t1(a, b REFERENCES t2)" {0 {}} + 3 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1)" {0 {}} + 4 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}} + 5 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2)" {0 {}} + 6 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t2(n,d))" {0 {}} + 7 "CREATE TABLE t1(a, b, FOREIGN KEY(a,b) REFERENCES t1(a,b))" {0 {}} + + A "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2)" + {1 {unknown column "c" in foreign key definition}} + B "CREATE TABLE t1(a, b, FOREIGN KEY(c,b) REFERENCES t2(d))" + {1 {number of columns in foreign key does not match the number of columns in the referenced table}} +} { + do_test e_fkey-54.$tn.off { + drop_all_tables + execsql {PRAGMA foreign_keys = OFF} + catchsql $zCreateTbl + } $lRes + do_test e_fkey-54.$tn.on { + drop_all_tables + execsql {PRAGMA foreign_keys = ON} + catchsql $zCreateTbl + } $lRes +} + +#------------------------------------------------------------------------- +# EVIDENCE-OF: R-47952-62498 It is not possible to use the "ALTER TABLE +# ... ADD COLUMN" syntax to add a column that includes a REFERENCES +# clause, unless the default value of the new column is NULL. Attempting +# to do so returns an error. +# +proc test_efkey_6 {tn zAlter isError} { + drop_all_tables + + do_test e_fkey-56.$tn.1 " + execsql { CREATE TABLE tbl(a, b); INSERT INTO tbl VALUES(1, 2); } + [list catchsql $zAlter] + " [lindex {{0 {}} {1 {Cannot add a REFERENCES column with non-NULL default value}}} $isError] + +} + +ifcapable altertable { + test_efkey_6 1 "ALTER TABLE tbl ADD COLUMN c REFERENCES xx" 0 + test_efkey_6 2 "ALTER TABLE tbl ADD COLUMN c DEFAULT NULL REFERENCES xx" 0 + test_efkey_6 3 "ALTER TABLE tbl ADD COLUMN c DEFAULT 0 REFERENCES xx" 1 +} + +#------------------------------------------------------------------------- +# Test that ALTER TABLE adjusts REFERENCES clauses when the parent table +# is RENAMED. +# +# EVIDENCE-OF: R-47080-02069 If an "ALTER TABLE ... RENAME TO" command +# is used to rename a table that is the parent table of one or more +# foreign key constraints, the definitions of the foreign key +# constraints are modified to refer to the parent table by its new name +# +# Test that these adjustments are visible in the sqlite_master table. +# +# EVIDENCE-OF: R-43040-62530 The text of the child CREATE TABLE +# statement or statements stored in the sqlite_schema table are modified +# to reflect the new parent table name. +# +ifcapable altertable { +do_test e_fkey-56.1 { + drop_all_tables + execsql { + CREATE TABLE 'p 1 "parent one"'(a REFERENCES 'p 1 "parent one"', b, PRIMARY KEY(b)); + + CREATE TABLE c1(c, d REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES 'p 1 "parent one"' ON UPDATE CASCADE); + + INSERT INTO 'p 1 "parent one"' VALUES(1, 1); + INSERT INTO c1 VALUES(1, 1); + INSERT INTO c2 VALUES(1, 1); + INSERT INTO c3 VALUES(1, 1); + + -- CREATE TABLE q(a, b, PRIMARY KEY(b)); + } +} {} +do_test e_fkey-56.2 { + execsql { ALTER TABLE 'p 1 "parent one"' RENAME TO p } +} {} +do_test e_fkey-56.3 { + execsql { + UPDATE p SET a = 'xxx', b = 'xxx'; + SELECT * FROM p; + SELECT * FROM c1; + SELECT * FROM c2; + SELECT * FROM c3; + } +} {xxx xxx 1 xxx 1 xxx 1 xxx} +do_test e_fkey-56.4 { + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} +} [list \ + {CREATE TABLE "p"(a REFERENCES "p", b, PRIMARY KEY(b))} \ + {CREATE TABLE c1(c, d REFERENCES "p" ON UPDATE CASCADE)} \ + {CREATE TABLE c2(e, f, FOREIGN KEY(f) REFERENCES "p" ON UPDATE CASCADE)} \ + {CREATE TABLE c3(e, 'f col 2', FOREIGN KEY('f col 2') REFERENCES "p" ON UPDATE CASCADE)} \ +] +} + +#------------------------------------------------------------------------- +# Check that a DROP TABLE does an implicit DELETE FROM. Which does not +# cause any triggers to fire, but does fire foreign key actions. +# +# EVIDENCE-OF: R-14208-23986 If foreign key constraints are enabled when +# it is prepared, the DROP TABLE command performs an implicit DELETE to +# remove all rows from the table before dropping it. +# +# EVIDENCE-OF: R-11078-03945 The implicit DELETE does not cause any SQL +# triggers to fire, but may invoke foreign key actions or constraint +# violations. +# +do_test e_fkey-57.1 { + drop_all_tables + execsql { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE SET NULL); + CREATE TABLE c2(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE SET DEFAULT); + CREATE TABLE c3(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE CASCADE); + CREATE TABLE c4(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE RESTRICT); + CREATE TABLE c5(c, d, FOREIGN KEY(c, d) REFERENCES p ON DELETE NO ACTION); + + CREATE TABLE c6(c, d, + FOREIGN KEY(c, d) REFERENCES p ON DELETE RESTRICT + DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE c7(c, d, + FOREIGN KEY(c, d) REFERENCES p ON DELETE NO ACTION + DEFERRABLE INITIALLY DEFERRED + ); + + CREATE TABLE log(msg); + CREATE TRIGGER tt AFTER DELETE ON p BEGIN + INSERT INTO log VALUES('delete ' || old.rowid); + END; + } +} {} + +do_test e_fkey-57.2 { + execsql { + INSERT INTO p VALUES('a', 'b'); + INSERT INTO c1 VALUES('a', 'b'); + INSERT INTO c2 VALUES('a', 'b'); + INSERT INTO c3 VALUES('a', 'b'); + BEGIN; + DROP TABLE p; + SELECT * FROM c1; + } +} {{} {}} +do_test e_fkey-57.3 { + execsql { SELECT * FROM c2 } +} {{} {}} +do_test e_fkey-57.4 { + execsql { SELECT * FROM c3 } +} {} +do_test e_fkey-57.5 { + execsql { SELECT * FROM log } +} {} +do_test e_fkey-57.6 { + execsql ROLLBACK +} {} +do_test e_fkey-57.7 { + execsql { + BEGIN; + DELETE FROM p; + SELECT * FROM log; + ROLLBACK; + } +} {{delete 1}} + +#------------------------------------------------------------------------- +# If an IMMEDIATE foreign key fails as a result of a DROP TABLE, the +# DROP TABLE command fails. +# +# EVIDENCE-OF: R-32768-47925 If an immediate foreign key constraint is +# violated, the DROP TABLE statement fails and the table is not dropped. +# +do_test e_fkey-58.1 { + execsql { + DELETE FROM c1; + DELETE FROM c2; + DELETE FROM c3; + } + execsql { INSERT INTO c5 VALUES('a', 'b') } + catchsql { DROP TABLE p } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-58.2 { + execsql { SELECT * FROM p } +} {a b} +do_test e_fkey-58.3 { + catchsql { + BEGIN; + DROP TABLE p; + } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-58.4 { + execsql { + SELECT * FROM p; + SELECT * FROM c5; + ROLLBACK; + } +} {a b a b} + +#------------------------------------------------------------------------- +# If a DEFERRED foreign key fails as a result of a DROP TABLE, attempting +# to commit the transaction fails unless the violation is fixed. +# +# EVIDENCE-OF: R-05903-08460 If a deferred foreign key constraint is +# violated, then an error is reported when the user attempts to commit +# the transaction if the foreign key constraint violations still exist +# at that point. +# +do_test e_fkey-59.1 { + execsql { + DELETE FROM c1 ; DELETE FROM c2 ; DELETE FROM c3 ; + DELETE FROM c4 ; DELETE FROM c5 ; DELETE FROM c6 ; + DELETE FROM c7 + } +} {} +do_test e_fkey-59.2 { + execsql { INSERT INTO c7 VALUES('a', 'b') } + execsql { + BEGIN; + DROP TABLE p; + } +} {} +do_test e_fkey-59.3 { + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-59.4 { + execsql { CREATE TABLE p(a, b, PRIMARY KEY(a, b)) } + catchsql COMMIT +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-59.5 { + execsql { INSERT INTO p VALUES('a', 'b') } + execsql COMMIT +} {} + +#------------------------------------------------------------------------- +# Any "foreign key mismatch" errors encountered while running an implicit +# "DELETE FROM tbl" are ignored. +# +# EVIDENCE-OF: R-57242-37005 Any "foreign key mismatch" errors +# encountered as part of an implicit DELETE are ignored. +# +drop_all_tables +do_test e_fkey-60.1 { + execsql { + PRAGMA foreign_keys = OFF; + + CREATE TABLE p(a PRIMARY KEY, b REFERENCES nosuchtable); + CREATE TABLE c1(c, d, FOREIGN KEY(c, d) REFERENCES a); + CREATE TABLE c2(c REFERENCES p(b), d); + CREATE TABLE c3(c REFERENCES p ON DELETE SET NULL, d); + + INSERT INTO p VALUES(1, 2); + INSERT INTO c1 VALUES(1, 2); + INSERT INTO c2 VALUES(1, 2); + INSERT INTO c3 VALUES(1, 2); + } +} {} +do_test e_fkey-60.2 { + execsql { PRAGMA foreign_keys = ON } + catchsql { DELETE FROM p } +} {1 {no such table: main.nosuchtable}} +do_test e_fkey-60.3 { + execsql { + BEGIN; + DROP TABLE p; + SELECT * FROM c3; + ROLLBACK; + } +} {{} 2} +do_test e_fkey-60.4 { + execsql { CREATE TABLE nosuchtable(x PRIMARY KEY) } + catchsql { DELETE FROM p } +} {1 {foreign key mismatch - "c2" referencing "p"}} +do_test e_fkey-60.5 { + execsql { DROP TABLE c1 } + catchsql { DELETE FROM p } +} {1 {foreign key mismatch - "c2" referencing "p"}} +do_test e_fkey-60.6 { + execsql { DROP TABLE c2 } + execsql { DELETE FROM p } +} {} + +#------------------------------------------------------------------------- +# Test that the special behaviors of ALTER and DROP TABLE are only +# activated when foreign keys are enabled. Special behaviors are: +# +# 1. ADD COLUMN not allowing a REFERENCES clause with a non-NULL +# default value. +# 2. Modifying foreign key definitions when a parent table is RENAMEd. +# 3. Running an implicit DELETE FROM command as part of DROP TABLE. +# +# EVIDENCE-OF: R-54142-41346 The properties of the DROP TABLE and ALTER +# TABLE commands described above only apply if foreign keys are enabled. +# +ifcapable altertable { +do_test e_fkey-61.1.1 { + drop_all_tables + execsql { CREATE TABLE t1(a, b) ; INSERT INTO t1 VALUES(1, 2) } + catchsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 } +} {1 {Cannot add a REFERENCES column with non-NULL default value}} +do_test e_fkey-61.1.2 { + execsql { PRAGMA foreign_keys = OFF } + execsql { ALTER TABLE t1 ADD COLUMN c DEFAULT 'xxx' REFERENCES t2 } + execsql { SELECT sql FROM sqlite_master WHERE name = 't1' } +} {{CREATE TABLE t1(a, b, c DEFAULT 'xxx' REFERENCES t2)}} +do_test e_fkey-61.1.3 { + execsql { PRAGMA foreign_keys = ON } +} {} + +do_test e_fkey-61.2.1 { + drop_all_tables + execsql { + CREATE TABLE p(a UNIQUE); + CREATE TABLE c(b REFERENCES p(a)); + BEGIN; + ALTER TABLE p RENAME TO parent; + SELECT sql FROM sqlite_master WHERE name = 'c'; + ROLLBACK; + } +} {{CREATE TABLE c(b REFERENCES "parent"(a))}} +do_test e_fkey-61.2.2 { + execsql { + PRAGMA foreign_keys = OFF; + PRAGMA legacy_alter_table = ON; + ALTER TABLE p RENAME TO parent; + SELECT sql FROM sqlite_master WHERE name = 'c'; + } +} {{CREATE TABLE c(b REFERENCES p(a))}} +do_test e_fkey-61.2.3 { + execsql { PRAGMA foreign_keys = ON } + execsql { PRAGMA legacy_alter_table = OFF } +} {} + +do_test e_fkey-61.3.1 { + drop_all_tables + execsql { + CREATE TABLE p(a UNIQUE); + CREATE TABLE c(b REFERENCES p(a) ON DELETE SET NULL); + INSERT INTO p VALUES('x'); + INSERT INTO c VALUES('x'); + BEGIN; + DROP TABLE p; + SELECT * FROM c; + ROLLBACK; + } +} {{}} +do_test e_fkey-61.3.2 { + execsql { + PRAGMA foreign_keys = OFF; + DROP TABLE p; + SELECT * FROM c; + } +} {x} +do_test e_fkey-61.3.3 { + execsql { PRAGMA foreign_keys = ON } +} {} +} + +########################################################################### +### SECTION 6: Limits and Unsupported Features +########################################################################### + +#------------------------------------------------------------------------- +# Test that MATCH clauses are parsed, but SQLite treats every foreign key +# constraint as if it were "MATCH SIMPLE". +# +# EVIDENCE-OF: R-24728-13230 SQLite parses MATCH clauses (i.e. does not +# report a syntax error if you specify one), but does not enforce them. +# +# EVIDENCE-OF: R-24450-46174 All foreign key constraints in SQLite are +# handled as if MATCH SIMPLE were specified. +# +foreach zMatch [list SIMPLE PARTIAL FULL Simple parTIAL FuLL ] { + drop_all_tables + do_test e_fkey-62.$zMatch.1 { + execsql " + CREATE TABLE p(a, b, c, PRIMARY KEY(b, c)); + CREATE TABLE c(d, e, f, FOREIGN KEY(e, f) REFERENCES p MATCH $zMatch); + " + } {} + do_test e_fkey-62.$zMatch.2 { + execsql { INSERT INTO p VALUES(1, 2, 3) } + + # MATCH SIMPLE behavior: Allow any child key that contains one or more + # NULL value to be inserted. Non-NULL values do not have to map to any + # parent key values, so long as at least one field of the child key is + # NULL. + execsql { INSERT INTO c VALUES('w', 2, 3) } + execsql { INSERT INTO c VALUES('x', 'x', NULL) } + execsql { INSERT INTO c VALUES('y', NULL, 'x') } + execsql { INSERT INTO c VALUES('z', NULL, NULL) } + + # Check that the FK is enforced properly if there are no NULL values + # in the child key columns. + catchsql { INSERT INTO c VALUES('a', 2, 4) } + } {1 {FOREIGN KEY constraint failed}} +} + +#------------------------------------------------------------------------- +# Test that SQLite does not support the SET CONSTRAINT statement. And +# that it is possible to create both immediate and deferred constraints. +# +# EVIDENCE-OF: R-21599-16038 In SQLite, a foreign key constraint is +# permanently marked as deferred or immediate when it is created. +# +drop_all_tables +do_test e_fkey-62.1 { + catchsql { SET CONSTRAINTS ALL IMMEDIATE } +} {1 {near "SET": syntax error}} +do_test e_fkey-62.2 { + catchsql { SET CONSTRAINTS ALL DEFERRED } +} {1 {near "SET": syntax error}} + +do_test e_fkey-62.3 { + execsql { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + CREATE TABLE cd(c, d, + FOREIGN KEY(c, d) REFERENCES p DEFERRABLE INITIALLY DEFERRED); + CREATE TABLE ci(c, d, + FOREIGN KEY(c, d) REFERENCES p DEFERRABLE INITIALLY IMMEDIATE); + BEGIN; + } +} {} +do_test e_fkey-62.4 { + catchsql { INSERT INTO ci VALUES('x', 'y') } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-62.5 { + catchsql { INSERT INTO cd VALUES('x', 'y') } +} {0 {}} +do_test e_fkey-62.6 { + catchsql { COMMIT } +} {1 {FOREIGN KEY constraint failed}} +do_test e_fkey-62.7 { + execsql { + DELETE FROM cd; + COMMIT; + } +} {} + +#------------------------------------------------------------------------- +# Test that the maximum recursion depth of foreign key action programs is +# governed by the SQLITE_MAX_TRIGGER_DEPTH and SQLITE_LIMIT_TRIGGER_DEPTH +# settings. +# +# EVIDENCE-OF: R-42264-30503 The SQLITE_MAX_TRIGGER_DEPTH and +# SQLITE_LIMIT_TRIGGER_DEPTH settings determine the maximum allowable +# depth of trigger program recursion. For the purposes of these limits, +# foreign key actions are considered trigger programs. +# +proc test_on_delete_recursion {limit} { + drop_all_tables + execsql { + BEGIN; + CREATE TABLE t0(a PRIMARY KEY, b); + INSERT INTO t0 VALUES('x0', NULL); + } + for {set i 1} {$i <= $limit} {incr i} { + execsql " + CREATE TABLE t$i ( + a PRIMARY KEY, b REFERENCES t[expr $i-1] ON DELETE CASCADE + ); + INSERT INTO t$i VALUES('x$i', 'x[expr $i-1]'); + " + } + execsql COMMIT + catchsql " + DELETE FROM t0; + SELECT count(*) FROM t$limit; + " +} +proc test_on_update_recursion {limit} { + drop_all_tables + execsql { + BEGIN; + CREATE TABLE t0(a PRIMARY KEY); + INSERT INTO t0 VALUES('xxx'); + } + for {set i 1} {$i <= $limit} {incr i} { + set j [expr $i-1] + + execsql " + CREATE TABLE t$i (a PRIMARY KEY REFERENCES t$j ON UPDATE CASCADE); + INSERT INTO t$i VALUES('xxx'); + " + } + execsql COMMIT + catchsql " + UPDATE t0 SET a = 'yyy'; + SELECT NOT (a='yyy') FROM t$limit; + " +} + +# If the current build was created using clang with the -fsanitize=address +# switch, then the library uses considerably more stack space than usual. +# So much more, that some of the following tests cause stack overflows +# if they are run under this configuration. +# +if {[clang_sanitize_address]==0} { + do_test e_fkey-63.1.1 { + test_on_delete_recursion $SQLITE_MAX_TRIGGER_DEPTH + } {0 0} + do_test e_fkey-63.1.2 { + test_on_delete_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1] + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.1.3 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5 + test_on_delete_recursion 5 + } {0 0} + do_test e_fkey-63.1.4 { + test_on_delete_recursion 6 + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.1.5 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000 + } {5} + do_test e_fkey-63.2.1 { + test_on_update_recursion $SQLITE_MAX_TRIGGER_DEPTH + } {0 0} + do_test e_fkey-63.2.2 { + test_on_update_recursion [expr $SQLITE_MAX_TRIGGER_DEPTH+1] + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.2.3 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 5 + test_on_update_recursion 5 + } {0 0} + do_test e_fkey-63.2.4 { + test_on_update_recursion 6 + } {1 {too many levels of trigger recursion}} + do_test e_fkey-63.2.5 { + sqlite3_limit db SQLITE_LIMIT_TRIGGER_DEPTH 1000000 + } {5} +} + +#------------------------------------------------------------------------- +# The setting of the recursive_triggers pragma does not affect foreign +# key actions. +# +# EVIDENCE-OF: R-44355-00270 The PRAGMA recursive_triggers setting does +# not affect the operation of foreign key actions. +# +foreach recursive_triggers_setting [list 0 1 ON OFF] { + drop_all_tables + execsql "PRAGMA recursive_triggers = $recursive_triggers_setting" + + do_test e_fkey-64.$recursive_triggers_setting.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1 ON DELETE CASCADE); + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 2); + INSERT INTO t1 VALUES(4, 3); + INSERT INTO t1 VALUES(5, 4); + SELECT count(*) FROM t1; + } + } {5} + do_test e_fkey-64.$recursive_triggers_setting.2 { + execsql { SELECT count(*) FROM t1 WHERE a = 1 } + } {1} + do_test e_fkey-64.$recursive_triggers_setting.3 { + execsql { + DELETE FROM t1 WHERE a = 1; + SELECT count(*) FROM t1; + } + } {0} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fts3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fts3.test new file mode 100644 index 0000000000000000000000000000000000000000..c06feab2d12f447e34aa349b11220b638af738a2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_fts3.test @@ -0,0 +1,707 @@ +# 2009 November 28 +# +# 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 to verify the "testable statements" in the +# fts3.in document. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +# Procs used to make the tests in this file easier to read. +# +proc ddl_test {tn ddl} { + uplevel [list do_write_test e_fts3-$tn sqlite_master $ddl] +} +proc write_test {tn tbl sql} { + uplevel [list do_write_test e_fts3-$tn $tbl $sql] +} +proc read_test {tn sql result} { + uplevel [list do_select_test e_fts3-$tn $sql $result] +} +proc error_test {tn sql result} { + uplevel [list do_error_test e_fts3-$tn $sql $result] +} + + +#------------------------------------------------------------------------- +# The body of the following [foreach] block contains test cases to verify +# that the example code in fts3.html works as expected. The tests run three +# times, with different values for DO_MALLOC_TEST. +# +# DO_MALLOC_TEST=0: Run tests with no OOM errors. +# DO_MALLOC_TEST=1: Run tests with transient OOM errors. +# DO_MALLOC_TEST=2: Run tests with persistent OOM errors. +# +foreach {DO_MALLOC_TEST enc} { + 0 utf-8 + 1 utf-8 + 2 utf-8 + 1 utf-16 +} { + +#if {$DO_MALLOC_TEST} break + +# Reset the database and database connection. If this iteration of the +# [foreach] loop is testing with OOM errors, disable the lookaside buffer. +# +db close +forcedelete test.db test.db-journal +sqlite3 db test.db +if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 } +db eval "PRAGMA encoding = '$enc'" + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +########################################################################## +# Test the example CREATE VIRTUAL TABLE statements in section 1.1 +# of fts3.in. +# +ddl_test 1.1.1.1 {CREATE VIRTUAL TABLE data USING fts3()} +read_test 1.1.1.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0} + +ddl_test 1.1.2.1 { + CREATE VIRTUAL TABLE pages USING fts3(title, keywords, body) +} +read_test 1.1.2.2 { + PRAGMA table_info(pages) +} {0 title {} 0 {} 0 1 keywords {} 0 {} 0 2 body {} 0 {} 0} + +ddl_test 1.1.3.1 { + CREATE VIRTUAL TABLE mail USING fts3( + subject VARCHAR(256) NOT NULL, + body TEXT CHECK(length(body)<10240) + ) +} +read_test 1.1.3.2 { + PRAGMA table_info(mail) +} {0 subject {} 0 {} 0 1 body {} 0 {} 0} + +# A very large string. Used to test if the constraint on column "body" of +# table "mail" is enforced (it should not be - FTS3 tables do not support +# constraints). +set largetext [string repeat "the quick brown fox " 5000] +write_test 1.1.3.3 mail_content { INSERT INTO mail VALUES(NULL, $largetext) } +read_test 1.1.3.4 { + SELECT subject IS NULL, length(body) FROM mail +} [list 1 100000] + +ddl_test 1.1.4.1 { + CREATE VIRTUAL TABLE papers USING fts3(author, document, tokenize=porter) +} +read_test 1.1.4.2 { + PRAGMA table_info(papers) +} {0 author {} 0 {} 0 1 document {} 0 {} 0} + +ddl_test 1.1.5.1 { + CREATE VIRTUAL TABLE simpledata USING fts3(tokenize=simple) +} +read_test 1.1.5.2 { + PRAGMA table_info(simpledata) +} {0 content {} 0 {} 0} + +ifcapable icu { + ddl_test 1.1.6.1 { + CREATE VIRTUAL TABLE names USING fts3(a, b, tokenize=icu en_AU) + } + read_test 1.1.6.2 { + PRAGMA table_info(names) + } {0 a {} 0 {} 0 1 b {} 0 {} 0} +} + +ddl_test 1.1.7.1 {DROP TABLE data} +ddl_test 1.1.7.2 {DROP TABLE pages} +ddl_test 1.1.7.3 {DROP TABLE mail} +ddl_test 1.1.7.4 {DROP TABLE papers} +ddl_test 1.1.7.5 {DROP TABLE simpledata} +read_test 1.1.7.6 {SELECT * FROM sqlite_master} {} + +# The following is not one of the examples in section 1.1. It tests +# specifying an FTS3 table with no module arguments using a slightly +# different syntax. +ddl_test 1.1.8.1 {CREATE VIRTUAL TABLE data USING fts3;} +read_test 1.1.8.2 {PRAGMA table_info(data)} {0 content {} 0 {} 0} +ddl_test 1.1.8.3 {DROP TABLE data} + +########################################################################## +# Test the examples in section 1.2 (populating fts3 tables) +# +ddl_test 1.2.1.1 { + CREATE VIRTUAL TABLE pages USING fts3(title, body); +} +write_test 1.2.1.2 pages_content { + INSERT INTO pages(docid, title, body) + VALUES(53, 'Home Page', 'SQLite is a software...'); +} +read_test 1.2.1.3 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...}} + +write_test 1.2.1.4 pages_content { + INSERT INTO pages(title, body) + VALUES('Download', 'All SQLite source code...'); +} +read_test 1.2.1.5 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...} 54 Download {All SQLite source code...}} + +write_test 1.2.1.6 pages_content { + UPDATE pages SET title = 'Download SQLite' WHERE rowid = 54 +} +read_test 1.2.1.7 { + SELECT docid, * FROM pages +} {53 {Home Page} {SQLite is a software...} 54 {Download SQLite} {All SQLite source code...}} + +write_test 1.2.1.8 pages_content { DELETE FROM pages } +read_test 1.2.1.9 { SELECT docid, * FROM pages } {} + +do_error_test fts3-1.2.1.10 { + INSERT INTO pages(rowid, docid, title, body) VALUES(1, 2, 'A title', 'A document body'); +} {SQL logic error} + +# Test the optimize() function example: +ddl_test 1.2.2.1 { CREATE VIRTUAL TABLE docs USING fts3 } +write_test 1.2.2.2 docs_content { + INSERT INTO docs VALUES('Others translate the first clause as'); +} +write_test 1.2.2.3 docs_content { + INSERT INTO docs VALUES('"which is for Solomon," meaning that'); +} +write_test 1.2.2.4 docs_content { + INSERT INTO docs VALUES('the book is dedicated to Solomon.'); +} +read_test 1.2.2.5 { SELECT count(*) FROM docs_segdir } {3} +write_test 1.2.2.6 docs_segdir { + INSERT INTO docs(docs) VALUES('optimize'); +} +read_test 1.2.2.7 { SELECT count(*) FROM docs_segdir } {1} +ddl_test 1.2.2.8 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 1.3 (querying FTS3 tables) +# +ddl_test 1.3.1.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } +read_test 1.3.1.2 { + SELECT * FROM mail WHERE rowid = 15; -- Fast. Rowid lookup. + SELECT * FROM mail WHERE body MATCH 'sqlite'; -- Fast. Full-text query. + SELECT * FROM mail WHERE mail MATCH 'search'; -- Fast. Full-text query. + SELECT * FROM mail WHERE rowid BETWEEN 15 AND 20; -- Slow. Linear scan. + SELECT * FROM mail WHERE subject = 'database'; -- Slow. Linear scan. + SELECT * FROM mail WHERE subject MATCH 'database'; -- Fast. Full-text query. +} {} +ddl_test 1.3.1.3 { DROP TABLE mail } + +ddl_test 1.3.2.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } + +write_test 1.3.2.2 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(1, 'software feedback', 'found it too slow') +} +write_test 1.3.2.3 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(2, 'software feedback', 'no feedback') +} +write_test 1.3.2.4 mail_content { + INSERT INTO mail(docid, subject, body) + VALUES(3, 'slow lunch order', 'was a software problem') +} +read_test 1.3.2.5 { + SELECT * FROM mail WHERE subject MATCH 'software' +} {{software feedback} {found it too slow} {software feedback} {no feedback}} +read_test 1.3.2.6 { + SELECT * FROM mail WHERE body MATCH 'feedback' +} {{software feedback} {no feedback}} +read_test 1.3.2.7 { + SELECT * FROM mail WHERE mail MATCH 'software' +} {{software feedback} {found it too slow} {software feedback} {no feedback} {slow lunch order} {was a software problem}} +read_test 1.3.2.7 { + SELECT * FROM mail WHERE mail MATCH 'slow' +} {{software feedback} {found it too slow} {slow lunch order} {was a software problem}} +ddl_test 1.3.2.8 { DROP TABLE mail } + +ddl_test 1.3.3.1 { CREATE VIRTUAL TABLE docs USING fts3(content) } +read_test 1.3.3.2 { SELECT * FROM docs WHERE docs MATCH 'sqlite' } {} +read_test 1.3.3.3 { SELECT * FROM docs WHERE docs.docs MATCH 'sqlite' } {} +read_test 1.3.3.4 { SELECT * FROM docs WHERE main.docs.docs MATCH 'sqlite' } {} +do_error_test e_fts3-1.3.3.5 { + SELECT * FROM docs WHERE main.docs MATCH 'sqlite' +} {no such column: main.docs} +ddl_test 1.3.2.8 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 3 (full-text index queries). +# +ddl_test 1.4.1.1 { CREATE VIRTUAL TABLE docs USING fts3(title, body) } +unset -nocomplain R +foreach {tn title body} { + 2 "linux driver" "a device" + 3 "driver" "linguistic trick" + 4 "problems" "linux problems" + 5 "linux" "big problems" + 6 "linux driver" "a device driver problem" + 7 "good times" "applications for linux" + 8 "not so good" "linux applications" + 9 "alternative" "linoleum appliances" + 10 "no L I N" "to be seen" +} { + write_test 1.4.1.$tn docs_content { INSERT INTO docs VALUES($title,$body) } + set R($tn) [list $title $body] +} + +read_test 1.4.1.11 { + SELECT * FROM docs WHERE docs MATCH 'linux' +} [concat $R(2) $R(4) $R(5) $R(6) $R(7) $R(8)] +read_test 1.4.1.12 { + SELECT * FROM docs WHERE docs MATCH 'lin*' +} [concat $R(2) $R(3) $R(4) $R(5) $R(6) $R(7) $R(8) $R(9)] +read_test 1.4.1.13 { + SELECT * FROM docs WHERE docs MATCH 'title:linux problems' +} [concat $R(5)] +read_test 1.4.1.14 { + SELECT * FROM docs WHERE body MATCH 'title:linux driver' +} [concat $R(6)] +read_test 1.4.1.15 { + SELECT * FROM docs WHERE docs MATCH '"linux applications"' +} [concat $R(8)] +read_test 1.4.1.16 { + SELECT * FROM docs WHERE docs MATCH '"lin* app*"' +} [concat $R(8) $R(9)] +ddl_test 1.4.1.17 { DROP TABLE docs } +unset R + +ddl_test 1.4.2.1 { CREATE VIRTUAL TABLE docs USING fts3() } +write_test 1.4.2.2 docs_content { + INSERT INTO docs VALUES( + 'SQLite is an ACID compliant embedded relational database management system') +} +foreach {tn query hit} { +3 {SELECT * FROM docs WHERE docs MATCH 'sqlite NEAR database'} 1 +4 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/6 sqlite'} 1 +5 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/5 sqlite'} 0 +6 {SELECT * FROM docs WHERE docs MATCH 'database NEAR/2 "ACID compliant"'} 1 +7 {SELECT * FROM docs WHERE docs MATCH '"ACID compliant" NEAR/2 sqlite'} 1 +8 {SELECT * FROM docs WHERE docs MATCH 'sqlite NEAR/2 acid NEAR/2 relational'} 1 +9 {SELECT * FROM docs WHERE docs MATCH 'acid NEAR/2 sqlite NEAR/2 relational'} 0 +} { + set res [db eval {SELECT * FROM docs WHERE $hit}] + read_test 1.4.2.$tn $query $res +} +ddl_test 1.4.2.10 { DROP TABLE docs } + +########################################################################## +# Test the example in section 3.1 (set operators with enhanced syntax). +# +set sqlite_fts3_enable_parentheses 1 +ddl_test 1.5.1.1 { CREATE VIRTUAL TABLE docs USING fts3() } +foreach {tn docid content} { + 2 1 "a database is a software system" + 3 2 "sqlite is a software system" + 4 3 "sqlite is a database" +} { + set R($docid) $content + write_test 1.5.1.$tn docs_content { + INSERT INTO docs(docid, content) VALUES($docid, $content) + } +} +read_test 1.5.1.4 { + SELECT * FROM docs WHERE docs MATCH 'sqlite AND database' +} [list $R(3)] +read_test 1.5.1.5 { + SELECT * FROM docs WHERE docs MATCH 'database sqlite' +} [list $R(3)] +read_test 1.5.1.6 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database' +} [list $R(1) $R(2) $R(3)] +read_test 1.5.1.7 { + SELECT * FROM docs WHERE docs MATCH 'database NOT sqlite' +} [list $R(1)] +read_test 1.5.1.8 { + SELECT * FROM docs WHERE docs MATCH 'database and sqlite' +} {} + +write_test 1.5.2.1 docs_content { + INSERT INTO docs + SELECT 'sqlite is also a library' UNION ALL + SELECT 'library software' +} +read_test 1.5.2.2 { + SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database OR library' +} {3 4 5} +read_test 1.5.2.3 { + SELECT docid FROM docs WHERE docs MATCH 'sqlite AND database' + UNION + SELECT docid FROM docs WHERE docs MATCH 'library' +} {3 4 5} +write_test 1.5.2.4 docs_content { + INSERT INTO docs + SELECT 'the sqlite library runs on linux' UNION ALL + SELECT 'as does the sqlite database (on linux)' UNION ALL + SELECT 'the sqlite database is accessed by the sqlite library' +} +read_test 1.5.2.2 { + SELECT docid FROM docs + WHERE docs MATCH '("sqlite database" OR "sqlite library") AND linux'; +} {6 7} +read_test 1.5.2.3 { + SELECT docid FROM docs WHERE docs MATCH 'linux' + INTERSECT + SELECT docid FROM ( + SELECT docid FROM docs WHERE docs MATCH '"sqlite library"' + UNION + SELECT docid FROM docs WHERE docs MATCH '"sqlite database"' + ); +} {6 7} + +########################################################################## +# Test the examples in section 3.2 (set operators with standard syntax). +# These tests reuse the table populated by the block above. +# +set sqlite_fts3_enable_parentheses 0 +read_test 1.6.1.1 { + SELECT * FROM docs WHERE docs MATCH 'sqlite -database' +} {{sqlite is a software system} {sqlite is also a library} {the sqlite library runs on linux}} +read_test 1.6.1.2 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database library' +} {{sqlite is also a library} {the sqlite library runs on linux} {the sqlite database is accessed by the sqlite library}} + +set sqlite_fts3_enable_parentheses 1 +read_test 1.6.1.3 { + SELECT * FROM docs WHERE docs MATCH 'sqlite OR database library' +} {{sqlite is a software system} {sqlite is a database} {sqlite is also a library} {the sqlite library runs on linux} {as does the sqlite database (on linux)} {the sqlite database is accessed by the sqlite library}} +read_test 1.6.1.4 { + SELECT * FROM docs WHERE docs MATCH '(sqlite OR database) library' +} {{sqlite is also a library} {the sqlite library runs on linux} {the sqlite database is accessed by the sqlite library}} +set sqlite_fts3_enable_parentheses 0 +ddl_test 1.6.1.5 { DROP TABLE docs } + +########################################################################## +# Test the examples in section 4 (auxillary functions). +# +ddl_test 1.7.1.1 { CREATE VIRTUAL TABLE mail USING fts3(subject, body) } + +write_test 1.7.1.2 mail_content { + INSERT INTO mail VALUES( + 'hello world', 'This message is a hello world message.'); +} +write_test 1.7.1.3 mail_content { + INSERT INTO mail VALUES( + 'urgent: serious', 'This mail is seen as a more serious mail'); +} + +read_test 1.7.1.4 { + SELECT offsets(mail) FROM mail WHERE mail MATCH 'world'; +} {{0 0 6 5 1 0 24 5}} +read_test 1.7.1.5 { + SELECT offsets(mail) FROM mail WHERE mail MATCH 'message' +} {{1 0 5 7 1 0 30 7}} +read_test 1.7.1.6 { + SELECT offsets(mail) FROM mail WHERE mail MATCH '"serious mail"' +} {{1 0 28 7 1 1 36 4}} + +ddl_test 1.7.2.1 { CREATE VIRTUAL TABLE text USING fts3() } + +write_test 1.7.2.2 text_content { + INSERT INTO text VALUES(' + During 30 Nov-1 Dec, 2-3oC drops. Cool in the upper portion, minimum temperature 14-16oC and cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6-12oC. Northeasterly winds 15-30 km/hr. After that, temperature increases. Northeasterly winds 15-30 km/hr. + '); +} + +read_test 1.7.2.3 { + SELECT snippet(text) FROM text WHERE text MATCH 'cold' +} {{...cool elsewhere, minimum temperature 17-20oC. Cold to very cold on mountaintops, minimum temperature 6...}} + +read_test 1.7.2.4 { + SELECT snippet(text, '[', ']', '...') FROM text WHERE text MATCH '"min* tem*"' +} {{...the upper portion, [minimum] [temperature] 14-16oC and cool elsewhere, [minimum] [temperature] 17-20oC. Cold...}} + +ddl_test 1.7.3.1 { DROP TABLE IF EXISTS t1 } +ddl_test 1.7.3.2 { CREATE VIRTUAL TABLE t1 USING fts3(a, b) } +write_test 1.7.3.3 t1_content { + INSERT INTO t1 VALUES( + 'transaction default models default', 'Non transaction reads'); +} +write_test 1.7.3.4 t1_content { + INSERT INTO t1 VALUES('the default transaction', 'these semantics present'); +} +write_test 1.7.3.5 t1_content { + INSERT INTO t1 VALUES('single request', 'default data'); +} +read_test 1.7.3.6 { + SELECT mit(matchinfo(t1)) FROM t1 + WHERE t1 MATCH 'default transaction "these semantics"'; +} {{3 2 1 3 2 0 1 1 1 2 2 0 1 1 0 0 0 1 1 1}} + +########################################################################## +# Test the example in section 5 (custom tokenizers). +# +ddl_test 1.8.1.1 { CREATE VIRTUAL TABLE simple USING fts3(tokenize=simple) } +write_test 1.8.1.2 simple_content { + INSERT INTO simple VALUES('Right now they''re very frustrated') +} +read_test 1.8.1.3 {SELECT docid FROM simple WHERE simple MATCH 'Frustrated'} {1} +read_test 1.8.1.4 {SELECT docid FROM simple WHERE simple MATCH 'Frustration'} {} + +ddl_test 1.8.2.1 { CREATE VIRTUAL TABLE porter USING fts3(tokenize=porter) } +write_test 1.8.2.2 porter_content { + INSERT INTO porter VALUES('Right now they''re very frustrated') +} +read_test 1.8.2.4 { + SELECT docid FROM porter WHERE porter MATCH 'Frustration' +} {1} + +} +# End of tests of example code in fts3.html +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that errors in the arguments passed to the snippet and offsets +# functions are handled correctly. +# +set DO_MALLOC_TEST 0 +ddl_test 2.1.0 { DROP TABLE IF EXISTS t1 } +ddl_test 2.1.1 { CREATE VIRTUAL TABLE t1 USING fts3(a, b) } +write_test 2.1.2 t1_content { + INSERT INTO t1 VALUES('one two three', x'A1B2C3D4E5F6'); +} +error_test 2.1.3 { + SELECT offsets(a) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to offsets} +error_test 2.1.4 { + SELECT offsets(b) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to offsets} +error_test 2.1.5 { + SELECT optimize(a) FROM t1 LIMIT 1 +} {illegal first argument to optimize} +error_test 2.1.6 { + SELECT snippet(a) FROM t1 WHERE a MATCH 'one' +} {illegal first argument to snippet} +error_test 2.1.7 { + SELECT snippet() FROM t1 WHERE a MATCH 'one' +} {unable to use function snippet in the requested context} +error_test 2.1.8 { + SELECT snippet(a, b, 'A', 'B', 'C', 'D', 'E') FROM t1 WHERE a MATCH 'one' +} {wrong number of arguments to function snippet()} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test the effect of an OOM error while installing the FTS3 module (i.e. +# opening a database handle). This case was not tested by the OOM testing +# of the document examples above. +# +do_malloc_test e_fts3-3 -tclbody { + if {[catch {sqlite3 db test.db}]} { error "out of memory" } +} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Verify the return values of the optimize() function. If no error occurs, +# the returned value should be "Index optimized" if the data structure +# was modified, or "Index already optimal" if it were not. +# +set DO_MALLOC_TEST 0 +ddl_test 4.1 { CREATE VIRTUAL TABLE t4 USING fts3(a, b) } +write_test 4.2 t4_content { + INSERT INTO t4 VALUES('In Xanadu', 'did Kubla Khan'); +} +write_test 4.3 t4_content { + INSERT INTO t4 VALUES('a stately pleasure', 'dome decree'); +} +do_test e_fts3-4.4 { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} {{Index optimized}} +do_test e_fts3-4.5 { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} {{Index already optimal}} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that the snippet function appears to work correctly with 1, 2, 3 +# or 4 arguments passed to it. +# +set DO_MALLOC_TEST 0 +ddl_test 5.1 { CREATE VIRTUAL TABLE t5 USING fts3(x) } +write_test 5.2 t5_content { + INSERT INTO t5 VALUES('In Xanadu did Kubla Khan A stately pleasure-dome decree Where Alph, the sacred river, ran Through caverns measureless to man Down to a sunless sea. So twice five miles of fertile ground With walls and towers were girdled round : And there were gardens bright with sinuous rills, Where blossomed many an incense-bearing tree ; And here were forests ancient as the hills, Enfolding sunny spots of greenery.'); +} +read_test 5.3 { + SELECT snippet(t5) FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.4 { + SELECT snippet(t5, '') FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.5 { + SELECT snippet(t5, '', '') FROM t5 WHERE t5 MATCH 'miles' +} {{...to a sunless sea. So twice five miles of fertile ground With walls and towers...}} +read_test 5.6 { + SELECT snippet(t5, '', '', 'XXX') FROM t5 WHERE t5 MATCH 'miles' +} {{XXXto a sunless sea. So twice five miles of fertile ground With walls and towersXXX}} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that an empty MATCH expression returns an empty result set. As +# does passing a NULL value as a MATCH expression. +# +set DO_MALLOC_TEST 0 +ddl_test 6.1 { CREATE VIRTUAL TABLE t6 USING fts3(x) } +write_test 6.2 t5_content { INSERT INTO t6 VALUES('a'); } +write_test 6.3 t5_content { INSERT INTO t6 VALUES('b'); } +write_test 6.4 t5_content { INSERT INTO t6 VALUES('c'); } +read_test 6.5 { SELECT * FROM t6 WHERE t6 MATCH '' } {} +read_test 6.6 { SELECT * FROM t6 WHERE x MATCH '' } {} +read_test 6.7 { SELECT * FROM t6 WHERE t6 MATCH NULL } {} +read_test 6.8 { SELECT * FROM t6 WHERE x MATCH NULL } {} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test a few facets of the FTS3 xFilter() callback implementation: +# +# 1. That the sqlite3_index_constraint.usable flag is respected. +# +# 2. That it is an error to use the "docid" or "rowid" column of +# an FTS3 table as the LHS of a MATCH operator. +# +# 3. That it is an error to AND together two MATCH expressions in +# that refer to a single FTS3 table in a WHERE clause. +# +# +set DO_MALLOC_TEST 0 +ddl_test 7.1.1 { CREATE VIRTUAL TABLE t7 USING fts3(a) } +ddl_test 7.1.2 { CREATE VIRTUAL TABLE t8 USING fts3(b) } +write_test 7.1.3 t7_content { INSERT INTO t7(docid, a) VALUES(4,'number four') } +write_test 7.1.4 t7_content { INSERT INTO t7(docid, a) VALUES(5,'number five') } +write_test 7.1.5 t8_content { INSERT INTO t8(docid, b) VALUES(4,'letter D') } +write_test 7.1.6 t8_content { INSERT INTO t8(docid, b) VALUES(5,'letter E') } +read_test 7.1.7 { + SELECT a || ':' || b FROM t7 JOIN t8 USING(docid) +} {{number four:letter D} {number five:letter E}} + +error_test 7.2.1 { + SELECT * FROM t7 WHERE docid MATCH 'number' +} {unable to use function MATCH in the requested context} +error_test 7.2.2 { + SELECT * FROM t7 WHERE rowid MATCH 'number' +} {unable to use function MATCH in the requested context} + +error_test 7.3.1 { + SELECT * FROM t7 WHERE a MATCH 'number' AND a MATCH 'four' +} {unable to use function MATCH in the requested context} +error_test 7.3.2 { + SELECT * FROM t7, t8 WHERE a MATCH 'number' AND a MATCH 'four' +} {unable to use function MATCH in the requested context} +error_test 7.3.3 { + SELECT * FROM t7, t8 WHERE b MATCH 'letter' AND b MATCH 'd' +} {unable to use function MATCH in the requested context} +read_test 7.3.4 { + SELECT * FROM t7, t8 WHERE a MATCH 'number' AND b MATCH 'letter' +} {{number four} {letter D} {number four} {letter E} {number five} {letter D} {number five} {letter E}} +read_test 7.3.5 { + SELECT * FROM t7 WHERE a MATCH 'number' AND docid = 4 +} {{number four}} + +#------------------------------------------------------------------------- +# Test the quoting of FTS3 table column names. Names may be quoted using +# any of "", '', ``` or []. +# +set DO_MALLOC_TEST 0 +ddl_test 8.1.1 { CREATE VIRTUAL TABLE t9a USING fts3("c1", [c2]) } +ddl_test 8.1.2 { CREATE VIRTUAL TABLE t9b USING fts3('c1', `c2`) } +read_test 8.1.3 { PRAGMA table_info(t9a) } {0 c1 {} 0 {} 0 1 c2 {} 0 {} 0} +read_test 8.1.4 { PRAGMA table_info(t9b) } {0 c1 {} 0 {} 0 1 c2 {} 0 {} 0} +ddl_test 8.2.1 { CREATE VIRTUAL TABLE t9c USING fts3("c""1", 'c''2') } +read_test 8.2.2 { PRAGMA table_info(t9c) } {0 c\"1 {} 0 {} 0 1 c'2 {} 0 {} 0} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test that FTS3 tables can be renamed using the ALTER RENAME command. +# OOM errors are tested during ALTER RENAME commands also. +# +foreach DO_MALLOC_TEST {0 1 2} { + db close + forcedelete test.db test.db-journal + sqlite3 db test.db + if {$DO_MALLOC_TEST} { sqlite3_db_config_lookaside db 0 0 0 } + + ddl_test 9.1.1 { CREATE VIRTUAL TABLE t10 USING fts3(x) } + write_test 9.1.2 t10_content { INSERT INTO t10 VALUES('fts3 tables') } + write_test 9.1.3 t10_content { INSERT INTO t10 VALUES('are renameable') } + + read_test 9.1.4 { + SELECT * FROM t10 WHERE t10 MATCH 'table*' + } {{fts3 tables}} + read_test 9.1.5 { + SELECT * FROM t10 WHERE x MATCH 'rename*' + } {{are renameable}} + + ddl_test 9.1.6 { ALTER TABLE t10 RENAME TO t11 } + + read_test 9.1.7 { + SELECT * FROM t11 WHERE t11 MATCH 'table*' + } {{fts3 tables}} + read_test 9.1.8 { + SELECT * FROM t11 WHERE x MATCH 'rename*' + } {{are renameable}} +} +#------------------------------------------------------------------------- + +#------------------------------------------------------------------------- +# Test a couple of cases involving corrupt data structures: +# +# 1) A case where a document referenced by the full-text index is +# not present in the %_content table. +# +# 2) A badly formatted b-tree segment node. +# +set DO_MALLOC_TEST 0 +ddl_test 10.1.1 { CREATE VIRTUAL TABLE ta USING fts3 } +write_test 10.1.2 ta_content { + INSERT INTO ta VALUES('During a summer vacation in 1790') } +write_test 10.1.3 ta_content { + INSERT INTO ta VALUES('Wordsworth went on a walking tour') } +sqlite3_db_config db DEFENSIVE 0 +write_test 10.1.4 ta_content { DELETE FROM ta_content WHERE rowid = 2 } +read_test 10.1.5 { + SELECT * FROM ta WHERE ta MATCH 'summer' +} {{During a summer vacation in 1790}} +error_test 10.1.6 { + SELECT * FROM ta WHERE ta MATCH 'walking' +} {database disk image is malformed} + +write_test 10.2.1 ta_content { DELETE FROM ta } +write_test 10.2.2 ta_content { + INSERT INTO ta VALUES('debate demonstrated the rising difficulty') } +write_test 10.2.3 ta_content { + INSERT INTO ta VALUES('Google released its browser beta') } + +set blob [db one {SELECT root FROM ta_segdir WHERE rowid = 2}] +binary scan $blob "a6 a3 a*" start middle end +set middle "\x0E\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x06\x06" +set blob [binary format "a6 a* a*" $start $middle $end] +write_test 10.2.4 ta_segdir { + UPDATE ta_segdir SET root = $blob WHERE rowid = 2 +} +error_test 10.2.5 { + SELECT * FROM ta WHERE ta MATCH 'beta' +} {database disk image is malformed} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_insert.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_insert.test new file mode 100644 index 0000000000000000000000000000000000000000..7561e58ccc074dcd9a19f725faa0aaaf96cae8af --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_insert.test @@ -0,0 +1,431 @@ +# 2010 September 18 +# +# 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. +# +#*********************************************************************** +# +# The majority of this file implements tests to verify that the "testable +# statements" in the lang_insert.html document are correct. +# +# Also, it contains tests to verify the statements in (the very short) +# lang_replace.html. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +# Organization of tests: +# +# e_insert-0.*: Test the syntax diagram. +# +# e_insert-1.*: Test statements of the form "INSERT ... VALUES(...)". +# +# e_insert-2.*: Test statements of the form "INSERT ... SELECT ...". +# +# e_insert-3.*: Test statements of the form "INSERT ... DEFAULT VALUES". +# +# e_insert-4.*: Test statements regarding the conflict clause. +# +# e_insert-5.*: Test that the qualified table name and "DEFAULT VALUES" +# syntaxes do not work in trigger bodies. +# + +do_execsql_test e_insert-0.0 { + CREATE TABLE a1(a, b); + CREATE TABLE a2(a, b, c DEFAULT 'xyz'); + CREATE TABLE a3(x DEFAULT 1.0, y DEFAULT 'string', z); + CREATE TABLE a4(c UNIQUE, d); +} {} + +proc do_insert_tests {args} { + uplevel do_select_tests $args +} + +# -- syntax diagram insert-stmt +# +do_insert_tests e_insert-0 { + 1 "INSERT INTO a1 DEFAULT VALUES" {} + 2 "INSERT INTO main.a1 DEFAULT VALUES" {} + 3 "INSERT OR ROLLBACK INTO main.a1 DEFAULT VALUES" {} + 4 "INSERT OR ROLLBACK INTO a1 DEFAULT VALUES" {} + 5 "INSERT OR ABORT INTO main.a1 DEFAULT VALUES" {} + 6 "INSERT OR ABORT INTO a1 DEFAULT VALUES" {} + 7 "INSERT OR REPLACE INTO main.a1 DEFAULT VALUES" {} + 8 "INSERT OR REPLACE INTO a1 DEFAULT VALUES" {} + 9 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {} + 10 "INSERT OR FAIL INTO a1 DEFAULT VALUES" {} + 11 "INSERT OR FAIL INTO main.a1 DEFAULT VALUES" {} + 12 "INSERT OR IGNORE INTO a1 DEFAULT VALUES" {} + 13 "REPLACE INTO a1 DEFAULT VALUES" {} + 14 "REPLACE INTO main.a1 DEFAULT VALUES" {} + 15 "INSERT INTO a1 VALUES(1, 2)" {} + 16 "INSERT INTO main.a1 VALUES(1, 2)" {} + 17 "INSERT OR ROLLBACK INTO main.a1 VALUES(1, 2)" {} + 18 "INSERT OR ROLLBACK INTO a1 VALUES(1, 2)" {} + 19 "INSERT OR ABORT INTO main.a1 VALUES(1, 2)" {} + 20 "INSERT OR ABORT INTO a1 VALUES(1, 2)" {} + 21 "INSERT OR REPLACE INTO main.a1 VALUES(1, 2)" {} + 22 "INSERT OR REPLACE INTO a1 VALUES(1, 2)" {} + 23 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {} + 24 "INSERT OR FAIL INTO a1 VALUES(1, 2)" {} + 25 "INSERT OR FAIL INTO main.a1 VALUES(1, 2)" {} + 26 "INSERT OR IGNORE INTO a1 VALUES(1, 2)" {} + 27 "REPLACE INTO a1 VALUES(1, 2)" {} + 28 "REPLACE INTO main.a1 VALUES(1, 2)" {} + 29 "INSERT INTO a1 (b, a) VALUES(1, 2)" {} + 30 "INSERT INTO main.a1 (b, a) VALUES(1, 2)" {} + 31 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2)" {} + 32 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2)" {} + 33 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2)" {} + 34 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2)" {} + 35 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {} + 36 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2)" {} + 37 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {} + 38 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2)" {} + 39 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2)" {} + 40 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2)" {} + 41 "REPLACE INTO a1 (b, a) VALUES(1, 2)" {} + 42 "REPLACE INTO main.a1 (b, a) VALUES(1, 2)" {} + 43 "INSERT INTO a1 SELECT c, b FROM a2" {} + 44 "INSERT INTO main.a1 SELECT c, b FROM a2" {} + 45 "INSERT OR ROLLBACK INTO main.a1 SELECT c, b FROM a2" {} + 46 "INSERT OR ROLLBACK INTO a1 SELECT c, b FROM a2" {} + 47 "INSERT OR ABORT INTO main.a1 SELECT c, b FROM a2" {} + 48 "INSERT OR ABORT INTO a1 SELECT c, b FROM a2" {} + 49 "INSERT OR REPLACE INTO main.a1 SELECT c, b FROM a2" {} + 50 "INSERT OR REPLACE INTO a1 SELECT c, b FROM a2" {} + 51 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {} + 52 "INSERT OR FAIL INTO a1 SELECT c, b FROM a2" {} + 53 "INSERT OR FAIL INTO main.a1 SELECT c, b FROM a2" {} + 54 "INSERT OR IGNORE INTO a1 SELECT c, b FROM a2" {} + 55 "REPLACE INTO a1 SELECT c, b FROM a2" {} + 56 "REPLACE INTO main.a1 SELECT c, b FROM a2" {} + 57 "INSERT INTO a1 (b, a) SELECT c, b FROM a2" {} + 58 "INSERT INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 59 "INSERT OR ROLLBACK INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 60 "INSERT OR ROLLBACK INTO a1 (b, a) SELECT c, b FROM a2" {} + 61 "INSERT OR ABORT INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 62 "INSERT OR ABORT INTO a1 (b, a) SELECT c, b FROM a2" {} + 63 "INSERT OR REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 64 "INSERT OR REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} + 65 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 66 "INSERT OR FAIL INTO a1 (b, a) SELECT c, b FROM a2" {} + 67 "INSERT OR FAIL INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 68 "INSERT OR IGNORE INTO a1 (b, a) SELECT c, b FROM a2" {} + 69 "REPLACE INTO a1 (b, a) SELECT c, b FROM a2" {} + 70 "REPLACE INTO main.a1 (b, a) SELECT c, b FROM a2" {} + 71 "INSERT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 72 "INSERT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 73 "INSERT OR ROLLBACK INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 74 "INSERT OR ROLLBACK INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 75 "INSERT OR ABORT INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 76 "INSERT OR ABORT INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 77 "INSERT OR REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 78 "INSERT OR REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 79 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 80 "INSERT OR FAIL INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 81 "INSERT OR FAIL INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} + 82 "INSERT OR IGNORE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 83 "REPLACE INTO a1 (b, a) VALUES(1, 2),(3,4)" {} + 84 "REPLACE INTO main.a1 (b, a) VALUES(1, 2),(3,4)" {} +} + +delete_all_data + +# EVIDENCE-OF: R-21490-41092 The first form (with the "VALUES" keyword) +# creates one or more new rows in an existing table. +# +do_insert_tests e_insert-1.1 { + 0 "SELECT count(*) FROM a2" {0} + + 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} + 1b "SELECT count(*) FROM a2" {1} + + 2a "INSERT INTO a2(a, b) VALUES(1, 2)" {} + 2b "SELECT count(*) FROM a2" {2} + + 3a "INSERT INTO a2(a) VALUES(3),(4)" {} + 3b "SELECT count(*) FROM a2" {4} +} + +# EVIDENCE-OF: R-19218-01018 If the column-name list after table-name is +# omitted then the number of values inserted into each row must be the +# same as the number of columns in the table. +# +# A test in the block above verifies that if the VALUES list has the +# correct number of columns (for table a2, 3 columns) works. So these +# tests just show that other values cause an error. +# +do_insert_tests e_insert-1.2 -error { + table %s has %d columns but %d values were supplied +} { + 1 "INSERT INTO a2 VALUES(1)" {a2 3 1} + 2 "INSERT INTO a2 VALUES(1,2)" {a2 3 2} + 3 "INSERT INTO a2 VALUES(1,2,3,4)" {a2 3 4} + 4 "INSERT INTO a2 VALUES(1,2,3,4,5)" {a2 3 5} +} + +# EVIDENCE-OF: R-29730-42609 In this case the result of evaluating the +# left-most expression from each term of the VALUES list is inserted +# into the left-most column of each new row, and so forth for each +# subsequent expression. +# +delete_all_data +do_insert_tests e_insert-1.3 { + 1a "INSERT INTO a2 VALUES(1, 2, 3)" {} + 1b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {1 2 3} + + 2a "INSERT INTO a2 VALUES('abc', NULL, 3*3+1)" {} + 2b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {abc {} 10} + + 3a "INSERT INTO a2 VALUES((SELECT count(*) FROM a2), 'x', 'y')" {} + 3b "SELECT * FROM a2 WHERE oid=last_insert_rowid()" {2 x y} +} + +# EVIDENCE-OF: R-21115-58321 If a column-name list is specified, then +# the number of values in each term of the VALUE list must match the +# number of specified columns. +# +do_insert_tests e_insert-1.4 -error { + %d values for %d columns +} { + 1 "INSERT INTO a2(a, b, c) VALUES(1)" {1 3} + 2 "INSERT INTO a2(a, b, c) VALUES(1,2)" {2 3} + 3 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4)" {4 3} + 4 "INSERT INTO a2(a, b, c) VALUES(1,2,3,4,5)" {5 3} + + 5 "INSERT INTO a2(c, a) VALUES(1)" {1 2} + 6 "INSERT INTO a2(c, a) VALUES(1,2,3)" {3 2} + 7 "INSERT INTO a2(c, a) VALUES(1,2,3,4)" {4 2} + 8 "INSERT INTO a2(c, a) VALUES(1,2,3,4,5)" {5 2} +} + +# EVIDENCE-OF: R-07016-26442 Each of the named columns of the new row is +# populated with the results of evaluating the corresponding VALUES +# expression. +# +# EVIDENCE-OF: R-12183-43719 Table columns that do not appear in the +# column list are populated with the default column value (specified as +# part of the CREATE TABLE statement), or with NULL if no default value +# is specified. +# +delete_all_data +do_insert_tests e_insert-1.5 { + 1a "INSERT INTO a2(b, c) VALUES('b', 'c')" {} + 1b "SELECT * FROM a2" {{} b c} + + 2a "INSERT INTO a2(a, b) VALUES('a', 'b')" {} + 2b "SELECT * FROM a2" {{} b c a b xyz} +} + +# EVIDENCE-OF: R-52173-30215 A new entry is inserted into the table for +# each row of data returned by executing the SELECT statement. +# +delete_all_data +do_insert_tests e_insert-2.1 { + 0 "SELECT count(*) FROM a1" {0} + + 1a "SELECT count(*) FROM (SELECT 1, 2)" {1} + 1b "INSERT INTO a1 SELECT 1, 2" {} + 1c "SELECT count(*) FROM a1" {1} + + 2a "SELECT count(*) FROM (SELECT b, a FROM a1)" {1} + 2b "INSERT INTO a1 SELECT b, a FROM a1" {} + 2c "SELECT count(*) FROM a1" {2} + + 3a "SELECT count(*) FROM (SELECT b, a FROM a1)" {2} + 3b "INSERT INTO a1 SELECT b, a FROM a1" {} + 3c "SELECT count(*) FROM a1" {4} + + 4a "SELECT count(*) FROM (SELECT b, a FROM a1)" {4} + 4b "INSERT INTO a1 SELECT b, a FROM a1" {} + 4c "SELECT count(*) FROM a1" {8} + + 4a "SELECT count(*) FROM (SELECT min(b), min(a) FROM a1)" {1} + 4b "INSERT INTO a1 SELECT min(b), min(a) FROM a1" {} + 4c "SELECT count(*) FROM a1" {9} +} + + +# EVIDENCE-OF: R-63614-47421 If a column-list is specified, the number +# of columns in the result of the SELECT must be the same as the number +# of items in the column-list. +# +do_insert_tests e_insert-2.2 -error { + %d values for %d columns +} { + 1 "INSERT INTO a3(x, y) SELECT a, b, c FROM a2" {3 2} + 2 "INSERT INTO a3(x, y) SELECT * FROM a2" {3 2} + 3 "INSERT INTO a3(x, y) SELECT * FROM a2 CROSS JOIN a1" {5 2} + 4 "INSERT INTO a3(x, y) SELECT * FROM a2 NATURAL JOIN a1" {3 2} + 5 "INSERT INTO a3(x, y) SELECT a2.a FROM a2,a1" {1 2} + + 6 "INSERT INTO a3(z) SELECT a, b, c FROM a2" {3 1} + 7 "INSERT INTO a3(z) SELECT * FROM a2" {3 1} + 8 "INSERT INTO a3(z) SELECT * FROM a2 CROSS JOIN a1" {5 1} + 9 "INSERT INTO a3(z) SELECT * FROM a2 NATURAL JOIN a1" {3 1} + 10 "INSERT INTO a3(z) SELECT a1.* FROM a2,a1" {2 1} +} + +# EVIDENCE-OF: R-58951-07798 Otherwise, if no column-list is specified, +# the number of columns in the result of the SELECT must be the same as +# the number of columns in the table. +# +do_insert_tests e_insert-2.3 -error { + table %s has %d columns but %d values were supplied +} { + 1 "INSERT INTO a1 SELECT a, b, c FROM a2" {a1 2 3} + 2 "INSERT INTO a1 SELECT * FROM a2" {a1 2 3} + 3 "INSERT INTO a1 SELECT * FROM a2 CROSS JOIN a1" {a1 2 5} + 4 "INSERT INTO a1 SELECT * FROM a2 NATURAL JOIN a1" {a1 2 3} + 5 "INSERT INTO a1 SELECT a2.a FROM a2,a1" {a1 2 1} +} + +# EVIDENCE-OF: R-31074-37730 Any SELECT statement, including compound +# SELECTs and SELECT statements with ORDER BY and/or LIMIT clauses, may +# be used in an INSERT statement of this form. +# +delete_all_data +do_execsql_test e_insert-2.3.0 { + INSERT INTO a1 VALUES('x', 'y'); +} {} +do_insert_tests e_insert-2.3 { + 1 "INSERT INTO a1 SELECT a,b FROM a1 UNION SELECT b,a FROM a1 ORDER BY 1" {} + 2 "INSERT INTO a1(b, a) SELECT * FROM a1 LIMIT 1" {} + 3 "INSERT INTO a1 SELECT 'a'||a, 'b'||b FROM a1 LIMIT 2 OFFSET 1" {} + 4 "INSERT INTO a1 SELECT * FROM a1 ORDER BY b, a" {} + S "SELECT * FROM a1" { + x y + x y y x + y x + ax by ay bx + ay bx ax by y x y x x y x y + } +} + +# EVIDENCE-OF: R-25149-22012 The INSERT ... DEFAULT VALUES statement +# inserts a single new row into the named table. +# +delete_all_data +do_insert_tests e_insert-3.1 { + 1 "SELECT count(*) FROM a3" {0} + 2a "INSERT INTO a3 DEFAULT VALUES" {} + 2b "SELECT count(*) FROM a3" {1} +} + +# EVIDENCE-OF: R-18927-01951 Each column of the new row is populated +# with its default value, or with a NULL if no default value is +# specified as part of the column definition in the CREATE TABLE +# statement. +# +delete_all_data +do_insert_tests e_insert-3.2 { + 1.1 "INSERT INTO a3 DEFAULT VALUES" {} + 1.2 "SELECT * FROM a3" {1.0 string {}} + + 2.1 "INSERT INTO a3 DEFAULT VALUES" {} + 2.2 "SELECT * FROM a3" {1.0 string {} 1.0 string {}} + + 3.1 "INSERT INTO a2 DEFAULT VALUES" {} + 3.2 "SELECT * FROM a2" {{} {} xyz} + + 4.1 "INSERT INTO a2 DEFAULT VALUES" {} + 4.2 "SELECT * FROM a2" {{} {} xyz {} {} xyz} + + 5.1 "INSERT INTO a1 DEFAULT VALUES" {} + 5.2 "SELECT * FROM a1" {{} {}} + + 6.1 "INSERT INTO a1 DEFAULT VALUES" {} + 6.2 "SELECT * FROM a1" {{} {} {} {}} +} + +# EVIDENCE-OF: R-00267-47727 The initial "INSERT" keyword can be +# replaced by "REPLACE" or "INSERT OR action" to specify an alternative +# constraint conflict resolution algorithm to use during that one INSERT +# command. +# +# EVIDENCE-OF: R-23110-47146 the parser allows the use of the single +# keyword REPLACE as an alias for "INSERT OR REPLACE". +# +# The two requirements above are tested by e_select-4.1.* and +# e_select-4.2.*, respectively. +# +# EVIDENCE-OF: R-03421-22330 The REPLACE command is an alias for the +# "INSERT OR REPLACE" variant of the INSERT command. +# +# This is a dup of R-23110-47146. Therefore it is also verified +# by e_select-4.2.*. This requirement is the only one from +# lang_replace.html. +# +do_execsql_test e_insert-4.1.0 { + INSERT INTO a4 VALUES(1, 'a'); + INSERT INTO a4 VALUES(2, 'a'); + INSERT INTO a4 VALUES(3, 'a'); +} {} +foreach {tn sql error ac data } { + 1.1 "INSERT INTO a4 VALUES(2,'b')" {UNIQUE constraint failed: a4.c} 1 {1 a 2 a 3 a} + 1.2 "INSERT OR REPLACE INTO a4 VALUES(2, 'b')" {} 1 {1 a 3 a 2 b} + 1.3 "INSERT OR IGNORE INTO a4 VALUES(3, 'c')" {} 1 {1 a 3 a 2 b} + 1.4 "BEGIN" {} 0 {1 a 3 a 2 b} + 1.5 "INSERT INTO a4 VALUES(1, 'd')" {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b} + 1.6 "INSERT OR ABORT INTO a4 VALUES(1, 'd')" + {UNIQUE constraint failed: a4.c} 0 {1 a 3 a 2 b} + 1.7 "INSERT OR ROLLBACK INTO a4 VALUES(1, 'd')" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} + 1.8 "INSERT INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b} + 1.9 "INSERT OR FAIL INTO a4 SELECT 4, 'e' UNION ALL SELECT 3, 'e'" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} + + 2.1 "INSERT INTO a4 VALUES(2,'f')" + {UNIQUE constraint failed: a4.c} 1 {1 a 3 a 2 b 4 e} + 2.2 "REPLACE INTO a4 VALUES(2, 'f')" {} 1 {1 a 3 a 4 e 2 f} +} { + do_catchsql_test e_insert-4.1.$tn.1 $sql [list [expr {$error!=""}] $error] + do_execsql_test e_insert-4.1.$tn.2 {SELECT * FROM a4} [list {*}$data] + do_test e_insert-4.1.$tn.3 {sqlite3_get_autocommit db} $ac +} + +# EVIDENCE-OF: R-59829-49719 The optional "schema-name." prefix on the +# table-name is supported for top-level INSERT statements only. +# +# EVIDENCE-OF: R-05731-00924 The table name must be unqualified for +# INSERT statements that occur within CREATE TRIGGER statements. +# +set err {1 {qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers}} + +do_catchsql_test e_insert-5.1.1 { + CREATE TRIGGER AFTER UPDATE ON a1 BEGIN + INSERT INTO main.a4 VALUES(new.a, new.b); + END; +} $err +do_catchsql_test e_insert-5.1.2 { + CREATE TEMP TABLE IF NOT EXISTS tmptable(a, b); + CREATE TRIGGER AFTER DELETE ON a3 BEGIN + INSERT INTO temp.tmptable VALUES(1, 2); + END; +} $err + +# EVIDENCE-OF: R-15888-36326 Similarly, the "DEFAULT VALUES" form of the +# INSERT statement is supported for top-level INSERT statements only and +# not for INSERT statements within triggers. +# +do_catchsql_test e_insert-5.2.1 { + CREATE TRIGGER AFTER UPDATE ON a1 BEGIN + INSERT INTO a4 DEFAULT VALUES; + END; +} {1 {near "DEFAULT": syntax error}} + + +delete_all_data + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_reindex.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_reindex.test new file mode 100644 index 0000000000000000000000000000000000000000..50d2e7d5166fa734b1afd368f78bace813aa9d73 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_reindex.test @@ -0,0 +1,299 @@ +# 2010 September 24 +# +# 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 to verify that the "testable statements" in +# the lang_reindex.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +proc do_reindex_tests {args} { + uplevel do_select_tests $args +} + +do_execsql_test e_reindex-0.0 { + CREATE TABLE t1(a, b); + CREATE INDEX i1 ON t1(a, b); + CREATE INDEX i2 ON t1(b, a); +} {} + +# -- syntax diagram reindex-stmt +# +do_reindex_tests e_reindex-0.1 { + 1 "REINDEX" {} + 2 "REINDEX nocase" {} + 3 "REINDEX binary" {} + 4 "REINDEX t1" {} + 5 "REINDEX main.t1" {} + 6 "REINDEX i1" {} + 7 "REINDEX main.i1" {} +} + +# EVIDENCE-OF: R-52173-44778 The REINDEX command is used to delete and +# recreate indices from scratch. +# +# Test this by corrupting some database indexes, running REINDEX, and +# observing that the corruption is gone. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test e_reindex-1.1 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + + CREATE TABLE saved(a,b,c,d,e); + INSERT INTO saved SELECT * FROM sqlite_master WHERE type = 'index'; + PRAGMA writable_schema = 1; + DELETE FROM sqlite_master WHERE type = 'index'; +} {} + +db close +sqlite3 db test.db +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test e_reindex-1.2 { + DELETE FROM t1 WHERE a = 3; + INSERT INTO t1 VALUES(7, 8); + INSERT INTO t1 VALUES(9, 10); + PRAGMA writable_schema = 1; + INSERT INTO sqlite_master SELECT * FROM saved; + DROP TABLE saved; +} {} + +db close +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} +] + +do_execsql_test e_reindex-1.4 { + REINDEX; + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +# The remaining tests in this file focus on testing that the REINDEX +# command reindexes the correct subset of the indexes in the database. +# They all use the following dataset. +# +db close +forcedelete test.db2 +forcedelete test.db +sqlite3 db test.db + +proc sort_by_length {lhs rhs} { + set res [expr {[string length $lhs] - [string length $rhs]}] + if {$res!=0} {return $res} + return [string compare $lhs $rhs] +} +array set V {one 1 two 2 three 3 four 4 five 5 six 6 seven 7 eight 8} +proc sort_by_value {lhs rhs} { + global V + set res [expr {$V($lhs) - $V($rhs)}] + if {$res!=0} {return $res} + return [string compare $lhs $rhs] +} + +db collate collA sort_by_length +db collate collB sort_by_value + +set BY(length) {one six two five four eight seven three} +set BY(value) {one two three four five six seven eight} + +do_execsql_test e_reindex-2.0 { + ATTACH 'test.db2' AS aux; + + CREATE TABLE t1(x); + CREATE INDEX i1_a ON t1(x COLLATE collA); + CREATE INDEX i1_b ON t1(x COLLATE collB); + INSERT INTO t1 VALUES('one'); + INSERT INTO t1 VALUES('two'); + INSERT INTO t1 VALUES('three'); + INSERT INTO t1 VALUES('four'); + INSERT INTO t1 VALUES('five'); + INSERT INTO t1 VALUES('six'); + INSERT INTO t1 VALUES('seven'); + INSERT INTO t1 VALUES('eight'); + + CREATE TABLE t2(x); + CREATE INDEX i2_a ON t2(x COLLATE collA); + CREATE INDEX i2_b ON t2(x COLLATE collB); + INSERT INTO t2 SELECT x FROM t1; + + CREATE TABLE aux.t1(x); + CREATE INDEX aux.i1_a ON t1(x COLLATE collA); + CREATE INDEX aux.i1_b ON t1(x COLLATE collB); + INSERT INTO aux.t1 SELECT x FROM main.t1; + +} {} + +proc test_index {tn tbl collation expected} { + set sql "SELECT x FROM $tbl ORDER BY x COLLATE $collation" + uplevel do_execsql_test e_reindex-2.$tn [list $sql] [list $::BY($expected)] +} + +proc set_collations {a b} { + db collate collA "sort_by_$a" + db collate collB "sort_by_$b" +} + +test_index 1.1 t1 collA length +test_index 1.2 t1 collB value +test_index 1.3 t2 collA length +test_index 1.4 t2 collB value +test_index 1.5 aux.t1 collA length +test_index 1.6 aux.t1 collB value + + +# EVIDENCE-OF: R-47362-07898 If the REINDEX keyword is not followed by a +# collation-sequence or database object identifier, then all indices in +# all attached databases are rebuilt. +# +set_collations value length +do_execsql_test e_reindex-2.2.1 "REINDEX" {} +test_index 2.2 t1 collA value +test_index 2.3 t1 collB length +test_index 2.4 t2 collA value +test_index 2.5 t2 collB length +test_index 2.6 aux.t1 collA value +test_index 2.7 aux.t1 collB length + +# EVIDENCE-OF: R-45878-07697 If the REINDEX keyword is followed by a +# collation-sequence name, then all indices in all attached databases +# that use the named collation sequences are recreated. +# +set_collations length value +do_execsql_test e_reindex-2.3.1 "REINDEX collA" {} +test_index 3.2 t1 collA length +test_index 3.3 t1 collB length +test_index 3.4 t2 collA length +test_index 3.5 t2 collB length +test_index 3.6 aux.t1 collA length +test_index 3.7 aux.t1 collB length +do_execsql_test e_reindex-2.3.8 "REINDEX collB" {} +test_index 3.9 t1 collA length +test_index 3.10 t1 collB value +test_index 3.11 t2 collA length +test_index 3.12 t2 collB value +test_index 3.13 aux.t1 collA length +test_index 3.14 aux.t1 collB value + +# EVIDENCE-OF: R-49616-30196 Or, if the argument attached to the REINDEX +# identifies a specific database table, then all indices attached to the +# database table are rebuilt. +# +set_collations value length +do_execsql_test e_reindex-2.4.1 "REINDEX t1" {} +test_index 4.2 t1 collA value +test_index 4.3 t1 collB length +test_index 4.4 t2 collA length +test_index 4.5 t2 collB value +test_index 4.6 aux.t1 collA length +test_index 4.7 aux.t1 collB value +do_execsql_test e_reindex-2.4.8 "REINDEX aux.t1" {} +test_index 4.9 t1 collA value +test_index 4.10 t1 collB length +test_index 4.11 t2 collA length +test_index 4.12 t2 collB value +test_index 4.13 aux.t1 collA value +test_index 4.14 aux.t1 collB length +do_execsql_test e_reindex-2.4.15 "REINDEX t2" {} +test_index 4.16 t1 collA value +test_index 4.17 t1 collB length +test_index 4.18 t2 collA value +test_index 4.19 t2 collB length +test_index 4.20 aux.t1 collA value +test_index 4.21 aux.t1 collB length + +# EVIDENCE-OF: R-58823-28748 If it identifies a specific database index, +# then just that index is recreated. +# +set_collations length value +do_execsql_test e_reindex-2.5.1 "REINDEX i1_a" {} +test_index 5.2 t1 collA length +test_index 5.3 t1 collB length +test_index 5.4 t2 collA value +test_index 5.5 t2 collB length +test_index 5.6 aux.t1 collA value +test_index 5.7 aux.t1 collB length +do_execsql_test e_reindex-2.5.8 "REINDEX i2_b" {} +test_index 5.9 t1 collA length +test_index 5.10 t1 collB length +test_index 5.11 t2 collA value +test_index 5.12 t2 collB value +test_index 5.13 aux.t1 collA value +test_index 5.14 aux.t1 collB length +do_execsql_test e_reindex-2.5.15 "REINDEX aux.i1_b" {} +test_index 5.16 t1 collA length +test_index 5.17 t1 collB length +test_index 5.18 t2 collA value +test_index 5.19 t2 collB value +test_index 5.20 aux.t1 collA value +test_index 5.21 aux.t1 collB value +do_execsql_test e_reindex-2.5.22 "REINDEX i1_b" {} +test_index 5.23 t1 collA length +test_index 5.24 t1 collB value +test_index 5.25 t2 collA value +test_index 5.26 t2 collB value +test_index 5.27 aux.t1 collA value +test_index 5.28 aux.t1 collB value +do_execsql_test e_reindex-2.5.29 "REINDEX i2_a" {} +test_index 5.30 t1 collA length +test_index 5.31 t1 collB value +test_index 5.32 t2 collA length +test_index 5.33 t2 collB value +test_index 5.34 aux.t1 collA value +test_index 5.35 aux.t1 collB value +do_execsql_test e_reindex-2.5.36 "REINDEX aux.i1_a" {} +test_index 5.37 t1 collA length +test_index 5.38 t1 collB value +test_index 5.39 t2 collA length +test_index 5.40 t2 collB value +test_index 5.41 aux.t1 collA length +test_index 5.42 aux.t1 collB value + +# EVIDENCE-OF: R-35892-30289 For a command of the form "REINDEX name", a +# match against collation-name takes precedence over a match against +# index-name or table-name. +# +set_collations value length +do_execsql_test e_reindex-2.6.0 { + CREATE TABLE collA(x); + CREATE INDEX icolla_a ON collA(x COLLATE collA); + CREATE INDEX icolla_b ON collA(x COLLATE collB); + + INSERT INTO collA SELECT x FROM t1; +} {} + +test_index 6.1 collA collA value +test_index 6.2 collA collB length + +set_collations length value +do_execsql_test e_reindex-2.6.3 "REINDEX collA" {} +test_index 6.4 collA collA length +test_index 6.5 collA collB length +do_execsql_test e_reindex-2.6.3 "REINDEX main.collA" {} +test_index 6.4 collA collA length +test_index 6.5 collA collB value + +set_collations value length +do_execsql_test e_reindex-2.6.6 "REINDEX main.collA" {} +test_index 6.7 collA collA value +test_index 6.8 collA collB length + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select.test new file mode 100644 index 0000000000000000000000000000000000000000..e2e969dcf9d86a30d2eb9bf030c9bad6263fb980 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select.test @@ -0,0 +1,2174 @@ +# 2010 July 16 +# +# 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 to verify that the "testable statements" in +# the lang_select.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !compound { + finish_test + return +} + +do_execsql_test e_select-1.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES('a', 'one'); + INSERT INTO t1 VALUES('b', 'two'); + INSERT INTO t1 VALUES('c', 'three'); + + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES('a', 'I'); + INSERT INTO t2 VALUES('b', 'II'); + INSERT INTO t2 VALUES('c', 'III'); + + CREATE TABLE t3(a, c); + INSERT INTO t3 VALUES('a', 1); + INSERT INTO t3 VALUES('b', 2); + + CREATE TABLE t4(a, c); + INSERT INTO t4 VALUES('a', NULL); + INSERT INTO t4 VALUES('b', 2); +} {} +set t1_cross_t2 [list \ + a one a I a one b II \ + a one c III b two a I \ + b two b II b two c III \ + c three a I c three b II \ + c three c III \ +] +set t1_cross_t1 [list \ + a one a one a one b two \ + a one c three b two a one \ + b two b two b two c three \ + c three a one c three b two \ + c three c three \ +] + + +# This proc is a specialized version of [do_execsql_test]. +# +# The second argument to this proc must be a SELECT statement that +# features a cross join of some time. Instead of the usual ",", +# "CROSS JOIN" or "INNER JOIN" join-op, the string %JOIN% must be +# substituted. +# +# This test runs the SELECT three times - once with: +# +# * s/%JOIN%/,/ +# * s/%JOIN%/JOIN/ +# * s/%JOIN%/INNER JOIN/ +# * s/%JOIN%/CROSS JOIN/ +# +# and checks that each time the results of the SELECT are $res. +# +proc do_join_test {tn select res} { + foreach {tn2 joinop} [list 1 , 2 "CROSS JOIN" 3 "INNER JOIN"] { + set S [string map [list %JOIN% $joinop] $select] + uplevel do_execsql_test $tn.$tn2 [list $S] [list $res] + } +} + +#------------------------------------------------------------------------- +# The following tests check that all paths on the syntax diagrams on +# the lang_select.html page may be taken. +# +# -- syntax diagram join-constraint +# +do_join_test e_select-0.1.1 { + SELECT count(*) FROM t1 %JOIN% t2 ON (t1.a=t2.a) +} {3} +do_join_test e_select-0.1.2 { + SELECT count(*) FROM t1 %JOIN% t2 USING (a) +} {3} +do_join_test e_select-0.1.3 { + SELECT count(*) FROM t1 %JOIN% t2 +} {9} +do_catchsql_test e_select-0.1.4 { + SELECT count(*) FROM t1, t2 ON (t1.a=t2.a) USING (a) +} {1 {near "USING": syntax error}} +do_catchsql_test e_select-0.1.5 { + SELECT count(*) FROM t1, t2 USING (a) ON (t1.a=t2.a) +} {1 {near "ON": syntax error}} + +# -- syntax diagram select-core +# +# 0: SELECT ... +# 1: SELECT DISTINCT ... +# 2: SELECT ALL ... +# +# 0: No FROM clause +# 1: Has FROM clause +# +# 0: No WHERE clause +# 1: Has WHERE clause +# +# 0: No GROUP BY clause +# 1: Has GROUP BY clause +# 2: Has GROUP BY and HAVING clauses +# +do_select_tests e_select-0.2 { + 0000.1 "SELECT 1, 2, 3 " {1 2 3} + 1000.1 "SELECT DISTINCT 1, 2, 3 " {1 2 3} + 2000.1 "SELECT ALL 1, 2, 3 " {1 2 3} + + 0100.1 "SELECT a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + 1100.1 "SELECT DISTINCT a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + 1200.1 "SELECT ALL a, b, a||b FROM t1 " { + a one aone b two btwo c three cthree + } + + 0010.1 "SELECT 1, 2, 3 WHERE 1 " {1 2 3} + 0010.2 "SELECT 1, 2, 3 WHERE 0 " {} + 0010.3 "SELECT 1, 2, 3 WHERE NULL " {} + + 1010.1 "SELECT DISTINCT 1, 2, 3 WHERE 1 " {1 2 3} + + 2010.1 "SELECT ALL 1, 2, 3 WHERE 1 " {1 2 3} + + 0110.1 "SELECT a, b, a||b FROM t1 WHERE a!='x' " { + a one aone b two btwo c three cthree + } + 0110.2 "SELECT a, b, a||b FROM t1 WHERE a=='x'" {} + + 1110.1 "SELECT DISTINCT a, b, a||b FROM t1 WHERE a!='x' " { + a one aone b two btwo c three cthree + } + + 2110.0 "SELECT ALL a, b, a||b FROM t1 WHERE a=='x'" {} + + 0001.1 "SELECT 1, 2, 3 GROUP BY 2" {1 2 3} + 0002.1 "SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 0002.2 "SELECT 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 1001.1 "SELECT DISTINCT 1, 2, 3 GROUP BY 2" {1 2 3} + 1002.1 "SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 1002.2 "SELECT DISTINCT 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 2001.1 "SELECT ALL 1, 2, 3 GROUP BY 2" {1 2 3} + 2002.1 "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)=1" {1 2 3} + 2002.2 "SELECT ALL 1, 2, 3 GROUP BY 2 HAVING count(*)>1" {} + + 0101.1 "SELECT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 0102.1 "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 0102.2 "SELECT count(*), max(a) FROM t1 GROUP BY b HAVING count(*)=2" {} + + 1101.1 "SELECT DISTINCT count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 1102.1 "SELECT DISTINCT count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 1102.2 "SELECT DISTINCT count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=2" {} + + 2101.1 "SELECT ALL count(*), max(a) FROM t1 GROUP BY b" {1 a 1 c 1 b} + 2102.1 "SELECT ALL count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=1" { + 1 a 1 c 1 b + } + 2102.2 "SELECT ALL count(*), max(a) FROM t1 + GROUP BY b HAVING count(*)=2" {} + + 0011.1 "SELECT 1, 2, 3 WHERE 1 GROUP BY 2" {1 2 3} + 0012.1 "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {} + 0012.2 "SELECT 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)>1" {} + + 1011.1 "SELECT DISTINCT 1, 2, 3 WHERE 0 GROUP BY 2" {} + 1012.1 "SELECT DISTINCT 1, 2, 3 WHERE 1 GROUP BY 2 HAVING count(*)=1" + {1 2 3} + 1012.2 "SELECT DISTINCT 1, 2, 3 WHERE NULL GROUP BY 2 HAVING count(*)>1" {} + + 2011.1 "SELECT ALL 1, 2, 3 WHERE 1 GROUP BY 2" {1 2 3} + 2012.1 "SELECT ALL 1, 2, 3 WHERE 0 GROUP BY 2 HAVING count(*)=1" {} + 2012.2 "SELECT ALL 1, 2, 3 WHERE 'abc' GROUP BY 2 HAVING count(*)>1" {} + + 0111.1 "SELECT count(*), max(a) FROM t1 WHERE a='a' GROUP BY b" {1 a} + 0112.1 "SELECT count(*), max(a) FROM t1 + WHERE a='c' GROUP BY b HAVING count(*)=1" {1 c} + 0112.2 "SELECT count(*), max(a) FROM t1 + WHERE 0 GROUP BY b HAVING count(*)=2" {} + 1111.1 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a<'c' GROUP BY b" + {1 a 1 b} + 1112.1 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE a>'a' + GROUP BY b HAVING count(*)=1" { + 1 c 1 b + } + 1112.2 "SELECT DISTINCT count(*), max(a) FROM t1 WHERE 0 + GROUP BY b HAVING count(*)=2" {} + + 2111.1 "SELECT ALL count(*), max(a) FROM t1 WHERE b>'one' GROUP BY b" + {1 c 1 b} + 2112.1 "SELECT ALL count(*), max(a) FROM t1 WHERE a!='b' + GROUP BY b HAVING count(*)=1" { + 1 a 1 c + } + 2112.2 "SELECT ALL count(*), max(a) FROM t1 + WHERE 0 GROUP BY b HAVING count(*)=2" {} +} + + +# -- syntax diagram result-column +# +do_select_tests e_select-0.3 { + 1 "SELECT * FROM t1" {a one b two c three} + 2 "SELECT t1.* FROM t1" {a one b two c three} + 3 "SELECT 'x'||a||'x' FROM t1" {xax xbx xcx} + 4 "SELECT 'x'||a||'x' alias FROM t1" {xax xbx xcx} + 5 "SELECT 'x'||a||'x' AS alias FROM t1" {xax xbx xcx} +} + +# -- syntax diagram join-source +# +# -- syntax diagram join-op +# +do_select_tests e_select-0.4 { + 1 "SELECT t1.rowid FROM t1" {1 2 3} + 2 "SELECT t1.rowid FROM t1,t2" {1 1 1 2 2 2 3 3 3} + 3 "SELECT t1.rowid FROM t1,t2,t3" {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} + + 4 "SELECT t1.rowid FROM t1" {1 2 3} + 5 "SELECT t1.rowid FROM t1 JOIN t2" {1 1 1 2 2 2 3 3 3} + 6 "SELECT t1.rowid FROM t1 JOIN t2 JOIN t3" + {1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3} + + 7 "SELECT t1.rowid FROM t1 NATURAL JOIN t3" {1 2} + 8 "SELECT t1.rowid FROM t1 NATURAL LEFT OUTER JOIN t3" {1 2 3} + 9 "SELECT t1.rowid FROM t1 NATURAL LEFT JOIN t3" {1 2 3} + 10 "SELECT t1.rowid FROM t1 NATURAL INNER JOIN t3" {1 2} + 11 "SELECT t1.rowid FROM t1 NATURAL CROSS JOIN t3" {1 2} + + 12 "SELECT t1.rowid FROM t1 JOIN t3" {1 1 2 2 3 3} + 13 "SELECT t1.rowid FROM t1 LEFT OUTER JOIN t3" {1 1 2 2 3 3} + 14 "SELECT t1.rowid FROM t1 LEFT JOIN t3" {1 1 2 2 3 3} + 15 "SELECT t1.rowid FROM t1 INNER JOIN t3" {1 1 2 2 3 3} + 16 "SELECT t1.rowid FROM t1 CROSS JOIN t3" {1 1 2 2 3 3} +} + +# -- syntax diagram compound-operator +# +do_select_tests e_select-0.5 { + 1 "SELECT rowid FROM t1 UNION ALL SELECT rowid+2 FROM t4" {1 2 3 3 4} + 2 "SELECT rowid FROM t1 UNION SELECT rowid+2 FROM t4" {1 2 3 4} + 3 "SELECT rowid FROM t1 INTERSECT SELECT rowid+2 FROM t4" {3} + 4 "SELECT rowid FROM t1 EXCEPT SELECT rowid+2 FROM t4" {1 2} +} + +# -- syntax diagram ordering-term +# +do_select_tests e_select-0.6 { + 1 "SELECT b||a FROM t1 ORDER BY b||a" {onea threec twob} + 2 "SELECT b||a FROM t1 ORDER BY (b||a) COLLATE nocase" {onea threec twob} + 3 "SELECT b||a FROM t1 ORDER BY (b||a) ASC" {onea threec twob} + 4 "SELECT b||a FROM t1 ORDER BY (b||a) DESC" {twob threec onea} +} + +# -- syntax diagram select-stmt +# +do_select_tests e_select-0.7 { + 1 "SELECT * FROM t1" {a one b two c three} + 2 "SELECT * FROM t1 ORDER BY b" {a one c three b two} + 3 "SELECT * FROM t1 ORDER BY b, a" {a one c three b two} + + 4 "SELECT * FROM t1 LIMIT 10" {a one b two c three} + 5 "SELECT * FROM t1 LIMIT 10 OFFSET 5" {} + 6 "SELECT * FROM t1 LIMIT 10, 5" {} + + 7 "SELECT * FROM t1 ORDER BY a LIMIT 10" {a one b two c three} + 8 "SELECT * FROM t1 ORDER BY b LIMIT 10 OFFSET 5" {} + 9 "SELECT * FROM t1 ORDER BY a,b LIMIT 10, 5" {} + + 10 "SELECT * FROM t1 UNION SELECT b, a FROM t1" + {a one b two c three one a three c two b} + 11 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b" + {one a two b three c a one c three b two} + 12 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b, a" + {one a two b three c a one c three b two} + 13 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10" + {a one b two c three one a three c two b} + 14 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10 OFFSET 5" + {two b} + 15 "SELECT * FROM t1 UNION SELECT b, a FROM t1 LIMIT 10, 5" + {} + 16 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a LIMIT 10" + {a one b two c three one a three c two b} + 17 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY b LIMIT 10 OFFSET 5" + {b two} + 18 "SELECT * FROM t1 UNION SELECT b, a FROM t1 ORDER BY a,b LIMIT 10, 5" + {} +} + +#------------------------------------------------------------------------- +# The following tests focus on FROM clause (join) processing. +# + +# EVIDENCE-OF: R-16074-54196 If the FROM clause is omitted from a simple +# SELECT statement, then the input data is implicitly a single row zero +# columns wide +# +do_select_tests e_select-1.1 { + 1 "SELECT 'abc'" {abc} + 2 "SELECT 'abc' WHERE NULL" {} + 3 "SELECT NULL" {{}} + 4 "SELECT count(*)" {1} + 5 "SELECT count(*) WHERE 0" {0} + 6 "SELECT count(*) WHERE 1" {1} +} + +# EVIDENCE-OF: R-45424-07352 If there is only a single table or subquery +# in the FROM clause, then the input data used by the SELECT statement +# is the contents of the named table. +# +# The results of the SELECT queries suggest that they are operating on the +# contents of the table 'xx'. +# +do_execsql_test e_select-1.2.0 { + CREATE TABLE xx(x, y); + INSERT INTO xx VALUES('IiJlsIPepMuAhU', X'10B00B897A15BAA02E3F98DCE8F2'); + INSERT INTO xx VALUES(NULL, -16.87); + INSERT INTO xx VALUES(-17.89, 'linguistically'); +} {} +do_select_tests e_select-1.2 { + 1 "SELECT quote(x), quote(y) FROM xx" { + 'IiJlsIPepMuAhU' X'10B00B897A15BAA02E3F98DCE8F2' + NULL -16.87 + -17.89 'linguistically' + } + + 2 "SELECT count(*), count(x), count(y) FROM xx" {3 2 3} + 3 "SELECT sum(x), sum(y) FROM xx" {-17.89 -16.87} +} + +# EVIDENCE-OF: R-28355-09804 If there is more than one table or subquery +# in FROM clause then the contents of all tables and/or subqueries are +# joined into a single dataset for the simple SELECT statement to +# operate on. +# +# There are more detailed tests for subsequent requirements that add +# more detail to this idea. We just add a single test that shows that +# data is coming from each of the three tables following the FROM clause +# here to show that the statement, vague as it is, is not incorrect. +# +do_select_tests e_select-1.3 { + 1 "SELECT * FROM t1, t2, t3" { + a one a I a 1 a one a I b 2 a one b II a 1 + a one b II b 2 a one c III a 1 a one c III b 2 + b two a I a 1 b two a I b 2 b two b II a 1 + b two b II b 2 b two c III a 1 b two c III b 2 + c three a I a 1 c three a I b 2 c three b II a 1 + c three b II b 2 c three c III a 1 c three c III b 2 + } +} + +# +# The following block of tests - e_select-1.4.* - test that the description +# of cartesian joins in the SELECT documentation is consistent with SQLite. +# In doing so, we test the following three requirements as a side-effect: +# +# EVIDENCE-OF: R-49872-03192 If the join-operator is "CROSS JOIN", +# "INNER JOIN", "JOIN" or a comma (",") and there is no ON or USING +# clause, then the result of the join is simply the cartesian product of +# the left and right-hand datasets. +# +# The tests are built on this assertion. Really, they test that the output +# of a CROSS JOIN, JOIN, INNER JOIN or "," join matches the expected result +# of calculating the cartesian product of the left and right-hand datasets. +# +# EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER +# JOIN", "JOIN" and "," join operators. +# +# EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the +# same result as the "INNER JOIN", "JOIN" and "," operators +# +# All tests are run 4 times, with the only difference in each run being +# which of the 4 equivalent cartesian product join operators are used. +# Since the output data is the same in all cases, we consider that this +# qualifies as testing the two statements above. +# +do_execsql_test e_select-1.4.0 { + CREATE TABLE x1(a, b); + CREATE TABLE x2(c, d, e); + CREATE TABLE x3(f, g, h, i); + + -- x1: 3 rows, 2 columns + INSERT INTO x1 VALUES(24, 'converging'); + INSERT INTO x1 VALUES(NULL, X'CB71'); + INSERT INTO x1 VALUES('blonds', 'proprietary'); + + -- x2: 2 rows, 3 columns + INSERT INTO x2 VALUES(-60.06, NULL, NULL); + INSERT INTO x2 VALUES(-58, NULL, 1.21); + + -- x3: 5 rows, 4 columns + INSERT INTO x3 VALUES(-39.24, NULL, 'encompass', -1); + INSERT INTO x3 VALUES('presenting', 51, 'reformation', 'dignified'); + INSERT INTO x3 VALUES('conducting', -87.24, 37.56, NULL); + INSERT INTO x3 VALUES('coldest', -96, 'dramatists', 82.3); + INSERT INTO x3 VALUES('alerting', NULL, -93.79, NULL); +} {} + +# EVIDENCE-OF: R-59089-25828 The columns of the cartesian product +# dataset are, in order, all the columns of the left-hand dataset +# followed by all the columns of the right-hand dataset. +# +do_join_test e_select-1.4.1.1 { + SELECT * FROM x1 %JOIN% x2 LIMIT 1 +} [concat {24 converging} {-60.06 {} {}}] + +do_join_test e_select-1.4.1.2 { + SELECT * FROM x2 %JOIN% x1 LIMIT 1 +} [concat {-60.06 {} {}} {24 converging}] + +do_join_test e_select-1.4.1.3 { + SELECT * FROM x3 %JOIN% x2 LIMIT 1 +} [concat {-39.24 {} encompass -1} {-60.06 {} {}}] + +do_join_test e_select-1.4.1.4 { + SELECT * FROM x2 %JOIN% x3 LIMIT 1 +} [concat {-60.06 {} {}} {-39.24 {} encompass -1}] + +# EVIDENCE-OF: R-44414-54710 There is a row in the cartesian product +# dataset formed by combining each unique combination of a row from the +# left-hand and right-hand datasets. +# +do_join_test e_select-1.4.2.1 { + SELECT * FROM x2 %JOIN% x3 ORDER BY +c, +f +} [list -60.06 {} {} -39.24 {} encompass -1 \ + -60.06 {} {} alerting {} -93.79 {} \ + -60.06 {} {} coldest -96 dramatists 82.3 \ + -60.06 {} {} conducting -87.24 37.56 {} \ + -60.06 {} {} presenting 51 reformation dignified \ + -58 {} 1.21 -39.24 {} encompass -1 \ + -58 {} 1.21 alerting {} -93.79 {} \ + -58 {} 1.21 coldest -96 dramatists 82.3 \ + -58 {} 1.21 conducting -87.24 37.56 {} \ + -58 {} 1.21 presenting 51 reformation dignified \ +] +# TODO: Come back and add a few more like the above. + +# EVIDENCE-OF: R-18439-38548 In other words, if the left-hand dataset +# consists of Nleft rows of Mleft columns, and the right-hand dataset of +# Nright rows of Mright columns, then the cartesian product is a dataset +# of Nleft×Nright rows, each containing Mleft+Mright columns. +# +# x1, x2 (Nlhs=3, Nrhs=2) (Mlhs=2, Mrhs=3) +do_join_test e_select-1.4.3.1 { + SELECT count(*) FROM x1 %JOIN% x2 +} [expr 3*2] +do_test e_select-1.4.3.2 { + expr {[llength [execsql {SELECT * FROM x1, x2}]] / 6} +} [expr 2+3] + +# x2, x3 (Nlhs=2, Nrhs=5) (Mlhs=3, Mrhs=4) +do_join_test e_select-1.4.3.3 { + SELECT count(*) FROM x2 %JOIN% x3 +} [expr 2*5] +do_test e_select-1.4.3.4 { + expr {[llength [execsql {SELECT * FROM x2 JOIN x3}]] / 10} +} [expr 3+4] + +# x3, x1 (Nlhs=5, Nrhs=3) (Mlhs=4, Mrhs=2) +do_join_test e_select-1.4.3.5 { + SELECT count(*) FROM x3 %JOIN% x1 +} [expr 5*3] +do_test e_select-1.4.3.6 { + expr {[llength [execsql {SELECT * FROM x3 CROSS JOIN x1}]] / 15} +} [expr 4+2] + +# x3, x3 (Nlhs=5, Nrhs=5) (Mlhs=4, Mrhs=4) +do_join_test e_select-1.4.3.7 { + SELECT count(*) FROM x3 %JOIN% x3 +} [expr 5*5] +do_test e_select-1.4.3.8 { + expr {[llength [execsql {SELECT * FROM x3 INNER JOIN x3 AS x4}]] / 25} +} [expr 4+4] + +# Some extra cartesian product tests using tables t1 and t2. +# +do_execsql_test e_select-1.4.4.1 { SELECT * FROM t1, t2 } $t1_cross_t2 +do_execsql_test e_select-1.4.4.2 { SELECT * FROM t1 AS x, t1 AS y} $t1_cross_t1 + +do_select_tests e_select-1.4.5 [list \ + 1 { SELECT * FROM t1 CROSS JOIN t2 } $t1_cross_t2 \ + 2 { SELECT * FROM t1 AS y CROSS JOIN t1 AS x } $t1_cross_t1 \ + 3 { SELECT * FROM t1 INNER JOIN t2 } $t1_cross_t2 \ + 4 { SELECT * FROM t1 AS y INNER JOIN t1 AS x } $t1_cross_t1 \ +] + +# EVIDENCE-OF: R-38465-03616 If there is an ON clause then the ON +# expression is evaluated for each row of the cartesian product as a +# boolean expression. Only rows for which the expression evaluates to +# true are included from the dataset. +# +foreach {tn select res} [list \ + 1 { SELECT * FROM t1 %JOIN% t2 ON (1) } $t1_cross_t2 \ + 2 { SELECT * FROM t1 %JOIN% t2 ON (0) } [list] \ + 3 { SELECT * FROM t1 %JOIN% t2 ON (NULL) } [list] \ + 4 { SELECT * FROM t1 %JOIN% t2 ON ('abc') } [list] \ + 5 { SELECT * FROM t1 %JOIN% t2 ON ('1ab') } $t1_cross_t2 \ + 6 { SELECT * FROM t1 %JOIN% t2 ON (0.9) } $t1_cross_t2 \ + 7 { SELECT * FROM t1 %JOIN% t2 ON ('0.9') } $t1_cross_t2 \ + 8 { SELECT * FROM t1 %JOIN% t2 ON (0.0) } [list] \ + \ + 9 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = t2.a) } \ + {one I two II three III} \ + 10 { SELECT t1.b, t2.b FROM t1 %JOIN% t2 ON (t1.a = 'a') } \ + {one I one II one III} \ + 11 { SELECT t1.b, t2.b + FROM t1 %JOIN% t2 ON (CASE WHEN t1.a = 'a' THEN NULL ELSE 1 END) } \ + {two I two II two III three I three II three III} \ +] { + do_join_test e_select-1.3.$tn $select $res +} + +# EVIDENCE-OF: R-49933-05137 If there is a USING clause then each of the +# column names specified must exist in the datasets to both the left and +# right of the join-operator. +# +do_select_tests e_select-1.4 -error { + cannot join using column %s - column not present in both tables +} { + 1 { SELECT * FROM t1, t3 USING (b) } "b" + 2 { SELECT * FROM t3, t1 USING (c) } "c" + 3 { SELECT * FROM t3, (SELECT a AS b, b AS c FROM t1) USING (a) } "a" +} + +# EVIDENCE-OF: R-22776-52830 For each pair of named columns, the +# expression "lhs.X = rhs.X" is evaluated for each row of the cartesian +# product as a boolean expression. Only rows for which all such +# expressions evaluates to true are included from the result set. +# +do_select_tests e_select-1.5 { + 1 { SELECT * FROM t1, t3 USING (a) } {a one 1 b two 2} + 2 { SELECT * FROM t3, t4 USING (a,c) } {b 2} +} + +# EVIDENCE-OF: R-54046-48600 When comparing values as a result of a +# USING clause, the normal rules for handling affinities, collation +# sequences and NULL values in comparisons apply. +# +# EVIDENCE-OF: R-38422-04402 The column from the dataset on the +# left-hand side of the join-operator is considered to be on the +# left-hand side of the comparison operator (=) for the purposes of +# collation sequence and affinity precedence. +# +do_execsql_test e_select-1.6.0 { + CREATE TABLE t5(a COLLATE nocase, b COLLATE binary); + INSERT INTO t5 VALUES('AA', 'cc'); + INSERT INTO t5 VALUES('BB', 'dd'); + INSERT INTO t5 VALUES(NULL, NULL); + CREATE TABLE t6(a COLLATE binary, b COLLATE nocase); + INSERT INTO t6 VALUES('aa', 'cc'); + INSERT INTO t6 VALUES('bb', 'DD'); + INSERT INTO t6 VALUES(NULL, NULL); +} {} +foreach {tn select res} { + 1 { SELECT * FROM t5 %JOIN% t6 USING (a) } {AA cc cc BB dd DD} + 2 { SELECT * FROM t6 %JOIN% t5 USING (a) } {} + 3 { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) %JOIN% t5 USING (a) } + {aa cc cc bb DD dd} + 4 { SELECT * FROM t5 %JOIN% t6 USING (a,b) } {AA cc} + 5 { SELECT * FROM t6 %JOIN% t5 USING (a,b) } {} +} { + do_join_test e_select-1.6.$tn $select $res +} + +# EVIDENCE-OF: R-57047-10461 For each pair of columns identified by a +# USING clause, the column from the right-hand dataset is omitted from +# the joined dataset. +# +# EVIDENCE-OF: R-56132-15700 This is the only difference between a USING +# clause and its equivalent ON constraint. +# +foreach {tn select res} { + 1a { SELECT * FROM t1 %JOIN% t2 USING (a) } + {a one I b two II c three III} + 1b { SELECT * FROM t1 %JOIN% t2 ON (t1.a=t2.a) } + {a one a I b two b II c three c III} + + 2a { SELECT * FROM t3 %JOIN% t4 USING (a) } + {a 1 {} b 2 2} + 2b { SELECT * FROM t3 %JOIN% t4 ON (t3.a=t4.a) } + {a 1 a {} b 2 b 2} + + 3a { SELECT * FROM t3 %JOIN% t4 USING (a,c) } {b 2} + 3b { SELECT * FROM t3 %JOIN% t4 ON (t3.a=t4.a AND t3.c=t4.c) } {b 2 b 2} + + 4a { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x + %JOIN% t5 USING (a) } + {aa cc cc bb DD dd} + 4b { SELECT * FROM (SELECT a COLLATE nocase, b FROM t6) AS x + %JOIN% t5 ON (x.a=t5.a) } + {aa cc AA cc bb DD BB dd} +} { + do_join_test e_select-1.7.$tn $select $res +} + +# EVIDENCE-OF: R-24610-05866 If the join-operator is a "LEFT JOIN" or +# "LEFT OUTER JOIN", then after the ON or USING filtering clauses have +# been applied, an extra row is added to the output for each row in the +# original left-hand input dataset that does not match any row in the +# right-hand dataset. +# +do_execsql_test e_select-1.8.0 { + CREATE TABLE t7(a, b, c); + CREATE TABLE t8(a, d, e); + + INSERT INTO t7 VALUES('x', 'ex', 24); + INSERT INTO t7 VALUES('y', 'why', 25); + + INSERT INTO t8 VALUES('x', 'abc', 24); + INSERT INTO t8 VALUES('z', 'ghi', 26); +} {} + +do_select_tests e_select-1.8 { + 1a "SELECT count(*) FROM t7 JOIN t8 ON (t7.a=t8.a)" {1} + 1b "SELECT count(*) FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" {2} + 2a "SELECT count(*) FROM t7 JOIN t8 USING (a)" {1} + 2b "SELECT count(*) FROM t7 LEFT JOIN t8 USING (a)" {2} +} + + +# EVIDENCE-OF: R-15607-52988 The added rows contain NULL values in the +# columns that would normally contain values copied from the right-hand +# input dataset. +# +do_select_tests e_select-1.9 { + 1a "SELECT * FROM t7 JOIN t8 ON (t7.a=t8.a)" {x ex 24 x abc 24} + 1b "SELECT * FROM t7 LEFT JOIN t8 ON (t7.a=t8.a)" + {x ex 24 x abc 24 y why 25 {} {} {}} + 2a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} + 2b "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} +} + +# EVIDENCE-OF: R-04932-55942 If the NATURAL keyword is in the +# join-operator then an implicit USING clause is added to the +# join-constraints. The implicit USING clause contains each of the +# column names that appear in both the left and right-hand input +# datasets. +# +do_select_tests e_select-1-10 { + 1a "SELECT * FROM t7 JOIN t8 USING (a)" {x ex 24 abc 24} + 1b "SELECT * FROM t7 NATURAL JOIN t8" {x ex 24 abc 24} + + 2a "SELECT * FROM t8 JOIN t7 USING (a)" {x abc 24 ex 24} + 2b "SELECT * FROM t8 NATURAL JOIN t7" {x abc 24 ex 24} + + 3a "SELECT * FROM t7 LEFT JOIN t8 USING (a)" {x ex 24 abc 24 y why 25 {} {}} + 3b "SELECT * FROM t7 NATURAL LEFT JOIN t8" {x ex 24 abc 24 y why 25 {} {}} + + 4a "SELECT * FROM t8 LEFT JOIN t7 USING (a)" {x abc 24 ex 24 z ghi 26 {} {}} + 4b "SELECT * FROM t8 NATURAL LEFT JOIN t7" {x abc 24 ex 24 z ghi 26 {} {}} + + 5a "SELECT * FROM t3 JOIN t4 USING (a,c)" {b 2} + 5b "SELECT * FROM t3 NATURAL JOIN t4" {b 2} + + 6a "SELECT * FROM t3 LEFT JOIN t4 USING (a,c)" {a 1 b 2} + 6b "SELECT * FROM t3 NATURAL LEFT JOIN t4" {a 1 b 2} +} + +# EVIDENCE-OF: R-49566-01570 If the left and right-hand input datasets +# feature no common column names, then the NATURAL keyword has no effect +# on the results of the join. +# +do_execsql_test e_select-1.11.0 { + CREATE TABLE t10(x, y); + INSERT INTO t10 VALUES(1, 'true'); + INSERT INTO t10 VALUES(0, 'false'); +} {} +do_select_tests e_select-1-11 { + 1a "SELECT a, x FROM t1 CROSS JOIN t10" {a 1 a 0 b 1 b 0 c 1 c 0} + 1b "SELECT a, x FROM t1 NATURAL CROSS JOIN t10" {a 1 a 0 b 1 b 0 c 1 c 0} +} + +# EVIDENCE-OF: R-39625-59133 A USING or ON clause may not be added to a +# join that specifies the NATURAL keyword. +# +foreach {tn sql} { + 1 {SELECT * FROM t1 NATURAL LEFT JOIN t2 USING (a)} + 2 {SELECT * FROM t1 NATURAL LEFT JOIN t2 ON (t1.a=t2.a)} + 3 {SELECT * FROM t1 NATURAL LEFT JOIN t2 ON (45)} +} { + do_catchsql_test e_select-1.12.$tn " + $sql + " {1 {a NATURAL join may not have an ON or USING clause}} +} + +#------------------------------------------------------------------------- +# The next block of tests - e_select-3.* - concentrate on verifying +# statements made regarding WHERE clause processing. +# +drop_all_tables +do_execsql_test e_select-3.0 { + CREATE TABLE x1(k, x, y, z); + INSERT INTO x1 VALUES(1, 'relinquished', 'aphasia', 78.43); + INSERT INTO x1 VALUES(2, X'A8E8D66F', X'07CF', -81); + INSERT INTO x1 VALUES(3, -22, -27.57, NULL); + INSERT INTO x1 VALUES(4, NULL, 'bygone', 'picky'); + INSERT INTO x1 VALUES(5, NULL, 96.28, NULL); + INSERT INTO x1 VALUES(6, 0, 1, 2); + + CREATE TABLE x2(k, x, y2); + INSERT INTO x2 VALUES(1, 50, X'B82838'); + INSERT INTO x2 VALUES(5, 84.79, 65.88); + INSERT INTO x2 VALUES(3, -22, X'0E1BE452A393'); + INSERT INTO x2 VALUES(7, 'mistrusted', 'standardized'); +} {} + +# EVIDENCE-OF: R-60775-64916 If a WHERE clause is specified, the WHERE +# expression is evaluated for each row in the input data as a boolean +# expression. Only rows for which the WHERE clause expression evaluates +# to true are included from the dataset before continuing. +# +do_execsql_test e_select-3.1.1 { SELECT k FROM x1 WHERE x } {3} +do_execsql_test e_select-3.1.2 { SELECT k FROM x1 WHERE y } {3 5 6} +do_execsql_test e_select-3.1.3 { SELECT k FROM x1 WHERE z } {1 2 6} +do_execsql_test e_select-3.1.4 { SELECT k FROM x1 WHERE '1'||z } {1 2 4 6} +do_execsql_test e_select-3.1.5 { SELECT k FROM x1 WHERE x IS NULL } {4 5} +do_execsql_test e_select-3.1.6 { SELECT k FROM x1 WHERE z - 78.43 } {2 4 6} + +do_execsql_test e_select-3.2.1a { + SELECT k FROM x1 LEFT JOIN x2 USING(k) +} {1 2 3 4 5 6} +do_execsql_test e_select-3.2.1b { + SELECT k FROM x1 LEFT JOIN x2 USING(k) WHERE x2.k ORDER BY +k +} {1 3 5} +do_execsql_test e_select-3.2.2 { + SELECT k FROM x1 LEFT JOIN x2 USING(k) WHERE x2.k IS NULL +} {2 4 6} + +do_execsql_test e_select-3.2.3 { + SELECT k FROM x1 NATURAL JOIN x2 WHERE x2.k +} {3} +do_execsql_test e_select-3.2.4 { + SELECT k FROM x1 NATURAL JOIN x2 WHERE x2.k-3 +} {} + +#------------------------------------------------------------------------- +# Tests below this point are focused on verifying the testable statements +# related to caculating the result rows of a simple SELECT statement. +# + +drop_all_tables +do_execsql_test e_select-4.0 { + CREATE TABLE z1(a, b, c); + CREATE TABLE z2(d, e); + CREATE TABLE z3(a, b); + + INSERT INTO z1 VALUES(51.65, -59.58, 'belfries'); + INSERT INTO z1 VALUES(-5, NULL, 75); + INSERT INTO z1 VALUES(-2.2, -23.18, 'suiters'); + INSERT INTO z1 VALUES(NULL, 67, 'quartets'); + INSERT INTO z1 VALUES(-1.04, -32.3, 'aspen'); + INSERT INTO z1 VALUES(63, 'born', -26); + + INSERT INTO z2 VALUES(NULL, 21); + INSERT INTO z2 VALUES(36, 6); + + INSERT INTO z3 VALUES('subsistence', 'gauze'); + INSERT INTO z3 VALUES(49.17, -67); +} {} + +# EVIDENCE-OF: R-36327-17224 If a result expression is the special +# expression "*" then all columns in the input data are substituted for +# that one expression. +# +# EVIDENCE-OF: R-43693-30522 If the expression is the alias of a table +# or subquery in the FROM clause followed by ".*" then all columns from +# the named table or subquery are substituted for the single expression. +# +do_select_tests e_select-4.1 { + 1 "SELECT * FROM z1 LIMIT 1" {51.65 -59.58 belfries} + 2 "SELECT * FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries {} 21} + 3 "SELECT z1.* FROM z1,z2 LIMIT 1" {51.65 -59.58 belfries} + 4 "SELECT z2.* FROM z1,z2 LIMIT 1" {{} 21} + 5 "SELECT z2.*, z1.* FROM z1,z2 LIMIT 1" {{} 21 51.65 -59.58 belfries} + + 6 "SELECT count(*), * FROM z1" {6 51.65 -59.58 belfries} + 7 "SELECT max(a), * FROM z1" {63 63 born -26} + 8 "SELECT *, min(a) FROM z1" {-5 {} 75 -5} + + 9 "SELECT *,* FROM z1,z2 LIMIT 1" { + 51.65 -59.58 belfries {} 21 51.65 -59.58 belfries {} 21 + } + 10 "SELECT z1.*,z1.* FROM z2,z1 LIMIT 1" { + 51.65 -59.58 belfries 51.65 -59.58 belfries + } +} + +# EVIDENCE-OF: R-38023-18396 It is an error to use a "*" or "alias.*" +# expression in any context other than a result expression list. +# +# EVIDENCE-OF: R-44324-41166 It is also an error to use a "*" or +# "alias.*" expression in a simple SELECT query that does not have a +# FROM clause. +# +foreach {tn select err} { + 1.1 "SELECT a, b, c FROM z1 WHERE *" {near "*": syntax error} + 1.2 "SELECT a, b, c FROM z1 GROUP BY *" {near "*": syntax error} + 1.3 "SELECT 1 + * FROM z1" {near "*": syntax error} + 1.4 "SELECT * + 1 FROM z1" {near "+": syntax error} + + 2.1 "SELECT *" {no tables specified} + 2.2 "SELECT * WHERE 1" {no tables specified} + 2.3 "SELECT * WHERE 0" {no tables specified} + 2.4 "SELECT count(*), *" {no tables specified} +} { + do_catchsql_test e_select-4.2.$tn $select [list 1 $err] +} + +# EVIDENCE-OF: R-08669-22397 The number of columns in the rows returned +# by a simple SELECT statement is equal to the number of expressions in +# the result expression list after substitution of * and alias.* +# expressions. +# +foreach {tn select nCol} { + 1 "SELECT * FROM z1" 3 + 2 "SELECT * FROM z1 NATURAL JOIN z3" 3 + 3 "SELECT z1.* FROM z1 NATURAL JOIN z3" 3 + 4 "SELECT z3.* FROM z1 NATURAL JOIN z3" 2 + 5 "SELECT z1.*, z3.* FROM z1 NATURAL JOIN z3" 5 + 6 "SELECT 1, 2, z1.* FROM z1" 5 + 7 "SELECT a, *, b, c FROM z1" 6 +} { + set ::stmt [sqlite3_prepare_v2 db $select -1 DUMMY] + do_test e_select-4.3.$tn { sqlite3_column_count $::stmt } $nCol + sqlite3_finalize $::stmt +} + + + +# In lang_select.html, a non-aggregate query is defined as any simple SELECT +# that has no GROUP BY clause and no aggregate expressions in the result +# expression list. Other queries are aggregate queries. Test cases +# e_select-4.4.* through e_select-4.12.*, inclusive, which test the part of +# simple SELECT that is different for aggregate and non-aggregate queries +# verify (in a way) that these definitions are consistent: +# +# EVIDENCE-OF: R-20637-43463 A simple SELECT statement is an aggregate +# query if it contains either a GROUP BY clause or one or more aggregate +# functions in the result-set. +# +# EVIDENCE-OF: R-23155-55597 Otherwise, if a simple SELECT contains no +# aggregate functions or a GROUP BY clause, it is a non-aggregate query. +# + +# EVIDENCE-OF: R-44050-47362 If the SELECT statement is a non-aggregate +# query, then each expression in the result expression list is evaluated +# for each row in the dataset filtered by the WHERE clause. +# +do_select_tests e_select-4.4 { + 1 "SELECT a, b FROM z1" + {51.65 -59.58 -5 {} -2.2 -23.18 {} 67 -1.04 -32.3 63 born} + + 2 "SELECT a IS NULL, b+1, * FROM z1" { + 0 -58.58 51.65 -59.58 belfries + 0 {} -5 {} 75 + 0 -22.18 -2.2 -23.18 suiters + 1 68 {} 67 quartets + 0 -31.3 -1.04 -32.3 aspen + 0 1 63 born -26 + } + + 3 "SELECT 32*32, d||e FROM z2" {1024 {} 1024 366} +} + + +# Test cases e_select-4.5.* and e_select-4.6.* together show that: +# +# EVIDENCE-OF: R-51988-01124 The single row of result-set data created +# by evaluating the aggregate and non-aggregate expressions in the +# result-set forms the result of an aggregate query without a GROUP BY +# clause. +# + +# EVIDENCE-OF: R-57629-25253 If the SELECT statement is an aggregate +# query without a GROUP BY clause, then each aggregate expression in the +# result-set is evaluated once across the entire dataset. +# +do_select_tests e_select-4.5 { + 1 "SELECT count(a), max(a), count(b), max(b) FROM z1" {5 63 5 born} + 2 "SELECT count(*), max(1)" {1 1} + + 3 "SELECT sum(b+1) FROM z1 NATURAL LEFT JOIN z3" {-43.06} + 4 "SELECT sum(b+2) FROM z1 NATURAL LEFT JOIN z3" {-38.06} + 5 "SELECT sum(b IS NOT NULL) FROM z1 NATURAL LEFT JOIN z3" {5} +} + +# EVIDENCE-OF: R-26684-40576 Each non-aggregate expression in the +# result-set is evaluated once for an arbitrarily selected row of the +# dataset. +# +# EVIDENCE-OF: R-27994-60376 The same arbitrarily selected row is used +# for each non-aggregate expression. +# +# Note: The results of many of the queries in this block of tests are +# technically undefined, as the documentation does not specify which row +# SQLite will arbitrarily select to use for the evaluation of the +# non-aggregate expressions. +# +drop_all_tables +do_execsql_test e_select-4.6.0 { + CREATE TABLE a1(one PRIMARY KEY, two); + INSERT INTO a1 VALUES(1, 1); + INSERT INTO a1 VALUES(2, 3); + INSERT INTO a1 VALUES(3, 6); + INSERT INTO a1 VALUES(4, 10); + + CREATE TABLE a2(one PRIMARY KEY, three); + INSERT INTO a2 VALUES(1, 1); + INSERT INTO a2 VALUES(3, 2); + INSERT INTO a2 VALUES(6, 3); + INSERT INTO a2 VALUES(10, 4); +} {} +do_select_tests e_select-4.6 { + 1 "SELECT one, two, count(*) FROM a1" {1 1 4} + 2 "SELECT one, two, count(*) FROM a1 WHERE one<3" {1 1 2} + 3 "SELECT one, two, count(*) FROM a1 WHERE one>3" {4 10 1} + 4 "SELECT *, count(*) FROM a1 JOIN a2" {1 1 1 1 16} + 5 "SELECT *, sum(three) FROM a1 NATURAL JOIN a2" {1 1 1 3} + 6 "SELECT *, sum(three) FROM a1 NATURAL JOIN a2" {1 1 1 3} + 7 "SELECT string_agg(three, ''), a1.* FROM a1 NATURAL JOIN a2" {12 1 1} +} + +# EVIDENCE-OF: R-04486-07266 Or, if the dataset contains zero rows, then +# each non-aggregate expression is evaluated against a row consisting +# entirely of NULL values. +# +do_select_tests e_select-4.7 { + 1 "SELECT one, two, count(*) FROM a1 WHERE 0" {{} {} 0} + 2 "SELECT sum(two), * FROM a1, a2 WHERE three>5" {{} {} {} {} {}} + 3 "SELECT max(one) IS NULL, one IS NULL, two IS NULL FROM a1 WHERE two=7" { + 1 1 1 + } +} + +# EVIDENCE-OF: R-64138-28774 An aggregate query without a GROUP BY +# clause always returns exactly one row of data, even if there are zero +# rows of input data. +# +foreach {tn select} { + 8.1 "SELECT count(*) FROM a1" + 8.2 "SELECT count(*) FROM a1 WHERE 0" + 8.3 "SELECT count(*) FROM a1 WHERE 1" + 8.4 "SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 1" + 8.5 "SELECT max(a1.one)+min(two), a1.one, two, * FROM a1, a2 WHERE 0" +} { + # Set $nRow to the number of rows returned by $select: + set ::stmt [sqlite3_prepare_v2 db $select -1 DUMMY] + set nRow 0 + while {"SQLITE_ROW" == [sqlite3_step $::stmt]} { incr nRow } + set rc [sqlite3_finalize $::stmt] + + # Test that $nRow==1 and that statement execution was successful + # (rc==SQLITE_OK). + do_test e_select-4.$tn [list list $rc $nRow] {SQLITE_OK 1} +} + +drop_all_tables +do_execsql_test e_select-4.9.0 { + CREATE TABLE b1(one PRIMARY KEY, two); + INSERT INTO b1 VALUES(1, 'o'); + INSERT INTO b1 VALUES(4, 'f'); + INSERT INTO b1 VALUES(3, 't'); + INSERT INTO b1 VALUES(2, 't'); + INSERT INTO b1 VALUES(5, 'f'); + INSERT INTO b1 VALUES(7, 's'); + INSERT INTO b1 VALUES(6, 's'); + + CREATE TABLE b2(x, y); + INSERT INTO b2 VALUES(NULL, 0); + INSERT INTO b2 VALUES(NULL, 1); + INSERT INTO b2 VALUES('xyz', 2); + INSERT INTO b2 VALUES('abc', 3); + INSERT INTO b2 VALUES('xyz', 4); + + CREATE TABLE b3(a COLLATE nocase, b COLLATE binary); + INSERT INTO b3 VALUES('abc', 'abc'); + INSERT INTO b3 VALUES('aBC', 'aBC'); + INSERT INTO b3 VALUES('Def', 'Def'); + INSERT INTO b3 VALUES('dEF', 'dEF'); +} {} + +# EVIDENCE-OF: R-40855-36147 If the SELECT statement is an aggregate +# query with a GROUP BY clause, then each of the expressions specified +# as part of the GROUP BY clause is evaluated for each row of the +# dataset according to the processing rules stated below for ORDER BY +# expressions. Each row is then assigned to a "group" based on the +# results; rows for which the results of evaluating the GROUP BY +# expressions are the same get assigned to the same group. +# +# These tests also show that the following is not untrue: +# +# EVIDENCE-OF: R-25883-55063 The expressions in the GROUP BY clause do +# not have to be expressions that appear in the result. +# +do_select_tests e_select-4.9 { + 1 "SELECT group_concat(one), two FROM b1 GROUP BY two" { + /#,# f 1 o #,# s #,# t/ + } + 2 "SELECT group_concat(one), sum(one) FROM b1 GROUP BY (one>4)" { + 1,2,3,4 10 5,6,7 18 + } + 3 "SELECT group_concat(one) FROM b1 GROUP BY (two>'o'), one%2" { + 4 1,5 2,6 3,7 + } + 4 "SELECT group_concat(one) FROM b1 GROUP BY (one==2 OR two=='o')" { + 4,3,5,7,6 1,2 + } +} + +# EVIDENCE-OF: R-14926-50129 For the purposes of grouping rows, NULL +# values are considered equal. +# +do_select_tests e_select-4.10 { + 1 "SELECT group_concat(y) FROM b2 GROUP BY x" {/#,# 3 #,#/} + 2 "SELECT count(*) FROM b2 GROUP BY CASE WHEN y<4 THEN NULL ELSE 0 END" {4 1} +} + +# EVIDENCE-OF: R-10470-30318 The usual rules for selecting a collation +# sequence with which to compare text values apply when evaluating +# expressions in a GROUP BY clause. +# +do_select_tests e_select-4.11 { + 1 "SELECT count(*) FROM b3 GROUP BY b" {1 1 1 1} + 2 "SELECT count(*) FROM b3 GROUP BY a" {2 2} + 3 "SELECT count(*) FROM b3 GROUP BY +b" {1 1 1 1} + 4 "SELECT count(*) FROM b3 GROUP BY +a" {2 2} + 5 "SELECT count(*) FROM b3 GROUP BY b||''" {1 1 1 1} + 6 "SELECT count(*) FROM b3 GROUP BY a||''" {1 1 1 1} +} + +# EVIDENCE-OF: R-63573-50730 The expressions in a GROUP BY clause may +# not be aggregate expressions. +# +foreach {tn select} { + 12.1 "SELECT * FROM b3 GROUP BY count(*)" + 12.2 "SELECT max(a) FROM b3 GROUP BY max(b)" + 12.3 "SELECT group_concat(a) FROM b3 GROUP BY a, max(b)" +} { + set res {1 {aggregate functions are not allowed in the GROUP BY clause}} + do_catchsql_test e_select-4.$tn $select $res +} + +# EVIDENCE-OF: R-31537-00101 If a HAVING clause is specified, it is +# evaluated once for each group of rows as a boolean expression. If the +# result of evaluating the HAVING clause is false, the group is +# discarded. +# +# This requirement is tested by all e_select-4.13.* tests. +# +# EVIDENCE-OF: R-04132-09474 If the HAVING clause is an aggregate +# expression, it is evaluated across all rows in the group. +# +# Tested by e_select-4.13.1.* +# +# EVIDENCE-OF: R-28262-47447 If a HAVING clause is a non-aggregate +# expression, it is evaluated with respect to an arbitrarily selected +# row from the group. +# +# Tested by e_select-4.13.2.* +# +# Tests in this block also show that this is not untrue: +# +# EVIDENCE-OF: R-55403-13450 The HAVING expression may refer to values, +# even aggregate functions, that are not in the result. +# +do_execsql_test e_select-4.13.0 { + CREATE TABLE c1(up, down); + INSERT INTO c1 VALUES('x', 1); + INSERT INTO c1 VALUES('x', 2); + INSERT INTO c1 VALUES('x', 4); + INSERT INTO c1 VALUES('x', 8); + INSERT INTO c1 VALUES('y', 16); + INSERT INTO c1 VALUES('y', 32); + + CREATE TABLE c2(i, j); + INSERT INTO c2 VALUES(1, 0); + INSERT INTO c2 VALUES(2, 1); + INSERT INTO c2 VALUES(3, 3); + INSERT INTO c2 VALUES(4, 6); + INSERT INTO c2 VALUES(5, 10); + INSERT INTO c2 VALUES(6, 15); + INSERT INTO c2 VALUES(7, 21); + INSERT INTO c2 VALUES(8, 28); + INSERT INTO c2 VALUES(9, 36); + + CREATE TABLE c3(i PRIMARY KEY, k TEXT); + INSERT INTO c3 VALUES(1, 'hydrogen'); + INSERT INTO c3 VALUES(2, 'helium'); + INSERT INTO c3 VALUES(3, 'lithium'); + INSERT INTO c3 VALUES(4, 'beryllium'); + INSERT INTO c3 VALUES(5, 'boron'); + INSERT INTO c3 VALUES(94, 'plutonium'); +} {} + +do_select_tests e_select-4.13 { + 1.1 "SELECT up FROM c1 GROUP BY up HAVING count(*)>3" {x} + 1.2 "SELECT up FROM c1 GROUP BY up HAVING sum(down)>16" {y} + 1.3 "SELECT up FROM c1 GROUP BY up HAVING sum(down)<16" {x} + 1.4 "SELECT up||down FROM c1 GROUP BY (down<5) HAVING max(down)<10" {x4} + + 2.1 "SELECT up FROM c1 GROUP BY up HAVING down>10" {y} + 2.2 "SELECT up FROM c1 GROUP BY up HAVING up='y'" {y} + + 2.3 "SELECT i, j FROM c2 GROUP BY i>4 HAVING j>6" {5 10} +} + +# EVIDENCE-OF: R-23927-54081 Each expression in the result-set is then +# evaluated once for each group of rows. +# +# EVIDENCE-OF: R-53735-47017 If the expression is an aggregate +# expression, it is evaluated across all rows in the group. +# +do_select_tests e_select-4.15 { + 1 "SELECT sum(down) FROM c1 GROUP BY up" {15 48} + 2 "SELECT sum(j), max(j) FROM c2 GROUP BY (i%3)" {54 36 27 21 39 28} + 3 "SELECT sum(j), max(j) FROM c2 GROUP BY (j%2)" {80 36 40 21} + 4 "SELECT 1+sum(j), max(j)+1 FROM c2 GROUP BY (j%2)" {81 37 41 22} + 5 "SELECT count(*), round(avg(i),2) FROM c1, c2 ON (i=down) GROUP BY j%2" + {3 4.33 1 2.0} +} + +# EVIDENCE-OF: R-62913-19830 Otherwise, it is evaluated against a single +# arbitrarily chosen row from within the group. +# +# EVIDENCE-OF: R-53924-08809 If there is more than one non-aggregate +# expression in the result-set, then all such expressions are evaluated +# for the same row. +# +do_select_tests e_select-4.15 { + 1 "SELECT i, j FROM c2 GROUP BY i%2" {2 1 1 0} + 2 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j<30" {2 1 1 0} + 3 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j>30" {} + 4 "SELECT i, j FROM c2 GROUP BY i%2 HAVING j>30" {} + 5 "SELECT count(*), i, k FROM c2 NATURAL JOIN c3 GROUP BY substr(k, 1, 1)" + {2 4 beryllium 2 1 hydrogen 1 3 lithium} +} + +# EVIDENCE-OF: R-19334-12811 Each group of input dataset rows +# contributes a single row to the set of result rows. +# +# EVIDENCE-OF: R-02223-49279 Subject to filtering associated with the +# DISTINCT keyword, the number of rows returned by an aggregate query +# with a GROUP BY clause is the same as the number of groups of rows +# produced by applying the GROUP BY and HAVING clauses to the filtered +# input dataset. +# +do_select_tests e_select.4.16 -count { + 1 "SELECT i, j FROM c2 GROUP BY i%2" 2 + 2 "SELECT i, j FROM c2 GROUP BY i" 9 + 3 "SELECT i, j FROM c2 GROUP BY i HAVING i<5" 4 +} + +#------------------------------------------------------------------------- +# The following tests attempt to verify statements made regarding the ALL +# and DISTINCT keywords. +# +drop_all_tables +do_execsql_test e_select-5.1.0 { + CREATE TABLE h1(a, b); + INSERT INTO h1 VALUES(1, 'one'); + INSERT INTO h1 VALUES(1, 'I'); + INSERT INTO h1 VALUES(1, 'i'); + INSERT INTO h1 VALUES(4, 'four'); + INSERT INTO h1 VALUES(4, 'IV'); + INSERT INTO h1 VALUES(4, 'iv'); + + CREATE TABLE h2(x COLLATE nocase); + INSERT INTO h2 VALUES('One'); + INSERT INTO h2 VALUES('Two'); + INSERT INTO h2 VALUES('Three'); + INSERT INTO h2 VALUES('Four'); + INSERT INTO h2 VALUES('one'); + INSERT INTO h2 VALUES('two'); + INSERT INTO h2 VALUES('three'); + INSERT INTO h2 VALUES('four'); + + CREATE TABLE h3(c, d); + INSERT INTO h3 VALUES(1, NULL); + INSERT INTO h3 VALUES(2, NULL); + INSERT INTO h3 VALUES(3, NULL); + INSERT INTO h3 VALUES(4, '2'); + INSERT INTO h3 VALUES(5, NULL); + INSERT INTO h3 VALUES(6, '2,3'); + INSERT INTO h3 VALUES(7, NULL); + INSERT INTO h3 VALUES(8, '2,4'); + INSERT INTO h3 VALUES(9, '3'); +} {} + +# EVIDENCE-OF: R-60770-10612 One of the ALL or DISTINCT keywords may +# follow the SELECT keyword in a simple SELECT statement. +# +do_select_tests e_select-5.1 { + 1 "SELECT ALL a FROM h1" {1 1 1 4 4 4} + 2 "SELECT DISTINCT a FROM h1" {1 4} +} + +# EVIDENCE-OF: R-08861-34280 If the simple SELECT is a SELECT ALL, then +# the entire set of result rows are returned by the SELECT. +# +# EVIDENCE-OF: R-01256-01950 If neither ALL or DISTINCT are present, +# then the behavior is as if ALL were specified. +# +# EVIDENCE-OF: R-14442-41305 If the simple SELECT is a SELECT DISTINCT, +# then duplicate rows are removed from the set of result rows before it +# is returned. +# +# The three testable statements above are tested by e_select-5.2.*, +# 5.3.* and 5.4.* respectively. +# +do_select_tests e_select-5 { + 3.1 "SELECT ALL x FROM h2" {One Two Three Four one two three four} + 3.2 "SELECT ALL x FROM h1, h2 ON (x=b)" {One one Four four} + + 3.1 "SELECT x FROM h2" {One Two Three Four one two three four} + 3.2 "SELECT x FROM h1, h2 ON (x=b)" {One one Four four} + + 4.1 "SELECT DISTINCT x FROM h2" {One Two Three Four} + 4.2 "SELECT DISTINCT x FROM h1, h2 ON (x=b)" {One Four} +} + +# EVIDENCE-OF: R-02054-15343 For the purposes of detecting duplicate +# rows, two NULL values are considered to be equal. +# +do_select_tests e_select-5.5 { + 1 "SELECT DISTINCT d FROM h3" {{} 2 2,3 2,4 3} +} + +# EVIDENCE-OF: R-47709-27231 The usual rules apply for selecting a +# collation sequence to compare text values. +# +do_select_tests e_select-5.6 { + 1 "SELECT DISTINCT b FROM h1" {one I i four IV iv} + 2 "SELECT DISTINCT b COLLATE nocase FROM h1" {one I four IV} + 3 "SELECT DISTINCT x FROM h2" {One Two Three Four} + 4 "SELECT DISTINCT x COLLATE binary FROM h2" { + One Two Three Four one two three four + } +} + +#------------------------------------------------------------------------- +# The following tests - e_select-7.* - test that statements made to do +# with compound SELECT statements are correct. +# + +# EVIDENCE-OF: R-39368-64333 In a compound SELECT, all the constituent +# SELECTs must return the same number of result columns. +# +# All the other tests in this section use compound SELECTs created +# using component SELECTs that do return the same number of columns. +# So the tests here just show that it is an error to attempt otherwise. +# +drop_all_tables +do_execsql_test e_select-7.1.0 { + CREATE TABLE j1(a, b, c); + CREATE TABLE j2(e, f); + CREATE TABLE j3(g); +} {} +do_select_tests e_select-7.1 -error { + SELECTs to the left and right of %s do not have the same number of result columns +} { + 1 "SELECT a, b FROM j1 UNION ALL SELECT g FROM j3" {{UNION ALL}} + 2 "SELECT * FROM j1 UNION ALL SELECT * FROM j3" {{UNION ALL}} + 3 "SELECT a, b FROM j1 UNION ALL SELECT g FROM j3" {{UNION ALL}} + 4 "SELECT a, b FROM j1 UNION ALL SELECT * FROM j3,j2" {{UNION ALL}} + 5 "SELECT * FROM j3,j2 UNION ALL SELECT a, b FROM j1" {{UNION ALL}} + + 6 "SELECT a, b FROM j1 UNION SELECT g FROM j3" {UNION} + 7 "SELECT * FROM j1 UNION SELECT * FROM j3" {UNION} + 8 "SELECT a, b FROM j1 UNION SELECT g FROM j3" {UNION} + 9 "SELECT a, b FROM j1 UNION SELECT * FROM j3,j2" {UNION} + 10 "SELECT * FROM j3,j2 UNION SELECT a, b FROM j1" {UNION} + + 11 "SELECT a, b FROM j1 INTERSECT SELECT g FROM j3" {INTERSECT} + 12 "SELECT * FROM j1 INTERSECT SELECT * FROM j3" {INTERSECT} + 13 "SELECT a, b FROM j1 INTERSECT SELECT g FROM j3" {INTERSECT} + 14 "SELECT a, b FROM j1 INTERSECT SELECT * FROM j3,j2" {INTERSECT} + 15 "SELECT * FROM j3,j2 INTERSECT SELECT a, b FROM j1" {INTERSECT} + + 16 "SELECT a, b FROM j1 EXCEPT SELECT g FROM j3" {EXCEPT} + 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j3" {EXCEPT} + 18 "SELECT a, b FROM j1 EXCEPT SELECT g FROM j3" {EXCEPT} + 19 "SELECT a, b FROM j1 EXCEPT SELECT * FROM j3,j2" {EXCEPT} + 20 "SELECT * FROM j3,j2 EXCEPT SELECT a, b FROM j1" {EXCEPT} +} + +# EVIDENCE-OF: R-01450-11152 As the components of a compound SELECT must +# be simple SELECT statements, they may not contain ORDER BY or LIMIT +# clauses. +# +foreach {tn select op1 op2} { + 1 "SELECT * FROM j1 ORDER BY a UNION ALL SELECT * FROM j2,j3" + {ORDER BY} {UNION ALL} + 2 "SELECT count(*) FROM j1 ORDER BY 1 UNION ALL SELECT max(e) FROM j2" + {ORDER BY} {UNION ALL} + 3 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 UNION ALL SELECT *,* FROM j2" + {ORDER BY} {UNION ALL} + 4 "SELECT * FROM j1 LIMIT 10 UNION ALL SELECT * FROM j2,j3" + LIMIT {UNION ALL} + 5 "SELECT * FROM j1 LIMIT 10 OFFSET 5 UNION ALL SELECT * FROM j2,j3" + LIMIT {UNION ALL} + 6 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) UNION ALL SELECT g FROM j2,j3" + LIMIT {UNION ALL} + + 7 "SELECT * FROM j1 ORDER BY a UNION SELECT * FROM j2,j3" + {ORDER BY} {UNION} + 8 "SELECT count(*) FROM j1 ORDER BY 1 UNION SELECT max(e) FROM j2" + {ORDER BY} {UNION} + 9 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 UNION SELECT *,* FROM j2" + {ORDER BY} {UNION} + 10 "SELECT * FROM j1 LIMIT 10 UNION SELECT * FROM j2,j3" + LIMIT {UNION} + 11 "SELECT * FROM j1 LIMIT 10 OFFSET 5 UNION SELECT * FROM j2,j3" + LIMIT {UNION} + 12 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) UNION SELECT g FROM j2,j3" + LIMIT {UNION} + + 13 "SELECT * FROM j1 ORDER BY a EXCEPT SELECT * FROM j2,j3" + {ORDER BY} {EXCEPT} + 14 "SELECT count(*) FROM j1 ORDER BY 1 EXCEPT SELECT max(e) FROM j2" + {ORDER BY} {EXCEPT} + 15 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 EXCEPT SELECT *,* FROM j2" + {ORDER BY} {EXCEPT} + 16 "SELECT * FROM j1 LIMIT 10 EXCEPT SELECT * FROM j2,j3" + LIMIT {EXCEPT} + 17 "SELECT * FROM j1 LIMIT 10 OFFSET 5 EXCEPT SELECT * FROM j2,j3" + LIMIT {EXCEPT} + 18 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) EXCEPT SELECT g FROM j2,j3" + LIMIT {EXCEPT} + + 19 "SELECT * FROM j1 ORDER BY a INTERSECT SELECT * FROM j2,j3" + {ORDER BY} {INTERSECT} + 20 "SELECT count(*) FROM j1 ORDER BY 1 INTERSECT SELECT max(e) FROM j2" + {ORDER BY} {INTERSECT} + 21 "SELECT count(*), * FROM j1 ORDER BY 1,2,3 INTERSECT SELECT *,* FROM j2" + {ORDER BY} {INTERSECT} + 22 "SELECT * FROM j1 LIMIT 10 INTERSECT SELECT * FROM j2,j3" + LIMIT {INTERSECT} + 23 "SELECT * FROM j1 LIMIT 10 OFFSET 5 INTERSECT SELECT * FROM j2,j3" + LIMIT {INTERSECT} + 24 "SELECT a FROM j1 LIMIT (SELECT e FROM j2) INTERSECT SELECT g FROM j2,j3" + LIMIT {INTERSECT} +} { + set err "$op1 clause should come after $op2 not before" + do_catchsql_test e_select-7.2.$tn $select [list 1 $err] +} + +# EVIDENCE-OF: R-45440-25633 ORDER BY and LIMIT clauses may only occur +# at the end of the entire compound SELECT, and then only if the final +# element of the compound is not a VALUES clause. +# +foreach {tn select} { + 1 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 ORDER BY a" + 2 "SELECT count(*) FROM j1 UNION ALL SELECT max(e) FROM j2 ORDER BY 1" + 3 "SELECT count(*), * FROM j1 UNION ALL SELECT *,* FROM j2 ORDER BY 1,2,3" + 4 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10" + 5 "SELECT * FROM j1 UNION ALL SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 6 "SELECT a FROM j1 UNION ALL SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 7 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 ORDER BY a" + 8 "SELECT count(*) FROM j1 UNION SELECT max(e) FROM j2 ORDER BY 1" + 8b "VALUES('8b') UNION SELECT max(e) FROM j2 ORDER BY 1" + 9 "SELECT count(*), * FROM j1 UNION SELECT *,* FROM j2 ORDER BY 1,2,3" + 10 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10" + 11 "SELECT * FROM j1 UNION SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 12 "SELECT a FROM j1 UNION SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 13 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 ORDER BY a" + 14 "SELECT count(*) FROM j1 EXCEPT SELECT max(e) FROM j2 ORDER BY 1" + 15 "SELECT count(*), * FROM j1 EXCEPT SELECT *,* FROM j2 ORDER BY 1,2,3" + 16 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10" + 17 "SELECT * FROM j1 EXCEPT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 18 "SELECT a FROM j1 EXCEPT SELECT g FROM j2,j3 LIMIT (SELECT 10)" + + 19 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 ORDER BY a" + 20 "SELECT count(*) FROM j1 INTERSECT SELECT max(e) FROM j2 ORDER BY 1" + 21 "SELECT count(*), * FROM j1 INTERSECT SELECT *,* FROM j2 ORDER BY 1,2,3" + 22 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10" + 23 "SELECT * FROM j1 INTERSECT SELECT * FROM j2,j3 LIMIT 10 OFFSET 5" + 24 "SELECT a FROM j1 INTERSECT SELECT g FROM j2,j3 LIMIT (SELECT 10)" +} { + do_test e_select-7.3.$tn { catch {execsql $select} msg } 0 +} +foreach {tn select} { + 50 "SELECT * FROM j1 ORDER BY 1 UNION ALL SELECT * FROM j2,j3" + 51 "SELECT * FROM j1 LIMIT 1 UNION ALL SELECT * FROM j2,j3" + 52 "SELECT count(*) FROM j1 UNION ALL VALUES(11) ORDER BY 1" + 53 "SELECT count(*) FROM j1 UNION ALL VALUES(11) LIMIT 1" +} { + do_test e_select-7.3.$tn { catch {execsql $select} msg } 1 +} + +# EVIDENCE-OF: R-08531-36543 A compound SELECT created using UNION ALL +# operator returns all the rows from the SELECT to the left of the UNION +# ALL operator, and all the rows from the SELECT to the right of it. +# +drop_all_tables +do_execsql_test e_select-7.4.0 { + CREATE TABLE q1(a TEXT, b INTEGER, c); + CREATE TABLE q2(d NUMBER, e BLOB); + CREATE TABLE q3(f REAL, g); + + INSERT INTO q1 VALUES(16, -87.66, NULL); + INSERT INTO q1 VALUES('legible', 94, -42.47); + INSERT INTO q1 VALUES('beauty', 36, NULL); + + INSERT INTO q2 VALUES('legible', 1); + INSERT INTO q2 VALUES('beauty', 2); + INSERT INTO q2 VALUES(-65.91, 4); + INSERT INTO q2 VALUES('emanating', -16.56); + + INSERT INTO q3 VALUES('beauty', 2); + INSERT INTO q3 VALUES('beauty', 2); +} {} +do_select_tests e_select-7.4 { + 1 {SELECT a FROM q1 UNION ALL SELECT d FROM q2} + {16 legible beauty legible beauty -65.91 emanating} + + 2 {SELECT * FROM q1 WHERE a=16 UNION ALL SELECT 'x', * FROM q2 WHERE oid=1} + {16 -87.66 {} x legible 1} + + 3 {SELECT count(*) FROM q1 UNION ALL SELECT min(e) FROM q2} + {3 -16.56} + + 4 {SELECT * FROM q2 UNION ALL SELECT * FROM q3} + {legible 1 beauty 2 -65.91 4 emanating -16.56 beauty 2 beauty 2} +} + +# EVIDENCE-OF: R-20560-39162 The UNION operator works the same way as +# UNION ALL, except that duplicate rows are removed from the final +# result set. +# +do_select_tests e_select-7.5 { + 1 {SELECT a FROM q1 UNION SELECT d FROM q2} + {-65.91 16 beauty emanating legible} + + 2 {SELECT * FROM q1 WHERE a=16 UNION SELECT 'x', * FROM q2 WHERE oid=1} + {16 -87.66 {} x legible 1} + + 3 {SELECT count(*) FROM q1 UNION SELECT min(e) FROM q2} + {-16.56 3} + + 4 {SELECT * FROM q2 UNION SELECT * FROM q3} + {-65.91 4 beauty 2 emanating -16.56 legible 1} +} + +# EVIDENCE-OF: R-45764-31737 The INTERSECT operator returns the +# intersection of the results of the left and right SELECTs. +# +do_select_tests e_select-7.6 { + 1 {SELECT a FROM q1 INTERSECT SELECT d FROM q2} {beauty legible} + 2 {SELECT * FROM q2 INTERSECT SELECT * FROM q3} {beauty 2} +} + +# EVIDENCE-OF: R-25787-28949 The EXCEPT operator returns the subset of +# rows returned by the left SELECT that are not also returned by the +# right-hand SELECT. +# +do_select_tests e_select-7.7 { + 1 {SELECT a FROM q1 EXCEPT SELECT d FROM q2} {16} + + 2 {SELECT * FROM q2 EXCEPT SELECT * FROM q3} + {-65.91 4 emanating -16.56 legible 1} +} + +# EVIDENCE-OF: R-40729-56447 Duplicate rows are removed from the results +# of INTERSECT and EXCEPT operators before the result set is returned. +# +do_select_tests e_select-7.8 { + 0 {SELECT * FROM q3} {beauty 2 beauty 2} + + 1 {SELECT * FROM q3 INTERSECT SELECT * FROM q3} {beauty 2} + 2 {SELECT * FROM q3 EXCEPT SELECT a,b FROM q1} {beauty 2} +} + +# EVIDENCE-OF: R-46765-43362 For the purposes of determining duplicate +# rows for the results of compound SELECT operators, NULL values are +# considered equal to other NULL values and distinct from all non-NULL +# values. +# +db nullvalue null +do_select_tests e_select-7.9 { + 1 {SELECT NULL UNION ALL SELECT NULL} {null null} + 2 {SELECT NULL UNION SELECT NULL} {null} + 3 {SELECT NULL INTERSECT SELECT NULL} {null} + 4 {SELECT NULL EXCEPT SELECT NULL} {} + + 5 {SELECT NULL UNION ALL SELECT 'ab'} {null ab} + 6 {SELECT NULL UNION SELECT 'ab'} {null ab} + 7 {SELECT NULL INTERSECT SELECT 'ab'} {} + 8 {SELECT NULL EXCEPT SELECT 'ab'} {null} + + 9 {SELECT NULL UNION ALL SELECT 0} {null 0} + 10 {SELECT NULL UNION SELECT 0} {null 0} + 11 {SELECT NULL INTERSECT SELECT 0} {} + 12 {SELECT NULL EXCEPT SELECT 0} {null} + + 13 {SELECT c FROM q1 UNION ALL SELECT g FROM q3} {null -42.47 null 2 2} + 14 {SELECT c FROM q1 UNION SELECT g FROM q3} {null -42.47 2} + 15 {SELECT c FROM q1 INTERSECT SELECT g FROM q3} {} + 16 {SELECT c FROM q1 EXCEPT SELECT g FROM q3} {null -42.47} +} +db nullvalue {} + +# EVIDENCE-OF: R-51232-50224 The collation sequence used to compare two +# text values is determined as if the columns of the left and right-hand +# SELECT statements were the left and right-hand operands of the equals +# (=) operator, except that greater precedence is not assigned to a +# collation sequence specified with the postfix COLLATE operator. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE y1(a COLLATE nocase, b COLLATE binary, c); + INSERT INTO y1 VALUES('Abc', 'abc', 'aBC'); +} {} +do_select_tests e_select-7.10 { + 1 {SELECT 'abc' UNION SELECT 'ABC'} {ABC abc} + 2 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC'} {ABC} + 3 {SELECT 'abc' UNION SELECT 'ABC' COLLATE nocase} {ABC} + 4 {SELECT 'abc' COLLATE binary UNION SELECT 'ABC' COLLATE nocase} {ABC abc} + 5 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC' COLLATE binary} {ABC} + + 6 {SELECT a FROM y1 UNION SELECT b FROM y1} {abc} + 7 {SELECT b FROM y1 UNION SELECT a FROM y1} {Abc abc} + 8 {SELECT a FROM y1 UNION SELECT c FROM y1} {aBC} + + 9 {SELECT a FROM y1 UNION SELECT c COLLATE binary FROM y1} {aBC} +} + +# EVIDENCE-OF: R-32706-07403 No affinity transformations are applied to +# any values when comparing rows as part of a compound SELECT. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE w1(a TEXT, b NUMBER); + CREATE TABLE w2(a, b TEXT); + + INSERT INTO w1 VALUES('1', 4.1); + INSERT INTO w2 VALUES(1, 4.1); +} {} + +do_select_tests e_select-7.11 { + 1 { SELECT a FROM w1 UNION SELECT a FROM w2 } {1 1} + 2 { SELECT a FROM w2 UNION SELECT a FROM w1 } {1 1} + 3 { SELECT b FROM w1 UNION SELECT b FROM w2 } {4.1 4.1} + 4 { SELECT b FROM w2 UNION SELECT b FROM w1 } {4.1 4.1} + + 5 { SELECT a FROM w1 INTERSECT SELECT a FROM w2 } {} + 6 { SELECT a FROM w2 INTERSECT SELECT a FROM w1 } {} + 7 { SELECT b FROM w1 INTERSECT SELECT b FROM w2 } {} + 8 { SELECT b FROM w2 INTERSECT SELECT b FROM w1 } {} + + 9 { SELECT a FROM w1 EXCEPT SELECT a FROM w2 } {1} + 10 { SELECT a FROM w2 EXCEPT SELECT a FROM w1 } {1} + 11 { SELECT b FROM w1 EXCEPT SELECT b FROM w2 } {4.1} + 12 { SELECT b FROM w2 EXCEPT SELECT b FROM w1 } {4.1} +} + + +# EVIDENCE-OF: R-32562-20566 When three or more simple SELECTs are +# connected into a compound SELECT, they group from left to right. In +# other words, if "A", "B" and "C" are all simple SELECT statements, (A +# op B op C) is processed as ((A op B) op C). +# +# e_select-7.12.1: Precedence of UNION vs. INTERSECT +# e_select-7.12.2: Precedence of UNION vs. UNION ALL +# e_select-7.12.3: Precedence of UNION vs. EXCEPT +# e_select-7.12.4: Precedence of INTERSECT vs. UNION ALL +# e_select-7.12.5: Precedence of INTERSECT vs. EXCEPT +# e_select-7.12.6: Precedence of UNION ALL vs. EXCEPT +# e_select-7.12.7: Check that "a EXCEPT b EXCEPT c" is processed as +# "(a EXCEPT b) EXCEPT c". +# +# The INTERSECT and EXCEPT operations are mutually commutative. So +# the e_select-7.12.5 test cases do not prove very much. +# +drop_all_tables +do_execsql_test e_select-7.12.0 { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + INSERT INTO t1 VALUES(2); + INSERT INTO t1 VALUES(3); +} {} +foreach {tn select res} { + 1a "(1,2) INTERSECT (1) UNION (3)" {1 3} + 1b "(3) UNION (1,2) INTERSECT (1)" {1} + + 2a "(1,2) UNION (3) UNION ALL (1)" {1 2 3 1} + 2b "(1) UNION ALL (3) UNION (1,2)" {1 2 3} + + 3a "(1,2) UNION (3) EXCEPT (1)" {2 3} + 3b "(1,2) EXCEPT (3) UNION (1)" {1 2} + + 4a "(1,2) INTERSECT (1) UNION ALL (3)" {1 3} + 4b "(3) UNION (1,2) INTERSECT (1)" {1} + + 5a "(1,2) INTERSECT (2) EXCEPT (2)" {} + 5b "(2,3) EXCEPT (2) INTERSECT (2)" {} + + 6a "(2) UNION ALL (2) EXCEPT (2)" {} + 6b "(2) EXCEPT (2) UNION ALL (2)" {2} + + 7 "(2,3) EXCEPT (2) EXCEPT (3)" {} +} { + set select [string map {( {SELECT x FROM t1 WHERE x IN (}} $select] + do_execsql_test e_select-7.12.$tn $select [list {*}$res] +} + + +#------------------------------------------------------------------------- +# ORDER BY clauses +# + +drop_all_tables +do_execsql_test e_select-8.1.0 { + CREATE TABLE d1(x, y, z); + + INSERT INTO d1 VALUES(1, 2, 3); + INSERT INTO d1 VALUES(2, 5, -1); + INSERT INTO d1 VALUES(1, 2, 8); + INSERT INTO d1 VALUES(1, 2, 7); + INSERT INTO d1 VALUES(2, 4, 93); + INSERT INTO d1 VALUES(1, 2, -20); + INSERT INTO d1 VALUES(1, 4, 93); + INSERT INTO d1 VALUES(1, 5, -1); + + CREATE TABLE d2(a, b); + INSERT INTO d2 VALUES('gently', 'failings'); + INSERT INTO d2 VALUES('commercials', 'bathrobe'); + INSERT INTO d2 VALUES('iterate', 'sexton'); + INSERT INTO d2 VALUES('babied', 'charitableness'); + INSERT INTO d2 VALUES('solemnness', 'annexed'); + INSERT INTO d2 VALUES('rejoicing', 'liabilities'); + INSERT INTO d2 VALUES('pragmatist', 'guarded'); + INSERT INTO d2 VALUES('barked', 'interrupted'); + INSERT INTO d2 VALUES('reemphasizes', 'reply'); + INSERT INTO d2 VALUES('lad', 'relenting'); +} {} + +# EVIDENCE-OF: R-44988-41064 Rows are first sorted based on the results +# of evaluating the left-most expression in the ORDER BY list, then ties +# are broken by evaluating the second left-most expression and so on. +# +do_select_tests e_select-8.1 { + 1 "SELECT * FROM d1 ORDER BY x, y, z" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } +} + +# EVIDENCE-OF: R-06617-54588 Each ORDER BY expression may be optionally +# followed by one of the keywords ASC (smaller values are returned +# first) or DESC (larger values are returned first). +# +# Test cases e_select-8.2.* test the above. +# +# EVIDENCE-OF: R-18705-33393 If neither ASC or DESC are specified, rows +# are sorted in ascending (smaller values first) order by default. +# +# Test cases e_select-8.3.* test the above. All 8.3 test cases are +# copies of 8.2 test cases with the explicit "ASC" removed. +# +do_select_tests e_select-8 { + 2.1 "SELECT * FROM d1 ORDER BY x ASC, y ASC, z ASC" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 2.2 "SELECT * FROM d1 ORDER BY x DESC, y DESC, z DESC" { + 2 5 -1 2 4 93 1 5 -1 1 4 93 + 1 2 8 1 2 7 1 2 3 1 2 -20 + } + 2.3 "SELECT * FROM d1 ORDER BY x DESC, y ASC, z DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 2.4 "SELECT * FROM d1 ORDER BY x DESC, y ASC, z ASC" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + + 3.1 "SELECT * FROM d1 ORDER BY x, y, z" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 3.3 "SELECT * FROM d1 ORDER BY x DESC, y, z DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 3.4 "SELECT * FROM d1 ORDER BY x DESC, y, z" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } +} + +# EVIDENCE-OF: R-29779-04281 If the ORDER BY expression is a constant +# integer K then the expression is considered an alias for the K-th +# column of the result set (columns are numbered from left to right +# starting with 1). +# +do_select_tests e_select-8.4 { + 1 "SELECT * FROM d1 ORDER BY 1 ASC, 2 ASC, 3 ASC" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 2 "SELECT * FROM d1 ORDER BY 1 DESC, 2 DESC, 3 DESC" { + 2 5 -1 2 4 93 1 5 -1 1 4 93 + 1 2 8 1 2 7 1 2 3 1 2 -20 + } + 3 "SELECT * FROM d1 ORDER BY 1 DESC, 2 ASC, 3 DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 4 "SELECT * FROM d1 ORDER BY 1 DESC, 2 ASC, 3 ASC" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + 5 "SELECT * FROM d1 ORDER BY 1, 2, 3" { + 1 2 -20 1 2 3 1 2 7 1 2 8 + 1 4 93 1 5 -1 2 4 93 2 5 -1 + } + 6 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3 DESC" { + 2 4 93 2 5 -1 1 2 8 1 2 7 + 1 2 3 1 2 -20 1 4 93 1 5 -1 + } + 7 "SELECT * FROM d1 ORDER BY 1 DESC, 2, 3" { + 2 4 93 2 5 -1 1 2 -20 1 2 3 + 1 2 7 1 2 8 1 4 93 1 5 -1 + } + 8 "SELECT z, x FROM d1 ORDER BY 2" { + /# 1 # 1 # 1 # 1 + # 1 # 1 # 2 # 2/ + } + 9 "SELECT z, x FROM d1 ORDER BY 1" { + /-20 1 -1 # -1 # 3 1 + 7 1 8 1 93 # 93 #/ + } +} + +# EVIDENCE-OF: R-63286-51977 If the ORDER BY expression is an identifier +# that corresponds to the alias of one of the output columns, then the +# expression is considered an alias for that column. +# +do_select_tests e_select-8.5 { + 1 "SELECT z+1 AS abc FROM d1 ORDER BY abc" { + -19 0 0 4 8 9 94 94 + } + 2 "SELECT z+1 AS abc FROM d1 ORDER BY abc DESC" { + 94 94 9 8 4 0 0 -19 + } + 3 "SELECT z AS x, x AS z FROM d1 ORDER BY z" { + /# 1 # 1 # 1 # 1 # 1 # 1 # 2 # 2/ + } + 4 "SELECT z AS x, x AS z FROM d1 ORDER BY x" { + /-20 1 -1 # -1 # 3 1 7 1 8 1 93 # 93 #/ + } +} + +# EVIDENCE-OF: R-65068-27207 Otherwise, if the ORDER BY expression is +# any other expression, it is evaluated and the returned value used to +# order the output rows. +# +# EVIDENCE-OF: R-03421-57988 If the SELECT statement is a simple SELECT, +# then an ORDER BY may contain any arbitrary expressions. +# +do_select_tests e_select-8.6 { + 1 "SELECT * FROM d1 ORDER BY x+y+z" { + 1 2 -20 1 5 -1 1 2 3 2 5 -1 + 1 2 7 1 2 8 1 4 93 2 4 93 + } + 2 "SELECT * FROM d1 ORDER BY x*z" { + 1 2 -20 2 5 -1 1 5 -1 1 2 3 + 1 2 7 1 2 8 1 4 93 2 4 93 + } + 3 "SELECT * FROM d1 ORDER BY y*z" { + 1 2 -20 2 5 -1 1 5 -1 1 2 3 + 1 2 7 1 2 8 2 4 93 1 4 93 + } +} + +# EVIDENCE-OF: R-28853-08147 However, if the SELECT is a compound +# SELECT, then ORDER BY expressions that are not aliases to output +# columns must be exactly the same as an expression used as an output +# column. +# +do_select_tests e_select-8.7.1 -error { + %s ORDER BY term does not match any column in the result set +} { + 1 "SELECT x FROM d1 UNION ALL SELECT a FROM d2 ORDER BY x*z" 1st + 2 "SELECT x,z FROM d1 UNION ALL SELECT a,b FROM d2 ORDER BY x, x/z" 2nd +} + +do_select_tests e_select-8.7.2 { + 1 "SELECT x*z FROM d1 UNION ALL SELECT a FROM d2 ORDER BY x*z" { + -20 -2 -1 3 7 8 93 186 babied barked commercials gently + iterate lad pragmatist reemphasizes rejoicing solemnness + } + 2 "SELECT x, x/z FROM d1 UNION ALL SELECT a,b FROM d2 ORDER BY x, x/z" { + 1 -1 1 0 1 0 1 0 1 0 1 0 2 -2 2 0 + babied charitableness barked interrupted commercials bathrobe gently + failings iterate sexton lad relenting pragmatist guarded reemphasizes reply + rejoicing liabilities solemnness annexed + } +} + +do_execsql_test e_select-8.8.0 { + CREATE TABLE d3(a); + INSERT INTO d3 VALUES('text'); + INSERT INTO d3 VALUES(14.1); + INSERT INTO d3 VALUES(13); + INSERT INTO d3 VALUES(X'78787878'); + INSERT INTO d3 VALUES(15); + INSERT INTO d3 VALUES(12.9); + INSERT INTO d3 VALUES(null); + + CREATE TABLE d4(x COLLATE nocase); + INSERT INTO d4 VALUES('abc'); + INSERT INTO d4 VALUES('ghi'); + INSERT INTO d4 VALUES('DEF'); + INSERT INTO d4 VALUES('JKL'); +} {} + +# EVIDENCE-OF: R-10883-17697 For the purposes of sorting rows, values +# are compared in the same way as for comparison expressions. +# +# The following tests verify that values of different types are sorted +# correctly, and that mixed real and integer values are compared properly. +# +do_execsql_test e_select-8.8.1 { + SELECT a FROM d3 ORDER BY a +} {{} 12.9 13 14.1 15 text xxxx} +do_execsql_test e_select-8.8.2 { + SELECT a FROM d3 ORDER BY a DESC +} {xxxx text 15 14.1 13 12.9 {}} + + +# EVIDENCE-OF: R-64199-22471 If the ORDER BY expression is assigned a +# collation sequence using the postfix COLLATE operator, then the +# specified collation sequence is used. +# +do_execsql_test e_select-8.9.1 { + SELECT x FROM d4 ORDER BY 1 COLLATE binary +} {DEF JKL abc ghi} +do_execsql_test e_select-8.9.2 { + SELECT x COLLATE binary FROM d4 ORDER BY 1 COLLATE nocase +} {abc DEF ghi JKL} + +# EVIDENCE-OF: R-09398-26102 Otherwise, if the ORDER BY expression is +# an alias to an expression that has been assigned a collation sequence +# using the postfix COLLATE operator, then the collation sequence +# assigned to the aliased expression is used. +# +# In the test 8.10.2, the only result-column expression has no alias. So the +# ORDER BY expression is not a reference to it and therefore does not inherit +# the collation sequence. In test 8.10.3, "x" is the alias (as well as the +# column name), so the ORDER BY expression is interpreted as an alias and the +# collation sequence attached to the result column is used for sorting. +# +do_execsql_test e_select-8.10.1 { + SELECT x COLLATE binary FROM d4 ORDER BY 1 +} {DEF JKL abc ghi} +do_execsql_test e_select-8.10.2 { + SELECT x COLLATE binary FROM d4 ORDER BY x +} {abc DEF ghi JKL} +do_execsql_test e_select-8.10.3 { + SELECT x COLLATE binary AS x FROM d4 ORDER BY x +} {DEF JKL abc ghi} + +# EVIDENCE-OF: R-27301-09658 Otherwise, if the ORDER BY expression is a +# column or an alias of an expression that is a column, then the default +# collation sequence for the column is used. +# +do_execsql_test e_select-8.11.1 { + SELECT x AS y FROM d4 ORDER BY y +} {abc DEF ghi JKL} +do_execsql_test e_select-8.11.2 { + SELECT x||'' FROM d4 ORDER BY x +} {abc DEF ghi JKL} + +# EVIDENCE-OF: R-49925-55905 Otherwise, the BINARY collation sequence is +# used. +# +do_execsql_test e_select-8.12.1 { + SELECT x FROM d4 ORDER BY x||'' +} {DEF JKL abc ghi} + +# EVIDENCE-OF: R-44130-32593 If an ORDER BY expression is not an integer +# alias, then SQLite searches the left-most SELECT in the compound for a +# result column that matches either the second or third rules above. If +# a match is found, the search stops and the expression is handled as an +# alias for the result column that it has been matched against. +# Otherwise, the next SELECT to the right is tried, and so on. +# +do_execsql_test e_select-8.13.0 { + CREATE TABLE d5(a, b); + CREATE TABLE d6(c, d); + CREATE TABLE d7(e, f); + + INSERT INTO d5 VALUES(1, 'f'); + INSERT INTO d6 VALUES(2, 'e'); + INSERT INTO d7 VALUES(3, 'd'); + INSERT INTO d5 VALUES(4, 'c'); + INSERT INTO d6 VALUES(5, 'b'); + INSERT INTO d7 VALUES(6, 'a'); + + CREATE TABLE d8(x COLLATE nocase); + CREATE TABLE d9(y COLLATE nocase); + + INSERT INTO d8 VALUES('a'); + INSERT INTO d9 VALUES('B'); + INSERT INTO d8 VALUES('c'); + INSERT INTO d9 VALUES('D'); +} {} +do_select_tests e_select-8.13 { + 1 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY a + } {1 2 3 4 5 6} + 2 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY c + } {1 2 3 4 5 6} + 3 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY e + } {1 2 3 4 5 6} + 4 { SELECT a FROM d5 UNION ALL SELECT c FROM d6 UNION ALL SELECT e FROM d7 + ORDER BY 1 + } {1 2 3 4 5 6} + + 5 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY b } + {f 1 c 4 4 c 1 f} + 6 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY 2 } + {f 1 c 4 4 c 1 f} + + 7 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY a } + {1 f 4 c c 4 f 1} + 8 { SELECT a, b FROM d5 UNION ALL SELECT b, a FROM d5 ORDER BY 1 } + {1 f 4 c c 4 f 1} + + 9 { SELECT a, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY a+1 } + {f 2 c 5 4 c 1 f} + 10 { SELECT a, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY 2 } + {f 2 c 5 4 c 1 f} + + 11 { SELECT a+1, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY a+1 } + {2 f 5 c c 5 f 2} + 12 { SELECT a+1, b FROM d5 UNION ALL SELECT b, a+1 FROM d5 ORDER BY 1 } + {2 f 5 c c 5 f 2} +} + +# EVIDENCE-OF: R-39265-04070 If no matching expression can be found in +# the result columns of any constituent SELECT, it is an error. +# +do_select_tests e_select-8.14 -error { + %s ORDER BY term does not match any column in the result set +} { + 1 { SELECT a FROM d5 UNION SELECT c FROM d6 ORDER BY a+1 } 1st + 2 { SELECT a FROM d5 UNION SELECT c FROM d6 ORDER BY a, a+1 } 2nd + 3 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY 'hello' } 1st + 4 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY blah } 1st + 5 { SELECT * FROM d5 INTERSECT SELECT * FROM d6 ORDER BY c,d,c+d } 3rd + 6 { SELECT * FROM d5 EXCEPT SELECT * FROM d7 ORDER BY 1,2,b,a/b } 4th +} + +# EVIDENCE-OF: R-03407-11483 Each term of the ORDER BY clause is +# processed separately and may be matched against result columns from +# different SELECT statements in the compound. +# +do_select_tests e_select-8.15 { + 1 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY a, d } + {1 e 1 f 4 b 4 c} + 2 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY c-1, b } + {1 e 1 f 4 b 4 c} + 3 { SELECT a, b FROM d5 UNION ALL SELECT c-1, d FROM d6 ORDER BY 1, 2 } + {1 e 1 f 4 b 4 c} +} + + +#------------------------------------------------------------------------- +# Tests related to statements made about the LIMIT/OFFSET clause. +# +do_execsql_test e_select-9.0 { + CREATE TABLE f1(a, b); + INSERT INTO f1 VALUES(26, 'z'); + INSERT INTO f1 VALUES(25, 'y'); + INSERT INTO f1 VALUES(24, 'x'); + INSERT INTO f1 VALUES(23, 'w'); + INSERT INTO f1 VALUES(22, 'v'); + INSERT INTO f1 VALUES(21, 'u'); + INSERT INTO f1 VALUES(20, 't'); + INSERT INTO f1 VALUES(19, 's'); + INSERT INTO f1 VALUES(18, 'r'); + INSERT INTO f1 VALUES(17, 'q'); + INSERT INTO f1 VALUES(16, 'p'); + INSERT INTO f1 VALUES(15, 'o'); + INSERT INTO f1 VALUES(14, 'n'); + INSERT INTO f1 VALUES(13, 'm'); + INSERT INTO f1 VALUES(12, 'l'); + INSERT INTO f1 VALUES(11, 'k'); + INSERT INTO f1 VALUES(10, 'j'); + INSERT INTO f1 VALUES(9, 'i'); + INSERT INTO f1 VALUES(8, 'h'); + INSERT INTO f1 VALUES(7, 'g'); + INSERT INTO f1 VALUES(6, 'f'); + INSERT INTO f1 VALUES(5, 'e'); + INSERT INTO f1 VALUES(4, 'd'); + INSERT INTO f1 VALUES(3, 'c'); + INSERT INTO f1 VALUES(2, 'b'); + INSERT INTO f1 VALUES(1, 'a'); +} {} + +# EVIDENCE-OF: R-30481-56627 Any scalar expression may be used in the +# LIMIT clause, so long as it evaluates to an integer or a value that +# can be losslessly converted to an integer. +# +do_select_tests e_select-9.1 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5 } {a b c d e} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2+3 } {a b c d e} + 3 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT a FROM f1 WHERE b = 'e') } + {a b c d e} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 5.0 } {a b c d e} + 5 { SELECT b FROM f1 ORDER BY a LIMIT '5' } {a b c d e} +} + +# EVIDENCE-OF: R-46155-47219 If the expression evaluates to a NULL value +# or any other value that cannot be losslessly converted to an integer, +# an error is returned. +# + +do_select_tests e_select-9.2 -error "datatype mismatch" { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 'hello' } {} + 2 { SELECT b FROM f1 ORDER BY a LIMIT NULL } {} + 3 { SELECT b FROM f1 ORDER BY a LIMIT X'ABCD' } {} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 5.1 } {} + 5 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT group_concat(b) FROM f1) } {} +} + +# EVIDENCE-OF: R-03014-26414 If the LIMIT expression evaluates to a +# negative value, then there is no upper bound on the number of rows +# returned. +# +do_select_tests e_select-9.4 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT -1 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} + 2 { SELECT b FROM f1 ORDER BY a LIMIT length('abc')-100 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} + 3 { SELECT b FROM f1 ORDER BY a LIMIT (SELECT count(*) FROM f1)/2 - 14 } + {a b c d e f g h i j k l m n o p q r s t u v w x y z} +} + +# EVIDENCE-OF: R-33750-29536 Otherwise, the SELECT returns the first N +# rows of its result set only, where N is the value that the LIMIT +# expression evaluates to. +# +do_select_tests e_select-9.5 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 0 } {} + 2 { SELECT b FROM f1 ORDER BY a DESC LIMIT 4 } {z y x w} + 3 { SELECT b FROM f1 ORDER BY a DESC LIMIT 8 } {z y x w v u t s} + 4 { SELECT b FROM f1 ORDER BY a DESC LIMIT '12.0' } {z y x w v u t s r q p o} +} + +# EVIDENCE-OF: R-54935-19057 Or, if the SELECT statement would return +# less than N rows without a LIMIT clause, then the entire result set is +# returned. +# +do_select_tests e_select-9.6 { + 1 { SELECT b FROM f1 WHERE a>21 ORDER BY a LIMIT 10 } {v w x y z} + 2 { SELECT count(*) FROM f1 GROUP BY a/5 ORDER BY 1 LIMIT 10 } {2 4 5 5 5 5} +} + + +# EVIDENCE-OF: R-24188-24349 The expression attached to the optional +# OFFSET clause that may follow a LIMIT clause must also evaluate to an +# integer, or a value that can be losslessly converted to an integer. +# +foreach {tn select} { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET 'hello' } + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET NULL } + 3 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET X'ABCD' } + 4 { SELECT b FROM f1 ORDER BY a LIMIT 2 OFFSET 5.1 } + 5 { SELECT b FROM f1 ORDER BY a + LIMIT 2 OFFSET (SELECT group_concat(b) FROM f1) + } +} { + do_catchsql_test e_select-9.7.$tn $select {1 {datatype mismatch}} +} + +# EVIDENCE-OF: R-20467-43422 If an expression has an OFFSET clause, then +# the first M rows are omitted from the result set returned by the +# SELECT statement and the next N rows are returned, where M and N are +# the values that the OFFSET and LIMIT clauses evaluate to, +# respectively. +# +do_select_tests e_select-9.8 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 10 OFFSET 5} {f g h i j k l m n o} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 2+3 OFFSET 10} {k l m n o} + 3 { SELECT b FROM f1 ORDER BY a + LIMIT (SELECT a FROM f1 WHERE b='j') + OFFSET (SELECT a FROM f1 WHERE b='b') + } {c d e f g h i j k l} + 4 { SELECT b FROM f1 ORDER BY a LIMIT '5' OFFSET 3.0 } {d e f g h} + 5 { SELECT b FROM f1 ORDER BY a LIMIT '5' OFFSET 0 } {a b c d e} + 6 { SELECT b FROM f1 ORDER BY a LIMIT 0 OFFSET 10 } {} + 7 { SELECT b FROM f1 ORDER BY a LIMIT 3 OFFSET '1'||'5' } {p q r} +} + +# EVIDENCE-OF: R-34648-44875 Or, if the SELECT would return less than +# M+N rows if it did not have a LIMIT clause, then the first M rows are +# skipped and the remaining rows (if any) are returned. +# +do_select_tests e_select-9.9 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 10 OFFSET 20} {u v w x y z} + 2 { SELECT a FROM f1 ORDER BY a DESC LIMIT 100 OFFSET 18+4} {4 3 2 1} +} + + +# EVIDENCE-OF: R-23293-62447 If the OFFSET clause evaluates to a +# negative value, the results are the same as if it had evaluated to +# zero. +# +do_select_tests e_select-9.10 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET -1 } {a b c d e} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET -500 } {a b c d e} + 3 { SELECT b FROM f1 ORDER BY a LIMIT 5 OFFSET 0 } {a b c d e} +} + +# EVIDENCE-OF: R-19509-40356 Instead of a separate OFFSET clause, the +# LIMIT clause may specify two scalar expressions separated by a comma. +# +# EVIDENCE-OF: R-33788-46243 In this case, the first expression is used +# as the OFFSET expression and the second as the LIMIT expression. +# +do_select_tests e_select-9.11 { + 1 { SELECT b FROM f1 ORDER BY a LIMIT 5, 10 } {f g h i j k l m n o} + 2 { SELECT b FROM f1 ORDER BY a LIMIT 10, 2+3 } {k l m n o} + 3 { SELECT b FROM f1 ORDER BY a + LIMIT (SELECT a FROM f1 WHERE b='b'), (SELECT a FROM f1 WHERE b='j') + } {c d e f g h i j k l} + 4 { SELECT b FROM f1 ORDER BY a LIMIT 3.0, '5' } {d e f g h} + 5 { SELECT b FROM f1 ORDER BY a LIMIT 0, '5' } {a b c d e} + 6 { SELECT b FROM f1 ORDER BY a LIMIT 10, 0 } {} + 7 { SELECT b FROM f1 ORDER BY a LIMIT '1'||'5', 3 } {p q r} + + 8 { SELECT b FROM f1 ORDER BY a LIMIT 20, 10 } {u v w x y z} + 9 { SELECT a FROM f1 ORDER BY a DESC LIMIT 18+4, 100 } {4 3 2 1} + + 10 { SELECT b FROM f1 ORDER BY a LIMIT -1, 5 } {a b c d e} + 11 { SELECT b FROM f1 ORDER BY a LIMIT -500, 5 } {a b c d e} + 12 { SELECT b FROM f1 ORDER BY a LIMIT 0, 5 } {a b c d e} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select2.test new file mode 100644 index 0000000000000000000000000000000000000000..8330894428e4fa90dba3195dbfbac21c1ea6575a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_select2.test @@ -0,0 +1,580 @@ +# 2010 September 24 +# +# 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 to verify that the "testable statements" in +# the lang_select.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#------------------------------------------------------------------------- +# te_* commands: +# +# +# te_read_sql DB SELECT-STATEMENT +# te_read_tbl DB TABLENAME +# +# These two commands are used to read a dataset from the database. A dataset +# consists of N rows of M named columns of values each, where each value has a +# type (null, integer, real, text or blob) and a value within the types domain. +# The tcl format for a "dataset" is a list of two elements: +# +# * A list of the column names. +# * A list of data rows. Each row is itself a list, where each element is +# the contents of a column of the row. Each of these is a list of two +# elements, the type name and the actual value. +# +# For example, the contents of table [t1] as a dataset is: +# +# CREATE TABLE t1(a, b); +# INSERT INTO t1 VALUES('abc', NULL); +# INSERT INTO t1 VALUES(43.1, 22); +# +# {a b} {{{TEXT abc} {NULL {}}} {{REAL 43.1} {INTEGER 22}}} +# +# The [te_read_tbl] command returns a dataset read from a table. The +# [te_read_sql] returns the dataset that results from executing a SELECT +# command. +# +# +# te_tbljoin ?SWITCHES? LHS-TABLE RHS-TABLE +# te_join ?SWITCHES? LHS-DATASET RHS-DATASET +# +# This command joins the two datasets and returns the resulting dataset. If +# there are no switches specified, then the results is the cartesian product +# of the two inputs. The [te_tbljoin] command reads the left and right-hand +# datasets from the specified tables. The [te_join] command is passed the +# datasets directly. +# +# Optional switches are as follows: +# +# -on SCRIPT +# -using COLUMN-LIST +# -left +# +# The -on option specifies a tcl script that is executed for each row in the +# cartesian product of the two datasets. The script has 4 arguments appended +# to it, in the following order: +# +# * The list of column-names from the left-hand dataset. +# * A single row from the left-hand dataset (one "data row" list as +# described above. +# * The list of column-names from the right-hand dataset. +# * A single row from the right-hand dataset. +# +# The script must return a boolean value - true if the combination of rows +# should be included in the output dataset, or false otherwise. +# +# The -using option specifies a list of the columns from the right-hand +# dataset that should be omitted from the output dataset. +# +# If the -left option is present, the join is done LEFT JOIN style. +# Specifically, an extra row is inserted if after the -on script is run there +# exist rows in the left-hand dataset that have no corresponding rows in +# the output. See the implementation for more specific comments. +# +# +# te_equals ?SWITCHES? COLNAME1 COLNAME2 <-on script args> +# +# The only supported switch is "-nocase". If it is present, then text values +# are compared in a case-independent fashion. Otherwise, they are compared +# as if using the SQLite BINARY collation sequence. +# +# +# te_and ONSCRIPT1 ONSCRIPT2... +# +# + + +# +# te_read_tbl DB TABLENAME +# te_read_sql DB SELECT-STATEMENT +# +# These two procs are used to extract datasets from the database, either +# by reading the contents of a named table (te_read_tbl), or by executing +# a SELECT statement (t3_read_sql). +# +# See the comment above, describing "te_* commands", for details of the +# return values. +# +proc te_read_tbl {db tbl} { + te_read_sql $db "SELECT * FROM '$tbl'" +} +proc te_read_sql {db sql} { + set S [sqlite3_prepare_v2 $db $sql -1 DUMMY] + + set cols [list] + for {set i 0} {$i < [sqlite3_column_count $S]} {incr i} { + lappend cols [sqlite3_column_name $S $i] + } + + set rows [list] + while {[sqlite3_step $S] == "SQLITE_ROW"} { + set r [list] + for {set i 0} {$i < [sqlite3_column_count $S]} {incr i} { + lappend r [list [sqlite3_column_type $S $i] [sqlite3_column_text $S $i]] + } + lappend rows $r + } + sqlite3_finalize $S + + return [list $cols $rows] +} + +#------- +# Usage: te_join ... +# +# Where a join-spec is an optional list of arguments as follows: +# +# ?-left? +# ?-using colname-list? +# ?-on on-expr-proc? +# +proc te_join {data1 data2 args} { + + set testproc "" + set usinglist [list] + set isleft 0 + for {set i 0} {$i < [llength $args]} {incr i} { + set a [lindex $args $i] + switch -- $a { + -on { set testproc [lindex $args [incr i]] } + -using { set usinglist [lindex $args [incr i]] } + -left { set isleft 1 } + default { + error "Unknown argument: $a" + } + } + } + + set c1 [lindex $data1 0] + set c2 [lindex $data2 0] + set omitlist [list] + set nullrowlist [list] + set cret $c1 + + set cidx 0 + foreach col $c2 { + set idx [lsearch $usinglist $col] + if {$idx>=0} {lappend omitlist $cidx} + if {$idx<0} { + lappend nullrowlist {NULL {}} + lappend cret $col + } + incr cidx + } + set omitlist [lsort -integer -decreasing $omitlist] + + + set rret [list] + foreach r1 [lindex $data1 1] { + set one 0 + foreach r2 [lindex $data2 1] { + set ok 1 + if {$testproc != ""} { + set ok [eval $testproc [list $c1 $r1 $c2 $r2]] + } + if {$ok} { + set one 1 + foreach idx $omitlist {set r2 [lreplace $r2 $idx $idx]} + lappend rret [concat $r1 $r2] + } + } + + if {$isleft && $one==0} { + lappend rret [concat $r1 $nullrowlist] + } + } + + list $cret $rret +} + +proc te_tbljoin {db t1 t2 args} { + te_join [te_read_tbl $db $t1] [te_read_tbl $db $t2] {*}$args +} + +proc te_apply_affinity {affinity typevar valvar} { + upvar $typevar type + upvar $valvar val + + switch -- $affinity { + integer { + if {[string is double $val]} { set type REAL } + if {[string is wideinteger $val]} { set type INTEGER } + if {$type == "REAL" && int($val)==$val} { + set type INTEGER + set val [expr {int($val)}] + } + } + text { + set type TEXT + } + none { } + + default { error "invalid affinity: $affinity" } + } +} + +#---------- +# te_equals ?SWITCHES? c1 c2 cols1 row1 cols2 row2 +# +proc te_equals {args} { + + if {[llength $args]<6} {error "invalid arguments to te_equals"} + foreach {c1 c2 cols1 row1 cols2 row2} [lrange $args end-5 end] break + + set nocase 0 + set affinity none + + for {set i 0} {$i < ([llength $args]-6)} {incr i} { + set a [lindex $args $i] + switch -- $a { + -nocase { + set nocase 1 + } + -affinity { + set affinity [string tolower [lindex $args [incr i]]] + } + default { + error "invalid arguments to te_equals" + } + } + } + + set idx2 [if {[string is integer $c2]} { set c2 } else { lsearch $cols2 $c2 }] + set idx1 [if {[string is integer $c1]} { set c1 } else { lsearch $cols1 $c1 }] + + set t1 [lindex $row1 $idx1 0] + set t2 [lindex $row2 $idx2 0] + set v1 [lindex $row1 $idx1 1] + set v2 [lindex $row2 $idx2 1] + + te_apply_affinity $affinity t1 v1 + te_apply_affinity $affinity t2 v2 + + if {$t1 == "NULL" || $t2 == "NULL"} { return 0 } + if {$nocase && $t1 == "TEXT"} { set v1 [string tolower $v1] } + if {$nocase && $t2 == "TEXT"} { set v2 [string tolower $v2] } + + + set res [expr {$t1 == $t2 && [string equal $v1 $v2]}] + return $res +} + +proc te_false {args} { return 0 } +proc te_true {args} { return 1 } + +proc te_and {args} { + foreach a [lrange $args 0 end-4] { + set res [eval $a [lrange $args end-3 end]] + if {$res == 0} {return 0} + } + return 1 +} + + +proc te_dataset_eq {testname got expected} { + uplevel #0 [list do_test $testname [list set {} $got] $expected] +} +proc te_dataset_eq_unordered {testname got expected} { + lset got 1 [lsort [lindex $got 1]] + lset expected 1 [lsort [lindex $expected 1]] + te_dataset_eq $testname $got $expected +} + +proc te_dataset_ne {testname got unexpected} { + uplevel #0 [list do_test $testname [list string equal $got $unexpected] 0] +} +proc te_dataset_ne_unordered {testname got unexpected} { + lset got 1 [lsort [lindex $got 1]] + lset unexpected 1 [lsort [lindex $unexpected 1]] + te_dataset_ne $testname $got $unexpected +} + + +#------------------------------------------------------------------------- +# +proc test_join {tn sqljoin tbljoinargs} { + set sql [te_read_sql db "SELECT * FROM $sqljoin"] + set te [te_tbljoin db {*}$tbljoinargs] + te_dataset_eq_unordered $tn $sql $te +} + +drop_all_tables +do_execsql_test e_select-2.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + CREATE TABLE t3(b COLLATE nocase); + + INSERT INTO t1 VALUES(2, 'B'); + INSERT INTO t1 VALUES(1, 'A'); + INSERT INTO t1 VALUES(4, 'D'); + INSERT INTO t1 VALUES(NULL, NULL); + INSERT INTO t1 VALUES(3, NULL); + + INSERT INTO t2 VALUES(1, 'A'); + INSERT INTO t2 VALUES(2, NULL); + INSERT INTO t2 VALUES(5, 'E'); + INSERT INTO t2 VALUES(NULL, NULL); + INSERT INTO t2 VALUES(3, 'C'); + + INSERT INTO t3 VALUES('a'); + INSERT INTO t3 VALUES('c'); + INSERT INTO t3 VALUES('b'); +} {} + +foreach {tn indexes} { + e_select-2.1.1 { } + e_select-2.1.2 { CREATE INDEX i1 ON t1(a) } + e_select-2.1.3 { CREATE INDEX i1 ON t2(a) } + e_select-2.1.4 { CREATE INDEX i1 ON t3(b) } +} { + + catchsql { DROP INDEX i1 } + catchsql { DROP INDEX i2 } + catchsql { DROP INDEX i3 } + execsql $indexes + + # EVIDENCE-OF: R-49872-03192 If the join-operator is "CROSS JOIN", + # "INNER JOIN", "JOIN" or a comma (",") and there is no ON or USING + # clause, then the result of the join is simply the cartesian product of + # the left and right-hand datasets. + # + # EVIDENCE-OF: R-46256-57243 There is no difference between the "INNER + # JOIN", "JOIN" and "," join operators. + # + # EVIDENCE-OF: R-25071-21202 The "CROSS JOIN" join operator produces the + # same result as the "INNER JOIN", "JOIN" and "," operators + # + test_join $tn.1.1 "t1, t2" {t1 t2} + test_join $tn.1.2 "t1 INNER JOIN t2" {t1 t2} + test_join $tn.1.3 "t1 CROSS JOIN t2" {t1 t2} + test_join $tn.1.4 "t1 JOIN t2" {t1 t2} + test_join $tn.1.5 "t2, t3" {t2 t3} + test_join $tn.1.6 "t2 INNER JOIN t3" {t2 t3} + test_join $tn.1.7 "t2 CROSS JOIN t3" {t2 t3} + test_join $tn.1.8 "t2 JOIN t3" {t2 t3} + test_join $tn.1.9 "t2, t2 AS x" {t2 t2} + test_join $tn.1.10 "t2 INNER JOIN t2 AS x" {t2 t2} + test_join $tn.1.11 "t2 CROSS JOIN t2 AS x" {t2 t2} + test_join $tn.1.12 "t2 JOIN t2 AS x" {t2 t2} + + # EVIDENCE-OF: R-38465-03616 If there is an ON clause then the ON + # expression is evaluated for each row of the cartesian product as a + # boolean expression. Only rows for which the expression evaluates to + # true are included from the dataset. + # + test_join $tn.2.1 "t1, t2 ON (t1.a=t2.a)" {t1 t2 -on {te_equals a a}} + test_join $tn.2.2 "t2, t1 ON (t1.a=t2.a)" {t2 t1 -on {te_equals a a}} + test_join $tn.2.3 "t2, t1 ON (1)" {t2 t1 -on te_true} + test_join $tn.2.4 "t2, t1 ON (NULL)" {t2 t1 -on te_false} + test_join $tn.2.5 "t2, t1 ON (1.1-1.1)" {t2 t1 -on te_false} + test_join $tn.2.6 "t1, t2 ON (1.1-1.0)" {t1 t2 -on te_true} + + + test_join $tn.3 "t1 LEFT JOIN t2 ON (t1.a=t2.a)" {t1 t2 -left -on {te_equals a a}} + test_join $tn.4 "t1 LEFT JOIN t2 USING (a)" { + t1 t2 -left -using a -on {te_equals a a} + } + test_join $tn.5 "t1 CROSS JOIN t2 USING(b, a)" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.6 "t1 NATURAL JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.7 "t1 NATURAL INNER JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.8 "t1 NATURAL CROSS JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.9 "t1 NATURAL INNER JOIN t2" { + t1 t2 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.10 "t1 NATURAL LEFT JOIN t2" { + t1 t2 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.11 "t1 NATURAL LEFT OUTER JOIN t2" { + t1 t2 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.12 "t2 NATURAL JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.13 "t2 NATURAL INNER JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.14 "t2 NATURAL CROSS JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.15 "t2 NATURAL INNER JOIN t1" { + t2 t1 -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.16 "t2 NATURAL LEFT JOIN t1" { + t2 t1 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.17 "t2 NATURAL LEFT OUTER JOIN t1" { + t2 t1 -left -using {a b} -on {te_and {te_equals a a} {te_equals b b}} + } + test_join $tn.18 "t1 LEFT JOIN t2 USING (b)" { + t1 t2 -left -using b -on {te_equals b b} + } + test_join $tn.19 "t1 JOIN t3 USING(b)" {t1 t3 -using b -on {te_equals b b}} + test_join $tn.20 "t3 JOIN t1 USING(b)" { + t3 t1 -using b -on {te_equals -nocase b b} + } + test_join $tn.21 "t1 NATURAL JOIN t3" { + t1 t3 -using b -on {te_equals b b} + } + test_join $tn.22 "t3 NATURAL JOIN t1" { + t3 t1 -using b -on {te_equals -nocase b b} + } + test_join $tn.23 "t1 NATURAL LEFT JOIN t3" { + t1 t3 -left -using b -on {te_equals b b} + } + test_join $tn.24 "t3 NATURAL LEFT JOIN t1" { + t3 t1 -left -using b -on {te_equals -nocase b b} + } + test_join $tn.25 "t1 LEFT JOIN t3 ON (t3.b=t1.b)" { + t1 t3 -left -on {te_equals -nocase b b} + } + test_join $tn.26 "t1 LEFT JOIN t3 ON (t1.b=t3.b)" { + t1 t3 -left -on {te_equals b b} + } + test_join $tn.27 "t1 JOIN t3 ON (t1.b=t3.b)" { t1 t3 -on {te_equals b b} } + + # EVIDENCE-OF: R-28760-53843 When more than two tables are joined + # together as part of a FROM clause, the join operations are processed + # in order from left to right. In other words, the FROM clause (A + # join-op-1 B join-op-2 C) is computed as ((A join-op-1 B) join-op-2 C). + # + # Tests 28a and 28b show that the statement above is true for this case. + # Test 28c shows that if the parenthesis force a different order of + # evaluation the result is different. Test 28d verifies that the result + # of the query with the parenthesis forcing a different order of evaluation + # is as calculated by the [te_*] procs. + # + set t3_natural_left_join_t2 [ + te_tbljoin db t3 t2 -left -using {b} -on {te_equals -nocase b b} + ] + set t1 [te_read_tbl db t1] + te_dataset_eq_unordered $tn.28a [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN t2 NATURAL JOIN t1" + ] [te_join $t3_natural_left_join_t2 $t1 \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + + te_dataset_eq_unordered $tn.28b [ + te_read_sql db "SELECT * FROM (t3 NATURAL LEFT JOIN t2) NATURAL JOIN t1" + ] [te_join $t3_natural_left_join_t2 $t1 \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + + te_dataset_ne_unordered $tn.28c [ + te_read_sql db "SELECT * FROM (t3 NATURAL LEFT JOIN t2) NATURAL JOIN t1" + ] [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN (t2 NATURAL JOIN t1)" + ] + + set t2_natural_join_t1 [te_tbljoin db t2 t1 -using {a b} \ + -using {a b} -on {te_and {te_equals a a} {te_equals -nocase b b}} \ + ] + set t3 [te_read_tbl db t3] + te_dataset_eq_unordered $tn.28d [ + te_read_sql db "SELECT * FROM t3 NATURAL LEFT JOIN (t2 NATURAL JOIN t1)" + ] [te_join $t3 $t2_natural_join_t1 \ + -left -using {b} -on {te_equals -nocase b b} \ + ] +} + +do_execsql_test e_select-2.2.0 { + CREATE TABLE t4(x TEXT COLLATE nocase); + CREATE TABLE t5(y INTEGER, z TEXT COLLATE binary); + + INSERT INTO t4 VALUES('2.0'); + INSERT INTO t4 VALUES('TWO'); + INSERT INTO t5 VALUES(2, 'two'); +} {} + +# EVIDENCE-OF: R-59237-46742 A subquery specified in the +# table-or-subquery following the FROM clause in a simple SELECT +# statement is handled as if it was a table containing the data returned +# by executing the subquery statement. +# +# EVIDENCE-OF: R-27438-53558 Each column of the subquery has the +# collation sequence and affinity of the corresponding expression in the +# subquery statement. +# +foreach {tn subselect select spec} { + 1 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss%" + {t1 %ss%} + + 2 "SELECT * FROM t2" "SELECT * FROM t1 JOIN %ss% AS x ON (t1.a=x.a)" + {t1 %ss% -on {te_equals 0 0}} + + 3 "SELECT * FROM t2" "SELECT * FROM %ss% AS x JOIN t1 ON (t1.a=x.a)" + {%ss% t1 -on {te_equals 0 0}} + + 4 "SELECT * FROM t1, t2" "SELECT * FROM %ss% AS x JOIN t3" + {%ss% t3} + + 5 "SELECT * FROM t1, t2" "SELECT * FROM %ss% NATURAL JOIN t3" + {%ss% t3 -using b -on {te_equals 1 0}} + + 6 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL JOIN %ss%" + {t3 %ss% -using b -on {te_equals -nocase 0 1}} + + 7 "SELECT * FROM t1, t2" "SELECT * FROM t3 NATURAL LEFT JOIN %ss%" + {t3 %ss% -left -using b -on {te_equals -nocase 0 1}} + + 8 "SELECT count(*) AS y FROM t4" "SELECT * FROM t5, %ss% USING (y)" + {t5 %ss% -using y -on {te_equals -affinity text 0 0}} + + 9 "SELECT count(*) AS y FROM t4" "SELECT * FROM %ss%, t5 USING (y)" + {%ss% t5 -using y -on {te_equals -affinity text 0 0}} + + 10 "SELECT x AS y FROM t4" "SELECT * FROM %ss% JOIN t5 USING (y)" + {%ss% t5 -using y -on {te_equals -nocase -affinity integer 0 0}} + + 11 "SELECT x AS y FROM t4" "SELECT * FROM t5 JOIN %ss% USING (y)" + {t5 %ss% -using y -on {te_equals -nocase -affinity integer 0 0}} + + 12 "SELECT y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)" + {%ss% t4 -using x -on {te_equals -nocase -affinity integer 0 0}} + + 13 "SELECT y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)" + {t4 %ss% -using x -on {te_equals -nocase -affinity integer 0 0}} + + 14 "SELECT +y AS x FROM t5" "SELECT * FROM %ss% JOIN t4 USING (x)" + {%ss% t4 -using x -on {te_equals -nocase -affinity text 0 0}} + + 15 "SELECT +y AS x FROM t5" "SELECT * FROM t4 JOIN %ss% USING (x)" + {t4 %ss% -using x -on {te_equals -nocase -affinity text 0 0}} +} { + + # Create a temporary table named %ss% containing the data returned by + # the sub-select. Then have the [te_tbljoin] proc use this table to + # compute the expected results of the $select query. Drop the temporary + # table before continuing. + # + execsql "CREATE TEMP TABLE '%ss%' AS $subselect" + set te [eval te_tbljoin db $spec] + execsql "DROP TABLE '%ss%'" + + # Check that the actual data returned by the $select query is the same + # as the expected data calculated using [te_tbljoin] above. + # + te_dataset_eq_unordered e_select-2.2.1.$tn [ + te_read_sql db [string map [list %ss% "($subselect)"] $select] + ] $te +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_totalchanges.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_totalchanges.test new file mode 100644 index 0000000000000000000000000000000000000000..bb5cfba8a51234440f44a29c5e08461c55e651e7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_totalchanges.test @@ -0,0 +1,214 @@ +# 2011 May 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_totalchanges + +# Like [do_execsql_test], except it appends the value returned by +# [db total_changes] to the result of executing the SQL script. +# +proc do_tc_test {tn sql res} { + uplevel [list \ + do_test $tn "concat \[execsql {$sql}\] \[db total_changes\]" $res + ] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b); + CREATE INDEX t1_b ON t1(b); + CREATE TABLE t2(x, y, PRIMARY KEY(x, y)) WITHOUT ROWID; + CREATE INDEX t2_y ON t2(y); +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-38914-26427 The total_changes() function returns the +# number of row changes caused by INSERT, UPDATE or DELETE statements +# since the current database connection was opened. +# +# 1.1.*: different types of I/U/D statements, +# 1.2.*: trigger programs. +# +do_tc_test 1.1.1 { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + UPDATE t1 SET a = a+1; + DELETE FROM t1; +} {6} +do_tc_test 1.1.2 { + DELETE FROM t1 +} {6} + +do_tc_test 1.1.3 { + WITH data(a,b) AS ( + SELECT 0, 0 UNION ALL SELECT a+1, b+1 FROM data WHERE a<99 + ) + INSERT INTO t1 SELECT * FROM data; +} {106} + +do_tc_test 1.1.4 { + INSERT INTO t2 SELECT * FROM t1 WHERE a<50; + UPDATE t2 SET y=y+1; +} {206} + +do_tc_test 1.1.5 { + DELETE FROM t2 WHERE y<=25 +} {231} + +do_execsql_test 1.2.1 { + DELETE FROM t1; + DELETE FROM t2; +} +sqlite3 db test.db ; # To reset total_changes +do_tc_test 1.2.2 { + CREATE TABLE log(detail); + CREATE TRIGGER t1_after_insert AFTER INSERT ON t1 BEGIN + INSERT INTO log VALUES('inserted into t1'); + END; + + CREATE TRIGGER t1_before_delete BEFORE DELETE ON t1 BEGIN + INSERT INTO log VALUES('deleting from t1'); + INSERT INTO log VALUES('here we go!'); + END; + + CREATE TRIGGER t1_after_update AFTER UPDATE ON t1 BEGIN + INSERT INTO log VALUES('update'); + DELETE FROM log; + END; + + INSERT INTO t1 VALUES('a', 'b'); -- 1 + 1 + UPDATE t1 SET b='c'; -- 1 + 1 + 2 + DELETE FROM t1; -- 1 + 1 + 1 +} {9} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-61766-15253 Executing any other type of SQL statement +# does not affect the value returned by sqlite3_total_changes(). +ifcapable altertable { + do_tc_test 2.1 { + INSERT INTO t1 VALUES(1, 2), (3, 4); + INSERT INTO t2 VALUES(1, 2), (3, 4); + } {15} + do_tc_test 2.2 { + SELECT count(*) FROM t1; + } {2 15} + do_tc_test 2.3 { + CREATE TABLE t4(a, b); + ALTER TABLE t4 ADD COLUMN c; + CREATE INDEX i4 ON t4(c); + ALTER TABLE t4 RENAME TO t5; + ANALYZE; + BEGIN; + DROP TABLE t2; + ROLLBACK; + VACUUM; + } {15} +} + + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-36043-10590 Changes made as part of foreign key +# actions are included in the count, but those made as part of REPLACE +# constraint resolution are not. +# +# 3.1.*: foreign key actions +# 3.2.*: REPLACE constraints. +# +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.1.1 { + CREATE TABLE p1(c PRIMARY KEY, d); + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE CASCADE); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON DELETE SET DEFAULT); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO p1 VALUES(3, 'three'); + INSERT INTO p1 VALUES(4, 'four'); + + INSERT INTO c1 VALUES(1, 'i'); + INSERT INTO c2 VALUES(2, 'ii'); + INSERT INTO c3 VALUES(3, 'iii'); + PRAGMA foreign_keys = ON; +} {7} + +do_tc_test 3.1.2 { DELETE FROM p1 WHERE c=1; } {9} +do_tc_test 3.1.3 { DELETE FROM p1 WHERE c=2; } {11} +do_tc_test 3.1.4 { DELETE FROM p1 WHERE c=3; } {13} +do_tc_test 3.1.5 { DELETE FROM p1 WHERE c=4; } {14} ; # only 1 this time. + +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.1.6 { + DROP TABLE c1; + DROP TABLE c2; + DROP TABLE c3; + CREATE TABLE c1(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET NULL); + CREATE TABLE c2(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE CASCADE); + CREATE TABLE c3(a, b, FOREIGN KEY(a) REFERENCES p1 ON UPDATE SET DEFAULT); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO p1 VALUES(3, 'three'); + INSERT INTO p1 VALUES(4, 'four'); + + INSERT INTO c1 VALUES(1, 'i'); + INSERT INTO c2 VALUES(2, 'ii'); + INSERT INTO c3 VALUES(3, 'iii'); + PRAGMA foreign_keys = ON; +} {7} + +do_tc_test 3.1.7 { UPDATE p1 SET c=c+4 WHERE c=1; } {9} +do_tc_test 3.1.8 { UPDATE p1 SET c=c+4 WHERE c=2; } {11} +do_tc_test 3.1.9 { UPDATE p1 SET c=c+4 WHERE c=3; } {13} +do_tc_test 3.1.10 { UPDATE p1 SET c=c+4 WHERE c=4; } {14} ; # only 1 this time. + +sqlite3 db test.db ; # To reset total_changes +do_tc_test 3.2.1 { + CREATE TABLE t3(a UNIQUE, b UNIQUE); + INSERT INTO t3 VALUES('one', 'one'); + INSERT INTO t3 VALUES('two', 'two'); + INSERT OR REPLACE INTO t3 VALUES('one', 'two'); +} {3} + +do_tc_test 3.2.2 { + INSERT INTO t3 VALUES('three', 'one'); + UPDATE OR REPLACE t3 SET b='two' WHERE b='one'; + SELECT * FROM t3; +} {three two 5} + +#-------------------------------------------------------------------------- +# EVIDENCE-OF: R-54872-08741 Changes to a view that are intercepted by +# INSTEAD OF triggers are not counted. +# +sqlite3 db test.db ; # To reset total_changes +do_tc_test 4.1 { + CREATE TABLE t6(x); + CREATE VIEW v1 AS SELECT * FROM t6; + CREATE TRIGGER v1_tr1 INSTEAD OF INSERT ON v1 BEGIN + SELECT 'no-op'; + END; + + INSERT INTO v1 VALUES('a'); + INSERT INTO v1 VALUES('b'); +} {0} +do_tc_test 4.2 { + CREATE TRIGGER v1_tr2 INSTEAD OF INSERT ON v1 BEGIN + INSERT INTO t6 VALUES(new.x); + END; + + INSERT INTO v1 VALUES('c'); + INSERT INTO v1 VALUES('d'); +} {2} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_update.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_update.test new file mode 100644 index 0000000000000000000000000000000000000000..a13b059b3292050e7725317970b3ea8db95072b5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_update.test @@ -0,0 +1,605 @@ +# 2010 September 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. +# +#*********************************************************************** +# +# This file implements tests to verify that the "testable statements" in +# the lang_update.html document are correct. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +#-------------------- +# Test organization: +# +# e_update-1.*: Test statements describing the workings of UPDATE statements. +# +# e_update-2.*: Test the restrictions on the UPDATE statement syntax that +# can be used within triggers. +# +# e_update-3.*: Test the special LIMIT/OFFSET and ORDER BY clauses that can +# be used with UPDATE when SQLite is compiled with +# SQLITE_ENABLE_UPDATE_DELETE_LIMIT. +# + +forcedelete test.db2 + +do_execsql_test e_update-0.0 { + ATTACH 'test.db2' AS aux; + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b, c); + CREATE TABLE t3(a, b UNIQUE); + CREATE TABLE t6(x, y); + CREATE INDEX i1 ON t1(a); + + CREATE TEMP TABLE t4(x, y); + CREATE TEMP TABLE t6(x, y); + + CREATE TABLE aux.t1(a, b); + CREATE TABLE aux.t5(a, b); +} {} + +proc do_update_tests {args} { + uplevel do_select_tests $args +} + +# -- syntax diagram update-stmt +# +do_update_tests e_update-0 { + 1 "UPDATE t1 SET a=10" {} + 2 "UPDATE t1 SET a=10, b=5" {} + 3 "UPDATE t1 SET a=10 WHERE b=5" {} + 4 "UPDATE t1 SET b=5,a=10 WHERE 1" {} + 5 "UPDATE main.t1 SET a=10" {} + 6 "UPDATE main.t1 SET a=10, b=5" {} + 7 "UPDATE main.t1 SET a=10 WHERE b=5" {} + 9 "UPDATE OR ROLLBACK t1 SET a=10" {} + 10 "UPDATE OR ROLLBACK t1 SET a=10, b=5" {} + 11 "UPDATE OR ROLLBACK t1 SET a=10 WHERE b=5" {} + 12 "UPDATE OR ROLLBACK t1 SET b=5,a=10 WHERE 1" {} + 13 "UPDATE OR ROLLBACK main.t1 SET a=10" {} + 14 "UPDATE OR ROLLBACK main.t1 SET a=10, b=5" {} + 15 "UPDATE OR ROLLBACK main.t1 SET a=10 WHERE b=5" {} + 16 "UPDATE OR ROLLBACK main.t1 SET b=5,a=10 WHERE 1" {} + 17 "UPDATE OR ABORT t1 SET a=10" {} + 18 "UPDATE OR ABORT t1 SET a=10, b=5" {} + 19 "UPDATE OR ABORT t1 SET a=10 WHERE b=5" {} + 20 "UPDATE OR ABORT t1 SET b=5,a=10 WHERE 1" {} + 21 "UPDATE OR ABORT main.t1 SET a=10" {} + 22 "UPDATE OR ABORT main.t1 SET a=10, b=5" {} + 23 "UPDATE OR ABORT main.t1 SET a=10 WHERE b=5" {} + 24 "UPDATE OR ABORT main.t1 SET b=5,a=10 WHERE 1" {} + 25 "UPDATE OR REPLACE t1 SET a=10" {} + 26 "UPDATE OR REPLACE t1 SET a=10, b=5" {} + 27 "UPDATE OR REPLACE t1 SET a=10 WHERE b=5" {} + 28 "UPDATE OR REPLACE t1 SET b=5,a=10 WHERE 1" {} + 29 "UPDATE OR REPLACE main.t1 SET a=10" {} + 30 "UPDATE OR REPLACE main.t1 SET a=10, b=5" {} + 31 "UPDATE OR REPLACE main.t1 SET a=10 WHERE b=5" {} + 32 "UPDATE OR REPLACE main.t1 SET b=5,a=10 WHERE 1" {} + 33 "UPDATE OR FAIL t1 SET a=10" {} + 34 "UPDATE OR FAIL t1 SET a=10, b=5" {} + 35 "UPDATE OR FAIL t1 SET a=10 WHERE b=5" {} + 36 "UPDATE OR FAIL t1 SET b=5,a=10 WHERE 1" {} + 37 "UPDATE OR FAIL main.t1 SET a=10" {} + 38 "UPDATE OR FAIL main.t1 SET a=10, b=5" {} + 39 "UPDATE OR FAIL main.t1 SET a=10 WHERE b=5" {} + 40 "UPDATE OR FAIL main.t1 SET b=5,a=10 WHERE 1" {} + 41 "UPDATE OR IGNORE t1 SET a=10" {} + 42 "UPDATE OR IGNORE t1 SET a=10, b=5" {} + 43 "UPDATE OR IGNORE t1 SET a=10 WHERE b=5" {} + 44 "UPDATE OR IGNORE t1 SET b=5,a=10 WHERE 1" {} + 45 "UPDATE OR IGNORE main.t1 SET a=10" {} + 46 "UPDATE OR IGNORE main.t1 SET a=10, b=5" {} + 47 "UPDATE OR IGNORE main.t1 SET a=10 WHERE b=5" {} + 48 "UPDATE OR IGNORE main.t1 SET b=5,a=10 WHERE 1" {} +} + +# EVIDENCE-OF: R-38515-45264 An UPDATE statement is used to modify a +# subset of the values stored in zero or more rows of the database table +# identified by the qualified-table-name specified as part of the UPDATE +# statement. +# +# Test cases e_update-1.1.1.* test the "identified by the +# qualified-table-name" part of the statement above. Tests +# e_update-1.1.2.* show that the "zero or more rows" part is +# accurate. +# +do_execsql_test e_update-1.1.0 { + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); + + INSERT INTO aux.t1 VALUES(1, 'I'); + INSERT INTO aux.t1 VALUES(2, 'II'); + INSERT INTO aux.t1 VALUES(3, 'III'); +} {} +do_update_tests e_update-1.1 { + 1.1 "UPDATE t1 SET a = a+1; SELECT * FROM t1" {2 i 3 ii 4 iii} + 1.2 "UPDATE main.t1 SET a = a+1; SELECT * FROM main.t1" {3 i 4 ii 5 iii} + 1.3 "UPDATE aux.t1 SET a = a+1; SELECT * FROM aux.t1" {2 I 3 II 4 III} + + 2.1 "UPDATE t1 SET a = a+1 WHERE a = 1; SELECT * FROM t1" {3 i 4 ii 5 iii} + 2.2 "UPDATE t1 SET a = a+1 WHERE a = 4; SELECT * FROM t1" {3 i 5 ii 5 iii} +} + +# EVIDENCE-OF: R-55869-30521 If the UPDATE statement does not have a +# WHERE clause, all rows in the table are modified by the UPDATE. +# +do_execsql_test e_update-1.2.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.2 { + 1 "UPDATE t1 SET b = 'roman' ; SELECT * FROM t1" + {1 roman 2 roman 3 roman} + + 2 "UPDATE t1 SET a = 'greek' ; SELECT * FROM t1" + {greek roman greek roman greek roman} +} + +# EVIDENCE-OF: R-58095-46013 Otherwise, the UPDATE affects only those +# rows for which the WHERE clause boolean expression is true. +# +do_execsql_test e_update-1.3.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(NULL, ''); + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.3 { + 1 "UPDATE t1 SET b = 'roman' WHERE a<2 ; SELECT * FROM t1" + {{} {} 1 roman 2 ii 3 iii} + + 2 "UPDATE t1 SET b = 'egyptian' WHERE (a-3)/10.0 ; SELECT * FROM t1" + {{} {} 1 egyptian 2 egyptian 3 iii} + + 3 "UPDATE t1 SET b = 'macedonian' WHERE a; SELECT * FROM t1" + {{} {} 1 macedonian 2 macedonian 3 macedonian} + + 4 "UPDATE t1 SET b = 'lithuanian' WHERE a IS NULL; SELECT * FROM t1" + {{} lithuanian 1 macedonian 2 macedonian 3 macedonian} +} + +# EVIDENCE-OF: R-58129-20729 It is not an error if the WHERE clause does +# not evaluate to true for any row in the table - this just means that +# the UPDATE statement affects zero rows. +# +do_execsql_test e_update-1.4.0 { + DELETE FROM main.t1; + INSERT INTO main.t1 VALUES(NULL, ''); + INSERT INTO main.t1 VALUES(1, 'i'); + INSERT INTO main.t1 VALUES(2, 'ii'); + INSERT INTO main.t1 VALUES(3, 'iii'); +} {} +do_update_tests e_update-1.4 -query { + SELECT * FROM t1 +} { + 1 "UPDATE t1 SET b = 'burmese' WHERE a=5" {{} {} 1 i 2 ii 3 iii} + + 2 "UPDATE t1 SET b = 'burmese' WHERE length(b)<1 AND a IS NOT NULL" + {{} {} 1 i 2 ii 3 iii} + + 3 "UPDATE t1 SET b = 'burmese' WHERE 0" {{} {} 1 i 2 ii 3 iii} + + 4 "UPDATE t1 SET b = 'burmese' WHERE (SELECT a FROM t1 WHERE rowid=1)" + {{} {} 1 i 2 ii 3 iii} +} + +# EVIDENCE-OF: R-40598-36595 For each affected row, the named columns +# are set to the values found by evaluating the corresponding scalar +# expressions. +# +# EVIDENCE-OF: R-40472-60438 Columns that do not appear in the list of +# assignments are left unmodified. +# +do_execsql_test e_update-1.5.0 { + INSERT INTO t2(rowid, a, b, c) VALUES(1, 3, 1, 4); + INSERT INTO t2(rowid, a, b, c) VALUES(2, 1, 5, 9); + INSERT INTO t2(rowid, a, b, c) VALUES(3, 2, 6, 5); +} {} +do_update_tests e_update-1.5 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET c = 1+1 WHERE a=2" + {3 1 4 1 5 9 2 6 2} + + 2 "UPDATE t2 SET b = 4/2, c=CAST((0.4*5) AS INTEGER) WHERE a<3" + {3 1 4 1 2 2 2 2 2} + + 3 "UPDATE t2 SET a = 1" + {1 1 4 1 2 2 1 2 2} + + 4 "UPDATE t2 SET b = (SELECT count(*)+2 FROM t2), c = 24/3+1 WHERE rowid=2" + {1 1 4 1 5 9 1 2 2} + + 5 "UPDATE t2 SET a = 3 WHERE c = 4" + {3 1 4 1 5 9 1 2 2} + + 6 "UPDATE t2 SET a = b WHERE rowid>2" + {3 1 4 1 5 9 2 2 2} + + 6 "UPDATE t2 SET b=6, c=5 WHERE a=b AND b=c" + {3 1 4 1 5 9 2 6 5} +} + +# EVIDENCE-OF: R-34751-18293 If a single column-name appears more than +# once in the list of assignment expressions, all but the rightmost +# occurrence is ignored. +# +do_update_tests e_update-1.6 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET c=5, c=6, c=7 WHERE rowid=1" {3 1 7 1 5 9 2 6 5} + 2 "UPDATE t2 SET c=7, c=6, c=5 WHERE rowid=1" {3 1 5 1 5 9 2 6 5} + 3 "UPDATE t2 SET c=5, b=6, c=7 WHERE rowid=1" {3 6 7 1 5 9 2 6 5} +} + +# EVIDENCE-OF: R-36239-04077 The scalar expressions may refer to columns +# of the row being updated. +# +# EVIDENCE-OF: R-04558-24451 In this case all scalar expressions are +# evaluated before any assignments are made. +# +do_execsql_test e_update-1.7.0 { + DELETE FROM t2; + INSERT INTO t2(rowid, a, b, c) VALUES(1, 3, 1, 4); + INSERT INTO t2(rowid, a, b, c) VALUES(2, 1, 5, 9); + INSERT INTO t2(rowid, a, b, c) VALUES(3, 2, 6, 5); +} {} +do_update_tests e_update-1.7 -query { + SELECT * FROM t2 +} { + 1 "UPDATE t2 SET a=b+c" {5 1 4 14 5 9 11 6 5} + 2 "UPDATE t2 SET a=b, b=a" {1 5 4 5 14 9 6 11 5} + 3 "UPDATE t2 SET a=c||c, c=NULL" {44 5 {} 99 14 {} 55 11 {}} +} + +# EVIDENCE-OF: R-28518-13457 The optional "OR action" conflict clause +# that follows the UPDATE keyword allows the user to nominate a specific +# constraint conflict resolution algorithm to use during this one UPDATE +# command. +# +do_execsql_test e_update-1.8.0 { + DELETE FROM t3; + INSERT INTO t3 VALUES(1, 'one'); + INSERT INTO t3 VALUES(2, 'two'); + INSERT INTO t3 VALUES(3, 'three'); + INSERT INTO t3 VALUES(4, 'four'); +} {} +foreach {tn sql error ac data } { + 1 "UPDATE t3 SET b='one' WHERE a=3" + {UNIQUE constraint failed: t3.b} 1 {1 one 2 two 3 three 4 four} + + 2 "UPDATE OR REPLACE t3 SET b='one' WHERE a=3" + {} 1 {2 two 3 one 4 four} + + 3 "UPDATE OR FAIL t3 SET b='three'" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} + + 4 "UPDATE OR IGNORE t3 SET b='three' WHERE a=3" + {} 1 {2 three 3 one 4 four} + + 5 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} + + 6 "BEGIN" {} 0 {2 three 3 one 4 four} + + 7 "UPDATE t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} + + 8 "UPDATE OR ABORT t3 SET b='three' WHERE a=3" + {UNIQUE constraint failed: t3.b} 0 {2 three 3 one 4 four} + + 9 "UPDATE OR FAIL t3 SET b='two'" + {UNIQUE constraint failed: t3.b} 0 {2 two 3 one 4 four} + + 10 "UPDATE OR IGNORE t3 SET b='four' WHERE a=3" + {} 0 {2 two 3 one 4 four} + + 11 "UPDATE OR REPLACE t3 SET b='four' WHERE a=3" + {} 0 {2 two 3 four} + + 12 "UPDATE OR ROLLBACK t3 SET b='four'" + {UNIQUE constraint failed: t3.b} 1 {2 three 3 one 4 four} +} { + do_catchsql_test e_update-1.8.$tn.1 $sql [list [expr {$error!=""}] $error] + do_execsql_test e_update-1.8.$tn.2 {SELECT * FROM t3} [list {*}$data] + do_test e_update-1.8.$tn.3 {sqlite3_get_autocommit db} $ac +} + + + +# EVIDENCE-OF: R-12123-54095 The table-name specified as part of an +# UPDATE statement within a trigger body must be unqualified. +# +# EVIDENCE-OF: R-43190-62442 In other words, the schema-name. prefix on +# the table name of the UPDATE is not allowed within triggers. +# +do_update_tests e_update-2.1 -error { + qualified table names are not allowed on INSERT, UPDATE, and DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + UPDATE main.t2 SET a=1, b=2, c=3; + END; + } {} + + 2 { + CREATE TRIGGER tr1 BEFORE UPDATE ON t2 BEGIN + UPDATE aux.t1 SET a=1, b=2; + END; + } {} + + 3 { + CREATE TRIGGER tr1 AFTER DELETE ON t4 BEGIN + UPDATE main.t1 SET a=1, b=2; + END; + } {} +} + +# EVIDENCE-OF: R-06085-13761 Unless the table to which the trigger is +# attached is in the TEMP database, the table being updated by the +# trigger program must reside in the same database as it. +# +do_update_tests e_update-2.2 -error { + no such table: %s +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN + UPDATE t4 SET x=x+1; + END; + INSERT INTO t1 VALUES(1, 2); + } "main.t4" + + 2 { + CREATE TRIGGER aux.tr1 AFTER INSERT ON t5 BEGIN + UPDATE t4 SET x=x+1; + END; + INSERT INTO t5 VALUES(1, 2); + } "aux.t4" +} +do_execsql_test e_update-2.2.X { + DROP TRIGGER tr1; + DROP TRIGGER aux.tr1; +} {} + +# EVIDENCE-OF: R-29512-54644 If the table to which the trigger is +# attached is in the TEMP database, then the unqualified name of the +# table being updated is resolved in the same way as it is for a +# top-level statement (by searching first the TEMP database, then the +# main database, then any other databases in the order they were +# attached). +# +do_execsql_test e_update-2.3.0 { + SELECT 'main', tbl_name FROM main.sqlite_master WHERE type = 'table'; + SELECT 'temp', tbl_name FROM sqlite_temp_master WHERE type = 'table'; + SELECT 'aux', tbl_name FROM aux.sqlite_master WHERE type = 'table'; +} [list {*}{ + main t1 + main t2 + main t3 + main t6 + temp t4 + temp t6 + aux t1 + aux t5 +}] +do_execsql_test e_update-2.3.1 { + DELETE FROM main.t6; + DELETE FROM temp.t6; + INSERT INTO main.t6 VALUES(1, 2); + INSERT INTO temp.t6 VALUES(1, 2); + + CREATE TRIGGER temp.tr1 AFTER INSERT ON t4 BEGIN + UPDATE t6 SET x=x+1; + END; + + INSERT INTO t4 VALUES(1, 2); + SELECT * FROM main.t6; + SELECT * FROM temp.t6; +} {1 2 2 2} +do_execsql_test e_update-2.3.2 { + DELETE FROM main.t1; + DELETE FROM aux.t1; + INSERT INTO main.t1 VALUES(1, 2); + INSERT INTO aux.t1 VALUES(1, 2); + + CREATE TRIGGER temp.tr2 AFTER DELETE ON t4 BEGIN + UPDATE t1 SET a=a+1; + END; + + DELETE FROM t4; + SELECT * FROM main.t1; + SELECT * FROM aux.t1; +} {2 2 1 2} +do_execsql_test e_update-2.3.3 { + DELETE FROM aux.t5; + INSERT INTO aux.t5 VALUES(1, 2); + + INSERT INTO t4 VALUES('x', 'y'); + CREATE TRIGGER temp.tr3 AFTER UPDATE ON t4 BEGIN + UPDATE t5 SET a=a+1; + END; + + UPDATE t4 SET x=10; + SELECT * FROM aux.t5; +} {2 2} + +# EVIDENCE-OF: R-19619-42762 The INDEXED BY and NOT INDEXED clauses are +# not allowed on UPDATE statements within triggers. +# +do_update_tests e_update-2.4 -error { + the %s %s clause is not allowed on UPDATE or DELETE statements within triggers +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 INDEXED BY i1 SET a=a+1; + END; + } {INDEXED BY} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 NOT INDEXED SET a=a+1; + END; + } {NOT INDEXED} +} + +ifcapable update_delete_limit { + +# EVIDENCE-OF: R-57359-59558 The LIMIT and ORDER BY clauses for UPDATE +# are unsupported within triggers, regardless of the compilation options +# used to build SQLite. +# +do_update_tests e_update-2.5 -error { + near "%s": syntax error +} { + 1 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 LIMIT 10; + END; + } {LIMIT} + + 2 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 ORDER BY a LIMIT 10; + END; + } {ORDER} + + 3 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 ORDER BY a LIMIT 10 OFFSET 2; + END; + } {ORDER} + + 4 { + CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN + UPDATE t1 SET a=a+1 LIMIT 10 OFFSET 2; + END; + } {LIMIT} +} + +# EVIDENCE-OF: R-59581-44104 If SQLite is built with the +# SQLITE_ENABLE_UPDATE_DELETE_LIMIT compile-time option then the syntax +# of the UPDATE statement is extended with optional ORDER BY and LIMIT +# clauses +# +# -- syntax diagram update-stmt-limited +# +do_update_tests e_update-3.0 { + 1 "UPDATE t1 SET a=b LIMIT 5" {} + 2 "UPDATE t1 SET a=b LIMIT 5-1 OFFSET 2+2" {} + 3 "UPDATE t1 SET a=b LIMIT 2+2, 16/4" {} + 4 "UPDATE t1 SET a=b ORDER BY a LIMIT 5" {} + 5 "UPDATE t1 SET a=b ORDER BY a LIMIT 5-1 OFFSET 2+2" {} + 6 "UPDATE t1 SET a=b ORDER BY a LIMIT 2+2, 16/4" {} + 7 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5" {} + 8 "UPDATE t1 SET a=b WHERE a>2 LIMIT 5-1 OFFSET 2+2" {} + 9 "UPDATE t1 SET a=b WHERE a>2 LIMIT 2+2, 16/4" {} + 10 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 5" {} + 11 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 5-1 OFFSET 2+2" {} + 12 "UPDATE t1 SET a=b WHERE a>2 ORDER BY a LIMIT 2+2, 16/4" {} +} + +do_execsql_test e_update-3.1.0 { + CREATE TABLE t7(q, r, s); + INSERT INTO t7 VALUES(1, 'one', 'X'); + INSERT INTO t7 VALUES(2, 'two', 'X'); + INSERT INTO t7 VALUES(3, 'three', 'X'); + INSERT INTO t7 VALUES(4, 'four', 'X'); + INSERT INTO t7 VALUES(5, 'five', 'X'); + INSERT INTO t7 VALUES(6, 'six', 'X'); + INSERT INTO t7 VALUES(7, 'seven', 'X'); + INSERT INTO t7 VALUES(8, 'eight', 'X'); + INSERT INTO t7 VALUES(9, 'nine', 'X'); + INSERT INTO t7 VALUES(10, 'ten', 'X'); +} {} + +# EVIDENCE-OF: R-58862-44169 If an UPDATE statement has a LIMIT clause, +# the maximum number of rows that will be updated is found by evaluating +# the accompanying expression and casting it to an integer value. +# +do_update_tests e_update-3.1 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT 5" {1 2 3 4 5 X X X X X} + 2 "UPDATE t7 SET s = r WHERE q>2 LIMIT 4" {1 2 three four five six X X X X} + 3 "UPDATE t7 SET s = q LIMIT 0" {1 2 three four five six X X X X} +} + +# EVIDENCE-OF: R-63582-45120 A negative value is interpreted as "no limit". +# +do_update_tests e_update-3.2 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 2 "UPDATE t7 SET s = r WHERE q>4 LIMIT -1" + {1 2 3 4 five six seven eight nine ten} + 3 "UPDATE t7 SET s = 'X' LIMIT -1" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-18628-11938 If the LIMIT expression evaluates to +# non-negative value N and the UPDATE statement has an ORDER BY clause, +# then all rows that would be updated in the absence of the LIMIT clause +# are sorted according to the ORDER BY and the first N updated. +# +do_update_tests e_update-3.3 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q ORDER BY r LIMIT 3" {X X X 4 5 X X 8 X X} + 2 "UPDATE t7 SET s = r ORDER BY r DESC LIMIT 2" {X two three 4 5 X X 8 X X} + 3 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {X two three 4 5 6 7 8 9 10} + + X "UPDATE t7 SET s = 'X'" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-30955-38324 If the UPDATE statement also has an OFFSET +# clause, then it is similarly evaluated and cast to an integer value. +# If the OFFSET expression evaluates to a non-negative value M, then the +# first M rows are skipped and the following N rows updated instead. +# +do_update_tests e_update-3.3 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q ORDER BY q LIMIT 3 OFFSET 2" {X X 3 4 5 X X X X X} + 2 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 2, 3 " {X X 3 4 5 6 7 8 X X} + + X "UPDATE t7 SET s = 'X'" {X X X X X X X X X X} +} + +# EVIDENCE-OF: R-19486-35828 If the UPDATE statement has no ORDER BY +# clause, then all rows that would be updated in the absence of the +# LIMIT clause are assembled in an arbitrary order before applying the +# LIMIT and OFFSET clauses to determine which are actually updated. +# +# In practice, "arbitrary order" is rowid order. This is also tested +# by e_update-3.2.* above. +# +do_update_tests e_update-3.4 -query { SELECT s FROM t7 } { + 1 "UPDATE t7 SET s = q LIMIT 4, 2" {X X X X 5 6 X X X X} + 2 "UPDATE t7 SET s = q LIMIT 2 OFFSET 7" {X X X X 5 6 X 8 9 X} +} + +# EVIDENCE-OF: R-10927-26133 The ORDER BY clause on an UPDATE statement +# is used only to determine which rows fall within the LIMIT. The order +# in which rows are modified is arbitrary and is not influenced by the +# ORDER BY clause. +# +do_execsql_test e_update-3.5.0 { + CREATE TABLE t8(x); + CREATE TRIGGER tr7 BEFORE UPDATE ON t7 BEGIN + INSERT INTO t8 VALUES(old.q); + END; +} {} +do_update_tests e_update-3.5 -query { SELECT x FROM t8 ; DELETE FROM t8 } { + 1 "UPDATE t7 SET s = q ORDER BY r LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 2 "UPDATE t7 SET s = q ORDER BY r ASC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 3 "UPDATE t7 SET s = q ORDER BY r DESC LIMIT -1" {1 2 3 4 5 6 7 8 9 10} + 4 "UPDATE t7 SET s = q ORDER BY q DESC LIMIT 5" {6 7 8 9 10} +} + + +} ;# ifcapable update_delete_limit + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_vacuum.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_vacuum.test new file mode 100644 index 0000000000000000000000000000000000000000..63bf7c125f050d908c44a41ddce8be1b6edd6f44 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_vacuum.test @@ -0,0 +1,347 @@ +# 2010 September 24 +# +# 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 to verify that the "testable statements" in +# the lang_vacuum.html document are correct. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +sqlite3_test_control_pending_byte 0x1000000 + +proc create_db {{sql ""}} { + catch { db close } + forcedelete test.db + sqlite3 db test.db + + db transaction { + execsql { PRAGMA page_size = 1024; } + execsql $sql + execsql { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES(1, randomblob(400)); + INSERT INTO t1 SELECT a+1, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+2, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+4, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+8, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+16, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+32, randomblob(400) FROM t1; + INSERT INTO t1 SELECT a+64, randomblob(400) FROM t1; + + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 SELECT * FROM t1; + } + } + + return [expr {[file size test.db] / 1024}] +} + +# This proc returns the number of contiguous blocks of pages that make up +# the table or index named by the only argument. For example, if the table +# occupies database pages 3, 4, 8 and 9, then this command returns 2 (there +# are 2 fragments - one consisting of pages 3 and 4, the other of fragments +# 8 and 9). +# +proc fragment_count {name} { + execsql { CREATE VIRTUAL TABLE temp.stat USING dbstat } + set nFrag 1 + db eval {SELECT pageno FROM stat WHERE name = 't1' ORDER BY pageno} { + if {[info exists prevpageno] && $prevpageno != $pageno-1} { + incr nFrag + } + set prevpageno $pageno + } + execsql { DROP TABLE temp.stat } + set nFrag +} + + +# -- syntax diagram vacuum-stmt +# +do_execsql_test e_vacuum-0.1 { VACUUM } {} + +# EVIDENCE-OF: R-51469-36013 Unless SQLite is running in +# "auto_vacuum=FULL" mode, when a large amount of data is deleted from +# the database file it leaves behind empty space, or "free" database +# pages. +# +# EVIDENCE-OF: R-60541-63059 Running VACUUM to rebuild the database +# reclaims this space and reduces the size of the database file. +# +foreach {tn avmode sz} { + 1 none 7 + 2 full 8 + 3 incremental 8 +} { + set nPage [create_db "PRAGMA auto_vacuum = $avmode"] + + do_execsql_test e_vacuum-1.1.$tn.1 { + DELETE FROM t1; + DELETE FROM t2; + } {} + + if {$avmode == "full"} { + # This branch tests the "unless ... auto_vacuum=FULL" in the requirement + # above. If auto_vacuum is set to FULL, then no empty space is left in + # the database file. + do_execsql_test e_vacuum-1.1.$tn.2 {PRAGMA freelist_count} 0 + } else { + set freelist [expr {$nPage - $sz}] + if {$avmode == "incremental"} { + # The page size is 1024 bytes. Therefore, assuming the database contains + # somewhere between 207 and 411 pages (it does), there are 2 pointer-map + # pages. + incr freelist -2 + } + do_execsql_test e_vacuum-1.1.$tn.3 {PRAGMA freelist_count} $freelist + do_execsql_test e_vacuum-1.1.$tn.4 {VACUUM} {} + } + + do_test e_vacuum-1.1.$tn.5 { expr {[file size test.db] / 1024} } $sz +} + +# EVIDENCE-OF: R-50943-18433 Frequent inserts, updates, and deletes can +# cause the database file to become fragmented - where data for a single +# table or index is scattered around the database file. +# +# EVIDENCE-OF: R-05791-54928 Running VACUUM ensures that each table and +# index is largely stored contiguously within the database file. +# +# e_vacuum-1.2.1 - Perform many INSERT, UPDATE and DELETE ops on table t1. +# e_vacuum-1.2.2 - Verify that t1 and its indexes are now quite fragmented. +# e_vacuum-1.2.3 - Run VACUUM. +# e_vacuum-1.2.4 - Verify that t1 and its indexes are now much +# less fragmented. +# +ifcapable vtab&&compound { + create_db + register_dbstat_vtab db + do_execsql_test e_vacuum-1.2.1 { + DELETE FROM t1 WHERE a%2; + INSERT INTO t1 SELECT b, a FROM t2 WHERE a%2; + UPDATE t1 SET b=randomblob(600) WHERE (a%2)==0; + } {} + + do_test e_vacuum-1.2.2.1 { expr [fragment_count t1]>100 } 1 + do_test e_vacuum-1.2.2.2 { expr [fragment_count sqlite_autoindex_t1_1]>100 } 1 + do_test e_vacuum-1.2.2.3 { expr [fragment_count sqlite_autoindex_t1_2]>100 } 1 + + do_execsql_test e_vacuum-1.2.3 { VACUUM } {} + + # In practice, the tables and indexes each end up stored as two fragments - + # one containing the root page and another containing all other pages. + # + do_test e_vacuum-1.2.4.1 { fragment_count t1 } 2 + do_test e_vacuum-1.2.4.2 { fragment_count sqlite_autoindex_t1_1 } 2 + do_test e_vacuum-1.2.4.3 { fragment_count sqlite_autoindex_t1_2 } 2 +} + +# EVIDENCE-OF: R-20474-44465 Normally, the database page_size and +# whether or not the database supports auto_vacuum must be configured +# before the database file is actually created. +# +do_test e_vacuum-1.3.1.1 { + create_db "PRAGMA page_size = 1024 ; PRAGMA auto_vacuum = FULL" + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } +} {1024 1} +do_test e_vacuum-1.3.1.2 { + execsql { PRAGMA page_size = 2048 } + execsql { PRAGMA auto_vacuum = NONE } + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } +} {1024 1} + +if {![nonzero_reserved_bytes]} { + # EVIDENCE-OF: R-08570-19916 However, when not in write-ahead log mode, + # the page_size and/or auto_vacuum properties of an existing database + # may be changed by using the page_size and/or pragma auto_vacuum + # pragmas and then immediately VACUUMing the database. + # + do_test e_vacuum-1.3.2.1 { + execsql { PRAGMA journal_mode = delete } + execsql { PRAGMA page_size = 2048 } + execsql { PRAGMA auto_vacuum = NONE } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + + # EVIDENCE-OF: R-48521-51450 When in write-ahead log mode, only the + # auto_vacuum support property can be changed using VACUUM. + # + if {[wal_is_capable]} { + do_test e_vacuum-1.3.3.1 { + execsql { PRAGMA journal_mode = wal } + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 0} + do_test e_vacuum-1.3.3.2 { + execsql { PRAGMA page_size = 1024 } + execsql { PRAGMA auto_vacuum = FULL } + execsql VACUUM + execsql { PRAGMA page_size ; PRAGMA auto_vacuum } + } {2048 1} + } +} + +# EVIDENCE-OF: R-40347-36128 By default, VACUUM operates on the main +# database. +forcedelete test.db2 +create_db { PRAGMA auto_vacuum = NONE } +do_execsql_test e_vacuum-2.1.1 { + ATTACH 'test.db2' AS aux; + PRAGMA aux.page_size = 1024; + CREATE TABLE aux.t3 AS SELECT * FROM t1; + DELETE FROM t3; +} {} +set original_size [file size test.db2] + +# Vacuuming the main database does not affect aux +do_execsql_test e_vacuum-2.1.3 { VACUUM } {} +do_test e_vacuum-2.1.6 { expr {[file size test.db2]==$::original_size} } 1 + +# EVIDENCE-OF: R-36598-60500 Attached databases can be vacuumed by +# appending the appropriate schema-name to the VACUUM statement. +do_execsql_test e_vacuum-2.1.7 { VACUUM aux; } {} +do_test e_vacuum-2.1.8 { expr {[file size test.db2]<$::original_size} } 1 + +# EVIDENCE-OF: R-17495-17419 The VACUUM command may change the ROWIDs of +# entries in any tables that do not have an explicit INTEGER PRIMARY +# KEY. +# +# Tests e_vacuum-3.1.1 - 3.1.2 demonstrate that rowids can change when +# a database is VACUUMed. Tests e_vacuum-3.1.3 - 3.1.4 show that adding +# an INTEGER PRIMARY KEY column to a table stops this from happening. +# +# Update 2019-01-07: Rowids are now preserved by VACUUM. +# +do_execsql_test e_vacuum-3.1.1 { + CREATE TABLE t4(x); + INSERT INTO t4(x) VALUES('x'); + INSERT INTO t4(x) VALUES('y'); + INSERT INTO t4(x) VALUES('z'); + DELETE FROM t4 WHERE x = 'y'; + SELECT rowid, x FROM t4; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.2 { + VACUUM; + SELECT rowid, x FROM t4; +} {1 x 2 z} + +# Rowids are preserved if an INTEGER PRIMARY KEY is used +do_execsql_test e_vacuum-3.1.3 { + CREATE TABLE t5(x, y INTEGER PRIMARY KEY); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + DELETE FROM t5 WHERE x = 'y'; + SELECT rowid, x FROM t5; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.4 { + VACUUM; + SELECT rowid, x FROM t5; +} {1 x 3 z} + +# Rowid is preserved for VACUUM INTO +do_execsql_test e_vacuum-3.1.5 { + DROP TABLE t5; + CREATE TABLE t5(x); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + DELETE FROM t5 WHERE x = 'y'; + SELECT rowid, x FROM t5; +} {1 x 3 z} +forcedelete test2.db +do_execsql_test e_vacuum-3.1.6 { + VACUUM INTO 'test2.db'; + ATTACH 'test2.db' AS aux1; + SELECT rowid, x FROM aux1.t5; + DETACH aux1; +} {1 x 3 z} + +# Rowids are not renumbered if the table being vacuumed +# has indexes. +do_execsql_test e_vacuum-3.1.7 { + DROP TABLE t5; + CREATE TABLE t5(x,y,z); + INSERT INTO t5(x) VALUES('x'); + INSERT INTO t5(x) VALUES('y'); + INSERT INTO t5(x) VALUES('z'); + UPDATE t5 SET y=x, z=random(); + DELETE FROM t5 WHERE x = 'y'; + CREATE INDEX t5x ON t5(x); + CREATE UNIQUE INDEX t5y ON t5(y); + CREATE INDEX t5zxy ON t5(z,x,y); + SELECT rowid, x FROM t5; +} {1 x 3 z} +do_execsql_test e_vacuum-3.1.8 { + VACUUM; + SELECT rowid, x FROM t5; +} {1 x 3 z} + +# EVIDENCE-OF: R-12218-18073 A VACUUM will fail if there is an open +# transaction on the database connection that is attempting to run the +# VACUUM. +# +do_execsql_test e_vacuum-3.2.1.1 { BEGIN } {} +do_catchsql_test e_vacuum-3.2.1.2 { + VACUUM +} {1 {cannot VACUUM from within a transaction}} +do_execsql_test e_vacuum-3.2.1.3 { COMMIT } {} +do_execsql_test e_vacuum-3.2.1.4 { VACUUM } {} +do_execsql_test e_vacuum-3.2.1.5 { SAVEPOINT x } {} +do_catchsql_test e_vacuum-3.2.1.6 { + VACUUM +} {1 {cannot VACUUM from within a transaction}} +do_execsql_test e_vacuum-3.2.1.7 { COMMIT } {} +do_execsql_test e_vacuum-3.2.1.8 { VACUUM } {} + +create_db +do_test e_vacuum-3.2.2.1 { + set res "" + db eval { SELECT a FROM t1 } { + if {$a == 10} { set res [catchsql VACUUM] } + } + set res +} {1 {cannot VACUUM - SQL statements in progress}} + + +# EVIDENCE-OF: R-55138-13241 An alternative to using the VACUUM command +# to reclaim space after data has been deleted is auto-vacuum mode, +# enabled using the auto_vacuum pragma. +# +do_test e_vacuum-3.3.1 { + create_db { PRAGMA auto_vacuum = FULL } + execsql { PRAGMA auto_vacuum } +} {1} + +# EVIDENCE-OF: R-64844-34873 When auto_vacuum is enabled for a database +# free pages may be reclaimed after deleting data, causing the file to +# shrink, without rebuilding the entire database using VACUUM. +# +do_test e_vacuum-3.3.2.1 { + create_db { PRAGMA auto_vacuum = FULL } + execsql { + DELETE FROM t1; + DELETE FROM t2; + } + expr {[file size test.db] / 1024} +} {8} +do_test e_vacuum-3.3.2.2 { + create_db { PRAGMA auto_vacuum = INCREMENTAL } + execsql { + DELETE FROM t1; + DELETE FROM t2; + PRAGMA incremental_vacuum; + } + expr {[file size test.db] / 1024} +} {8} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_wal.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_wal.test new file mode 100644 index 0000000000000000000000000000000000000000..c9c5e9643fcf8a2483f4a929b6d5fa66afb397ab --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_wal.test @@ -0,0 +1,231 @@ +# 2011 May 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix e_wal + +db close +forcedelete test.db-shm +testvfs oldvfs -iversion 1 + + +# EVIDENCE-OF: R-58297-14483 WAL databases can be created, read, and +# written even if shared memory is unavailable as long as the +# locking_mode is set to EXCLUSIVE before the first attempted access. +# +# EVIDENCE-OF: R-00449-33772 This feature allows WAL databases to be +# created, read, and written by legacy VFSes that lack the "version 2" +# shared-memory methods xShmMap, xShmLock, xShmBarrier, and xShmUnmap on +# the sqlite3_io_methods object. +# +# 1.1: "create" tests. +# 1.2: "read" tests. +# 1.3: "write" tests. +# +# All three done with VFS "oldvfs", which has iVersion==1 and so does +# not support shared memory. +# +sqlite3 db test.db -vfs oldvfs +do_execsql_test 1.1.1 { + PRAGMA journal_mode = WAL; +} {delete} +do_execsql_test 1.1.2 { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA journal_mode = WAL; +} {exclusive wal} +do_execsql_test 1.1.3 { + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1, 2); +} {} +do_test 1.1.4 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +do_test 1.2.1 { + db close + sqlite3 db test.db -vfs oldvfs + catchsql { SELECT * FROM t1 } +} {1 {unable to open database file}} +do_test 1.2.2 { + execsql { PRAGMA locking_mode = EXCLUSIVE } + execsql { SELECT * FROM t1 } +} {1 2} +do_test 1.2.3 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +do_test 1.3.1 { + db close + sqlite3 db test.db -vfs oldvfs + catchsql { INSERT INTO t1 VALUES(3, 4) } +} {1 {unable to open database file}} +do_test 1.3.2 { + execsql { PRAGMA locking_mode = EXCLUSIVE } + execsql { INSERT INTO t1 VALUES(3, 4) } + execsql { SELECT * FROM t1 } +} {1 2 3 4} +do_test 1.3.3 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +# EVIDENCE-OF: R-31969-57825 If EXCLUSIVE locking mode is set prior to +# the first WAL-mode database access, then SQLite never attempts to call +# any of the shared-memory methods and hence no shared-memory wal-index +# is ever created. +# +db close +sqlite3 db test.db +do_execsql_test 2.1.1 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM t1; +} {exclusive 1 2 3 4} +do_test 2.1.2 { + list [file exists test.db-shm] [file exists test.db-wal] +} {0 1} + +# EVIDENCE-OF: R-36328-16367 In that case, the database connection +# remains in EXCLUSIVE mode as long as the journal mode is WAL; attempts +# to change the locking mode using "PRAGMA locking_mode=NORMAL;" are +# no-ops. +# +do_execsql_test 2.2.1 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {exclusive 1 2 3 4} +do_test 2.2.2 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {1 {database is locked}} +db2 close + +# EVIDENCE-OF: R-63522-46088 The only way to change out of EXCLUSIVE +# locking mode is to first change out of WAL journal mode. +# +do_execsql_test 2.3.1 { + PRAGMA journal_mode = DELETE; + SELECT * FROM t1; +} {delete 1 2 3 4} +do_test 2.3.2 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {1 {database is locked}} +do_execsql_test 2.3.3 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {normal 1 2 3 4} +do_test 2.3.4 { + sqlite3 db2 test.db + catchsql {SELECT * FROM t1} db2 +} {0 {1 2 3 4}} +db2 close +db close + + +# EVIDENCE-OF: R-57239-11845 If NORMAL locking mode is in effect for the +# first WAL-mode database access, then the shared-memory wal-index is +# created. +# +do_test 3.0 { + sqlite3 db test.db + execsql { PRAGMA journal_mode = WAL } + db close +} {} +do_test 3.1 { + sqlite3 db test.db + execsql { SELECT * FROM t1 } + list [file exists test.db-shm] [file exists test.db-wal] +} {1 1} + +# EVIDENCE-OF: R-13779-07711 As long as exactly one connection is using +# a shared-memory wal-index, the locking mode can be changed freely +# between NORMAL and EXCLUSIVE. +# +do_execsql_test 3.2.1 { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA locking_mode = NORMAL; + PRAGMA locking_mode = EXCLUSIVE; + INSERT INTO t1 VALUES(5, 6); +} {exclusive normal exclusive} +do_test 3.2.2 { + sqlite3 db2 test.db + catchsql { SELECT * FROM t1 } db2 +} {1 {database is locked}} + +# EVIDENCE-OF: R-10993-11647 It is only when the shared-memory wal-index +# is omitted, when the locking mode is EXCLUSIVE prior to the first +# WAL-mode database access, that the locking mode is stuck in EXCLUSIVE. +# +do_execsql_test 3.2.3 { + PRAGMA locking_mode = NORMAL; + SELECT * FROM t1; +} {normal 1 2 3 4 5 6} +do_test 3.2.4 { + catchsql { SELECT * FROM t1 } db2 +} {0 {1 2 3 4 5 6}} + +do_catchsql_test 3.2.5 { + PRAGMA locking_mode = EXCLUSIVE; + INSERT INTO t1 VALUES(7, 8); +} {1 {database is locked}} + +db2 close + +# EVIDENCE-OF: R-46197-42811 This means that the underlying VFS must +# support the "version 2" shared-memory. +# +# EVIDENCE-OF: R-55316-21772 If the VFS does not support shared-memory +# methods, then the attempt to open a database that is already in WAL +# mode, or the attempt convert a database into WAL mode, will fail. +# +db close +do_test 3.4.1 { + sqlite3 db test.db -vfs oldvfs + catchsql { SELECT * FROM t1 } +} {1 {unable to open database file}} +db close +do_test 3.4.2 { + forcedelete test.db2 + sqlite3 db test.db2 -vfs oldvfs + catchsql { PRAGMA journal_mode = WAL } +} {0 delete} +db close + + +# EVIDENCE-OF: R-45540-25505 To prevent older versions of SQLite (prior +# to version 3.7.0, 2010-07-22) from trying to recover a WAL-mode +# database (and making matters worse) the database file format version +# numbers (bytes 18 and 19 in the database header) are increased from 1 +# to 2 in WAL mode. +# +reset_db +do_execsql_test 4.1.1 { CREATE TABLE t1(x, y) } +do_test 4.1.2 { hexio_read test.db 18 2 } {0101} +do_execsql_test 4.1.3 { PRAGMA journal_mode = wAL } {wal} +do_test 4.1.4 { hexio_read test.db 18 2 } {0202} + + +# EVIDENCE-OF: R-02535-05811 One can explicitly change out of WAL mode +# using a pragma such as this: PRAGMA journal_mode=DELETE; +# +do_execsql_test 4.2.1 { INSERT INTO t1 VALUES(1, 1); } {} +do_test 4.2.2 { file exists test.db-wal } {1} +do_execsql_test 4.2.3 { PRAGMA journal_mode = delete } {delete} +do_test 4.2.4 { file exists test.db-wal } {0} + +# EVIDENCE-OF: R-60175-02388 Deliberately changing out of WAL mode +# changes the database file format version numbers back to 1 so that +# older versions of SQLite can once again access the database file. +# +do_test 4.3 { hexio_read test.db 18 2 } {0101} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walauto.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walauto.test new file mode 100644 index 0000000000000000000000000000000000000000..7665b1bf735f96ba70a0af31d9c43d819b11902b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walauto.test @@ -0,0 +1,214 @@ +# 2014 December 04 +# +# 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 +source $testdir/wal_common.tcl +set testprefix e_walauto + +# Do not run this test on OpenBSD, as it depends on read() and mmap both +# accessing the same coherent view of the "test.db-shm" file. This doesn't +# work on OpenBSD. +# +if {$tcl_platform(os) == "OpenBSD"} { + finish_test + return +} + +# This module uses hard-coded offsets which do not work if the reserved_bytes +# value is nonzero. +if {[nonzero_reserved_bytes]} {finish_test; return;} + + +proc read_nbackfill {} { + seek $::shmfd 96 + binary scan [read $::shmfd 4] n nBackfill + set nBackfill +} +proc read_mxframe {} { + seek $::shmfd 16 + binary scan [read $::shmfd 4] n mxFrame + set mxFrame +} + +# Assuming that the main db for database handle +# +proc do_autocommit_threshold_test {tn value} { + + set nBackfillSaved [read_nbackfill] + while {1} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + if {[read_mxframe] >= $value} break + } + + set nBackfillNew [read_nbackfill] + uplevel [list do_test $tn "expr $nBackfillNew > $nBackfillSaved" 1] +} + +# EVIDENCE-OF: R-30135-06439 The wal_autocheckpoint pragma can be used +# to invoke this interface from SQL. +# +# All tests in this file are run twice - once using the +# sqlite3_wal_autocheckpoint() API, and once using "PRAGMA +# wal_autocheckpoint". +# +foreach {tn code} { + 1 { + proc autocheckpoint {db value} { + uplevel [list $db eval "PRAGMA wal_autocheckpoint = $value"] + } + } + + 2 { + proc autocheckpoint {db value} { + uplevel [list sqlite3_wal_autocheckpoint $db $value] + return $value + } + } +} { + + eval $code + + reset_db + execsql { PRAGMA auto_vacuum = 0 } + do_execsql_test 1.$tn.0 { PRAGMA journal_mode = WAL } {wal} + do_execsql_test 1.$tn.1 { CREATE TABLE t1(a, b) } + set shmfd [open "test.db-shm" rb] + + # EVIDENCE-OF: R-41531-51083 Every new database connection defaults to + # having the auto-checkpoint enabled with a threshold of 1000 or + # SQLITE_DEFAULT_WAL_AUTOCHECKPOINT pages. + # + do_autocommit_threshold_test 1.$tn.2 1000 + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + do_autocommit_threshold_test 1.$tn.3 1000 + + # EVIDENCE-OF: R-38128-34102 The sqlite3_wal_autocheckpoint(D,N) is a + # wrapper around sqlite3_wal_hook() that causes any database on database + # connection D to automatically checkpoint after committing a + # transaction if there are N or more frames in the write-ahead log file. + # + do_test 1.$tn.4 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + autocheckpoint db 100 + } {100} + do_autocommit_threshold_test 1.$tn.5 100 + + do_test 1.$tn.6 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + autocheckpoint db 500 + } {500} + do_autocommit_threshold_test 1.$tn.7 500 + + # EVIDENCE-OF: R-26993-43540 Passing zero or a negative value as the + # nFrame parameter disables automatic checkpoints entirely. + # + do_test 1.$tn.7 { + autocheckpoint db 0 ;# Set to zero + for {set i 0} {$i < 10000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] > (5 * 1024 * 1024)} + } 1 + do_test 1.$tn.8 { + sqlite3_wal_checkpoint_v2 db truncate + file size test.db-wal + } 0 + do_test 1.$tn.9 { + autocheckpoint db -4 ;# Set to a negative value + for {set i 0} {$i < 10000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] > (5 * 1024 * 1024)} + } 1 + + # EVIDENCE-OF: R-10203-42688 The callback registered by this function + # replaces any existing callback registered using sqlite3_wal_hook(). + # + set ::wal_hook_callback 0 + proc wal_hook_callback {args} { incr ::wal_hook_callback ; return 0 } + do_test 1.$tn.10.1 { + db wal_hook wal_hook_callback + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + set ::wal_hook_callback + } 2 + do_test 1.$tn.10.2 { + autocheckpoint db 100 + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + set ::wal_hook_callback + } 2 + + # EVIDENCE-OF: R-17497-43474 Likewise, registering a callback using + # sqlite3_wal_hook() disables the automatic checkpoint mechanism + # configured by this function. + do_test 1.$tn.11.1 { + sqlite3_wal_checkpoint_v2 db truncate + file size test.db-wal + } 0 + do_test 1.$tn.11.2 { + autocheckpoint db 100 + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] < (1 * 1024 * 1024)} + } 1 + do_test 1.$tn.11.3 { + db wal_hook wal_hook_callback + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + expr {[file size test.db-wal] < (1 * 1024 * 1024)} + } 0 + + # EVIDENCE-OF: R-33080-59193 Checkpoints initiated by this mechanism + # are PASSIVE. + # + set ::busy_callback_count 0 + proc busy_callback {args} { + incr ::busy_callback_count + return 0 + } + do_test 1.$tn.12.1 { + sqlite3_wal_checkpoint_v2 db truncate + autocheckpoint db 100 + db busy busy_callback + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } {} + do_test 1.$tn.12.2 { + sqlite3 db2 test.db + db2 eval { BEGIN; SELECT * FROM t1 LIMIT 10; } + read_nbackfill + } {0} + do_test 1.$tn.12.3 { + for {set i 0} {$i < 1000} {incr i} { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + } + read_nbackfill + } {2} + do_test 1.$tn.12.4 { + set ::busy_callback_count + } {0} + db2 close + + do_test 1.$tn.12.5 { + db eval { INSERT INTO t1 VALUES(randomblob(100), randomblob(100)) } + read_nbackfill + } {1559} + + db close + close $shmfd +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walckpt.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walckpt.test new file mode 100644 index 0000000000000000000000000000000000000000..3b1f3b015a6a8ee48d22f73b2128e6c8d6ccb86a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walckpt.test @@ -0,0 +1,753 @@ +# 2014 December 04 +# +# 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 +source $testdir/lock_common.tcl +source $testdir/wal_common.tcl +set testprefix e_walckpt + +# The following two commands are used to determine if any of the files +# "test.db", "test.db2" and "test.db3" are modified by a test case. +# +# The [save_db_hashes] command saves a hash of the current contents of +# all three files in global variables. The [compare_db_hashes] compares +# the current contents with the saved hashes and returns a list of the +# files that have changed. +# +proc save_db_hashes {} { + global H + foreach f {test.db test.db2 test.db3} { + set H($f) 0 + catch { set H($f) [md5file $f] } + } +} +proc compare_db_hashes {} { + global H + set ret [list] + foreach f {test.db test.db2 test.db3} { + set expect 0 + catch { set expect [md5file $f] } + if {$H($f) != $expect} { lappend ret $f } + } + set ret +} + +#------------------------------------------------------------------------- +# All calls to the [sqlite3_wal_checkpoint_v2] command made within this +# file use this wrapper. It's sole purpose is to throw an error if the +# following requirement is violated: +# +# EVIDENCE-OF: R-60567-47780 Unless it returns SQLITE_MISUSE, the +# sqlite3_wal_checkpoint_v2() interface sets the error information that +# is queried by sqlite3_errcode() and sqlite3_errmsg(). +# +proc wal_checkpoint_v2 {db args} { + set rc [catch { + uplevel sqlite3_wal_checkpoint_v2 $db $args + } msg] + + set errcode "SQLITE_OK" + if {$rc} { + set errcode [lindex [split $msg " "] 0] + } elseif { [lindex $msg 0] } { + set errcode "SQLITE_BUSY" + } + + if {$errcode != "SQLITE_MISUSE" && [sqlite3_errcode $db] != $errcode} { + error "sqlite3_errcode mismatch! (1) $errcode!=[sqlite3_errcode $db]" + } + + if {$rc==0} { + return $msg + } else { + error $msg + } +} + + +# The following tests are run 3 times, each using a different method of +# invoking a checkpoint: +# +# 1) Using sqlite3_wal_checkpoint_v2() +# 2) Using "PRAGMA wal_checkpoint" +# 3) Using sqlite3_wal_checkpoint() in place of checkpoint_v2(PASSIVE) +# +# Cases (2) and (3) are to show that the following statements are +# correct, respectively: +# +# EVIDENCE-OF: R-36706-10507 The PRAGMA wal_checkpoint command can be +# used to invoke this interface from SQL. +# +# EVIDENCE-OF: R-41613-20553 The sqlite3_wal_checkpoint(D,X) is +# equivalent to +# sqlite3_wal_checkpoint_v2(D,X,SQLITE_CHECKPOINT_PASSIVE,0,0). +# +foreach {tn script} { + 1 { + proc checkpoint {db mode args} { + eval wal_checkpoint_v2 [list $db] [list $mode] $args + } + } + + 2 { + proc checkpoint {db mode args} { + set sql "PRAGMA wal_checkpoint = $mode" + if {[llength $args] && [lindex $args 0]!=""} { + set sql "PRAGMA [lindex $args 0].wal_checkpoint = $mode" + } + set rc [catch { $db eval $sql } msg] + if {$rc} { + regsub {database} $msg {database:} msg + error "[sqlite3_errcode $db] - $msg" + } + set msg + } + } + + 3 { + proc checkpoint {db mode args} { + if {$mode == "passive"} { + set rc [eval sqlite3_wal_checkpoint [list $db] $args] + if {$rc != "SQLITE_OK"} { + error "$rc - [sqlite3_errmsg $db]" + } + } else { + eval wal_checkpoint_v2 [list $db] [list $mode] $args + } + } + } + +} { + + eval $script + + reset_db + forcedelete test.db2 test.db3 test.db4 + execsql { + ATTACH 'test.db2' AS aux; + ATTACH 'test.db3' AS aux2; + ATTACH 'test.db4' AS aux3; + CREATE TABLE t1(x); + CREATE TABLE aux.t2(x); + CREATE TABLE aux2.t3(x); + CREATE TABLE aux3.t4(x); + PRAGMA main.journal_mode = WAL; + PRAGMA aux.journal_mode = WAL; + PRAGMA aux2.journal_mode = WAL; + /* Leave aux4 in rollback mode */ + } + + # EVIDENCE-OF: R-49787-09095 The sqlite3_wal_checkpoint_v2(D,X,M,L,C) + # interface runs a checkpoint operation on database X of database + # connection D in mode M. Status information is written back into + # integers pointed to by L and C. + # + # Tests 1, 2 and 3 below verify the "on database X" part of the + # above. Other parts of this requirement are tested below. + # + # EVIDENCE-OF: R-00653-06026 If parameter zDb is NULL or points to a + # zero length string, then the specified operation is attempted on all + # WAL databases attached to database connection db. + # + # Tests 4 and 5 below test this. + # + foreach {tn2 zDb dblist} { + 1 main test.db + 2 aux test.db2 + 3 aux2 test.db3 + 4 "" {test.db test.db2 test.db3} + 5 - {test.db test.db2 test.db3} + 6 temp {} + } { + do_test $tn.1.$tn2 { + execsql { + INSERT INTO t1 VALUES(1); + INSERT INTO t2 VALUES(2); + INSERT INTO t3 VALUES(3); + } + save_db_hashes + + if {$zDb == "-"} { + checkpoint db passive + } else { + checkpoint db passive $zDb + } + + compare_db_hashes + } $dblist + } + + # EVIDENCE-OF: R-38207-48996 If zDb is not NULL (or a zero length + # string) and is not the name of any attached database, SQLITE_ERROR is + # returned to the caller. + do_test $tn.2.1 { + list [catch { checkpoint db passive notadb } msg] $msg + } {1 {SQLITE_ERROR - unknown database: notadb}} + + # EVIDENCE-OF: R-14303-42483 If database zDb is the name of an attached + # database that is not in WAL mode, SQLITE_OK is returned and both + # *pnLog and *pnCkpt set to -1. + # + if {$tn==3} { + # With sqlite3_wal_checkpoint() the two output variables cannot be + # tested. So just test that no error is returned when attempting to + # checkpoint a db in rollback mode. + do_test $tn.2.2.a { checkpoint db passive aux3 } {} + } else { + do_test $tn.2.2.b { checkpoint db passive aux3 } {0 -1 -1} + } + + # EVIDENCE-OF: R-62028-47212 All calls obtain an exclusive "checkpoint" + # lock on the database file. + db close + testvfs tvfs + tvfs filter xShmLock + tvfs script filelock + proc filelock {method file handle details} { + # Test for an exclusive checkpoint lock. A checkpoint lock locks a + # single byte starting at offset 1. + if {$details == "1 1 lock exclusive"} { set ::seen_checkpoint_lock 1 } + } + sqlite3 db test.db -vfs tvfs + do_test $tn.3.1 { + execsql { INSERT INTO t1 VALUES('xyz') } + unset -nocomplain ::seen_checkpoint_lock + checkpoint db passive + set ::seen_checkpoint_lock + } {1} + db close + tvfs delete + reset_db + + + + + #----------------------------------------------------------------------- + # EVIDENCE-OF: R-10421-19736 If any other process is running a + # checkpoint operation at the same time, the lock cannot be obtained and + # SQLITE_BUSY is returned. + # + # EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured, + # it will not be invoked in this case. + # + testvfs tvfs + tvfs filter xWrite + sqlite3 db test.db -vfs tvfs + sqlite3 db2 test.db -vfs tvfs + + do_test $tn.3.2.1 { + db2 eval { + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(x, y); + INSERT INTO t1 VALUES(1,2); + INSERT INTO t1 VALUES(3,4); + INSERT INTO t1 VALUES(5,6); + } + file size test.db-wal + } [wal_file_size 5 1024] + + + # Connection [db] runs a checkpoint. During this checkpoint, each + # time it calls xWrite() to write a page into the database file, we + # attempt to start a checkpoint using [db2]. According to the + # first requirement being tested, this should return SQLITE_BUSY. According + # to the second, the busy-handler belonging to [db2] should not be + # invoked. + # + set ::write_count 0 + set ::write_errors [list] + proc busy_callback {args} { + lappend ::write_errors "busy handler called!" + } + proc write_callback {args} { + set rc [catch {checkpoint db2 passive} msg] + if {0==[regexp "database is locked" $msg] && $msg!="1 -1 -1"} { + lappend ::write_errors "$rc $msg" + } + incr ::write_count + } + db2 busy busy_callback + tvfs script write_callback + + do_test $tn.3.2.2 { + db eval {SELECT * FROM sqlite_master} + checkpoint db full + set ::write_count + } {2} + + do_test $tn.3.2.3 { + set ::write_errors + } {} + + db close + db2 close + tvfs delete + + proc busy_handler {mode busy_handler_mode n} { + incr ::busy_handler_counter + switch -- $busy_handler_mode { + 1 { + # Do nothing. Do not block. + return 1 + } + + 2 { + # Close first the reader, then later the writer. Give up before + # closing the [db6] reader. + if {$n==5} { catch {db2 eval commit} } + if {$n==10} { catch {db3 eval commit} } + if {$n==15} { return 1 } + return 0 + } + + 3 { + # Close first the writer, then later the reader. And finally the + # [db6] reader. + if {$n==5} { catch {db2 eval commit} } + if {$n==10} { catch {db3 eval commit} } + if {$n==15} { catch {db6 eval commit} } + return 0 + } + } + } + + foreach {mode busy_handler_mode} { + passive 1 + full 1 full 2 full 3 + restart 1 restart 2 restart 3 + truncate 1 truncate 2 truncate 3 + } { + set tp "$tn.$mode.$busy_handler_mode" + + set ::sync_counter 0 + + # Set up a callback function for xSync and xWrite calls made during + # the checkpoint. + # + set ::checkpoint_ongoing 0 + proc tvfs_callback {method args} { + if {$::checkpoint_ongoing==0} return + + set tail [file tail [lindex $args 0]] + if {$method == "xSync" && $tail == "test.db"} { + incr ::sync_counter + } + if {$method == "xWrite" && $tail=="test.db"} { + if {$::write_ok < 0} { + set ::write_ok [expr ![catch {db5 eval { BEGIN IMMEDIATE }}]] + catch { db5 eval ROLLBACK } + } + if {$::read_ok < 0} { + set ::read_ok [expr ![catch {db5 eval { SELECT * FROM t1 }}]] + } + + # If one has not already been opened, open a read-transaction using + # connection [db6] + catch { db6 eval { BEGIN ; SELECT * FROM sqlite_master } } msg + } + if {$method == "xShmLock" } { + set details [lindex $args 2] + if {$details == "0 1 lock exclusive"} { set ::seen_writer_lock 1 } + } + } + + catch { db close } + forcedelete test.db + testvfs tvfs + sqlite3 db test.db -vfs tvfs + #tvfs filter xSync + tvfs script tvfs_callback + + do_execsql_test $tp.0 { + CREATE TABLE t1(a, b); + CREATE TABLE t2(a, b); + PRAGMA journal_mode = wal; + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(3, 4); + INSERT INTO t1 VALUES(5, 6); + } {wal} + + # Open a reader on the current database snapshot. + do_test $tp.1 { + sqlite3 db2 test.db -vfs tvfs + execsql { + BEGIN; + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } db2 + } {1 2 3 4 5 6} + + # Open a writer. Write a transaction. Then begin, but do not commit, + # a second transaction. + do_test $tp.2 { + sqlite3 db3 test.db -vfs tvfs + execsql { + INSERT INTO t2 VALUES(7, 8); + BEGIN; + INSERT INTO t2 VALUES(9, 10); + SELECT * FROM t1 UNION ALL SELECT * FROM t2; + } db3 + } {1 2 3 4 5 6 7 8 9 10} + + sqlite3 db5 test.db -vfs tvfs + sqlite3 db6 test.db -vfs tvfs + + # Register a busy-handler with connection [db]. + # + db busy [list busy_handler $mode $busy_handler_mode] + set ::sync_counter 0 + set ::busy_handler_counter 0 + set ::read_ok -1 + set ::write_ok -1 + set ::seen_writer_lock 0 + + set ::checkpoint_ongoing 1 + do_test $tp.3 { + checkpoint db $mode main + set {} {} + } {} + set ::checkpoint_ongoing 0 + set ::did_restart_blocking [expr {[catch {db6 eval commit}]}] + + if { $mode=="passive" } { + # EVIDENCE-OF: R-16333-64433 Checkpoint as many frames as possible + # without waiting for any database readers or writers to finish, then + # sync the database file if all frames in the log were checkpointed. + # + # "As many frames as possible" means all but the last two transactions + # (the two that write to table t2, of which the scond is unfinished). + # So copying the db file only we see the t1 change, but not the t2 + # modifications. + # + # The busy handler is not invoked (see below) and the db reader and + # writer are still active - so the checkpointer did not wait for either + # readers or writers. As a result the checkpoint was not finished and + # so the db file is not synced. + # + # EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked + # in the SQLITE_CHECKPOINT_PASSIVE mode. + # + # It's not. Test case "$tp.6". + # + do_test $tp.4 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6} + do_test $tp.5 { set ::sync_counter } 0 + do_test $tp.6 { set ::busy_handler_counter } 0 + db4 close + + db2 eval COMMIT + db3 eval COMMIT + + # EVIDENCE-OF: R-65499-53765 On the other hand, passive mode might leave + # the checkpoint unfinished if there are concurrent readers or writers. + # + # The reader and writer have now dropped their locks. And so a + # checkpoint now is able to checkpoint more frames. Showing that the + # attempt above was left "unfinished". + # + # Also, because the checkpoint finishes this time, the db is synced. + # Which is part of R-16333-64433 above. + # + set ::checkpoint_ongoing 1 + do_test $tp.7 { + checkpoint db $mode main + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6 7 8 9 10} + set ::checkpoint_ongoing 0 + do_test $tp.7 { set ::sync_counter } 1 + do_test $tp.8 { set ::busy_handler_counter } 0 + db4 close + } + + if { $mode=="full" || $mode=="restart" || $mode=="truncate" } { + + # EVIDENCE-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and + # TRUNCATE modes also obtain the exclusive "writer" lock on the + # database file. + # + # Or at least attempts to obtain. + # + do_test $tp.9 { + set ::seen_writer_lock + } {1} + + if {$busy_handler_mode==2 || $busy_handler_mode==3} { + # EVIDENCE-OF: R-59171-47567 This mode blocks (it invokes the + # busy-handler callback) until there is no database writer and all + # readers are reading from the most recent database snapshot. + # + # The test below shows that both the reader and writer have + # finished: + # + # Also restated by the following two. That both busy_handler_mode + # values 2 and 3 work show that both of the following are true - as + # they release the reader and writer transactions in different + # orders. + # + # EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained + # immediately, and a busy-handler is configured, it is invoked and the + # writer lock retried until either the busy-handler returns 0 or the + # lock is successfully obtained. + # + # EVIDENCE-OF: R-48107-00250 The busy-handler is also invoked while + # waiting for database readers as described above. + # + do_test $tp.7 { + list [catchsql COMMIT db2] [catchsql COMMIT db3] + } [list \ + {1 {cannot commit - no transaction is active}} \ + {1 {cannot commit - no transaction is active}} \ + ] + + # EVIDENCE-OF: R-29177-48281 It then checkpoints all frames in the log + # file and syncs the database file. + # + do_test $tp.8 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6 7 8 9 10} + do_test $tp.9 { set ::sync_counter } 1 + db4 close + + # EVIDENCE-OF: R-51867-44713 This mode blocks new database writers + # while it is pending, but new database readers are allowed to continue + # unimpeded. + # + # EVIDENCE-OF: R-47276-58266 Like SQLITE_CHECKPOINT_FULL, this mode + # blocks new database writer attempts while it is pending, but does not + # impede readers. + # + # The first of the above two refers to "full" mode. The second + # to "restart". + # + do_test $tp.10.1 { + list $::write_ok $::read_ok + } {0 1} + + # EVIDENCE-OF: R-12410-31217 This mode works the same way as + # SQLITE_CHECKPOINT_FULL with the addition that after checkpointing the + # log file it blocks (calls the busy-handler callback) until all + # readers are reading from the database file only. + # + # The stuff above passed, so the first part of this requirement + # is met. The second part is tested below. If the checkpoint mode + # was "restart" or "truncate", then the busy-handler will have + # been called to block on wal-file readers. + # + do_test $tp.11 { + set ::did_restart_blocking + } [expr {($mode=="restart"||$mode=="truncate")&&$busy_handler_mode==3}] + + # EVIDENCE-OF: R-44699-57140 This mode works the same way as + # SQLITE_CHECKPOINT_RESTART with the addition that it also truncates + # the log file to zero bytes just prior to a successful return. + if {$mode=="truncate" && $busy_handler_mode==3} { + do_test $tp.12 { + file size test.db-wal + } 0 + } + } elseif {$busy_handler_mode==1} { + + # EVIDENCE-OF: R-34519-06271 SQLITE_BUSY is returned in this case. + if {$tn!=2} { + # ($tn==2) is the loop that uses "PRAGMA wal_checkpoint" + do_test $tp.13 { sqlite3_errcode db } {SQLITE_BUSY} + } + + # EVIDENCE-OF: R-49155-63541 If the busy-handler returns 0 before the + # writer lock is obtained or while waiting for database readers, the + # checkpoint operation proceeds from that point in the same way as + # SQLITE_CHECKPOINT_PASSIVE - checkpointing as many frames as possible + # without blocking any further. + do_test $tp.14 { + forcecopy test.db abc.db + sqlite3 db4 abc.db + db4 eval { SELECT * FROM t1 UNION ALL SELECT * FROM t2 } + } {1 2 3 4 5 6} + do_test $tp.15 { set ::sync_counter } 0 + do_test $tp.16 { set ::busy_handler_counter } 1 + db4 close + } + } + + db2 close + db3 close + db5 close + db6 close + } + + db close + tvfs delete +} + +#----------------------------------------------------------------------- +# EVIDENCE-OF: R-03996-12088 The M parameter must be a valid checkpoint +# mode: +# +# Valid checkpoint modes are 0, 1, 2 and 3. +# +sqlite3 db test.db +foreach {tn mode res} { + 0 -1001 {1 {SQLITE_MISUSE - not an error}} + 1 -1 {1 {SQLITE_MISUSE - not an error}} + 2 0 {0 {0 -1 -1}} + 3 1 {0 {0 -1 -1}} + 4 2 {0 {0 -1 -1}} + 5 3 {0 {0 -1 -1}} + 6 4 {1 {SQLITE_MISUSE - not an error}} + 7 114 {1 {SQLITE_MISUSE - not an error}} + 8 1000000 {1 {SQLITE_MISUSE - not an error}} +} { + do_test 4.$tn { + list [catch "wal_checkpoint_v2 db $mode" msg] $msg + } $res +} +db close + +foreach tn {1 2 3} { + forcedelete test.db test.db2 test.db3 + testvfs tvfs + + sqlite3 db test.db -vfs tvfs + execsql { + ATTACH 'test.db2' AS aux2; + ATTACH 'test.db3' AS aux3; + PRAGMA main.journal_mode = WAL; + PRAGMA aux2.journal_mode = WAL; + PRAGMA aux3.journal_mode = WAL; + + CREATE TABLE main.t1(x,y); + CREATE TABLE aux2.t2(x,y); + CREATE TABLE aux3.t3(x,y); + + INSERT INTO t1 VALUES('a', 'b'); + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t3 VALUES('a', 'b'); + } + sqlite3 db2 test.db2 -vfs tvfs + + switch -- $tn { + 1 { + # EVIDENCE-OF: R-41299-52117 If no error (SQLITE_BUSY or otherwise) is + # encountered while processing the attached databases, SQLITE_OK is + # returned. + do_test 5.$tn.1 { + lindex [wal_checkpoint_v2 db truncate] 0 + } {0} ;# 0 -> SQLITE_OK + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 1 1} + } + + 2 { + # EVIDENCE-OF: R-38578-34175 If an SQLITE_BUSY error is encountered when + # processing one or more of the attached WAL databases, the operation is + # still attempted on any remaining attached databases and SQLITE_BUSY is + # returned at the end. + db2 eval { BEGIN; INSERT INTO t2 VALUES('d', 'e'); } + do_test 5.$tn.1 { + lindex [wal_checkpoint_v2 db truncate] 0 + } {1} ;# 1 -> SQLITE_BUSY + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 0 1} + db2 eval ROLLBACK + } + + 3 { + # EVIDENCE-OF: R-38049-07913 If any other error occurs while processing + # an attached database, processing is abandoned and the error code is + # returned to the caller immediately. + tvfs filter xWrite + tvfs script inject_ioerr + proc inject_ioerr {method file args} { + if {[file tail $file]=="test.db2"} { + return "SQLITE_IOERR" + } + return 0 + } + do_test 5.$tn.1 { + list [catch { wal_checkpoint_v2 db truncate } msg] $msg + } {1 {SQLITE_IOERR - disk I/O error}} + do_test 5.$tn.2 { + list [expr [file size test.db-wal]==0] \ + [expr [file size test.db2-wal]==0] \ + [expr [file size test.db3-wal]==0] + } {1 0 0} + tvfs script "" + } + } + + db close + db2 close +} + +reset_db +sqlite3 db2 test.db + +do_test 6.1 { + execsql { + PRAGMA auto_vacuum = 0; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + } + file size test.db-wal +} [wal_file_size 3 1024] + +do_test 6.2 { + db2 eval { BEGIN; SELECT * FROM t1; } + db eval { INSERT INTO t1 VALUES(3, 4) } + file size test.db-wal +} [wal_file_size 4 1024] + +# At this point the log file contains 4 frames. 3 of which it should +# be possible to checkpoint. +# +# EVIDENCE-OF: R-16642-42503 If pnLog is not NULL, then *pnLog is set to +# the total number of frames in the log file or to -1 if the checkpoint +# could not run because of an error or because the database is not in +# WAL mode. +# +# EVIDENCE-OF: R-10514-25250 If pnCkpt is not NULL,then *pnCkpt is set +# to the total number of checkpointed frames in the log file (including +# any that were already checkpointed before the function was called) or +# to -1 if the checkpoint could not run due to an error or because the +# database is not in WAL mode. +# +do_test 6.4 { + lrange [wal_checkpoint_v2 db passive] 1 2 +} {4 3} + +# EVIDENCE-OF: R-37257-17813 Note that upon successful completion of an +# SQLITE_CHECKPOINT_TRUNCATE, the log file will have been truncated to +# zero bytes and so both *pnLog and *pnCkpt will be set to zero. +# +do_test 6.5 { + db2 eval COMMIT + wal_checkpoint_v2 db truncate +} {0 0 0} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walhook.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walhook.test new file mode 100644 index 0000000000000000000000000000000000000000..b4a31563677b3da088b1e262ea39e291896251d8 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/e_walhook.test @@ -0,0 +1,200 @@ +# 2014 December 04 +# +# 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 +source $testdir/wal_common.tcl +set testprefix e_walhook + + +# EVIDENCE-OF: R-00752-43975 The sqlite3_wal_hook() function is used to +# register a callback that is invoked each time data is committed to a +# database in wal mode. +# +# 1.1: shows that the wal-hook is not invoked in rollback mode. +# 1.2: but is invoked in wal mode. +# +set ::wal_hook_count 0 +proc my_wal_hook {args} { + incr ::wal_hook_count + return 0 +} + +do_test 1.1.1 { + db wal_hook my_wal_hook + execsql { + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(1); + } + set ::wal_hook_count +} 0 +do_test 1.1.2 { + execsql { PRAGMA journal_mode = wal } + set ::wal_hook_count +} 0 + +do_test 1.3 { + execsql { INSERT INTO t1 VALUES(2) } + set wal_hook_count +} 1 + +do_test 1.4 { + execsql { + BEGIN; + INSERT INTO t1 VALUES(3); + INSERT INTO t1 VALUES(4); + COMMIT; + } + set wal_hook_count +} 2 + +# EVIDENCE-OF: R-65366-15139 The callback is invoked by SQLite after the +# commit has taken place and the associated write-lock on the database +# released +# +set ::read_ok 0 +proc my_wal_hook {args} { + sqlite3 db2 test.db + if {[db2 eval { SELECT * FROM t1 }] == "1 2 3 4 5"} { + set ::read_ok 1 + } + db2 close +} +do_test 2.1 { + execsql { INSERT INTO t1 VALUES(5) } + set ::read_ok +} 1 + +# EVIDENCE-OF: R-44294-52863 The third parameter is the name of the +# database that was written to - either "main" or the name of an +# ATTACH-ed database. +# +# EVIDENCE-OF: R-18913-19355 The fourth parameter is the number of pages +# currently in the write-ahead log file, including those that were just +# committed. +# +set ::wal_hook_args [list] +proc my_wal_hook {dbname nEntry} { + set ::wal_hook_args [list $dbname $nEntry] +} +forcedelete test.db2 +do_test 3.0 { + execsql { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t2(x); + PRAGMA aux.journal_mode = wal; + } +} {wal} + +# Database "aux" +do_test 3.1.1 { + set wal_hook_args [list] + execsql { INSERT INTO t2 VALUES('a') } +} {} +do_test 3.1.2 { + set wal_hook_args +} [list aux [wal_frame_count test.db2-wal 1024]] + +# Database "main" +do_test 3.2.1 { + set wal_hook_args [list] + execsql { INSERT INTO t1 VALUES(6) } +} {} +do_test 3.1.2 { + set wal_hook_args +} [list main [wal_frame_count test.db-wal 1024]] + +# EVIDENCE-OF: R-14034-00929 If an error code is returned, that error +# will propagate back up through the SQLite code base to cause the +# statement that provoked the callback to report an error, though the +# commit will have still occurred. +# +proc my_wal_hook {args} { return 1 ;# SQLITE_ERROR } +do_catchsql_test 4.1 { + INSERT INTO t1 VALUES(7) +} {1 {SQL logic error}} + +proc my_wal_hook {args} { return 5 ;# SQLITE_BUSY } +do_catchsql_test 4.2 { + INSERT INTO t1 VALUES(8) +} {1 {database is locked}} + +proc my_wal_hook {args} { return 14 ;# SQLITE_CANTOPEN } +do_catchsql_test 4.3 { + INSERT INTO t1 VALUES(9) +} {1 {unable to open database file}} + +do_execsql_test 4.4 { + SELECT * FROM t1 +} {1 2 3 4 5 6 7 8 9} + +# EVIDENCE-OF: R-10466-53920 Calling sqlite3_wal_hook() replaces any +# previously registered write-ahead log callback. +set ::old_wal_hook 0 +proc my_old_wal_hook {args} { + incr ::old_wal_hook + return 0 +} +db wal_hook my_old_wal_hook +do_test 5.1 { + execsql { INSERT INTO t1 VALUES(10) } + set ::old_wal_hook +} {1} + +# Replace old_wal_hook. Observe that it is not invoked after it has +# been replaced. +proc my_new_wal_hook {args} { return 0 } +db wal_hook my_new_wal_hook +do_test 5.2 { + execsql { INSERT INTO t1 VALUES(11) } + set ::old_wal_hook +} {1} + + + +# EVIDENCE-OF: R-57445-43425 Note that the sqlite3_wal_autocheckpoint() +# interface and the wal_autocheckpoint pragma both invoke +# sqlite3_wal_hook() and will overwrite any prior sqlite3_wal_hook() +# settings. +# +set ::old_wal_hook 0 +proc my_old_wal_hook {args} { incr ::old_wal_hook ; return 0 } +db wal_hook my_old_wal_hook +do_test 6.1.1 { + execsql { INSERT INTO t1 VALUES(12) } + set ::old_wal_hook +} {1} +do_test 6.1.2 { + execsql { PRAGMA wal_autocheckpoint = 1000 } + execsql { INSERT INTO t1 VALUES(12) } + set ::old_wal_hook +} {1} + +# EVIDENCE-OF: R-52629-38967 The first parameter passed to the callback +# function when it is invoked is a copy of the third parameter passed to +# sqlite3_wal_hook() when registering the callback. +# +# This is tricky to test using the tcl interface. However, the +# mechanism used to invoke the tcl script registered as a wal-hook +# depends on the context pointer being correctly passed through. And +# since multiple different wal-hook scripts have been successfully +# invoked by this test script, consider this tested. +# +# EVIDENCE-OF: R-23378-42536 The second is a copy of the database +# handle. +# +# There is an assert() in the C wal-hook used by tclsqlite.c to +# prove this. And that hook has been invoked multiple times when +# running this script. So consider this requirement tested as well. +# + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/emptytable.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/emptytable.test new file mode 100644 index 0000000000000000000000000000000000000000..79cd16e9133d4bd1bd9e4e76ed3b982789201e6e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/emptytable.test @@ -0,0 +1,50 @@ +# 2017-02-15 +# +# 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. +# +#*********************************************************************** +# +# Test cases to show that a join involving an empty table is very fast. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Build some test data +# +do_execsql_test emptytable-100 { + CREATE TABLE t1(a); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a) SELECT x FROM c; + CREATE TABLE empty(x); + SELECT count(*) FROM t1; +} {100} + +# Interrupt queries after 1M cycles to prevent burning excess CPU +proc stopDb {args} { + db interrupt +} +db progress 1000000 {stopDb} + +# Prior to the query planner optimization on 2017-02-15, this query would +# take a ridiculous amount of time. If that optimization stops working, +# the result here will be in interrupt for running too long. +# +do_catchsql_test emptytable-110 { + SELECT count(*) FROM t1, t1, t1, t1, t1, t1, empty; +} {0 0} + +do_catchsql_test emptytable-120 { + SELECT count(*) FROM t1, t1 LEFT JOIN empty; +} {0 10000} +do_catchsql_test emptytable-121 { + SELECT count(*) FROM t1, t1 LEFT JOIN t1, empty; +} {0 0} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/enc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc.test new file mode 100644 index 0000000000000000000000000000000000000000..0aec224e2d874427e7067ece16836d5933d0d38c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc.test @@ -0,0 +1,281 @@ +# 2002 May 24 +# +# 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. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# +# $Id: enc.test,v 1.7 2007/05/23 16:23:09 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Skip this test if the build does not support multiple encodings. +# +ifcapable {!utf16} { + finish_test + return +} + +proc do_bincmp_test {testname got expect} { + binary scan $expect \c* expectvals + binary scan $got \c* gotvals + do_test $testname [list set dummy $gotvals] $expectvals +} + +# $utf16 is a UTF-16 encoded string. Swap each pair of bytes around +# to change the byte-order of the string. +proc swap_byte_order {utf16} { + binary scan $utf16 \c* ints + + foreach {a b} $ints { + lappend ints2 $b + lappend ints2 $a + } + + return [binary format \c* $ints2] +} + +# +# Test that the SQLite routines for converting between UTF encodings +# produce the same results as their TCL counterparts. +# +# $testname is the prefix to be used for the test names. +# $str is a string to use for testing (encoded in UTF-8, as normal for TCL). +# +# The test procedure is: +# 1. Convert the string from UTF-8 to UTF-16le and check that the TCL and +# SQLite routines produce the same results. +# +# 2. Convert the string from UTF-8 to UTF-16be and check that the TCL and +# SQLite routines produce the same results. +# +# 3. Use the SQLite routines to convert the native machine order UTF-16 +# representation back to the original UTF-8. Check that the result +# matches the original representation. +# +# 4. Add a byte-order mark to each of the UTF-16 representations and +# check that the SQLite routines can convert them back to UTF-8. For +# byte-order mark info, refer to section 3.10 of the unicode standard. +# +# 5. Take the byte-order marked UTF-16 strings from step 4 and ensure +# that SQLite can convert them both to native byte order UTF-16 +# strings, sans BOM. +# +# Coverage: +# +# sqlite_utf8to16be (step 2) +# sqlite_utf8to16le (step 1) +# sqlite_utf16to8 (steps 3, 4) +# sqlite_utf16to16le (step 5) +# sqlite_utf16to16be (step 5) +# +proc test_conversion {testname str} { + + # Step 1. + set utf16le_sqlite3 [test_translate $str UTF8 UTF16LE] + set utf16le_tcl [encoding convertto unicode $str] + append utf16le_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)!="littleEndian" } { + set utf16le_tcl [swap_byte_order $utf16le_tcl] + } + do_bincmp_test $testname.1 $utf16le_sqlite3 $utf16le_tcl + set utf16le $utf16le_tcl + + # Step 2. + set utf16be_sqlite3 [test_translate $str UTF8 UTF16BE] + set utf16be_tcl [encoding convertto unicode $str] + append utf16be_tcl "\x00\x00" + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16be_tcl [swap_byte_order $utf16be_tcl] + } + do_bincmp_test $testname.2 $utf16be_sqlite3 $utf16be_tcl + set utf16be $utf16be_tcl + + # Step 3. + if { $::tcl_platform(byteOrder)=="littleEndian" } { + set utf16 $utf16le + } else { + set utf16 $utf16be + } + set utf8_sqlite3 [test_translate $utf16 UTF16 UTF8] + do_bincmp_test $testname.3 $utf8_sqlite3 [binarize $str] + + # Step 4 (little endian). + append utf16le_bom "\xFF\xFE" $utf16le + set utf8_sqlite3 [test_translate $utf16le_bom UTF16 UTF8 1] + do_bincmp_test $testname.4.le $utf8_sqlite3 [binarize $str] + + # Step 4 (big endian). + append utf16be_bom "\xFE\xFF" $utf16be + set utf8_sqlite3 [test_translate $utf16be_bom UTF16 UTF8] + do_bincmp_test $testname.4.be $utf8_sqlite3 [binarize $str] + + # Step 5 (little endian to little endian). + set utf16_sqlite3 [test_translate $utf16le_bom UTF16LE UTF16LE] + do_bincmp_test $testname.5.le.le $utf16_sqlite3 $utf16le + + # Step 5 (big endian to big endian). + set utf16_sqlite3 [test_translate $utf16be_bom UTF16 UTF16BE] + do_bincmp_test $testname.5.be.be $utf16_sqlite3 $utf16be + + # Step 5 (big endian to little endian). + set utf16_sqlite3 [test_translate $utf16be_bom UTF16 UTF16LE] + do_bincmp_test $testname.5.be.le $utf16_sqlite3 $utf16le + + # Step 5 (little endian to big endian). + set utf16_sqlite3 [test_translate $utf16le_bom UTF16 UTF16BE] + do_bincmp_test $testname.5.le.be $utf16_sqlite3 $utf16be +} + +translate_selftest + +test_conversion enc-1 "hello world" +test_conversion enc-2 "sqlite" +test_conversion enc-3 "" +test_conversion enc-X "\u0100" +test_conversion enc-4 "\u1234" +test_conversion enc-5 "\u4321abc" +test_conversion enc-6 "\u4321\u1234" +test_conversion enc-7 [string repeat "abcde\u00EF\u00EE\uFFFCabc" 100] +test_conversion enc-8 [string repeat "\u007E\u007F\u0080\u0081" 100] +test_conversion enc-9 [string repeat "\u07FE\u07FF\u0800\u0801\uFFF0" 100] +test_conversion enc-10 [string repeat "\uE000" 100] + +proc test_collate {enc zLeft zRight} { + return [string compare $zLeft $zRight] +} +add_test_collate $::DB 0 0 1 +do_test enc-11.1 { + execsql { + CREATE TABLE ab(a COLLATE test_collate, b); + INSERT INTO ab VALUES(CAST (X'C388' AS TEXT), X'888800'); + INSERT INTO ab VALUES(CAST (X'C0808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808388' AS TEXT), X'888800'); + CREATE INDEX ab_i ON ab(a, b); + } +} {} +do_test enc-11.2 { + set cp200 "\u00C8" + execsql { + SELECT count(*) FROM ab WHERE a = $::cp200; + } +} {2} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +forcedelete test.db3 + +do_execsql_test enc-12.0 { + PRAGMA encoding = 'utf-8'; + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 'b', 'c'); + ATTACH 'test.db3' AS aux; + CREATE TABLE aux.t3(x, y, z); + INSERT INTO t3 VALUES('xxx', 'yyy', 'zzz'); + PRAGMA encoding; +} {UTF-8} + +do_test enc-12.1 { + sqlite3 db2 test.db2 + db2 eval { + PRAGMA encoding = 'UTF-16le'; + CREATE TABLE t2(d, e, f); + INSERT INTO t2 VALUES('d', 'e', 'f'); + PRAGMA encoding; + } +} {UTF-16le} + +do_test enc-12.2 { + db2 backup test.db + db2 close +} {} + +do_catchsql_test enc-12.3 { + SELECT * FROM t2; +} {1 {attached databases must use the same text encoding as main database}} + +db close +sqlite3 db test.db3 +do_execsql_test enc-12.4 { + SELECT * FROM t3; + PRAGMA encoding = 'UTF-16le'; + SELECT * FROM t3; +} {xxx yyy zzz xxx yyy zzz} + +db close +sqlite3 db test.db3 +breakpoint +do_execsql_test enc-12.5 { + PRAGMA encoding = 'UTF-16le'; + PRAGMA encoding; +} {UTF-8} + +reset_db +do_execsql_test enc-12.6 { + PRAGMA encoding = 'UTF-8'; + CREATE TEMP TABLE t1(a, b, c); + INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz'); +} +do_test enc-12.7 { + sqlite3 db2 test.db2 + db2 backup test.db + db2 close + db eval { + SELECT * FROM t1; + } +} {xxx yyy zzz} +do_catchsql_test enc-12.8 { + SELECT * FROM t2; + SELECT * FROM t1; +} {1 {attached databases must use the same text encoding as main database}} + +db close +sqlite3 db test.db +do_execsql_test enc-12.9 { + CREATE TEMP TABLE t1(a, b, c); + INSERT INTO t1 VALUES('xxx', 'yyy', 'zzz'); +} +do_execsql_test enc-12.10 { + SELECT * FROM t2; + SELECT * FROM t1; +} {d e f xxx yyy zzz} + + +# 2024-11-04 +# https://sqlite.org/forum/forumpost/bc75a4d20b756044 +# +# Ensure the database encoding is detected in a timely manner, +# and before we get too far along in generating and running +# bytecode. +# +# See also check-in https://sqlite.org/src/info/a02da71f3a. +# +db close +forcedelete utf16.db +sqlite3 db utf16.db +db eval {PRAGMA encoding=UTF16; CREATE TABLE t2(y); INSERT INTO t2 VALUES('utf16');} +db close +sqlite3 db utf16.db +do_test enc-13.1 { + db eval {PRAGMA function_list} {db eval {SELECT * FROM sqlite_schema}} +} {} +ifcapable rtree { + db eval {CREATE VIRTUAL TABLE t3 USING rtree(id,x1,x2)} + db close + sqlite3 db utf16.db + do_execsql_test enc-13.2 { + WITH t1(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM t1 WHERE x<3) + SELECT rtreecheck('t3') FROM t1; + } {ok ok ok} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/enc3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc3.test new file mode 100644 index 0000000000000000000000000000000000000000..c9d39cbf3a756ec1cb734204a4985966cb1279aa --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc3.test @@ -0,0 +1,107 @@ +# 2002 May 24 +# +# 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. +# +# The focus of this file is testing of the proper handling of conversions +# to the native text representation. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {utf16} { + do_test enc3-1.1 { + execsql { + PRAGMA encoding=utf16le; + PRAGMA encoding; + } + } {UTF-16le} +} +do_test enc3-1.2 { + execsql { + CREATE TABLE t1(x,y); + INSERT INTO t1 VALUES('abc''123',5); + SELECT * FROM t1 + } +} {abc'123 5} +do_test enc3-1.3 { + execsql { + SELECT quote(x) || ' ' || quote(y) FROM t1 + } +} {{'abc''123' 5}} +ifcapable {bloblit} { + do_test enc3-1.4 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES(x'616263646566',NULL); + SELECT * FROM t1 + } + } {abcdef {}} + do_test enc3-1.5 { + execsql { + SELECT quote(x) || ' ' || quote(y) FROM t1 + } + } {{X'616263646566' NULL}} +} +ifcapable {bloblit && utf16} { + do_test enc3-2.1 { + execsql { + PRAGMA encoding + } + } {UTF-16le} + do_test enc3-2.2 { + execsql { + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(x'61006200630064006500'); + SELECT CAST(a AS text) FROM t2 WHERE CAST(a AS text) LIKE 'abc%'; + } + } {abcde} + do_test enc3-2.3 { + execsql { + SELECT CAST(x'61006200630064006500' AS text); + } + } {abcde} + do_test enc3-2.4 { + execsql { + SELECT rowid FROM t2 + WHERE CAST(a AS text) LIKE CAST(x'610062002500' AS text); + } + } {1} +} + +# Try to attach a database with a different encoding. +# +ifcapable {utf16 && shared_cache} { + db close + forcedelete test8.db test8.db-journal + set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + sqlite3 dbaux test8.db + sqlite3 db test.db + db eval {SELECT 1 FROM sqlite_master LIMIT 1} + do_test enc3-3.1 { + dbaux eval { + PRAGMA encoding='utf8'; + CREATE TABLE t1(x); + PRAGMA encoding + } + } {UTF-8} + do_test enc3-3.2 { + catchsql { + ATTACH 'test.db' AS utf16; + SELECT 1 FROM utf16.sqlite_master LIMIT 1; + } dbaux + } {1 {attached databases must use the same text encoding as main database}} + dbaux close + forcedelete test8.db test8.db-journal + sqlite3_enable_shared_cache $::enable_shared_cache +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/enc4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc4.test new file mode 100644 index 0000000000000000000000000000000000000000..94869b6fb75050b9f23fdf7966eefda3cbe1207a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/enc4.test @@ -0,0 +1,137 @@ +# 2010 Sept 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The focus of +# this file is testing the SQLite routines used for converting between the +# various suported unicode encodings (UTF-8, UTF-16, UTF-16le and +# UTF-16be). +# +# $Id: enc4.test,v 1.0 2010/09/29 08:29:32 shaneh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If UTF16 support is disabled, ignore the tests in this file +# +ifcapable {!utf16} { + finish_test + return +} + +db close + +# The three unicode encodings understood by SQLite. +set encodings [list UTF-8 UTF-16le UTF-16be] + +# initial value to use in SELECT +set inits [list 1 1.0 1. 1e0] + +# vals +set vals [list\ +"922337203685477580792233720368547758079223372036854775807"\ +"100000000000000000000000000000000000000000000000000000000"\ +"1.0000000000000000000000000000000000000000000000000000000"\ +] + +set i 1 +foreach enc $encodings { + + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA encoding = \"$enc\"" + + do_test enc4-$i.1 { + db eval {PRAGMA encoding} + } $enc + + set j 1 + foreach init $inits { + + do_test enc4-$i.$j.2 { + set S [sqlite3_prepare_v2 db "SELECT $init+?" -1 dummy] + sqlite3_expired $S + } {0} + + set k 1 + foreach val $vals { + for {set x 1} {$x<16} {incr x} { + set part [expr $init + [string range $val 0 [expr $x-1]]] + + do_realnum_test enc4-$i.$j.$k.3.$x { + sqlite3_reset $S + sqlite3_bind_text $S 1 $val $x + sqlite3_step $S + sqlite3_column_text $S 0 + } [list $part] + + do_realnum_test enc4-$i.$j.$k.4.$x { + sqlite3_reset $S + sqlite3_bind_text16 $S 1 [encoding convertto unicode $val] [expr $x*2] + sqlite3_step $S + sqlite3_column_text $S 0 + } [list $part] + } + + incr k + } + + do_test enc4-$i.$j.5 { + sqlite3_finalize $S + } {SQLITE_OK} + + incr j + } + + db close + incr i +} + +forcedelete test.db +sqlite3 db test.db + +do_test enc4-4.1 { + db eval "select 1+1." +} {2.0} + +do_test enc4-4.2.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+1." -1 dummy] + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.2.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test enc4-4.3.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] + sqlite3_bind_text $S 1 "1." 2 + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.3.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +do_test enc4-4.4.1 { + set S [sqlite3_prepare_v2 db "SELECT 1+?" -1 dummy] + sqlite3_bind_text $S 1 "1.0" 2 + sqlite3_step $S + sqlite3_column_text $S 0 +} {2.0} + +do_test enc4-4.4.2 { + sqlite3_finalize $S +} {SQLITE_OK} + +db close + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/eqp2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/eqp2.test new file mode 100644 index 0000000000000000000000000000000000000000..3c634fc28a96f17b6374a34000d4f4ae2a2240b5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/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/local-test-sqlite3-delta-01/afc-sqlite3/test/errmsg.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/errmsg.test new file mode 100644 index 0000000000000000000000000000000000000000..f32da59a391d48243ebbf7ee01c3f7f1ae68b01c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/errmsg.test @@ -0,0 +1,118 @@ +# 2001 September 15 +# +# 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. +# +#*********************************************************************** +# Test that if sqlite3_prepare_v2() is used to prepare a query, the +# error-message associated with an sqlite3_step() error is available +# immediately. Whereas if sqlite3_prepare() is used, it is not available +# until sqlite3_finalize() or sqlite3_reset() has been called. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix errmsg + +# Test organization: +# +# errmsg-1.* User-defined SQL function errors +# errmsg-2.* Errors generated by the VDBE (constraint failures etc.) +# errmsg-3.* SQLITE_SCHEMA and statement recompilation errors. +# + +proc error_messages_worker {prepare sql schema} { + set ret [list] + + set stmt [$prepare db $sql -1 dummy] + execsql $schema + lappend ret [sqlite3_step $stmt] + lappend ret [sqlite3_errmsg db] + lappend ret [sqlite3_finalize $stmt] + lappend ret [sqlite3_errmsg db] + + set ret +} + +proc error_messages_v2 {sql {schema {}}} { + error_messages_worker sqlite3_prepare_v2 $sql $schema +} + +proc error_messages {sql {schema {}}} { + error_messages_worker sqlite3_prepare $sql $schema +} + +proc sql_error {msg} { error $msg } +db func sql_error sql_error + +#------------------------------------------------------------------------- +# Test error messages returned by user-defined SQL functions. +# +do_test 1.1 { + error_messages "SELECT sql_error('custom message')" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_ERROR {custom message} +}] +do_test 1.2 { + error_messages_v2 "SELECT sql_error('custom message')" +} [list {*}{ + SQLITE_ERROR {custom message} + SQLITE_ERROR {custom message} +}] + +#------------------------------------------------------------------------- +# Test error messages generated directly by VDBE code (e.g. constraint +# failures). +# +do_execsql_test 2.1 { + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + INSERT INTO t1 VALUES('abc', 'def'); +} +do_test 2.2 { + error_messages "INSERT INTO t1 VALUES('ghi', 'def')" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} +}] +verify_ex_errcode 2.2b SQLITE_CONSTRAINT_UNIQUE +do_test 2.3 { + error_messages_v2 "INSERT INTO t1 VALUES('ghi', 'def')" +} [list {*}{ + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} + SQLITE_CONSTRAINT {UNIQUE constraint failed: t1.b} +}] +verify_ex_errcode 2.3b SQLITE_CONSTRAINT_UNIQUE + +#------------------------------------------------------------------------- +# Test SQLITE_SCHEMA errors. And, for _v2(), test that if the schema +# change invalidates the SQL statement itself the error message is returned +# correctly. +# +do_execsql_test 3.1.1 { + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 VALUES('abc', 'def'); +} +do_test 3.1.2 { + error_messages "SELECT a FROM t2" "DROP TABLE t2" +} [list {*}{ + SQLITE_ERROR {SQL logic error} + SQLITE_SCHEMA {database schema has changed} +}] +do_execsql_test 3.2.1 { + CREATE TABLE t2(a PRIMARY KEY, b UNIQUE); + INSERT INTO t2 VALUES('abc', 'def'); +} +do_test 3.2.2 { + error_messages_v2 "SELECT a FROM t2" "DROP TABLE t2" +} [list {*}{ + SQLITE_ERROR {no such table: t2} + SQLITE_ERROR {no such table: t2} +}] + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive.test new file mode 100644 index 0000000000000000000000000000000000000000..494ede7f7660b9e3000cc06a605406157559d8fc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive.test @@ -0,0 +1,540 @@ +# 2007 March 24 +# +# 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. The focus +# of these tests is exclusive access mode (i.e. the thing activated by +# "PRAGMA locking_mode = EXCLUSIVE"). +# +# $Id: exclusive.test,v 1.15 2009/06/26 12:30:40 danielk1977 Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!pager_pragmas} { + finish_test + return +} + +forcedelete test2.db-journal +forcedelete test2.db +forcedelete test3.db-journal +forcedelete test3.db +forcedelete test4.db-journal +forcedelete test4.db + +#---------------------------------------------------------------------- +# Test cases exclusive-1.X test the PRAGMA logic. +# +do_test exclusive-1.0 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +do_test exclusive-1.1 { + execsql { + pragma locking_mode = exclusive; + } +} {exclusive} +do_test exclusive-1.2 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list exclusive exclusive exclusive] +do_test exclusive-1.3 { + execsql { + pragma locking_mode = normal; + } +} {normal} +do_test exclusive-1.4 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +do_test exclusive-1.5 { + execsql { + pragma locking_mode = invalid; + } +} {normal} +do_test exclusive-1.6 { + execsql { + pragma locking_mode; + pragma main.locking_mode; + pragma temp.locking_mode; + } +} [list normal normal exclusive] +ifcapable attach { + do_test exclusive-1.7 { + execsql { + pragma locking_mode = exclusive; + ATTACH 'test2.db' as aux; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + } + } {exclusive exclusive} + do_test exclusive-1.8 { + execsql { + pragma main.locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + } + } [list normal exclusive exclusive] + do_test exclusive-1.9 { + execsql { + pragma locking_mode; + } + } {exclusive} + do_test exclusive-1.10 { + execsql { + ATTACH 'test3.db' as aux2; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } {normal exclusive exclusive} + do_test exclusive-1.11 { + execsql { + pragma aux.locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } {normal normal exclusive} + do_test exclusive-1.12 { + execsql { + pragma locking_mode = normal; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + } + } [list normal exclusive normal normal] + do_test exclusive-1.13 { + execsql { + ATTACH 'test4.db' as aux3; + } + execsql { + pragma main.locking_mode; + pragma temp.locking_mode; + pragma aux.locking_mode; + pragma aux2.locking_mode; + pragma aux3.locking_mode; + } + } [list normal exclusive normal normal normal] + + do_test exclusive-1.99 { + execsql { + DETACH aux; + DETACH aux2; + DETACH aux3; + } + } {} +} + +#---------------------------------------------------------------------- +# Test cases exclusive-2.X verify that connections in exclusive +# locking_mode do not relinquish locks. +# +do_test exclusive-2.0 { + execsql { + CREATE TABLE abc(a, b, c); + INSERT INTO abc VALUES(1, 2, 3); + PRAGMA locking_mode = exclusive; + } +} {exclusive} +do_test exclusive-2.1 { + sqlite3 db2 test.db + execsql { + INSERT INTO abc VALUES(4, 5, 6); + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6} +do_test exclusive-2.2 { + # This causes connection 'db' (in exclusive mode) to establish + # a shared-lock on the db. The other connection should now be + # locked out as a writer. + execsql { + SELECT * FROM abc; + } db +} {1 2 3 4 5 6} +do_test exclusive-2.4 { + execsql { + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6} +do_test exclusive-2.5 { + catchsql { + INSERT INTO abc VALUES(7, 8, 9); + } db2 +} {1 {database is locked}} +sqlite3_soft_heap_limit 0 +do_test exclusive-2.6 { + # Because connection 'db' only has a shared-lock, the other connection + # will be able to get a RESERVED, but will fail to upgrade to EXCLUSIVE. + execsql { + BEGIN; + INSERT INTO abc VALUES(7, 8, 9); + } db2 + catchsql { + COMMIT + } db2 +} {1 {database is locked}} +do_test exclusive-2.7 { + catchsql { + COMMIT + } db2 +} {1 {database is locked}} +do_test exclusive-2.8 { + execsql { + ROLLBACK; + } db2 +} {} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) + +do_test exclusive-2.9 { + # Write the database to establish the exclusive lock with connection 'db. + execsql { + INSERT INTO abc VALUES(7, 8, 9); + } db + catchsql { + SELECT * FROM abc; + } db2 +} {1 {database is locked}} +do_test exclusive-2.10 { + # Changing the locking-mode does not release any locks. + execsql { + PRAGMA locking_mode = normal; + } db + catchsql { + SELECT * FROM abc; + } db2 +} {1 {database is locked}} +do_test exclusive-2.11 { + # After changing the locking mode, accessing the db releases locks. + execsql { + SELECT * FROM abc; + } db + execsql { + SELECT * FROM abc; + } db2 +} {1 2 3 4 5 6 7 8 9} +db2 close + +#---------------------------------------------------------------------- +# Tests exclusive-3.X - test that a connection in exclusive mode +# truncates instead of deletes the journal file when committing +# a transaction. +# +# These tests are not run on windows because the windows backend +# opens the journal file for exclusive access, preventing its contents +# from being inspected externally. +# +if {$tcl_platform(platform) != "windows" + && [atomic_batch_write test.db]==0 +} { + + # Return a list of two booleans (either 0 or 1). The first is true + # if the named file exists. The second is true only if the file + # exists and the first 28 bytes contain at least one non-zero byte. + # + proc filestate {fname} { + set exists 0 + set content 0 + if {[file exists $fname]} { + set exists 1 + set hdr [hexio_read $fname 0 28] + set content [expr {0==[string match $hdr [string repeat 0 56]]}] + } + list $exists $content + } + + do_test exclusive-3.0 { + filestate test.db-journal + } {0 0} + do_test exclusive-3.1 { + execsql { + PRAGMA locking_mode = exclusive; + BEGIN; + DELETE FROM abc; + } + filestate test.db-journal + } {1 1} + do_test exclusive-3.2 { + execsql { + COMMIT; + } + filestate test.db-journal + } {1 0} + do_test exclusive-3.3 { + execsql { + INSERT INTO abc VALUES('A', 'B', 'C'); + SELECT * FROM abc; + } + } {A B C} + do_test exclusive-3.4 { + execsql { + BEGIN; + UPDATE abc SET a = 1, b = 2, c = 3; + ROLLBACK; + SELECT * FROM abc; + } + } {A B C} + do_test exclusive-3.5 { + filestate test.db-journal + } {1 0} + do_test exclusive-3.6 { + execsql { + PRAGMA locking_mode = normal; + SELECT * FROM abc; + } + filestate test.db-journal + } {0 0} +} + +#---------------------------------------------------------------------- +# Tests exclusive-4.X - test that rollback works correctly when +# in exclusive-access mode. +# + +# The following procedure computes a "signature" for table "t3". If +# T3 changes in any way, the signature should change. +# +# This is used to test ROLLBACK. We gather a signature for t3, then +# make lots of changes to t3, then rollback and take another signature. +# The two signatures should be the same. +# +proc signature {} { + return [db eval {SELECT count(*), md5sum(x) FROM t3}] +} + +do_test exclusive-4.0 { + execsql { PRAGMA locking_mode = exclusive; } + execsql { PRAGMA default_cache_size = 10; } + execsql { + BEGIN; + CREATE TABLE t3(x TEXT); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 VALUES(randstr(10,400)); + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + INSERT INTO t3 SELECT randstr(10,400) FROM t3; + COMMIT; + } + execsql {SELECT count(*) FROM t3;} +} {32} + +set ::X [signature] +do_test exclusive-4.1 { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + SELECT count(*) FROM t3; + ROLLBACK; + } + signature +} $::X + +do_test exclusive-4.2 { + execsql { + BEGIN; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + DELETE FROM t3 WHERE random()%10!=0; + INSERT INTO t3 SELECT randstr(10,10)||x FROM t3; + ROLLBACK; + } + signature +} $::X + +do_test exclusive-4.3 { + execsql { + INSERT INTO t3 SELECT randstr(10,400) FROM t3 WHERE random()%10==0; + } +} {} + +do_test exclusive-4.4 { + catch {set ::X [signature]} +} {0} +do_test exclusive-4.5 { + execsql { + PRAGMA locking_mode = NORMAL; + DROP TABLE t3; + DROP TABLE abc; + } +} {normal} + +#---------------------------------------------------------------------- +# Tests exclusive-5.X - test that statement journals are truncated +# instead of deleted when in exclusive access mode. +# +if {[atomic_batch_write test.db]==0} { + +# Close and reopen the database so that the temp database is no +# longer active. +# +db close +sqlite3 db test.db + +# if we're using proxy locks, we use 3 filedescriptors for a db +# that is open but NOT writing changes, normally +# sqlite uses 1 (proxy locking adds the conch and the local lock) +set using_proxy 0 +foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] { + set using_proxy $value +} +set extrafds 0 +if {$using_proxy!=0} { + set extrafds 2 +} + +do_test exclusive-5.0 { + execsql { + CREATE TABLE abc(a UNIQUE, b UNIQUE, c UNIQUE); + BEGIN; + INSERT INTO abc VALUES(1, 2, 3); + INSERT INTO abc SELECT a+1, b+1, c+1 FROM abc; + } +} {} +do_test exclusive-5.1 { + # Three files are open: The db, journal and statement-journal. + # (2016-03-04) The statement-journal is now opened lazily + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.2 { + execsql { + COMMIT; + } + # One file open: the db. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {1} +do_test exclusive-5.3 { + execsql { + PRAGMA locking_mode = exclusive; + BEGIN; + INSERT INTO abc VALUES(5, 6, 7); + } + # Two files open: the db and journal. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.4 { + execsql { + INSERT INTO abc SELECT a+10, b+10, c+10 FROM abc; + } + # Three files are open: The db, journal and statement-journal. + # 2016-03-04: The statement-journal open is deferred + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.5 { + execsql { + COMMIT; + } + # Three files are still open: The db, journal and statement-journal. + # 2016-03-04: The statement-journal open is deferred + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {2} +do_test exclusive-5.6 { + execsql { + PRAGMA locking_mode = normal; + SELECT * FROM abc; + } +} {normal 1 2 3 2 3 4 5 6 7 11 12 13 12 13 14 15 16 17} +do_test exclusive-5.7 { + # Just the db open. + set sqlite_open_file_count + expr $sqlite_open_file_count-$extrafds +} {1} + +#------------------------------------------------------------------------- + +do_execsql_test exclusive-6.1 { + CREATE TABLE t4(a, b); + INSERT INTO t4 VALUES('Eden', 1955); + BEGIN; + INSERT INTO t4 VALUES('Macmillan', 1957); + INSERT INTO t4 VALUES('Douglas-Home', 1963); + INSERT INTO t4 VALUES('Wilson', 1964); +} +do_test exclusive-6.2 { + forcedelete test2.db test2.db-journal + copy_file test.db test2.db + copy_file test.db-journal test2.db-journal + sqlite3 db test2.db +} {} + +do_execsql_test exclusive-6.3 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM t4; +} {exclusive Eden 1955} + +do_test exclusive-6.4 { + db close + forcedelete test.db test.db-journal + set fd [open test.db-journal w] + puts $fd x + close $fd + sqlite3 db test.db +} {} + +do_execsql_test exclusive-6.5 { + PRAGMA locking_mode = EXCLUSIVE; + SELECT * FROM sqlite_master; +} {exclusive} + +# 2019-12-26 ticket fb3b3024ea238d5c +if {[permutation]!="journaltest"} { + # The custom VFS used by the "journaltest" permutation cannot open the + # shared-memory file. So, while it is able to switch the db file to + # journal_mode=WAL when locking_mode=EXCLUSIVE, it can no longer access + # it once the locking_mode is changed back to NORMAL. + do_test exclusive-7.1 { + db close + forcedelete test.db test.db-journal test.db-wal + sqlite3 db test.db + # The following sequence of pragmas would trigger an assert() + # associated with Pager.changeCountDone inside of assert_pager_state(), + # prior to the fix. + db eval { + PRAGMA locking_mode = EXCLUSIVE; + PRAGMA journal_mode = WAL; + PRAGMA locking_mode = NORMAL; + PRAGMA user_version; + PRAGMA journal_mode = DELETE; + } + } {exclusive wal normal 0 delete} +} + + +} ;# atomic_batch_write==0 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive2.test new file mode 100644 index 0000000000000000000000000000000000000000..0a5d2b6eb8834c13513f1e9096c425e2e2206428 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/exclusive2.test @@ -0,0 +1,324 @@ +# 2007 March 24 +# +# 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. +# +# $Id: exclusive2.test,v 1.10 2008/11/27 02:22:11 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +ifcapable {!pager_pragmas} { + finish_test + return +} + +# Tests in this file verify that locking_mode=exclusive causes SQLite to +# use cached pages even if the database is changed on disk. This doesn't +# work with mmap. +if {[permutation]=="mmap"} { + finish_test + return +} + +# This module does not work right if the cache spills at unexpected +# moments. So disable the soft-heap-limit. +# +sqlite3_soft_heap_limit 0 + +proc pagerChangeCounter {filename new {fd ""}} { + if {$fd==""} { + set fd [open $filename RDWR] + fconfigure $fd -translation binary + set needClose 1 + } else { + set needClose 0 + } + if {$new ne ""} { + seek $fd 24 + set a [expr {($new&0xFF000000)>>24}] + set b [expr {($new&0x00FF0000)>>16}] + set c [expr {($new&0x0000FF00)>>8}] + set d [expr {($new&0x000000FF)}] + puts -nonewline $fd [binary format cccc $a $b $c $d] + flush $fd + } + + seek $fd 24 + foreach {a b c d} [list 0 0 0 0] {} + binary scan [read $fd 4] cccc a b c d + set ret [expr ($a&0x000000FF)<<24] + incr ret [expr ($b&0x000000FF)<<16] + incr ret [expr ($c&0x000000FF)<<8] + incr ret [expr ($d&0x000000FF)<<0] + + if {$needClose} {close $fd} + return $ret +} + +proc readPagerChangeCounter {filename} { + set fd [open $filename RDONLY] + fconfigure $fd -translation binary + + seek $fd 24 + foreach {a b c d} [list 0 0 0 0] {} + binary scan [read $fd 4] cccc a b c d + set ret [expr ($a&0x000000FF)<<24] + incr ret [expr ($b&0x000000FF)<<16] + incr ret [expr ($c&0x000000FF)<<8] + incr ret [expr ($d&0x000000FF)<<0] + + close $fd + return $ret +} + + +proc t1sig {{db db}} { + execsql {SELECT count(*), md5sum(a) FROM t1} $db +} +do_test exclusive2-1.0 { + readPagerChangeCounter test.db +} {0} + +#----------------------------------------------------------------------- +# The following tests - exclusive2-1.X - check that: +# +# 1-3: Build a database with connection 1, calculate a signature. +# 4-7: Modify the database using a second connection in a way that +# does not modify the freelist, then reset the pager change-counter +# to the value it had before the modifications. +# 8: Check that using the first connection, the database signature +# is still the same. This is because it uses the in-memory cache. +# It can't tell the db has changed because we reset the change-counter. +# 9: Increment the change-counter. +# 10: Ensure that the first connection now sees the updated database. It +# sees the change-counter has been incremented and discards the +# invalid in-memory cache. +# +# This will only work if the database cache is large enough to hold +# the entire database. In the case of 1024 byte pages, this means +# the cache size must be at least 17. Otherwise, some pages will be +# loaded from the database file in step 8. +# +# For similar reasons, this test does not work with the memsubsys1 permutation. +# Permutation memsubsys1 configures the pcache subsystem to use a static +# allocation of 24 pages (shared between all pagers). This is not enough for +# this test. +# +do_test exclusive2-1.1 { + execsql { + BEGIN; + CREATE TABLE t1(a, b); + INSERT INTO t1(a, b) VALUES(randstr(10, 400), 0); + INSERT INTO t1(a, b) VALUES(randstr(10, 400), 0); + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + INSERT INTO t1(a, b) SELECT randstr(10, 400), 0 FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {64} +do_test exclusive2-1.2.1 { + # Make sure the pager cache is large enough to store the + # entire database. + set nPage [expr [file size test.db]/1024] + if {$::SQLITE_DEFAULT_CACHE_SIZE < $nPage} { + execsql "PRAGMA cache_size = $nPage" + } + expr {[execsql {PRAGMA cache_size}] >= $nPage} +} {1} +do_test exclusive2-1.2 { + set ::sig [t1sig] + readPagerChangeCounter test.db +} {1} +do_test exclusive2-1.3 { + t1sig +} $::sig +do_test exclusive2-1.4 { + sqlite3 db2 test.db + t1sig db2 +} $::sig +do_test exclusive2-1.5 { + execsql { + UPDATE t1 SET b=a, a=0; + } db2 + expr {[t1sig db2] eq $::sig} +} 0 +do_test exclusive2-1.6 { + readPagerChangeCounter test.db +} {2} +do_test exclusive2-1.7 { + pagerChangeCounter test.db 1 +} {1} +if {[permutation] != "memsubsys1"} { + do_test exclusive2-1.9 { + t1sig + expr {[t1sig] eq $::sig} + } {1} +} +do_test exclusive2-1.10 { + pagerChangeCounter test.db 2 +} {2} +do_test exclusive2-1.11 { + expr {[t1sig] eq $::sig} +} {0} +db2 close + +#-------------------------------------------------------------------- +# These tests - exclusive2-2.X - are similar to exclusive2-1.X, +# except that they are run with locking_mode=EXCLUSIVE. +# +# 1-3: Build a database with exclusive-access connection 1, +# calculate a signature. +# 4: Corrupt the database by writing 10000 bytes of garbage +# starting at the beginning of page 2. Check that connection 1 +# still works. It should be accessing the in-memory cache. +# 5-6: Modify the dataase change-counter. Connection 1 still works +# entirely from in-memory cache, because it doesn't check the +# change-counter. +# 7-8 Set the locking-mode back to normal. After the db is unlocked, +# SQLite detects the modified change-counter and discards the +# in-memory cache. Then it finds the corruption caused in step 4.... +# +# As above, this test is only applicable if the pager cache is +# large enough to hold the entire database. With 1024 byte pages, +# this means 19 pages. We also need to disable the soft-heap-limit +# to prevent memory-induced cache spills. +# +do_test exclusive2-2.1 { + execsql {PRAGMA cache_size=1000;} + execsql {PRAGMA locking_mode = exclusive;} + execsql { + BEGIN; + DELETE FROM t1; + INSERT INTO t1(a) VALUES(randstr(10, 400)); + INSERT INTO t1(a) VALUES(randstr(10, 400)); + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + INSERT INTO t1(a) SELECT randstr(10, 400) FROM t1; + COMMIT; + SELECT count(*) FROM t1; + } +} {64} +do_test exclusive2-2.2.1 { + # Make sure the pager cache is large enough to store the + # entire database. + set nPage [expr [file size test.db]/1024] + if {$::SQLITE_DEFAULT_CACHE_SIZE < $nPage} { + execsql "PRAGMA cache_size = $nPage" + } + expr {[execsql {PRAGMA cache_size}] >= $nPage} +} {1} +do_test exclusive2-2.2 { + set ::sig [t1sig] + readPagerChangeCounter test.db +} {3} +do_test exclusive2-2.3 { + t1sig +} $::sig + +do_test exclusive2-2.4 { + set ::fd [open test.db RDWR] + fconfigure $::fd -translation binary + seek $::fd 1024 + puts -nonewline $::fd [string repeat [binary format c 0] 10000] + flush $::fd + t1sig +} $::sig + +do_test exclusive2-2.5 { + pagerChangeCounter test.db 5 $::fd +} {5} +do_test exclusive2-2.6 { + t1sig +} $::sig +do_test exclusive2-2.7 { + execsql {PRAGMA locking_mode = normal} + t1sig +} $::sig + +do_test exclusive2-2.8 { + set rc [catch {t1sig} msg] + list $rc $msg +} {1 {database disk image is malformed}} + +#-------------------------------------------------------------------- +# These tests - exclusive2-3.X - verify that the pager change-counter +# is only incremented by the first change when in exclusive access +# mode. In normal mode, the change-counter is incremented once +# per write-transaction. +# + +db close +catch {close $::fd} +forcedelete test.db +forcedelete test.db-journal + +do_test exclusive2-3.0 { + sqlite3 db test.db + execsql { + BEGIN; + CREATE TABLE t1(a UNIQUE); + INSERT INTO t1 VALUES(randstr(200, 200)); + INSERT INTO t1 VALUES(randstr(200, 200)); + COMMIT; + } + readPagerChangeCounter test.db +} {1} +do_test exclusive2-3.1 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {2} +do_test exclusive2-3.2 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {3} +do_test exclusive2-3.3 { + execsql { + PRAGMA locking_mode = exclusive; + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.4 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.5 { + execsql { + PRAGMA locking_mode = normal; + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {4} +do_test exclusive2-3.6 { + execsql { + INSERT INTO t1 VALUES(randstr(200, 200)); + } + readPagerChangeCounter test.db +} {5} +sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/exists.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/exists.test new file mode 100644 index 0000000000000000000000000000000000000000..5f9e36eb008914bee147ca1d698fb25d986e1d0f --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/exists.test @@ -0,0 +1,199 @@ +# 2011 April 9 +# +# 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. The +# focus of this file is testing the various schema modification statements +# that feature "IF EXISTS" or "IF NOT EXISTS" clauses. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/lock_common.tcl + + +foreach jm {rollback wal} { + if {![wal_is_capable] && $jm=="wal"} continue + + set testprefix exists-$jm + + # This block of tests is targeted at CREATE XXX IF NOT EXISTS statements. + # + do_multiclient_test tn { + + # TABLE objects. + # + do_test 1.$tn.1.1 { + if {$jm == "wal"} { sql2 { PRAGMA journal_mode = WAL } } + sql2 { CREATE TABLE t1(x) } + sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) } + sql2 { DROP TABLE t1 } + sql1 { CREATE TABLE IF NOT EXISTS t1(a, b) } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {t1} + + do_test 1.$tn.1.2 { + sql2 { CREATE TABLE t2(x) } + sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 } + sql2 { DROP TABLE t2 } + sql1 { CREATE TABLE IF NOT EXISTS t2 AS SELECT * FROM t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {t1 t2} + + + # INDEX objects. + # + do_test 1.$tn.2 { + sql2 { CREATE INDEX i1 ON t1(a) } + sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) } + sql2 { DROP INDEX i1 } + sql1 { CREATE INDEX IF NOT EXISTS i1 ON t1(a, b) } + sql2 { SELECT name FROM sqlite_master WHERE type = 'index' } + } {i1} + + # VIEW objects. + # + do_test 1.$tn.3 { + sql2 { CREATE VIEW v1 AS SELECT * FROM t1 } + sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 } + sql2 { DROP VIEW v1 } + sql1 { CREATE VIEW IF NOT EXISTS v1 AS SELECT * FROM t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'view' } + } {v1} + + # TRIGGER objects. + # + do_test $tn.4 { + sql2 { CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql2 { DROP TRIGGER tr1 } + sql1 { CREATE TRIGGER IF NOT EXISTS tr1 AFTER INSERT ON t1 BEGIN SELECT 1; END } + sql2 { SELECT name FROM sqlite_master WHERE type = 'trigger' } + } {tr1} + } + + # This block of tests is targeted at DROP XXX IF EXISTS statements. + # + do_multiclient_test tn { + + # TABLE objects. + # + do_test 2.$tn.1 { + if {$jm == "wal"} { sql1 { PRAGMA journal_mode = WAL } } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { CREATE TABLE t1(x) } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'table' } + } {} + + # INDEX objects. + # + do_test 2.$tn.2 { + sql1 { CREATE TABLE t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { CREATE INDEX i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'index' } + } {} + + # VIEW objects. + # + do_test 2.$tn.3 { + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { CREATE VIEW v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'view' } + } {} + + # TRIGGER objects. + # + do_test 2.$tn.4 { + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { CREATE TRIGGER tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { SELECT name FROM sqlite_master WHERE type = 'trigger' } + } {} + } + + # This block of tests is targeted at DROP XXX IF EXISTS statements with + # attached databases. + # + do_multiclient_test tn { + + forcedelete test.db2 + do_test 3.$tn.0 { + sql1 { ATTACH 'test.db2' AS aux } + sql2 { ATTACH 'test.db2' AS aux } + } {} + + # TABLE objects. + # + do_test 3.$tn.1.1 { + sql1 { DROP TABLE IF EXISTS aux.t1 } + sql2 { CREATE TABLE aux.t1(x) } + sql1 { DROP TABLE IF EXISTS aux.t1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'table' } + } {} + do_test 3.$tn.1.2 { + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { CREATE TABLE aux.t1(x) } + sql1 { DROP TABLE IF EXISTS t1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'table' } + } {} + + # INDEX objects. + # + do_test 3.$tn.2.1 { + sql1 { CREATE TABLE aux.t2(x) } + sql1 { DROP INDEX IF EXISTS aux.i2 } + sql2 { CREATE INDEX aux.i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS aux.i2 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'index' } + } {} + do_test 3.$tn.2.2 { + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { CREATE INDEX aux.i2 ON t2(x) } + sql1 { DROP INDEX IF EXISTS i2 } + sql2 { SELECT * FROM aux.sqlite_master WHERE type = 'index' } + } {} + + # VIEW objects. + # + do_test 3.$tn.3.1 { + sql1 { DROP VIEW IF EXISTS aux.v1 } + sql2 { CREATE VIEW aux.v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS aux.v1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'view' } + } {} + do_test 3.$tn.3.2 { + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { CREATE VIEW aux.v1 AS SELECT * FROM t2 } + sql1 { DROP VIEW IF EXISTS v1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'view' } + } {} + + # TRIGGER objects. + # + do_test 3.$tn.4.1 { + sql1 { DROP TRIGGER IF EXISTS aux.tr1 } + sql2 { CREATE TRIGGER aux.tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS aux.tr1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'trigger' } + } {} + do_test 3.$tn.4.2 { + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { CREATE TRIGGER aux.tr1 AFTER INSERT ON t2 BEGIN SELECT 1; END } + sql1 { DROP TRIGGER IF EXISTS tr1 } + sql2 { SELECT name FROM aux.sqlite_master WHERE type = 'trigger' } + } {} + } +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/expr.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/expr.test new file mode 100644 index 0000000000000000000000000000000000000000..55b1dc95021a435fc518b1289dff042e412655ac --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/expr.test @@ -0,0 +1,1084 @@ +# 2001 September 15 +# +# 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. The +# focus of this file is testing expressions. +# +# $Id: expr.test,v 1.67 2009/02/04 03:59:25 shane Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Create a table to work with. +# +ifcapable floatingpoint { + execsql {CREATE TABLE test1(i1 int, i2 int, r1 real, r2 real, t1 text, t2 text)} + execsql {INSERT INTO test1 VALUES(1,2,1.1,2.2,'hello','world')} +} +ifcapable !floatingpoint { + execsql {CREATE TABLE test1(i1 int, i2 int, t1 text, t2 text)} + execsql {INSERT INTO test1 VALUES(1,2,'hello','world')} +} + +proc test_expr {name settings expr result} { + do_test $name [format { + execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;} + } $settings $expr] $result +} +proc test_realnum_expr {name settings expr result} { + do_realnum_test $name [format { + execsql {BEGIN; UPDATE test1 SET %s; SELECT %s FROM test1; ROLLBACK;} + } $settings $expr] $result +} + +test_expr expr-1.1 {i1=10, i2=20} {i1+i2} 30 +test_expr expr-1.2 {i1=10, i2=20} {i1-i2} -10 +test_expr expr-1.3 {i1=10, i2=20} {i1*i2} 200 +test_expr expr-1.4 {i1=10, i2=20} {i1/i2} 0 +test_expr expr-1.5 {i1=10, i2=20} {i2/i1} 2 +test_expr expr-1.6 {i1=10, i2=20} {i2i1} 1 +test_expr expr-1.9 {i1=10, i2=20} {i2>=i1} 1 +test_expr expr-1.10 {i1=10, i2=20} {i2!=i1} 1 +test_expr expr-1.11 {i1=10, i2=20} {i2=i1} 0 +test_expr expr-1.12 {i1=10, i2=20} {i2<>i1} 1 +test_expr expr-1.13 {i1=10, i2=20} {i2==i1} 0 +test_expr expr-1.14 {i1=20, i2=20} {i2i1} 0 +test_expr expr-1.17 {i1=20, i2=20} {i2>=i1} 1 +test_expr expr-1.18 {i1=20, i2=20} {i2!=i1} 0 +test_expr expr-1.19 {i1=20, i2=20} {i2=i1} 1 +test_expr expr-1.20 {i1=20, i2=20} {i2<>i1} 0 +test_expr expr-1.21 {i1=20, i2=20} {i2==i1} 1 +ifcapable floatingpoint { + test_expr expr-1.22 {i1=1, i2=2, r1=3.0} {i1+i2*r1} {7.0} + test_expr expr-1.23 {i1=1, i2=2, r1=3.0} {(i1+i2)*r1} {9.0} +} +test_expr expr-1.24 {i1=1, i2=2} {min(i1,i2,i1+i2,i1-i2)} {-1} +test_expr expr-1.25 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} +test_expr expr-1.26 {i1=1, i2=2} {max(i1,i2,i1+i2,i1-i2)} {3} +test_expr expr-1.27 {i1=1, i2=2} {i1==1 AND i2=2} {1} +test_expr expr-1.28 {i1=1, i2=2} {i1=2 AND i2=1} {0} +test_expr expr-1.29 {i1=1, i2=2} {i1=1 AND i2=1} {0} +test_expr expr-1.30 {i1=1, i2=2} {i1=2 AND i2=2} {0} +test_expr expr-1.31 {i1=1, i2=2} {i1==1 OR i2=2} {1} +test_expr expr-1.32 {i1=1, i2=2} {i1=2 OR i2=1} {0} +test_expr expr-1.33 {i1=1, i2=2} {i1=1 OR i2=1} {1} +test_expr expr-1.34 {i1=1, i2=2} {i1=2 OR i2=2} {1} +test_expr expr-1.35 {i1=1, i2=2} {i1-i2=-1} {1} +test_expr expr-1.36 {i1=1, i2=0} {not i1} {0} +test_expr expr-1.37 {i1=1, i2=0} {not i2} {1} +test_expr expr-1.38 {i1=1} {-i1} {-1} +test_expr expr-1.39 {i1=1} {+i1} {1} +test_expr expr-1.40 {i1=1, i2=2} {+(i2+i1)} {3} +test_expr expr-1.41 {i1=1, i2=2} {-(i2+i1)} {-3} +test_expr expr-1.42 {i1=1, i2=2} {i1|i2} {3} +test_expr expr-1.42b {i1=1, i2=2} {4|2} {6} +test_expr expr-1.43 {i1=1, i2=2} {i1&i2} {0} +test_expr expr-1.43b {i1=1, i2=2} {4&5} {4} +test_expr expr-1.44 {i1=1} {~i1} {-2} +test_expr expr-1.44b {i1=NULL} {~i1} {{}} +test_expr expr-1.45a {i1=1, i2=3} {i1<>i2} {8} +test_expr expr-1.45c {i1=1, i2=0} {i1<>i2} {0} +test_expr expr-1.46a {i1=32, i2=3} {i1>>i2} {4} +test_expr expr-1.46b {i1=32, i2=6} {i1>>i2} {0} +test_expr expr-1.46c {i1=-32, i2=3} {i1>>i2} {-4} +test_expr expr-1.46d {i1=-32, i2=100} {i1>>i2} {-1} +test_expr expr-1.46e {i1=32, i2=-3} {i1>>i2} {256} +test_expr expr-1.47 {i1=9999999999, i2=8888888888} {i1i2} 1 +test_expr expr-1.50 {i1=99999999999, i2=99999999998} {i1i2} 1 +test_expr expr-1.53 {i1=099999999999, i2=99999999999} {i1i2} 0 +test_expr expr-1.56 {i1=25, i2=11} {i1%i2} 3 +test_expr expr-1.58 {i1=NULL, i2=1} {coalesce(i1+i2,99)} 99 +test_expr expr-1.59 {i1=1, i2=NULL} {coalesce(i1+i2,99)} 99 +test_expr expr-1.60 {i1=NULL, i2=NULL} {coalesce(i1+i2,99)} 99 +test_expr expr-1.61 {i1=NULL, i2=1} {coalesce(i1-i2,99)} 99 +test_expr expr-1.62 {i1=1, i2=NULL} {coalesce(i1-i2,99)} 99 +test_expr expr-1.63 {i1=NULL, i2=NULL} {coalesce(i1-i2,99)} 99 +test_expr expr-1.64 {i1=NULL, i2=1} {coalesce(i1*i2,99)} 99 +test_expr expr-1.65 {i1=1, i2=NULL} {coalesce(i1*i2,99)} 99 +test_expr expr-1.66 {i1=NULL, i2=NULL} {coalesce(i1*i2,99)} 99 +test_expr expr-1.67 {i1=NULL, i2=1} {coalesce(i1/i2,99)} 99 +test_expr expr-1.68 {i1=1, i2=NULL} {coalesce(i1/i2,99)} 99 +test_expr expr-1.69 {i1=NULL, i2=NULL} {coalesce(i1/i2,99)} 99 +test_expr expr-1.70 {i1=NULL, i2=1} {coalesce(i1i2,99)} 99 +test_expr expr-1.72 {i1=NULL, i2=NULL} {coalesce(i1<=i2,99)} 99 +test_expr expr-1.73 {i1=NULL, i2=1} {coalesce(i1>=i2,99)} 99 +test_expr expr-1.74 {i1=1, i2=NULL} {coalesce(i1!=i2,99)} 99 +test_expr expr-1.75 {i1=NULL, i2=NULL} {coalesce(i1==i2,99)} 99 +test_expr expr-1.76 {i1=NULL, i2=NULL} {coalesce(not i1,99)} 99 +test_expr expr-1.77 {i1=NULL, i2=NULL} {coalesce(-i1,99)} 99 +test_expr expr-1.78 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL AND i2=5,99)} 99 +test_expr expr-1.79 {i1=NULL, i2=NULL} {coalesce(i1 IS NULL OR i2=5,99)} 1 +test_expr expr-1.80 {i1=NULL, i2=NULL} {coalesce(i1=5 AND i2 IS NULL,99)} 99 +test_expr expr-1.81 {i1=NULL, i2=NULL} {coalesce(i1=5 OR i2 IS NULL,99)} 1 +test_expr expr-1.82 {i1=NULL, i2=3} {coalesce(min(i1,i2,1),99)} 99 +test_expr expr-1.83 {i1=NULL, i2=3} {coalesce(max(i1,i2,1),99)} 99 +test_expr expr-1.84 {i1=3, i2=NULL} {coalesce(min(i1,i2,1),99)} 99 +test_expr expr-1.85 {i1=3, i2=NULL} {coalesce(max(i1,i2,1),99)} 99 +test_expr expr-1.86 {i1=3, i2=8} {5 between i1 and i2} 1 +test_expr expr-1.87 {i1=3, i2=8} {5 not between i1 and i2} 0 +test_expr expr-1.88 {i1=3, i2=8} {55 between i1 and i2} 0 +test_expr expr-1.89 {i1=3, i2=8} {55 not between i1 and i2} 1 +test_expr expr-1.90 {i1=3, i2=NULL} {5 between i1 and i2} {{}} +test_expr expr-1.91 {i1=3, i2=NULL} {5 not between i1 and i2} {{}} +test_expr expr-1.92 {i1=3, i2=NULL} {2 between i1 and i2} 0 +test_expr expr-1.93 {i1=3, i2=NULL} {2 not between i1 and i2} 1 +test_expr expr-1.94 {i1=NULL, i2=8} {2 between i1 and i2} {{}} +test_expr expr-1.95 {i1=NULL, i2=8} {2 not between i1 and i2} {{}} +test_expr expr-1.94 {i1=NULL, i2=8} {55 between i1 and i2} 0 +test_expr expr-1.95 {i1=NULL, i2=8} {55 not between i1 and i2} 1 +test_expr expr-1.96 {i1=NULL, i2=3} {coalesce(i1<>i2,99)} 99 +test_expr expr-1.98 {i1=NULL, i2=NULL} {coalesce(i1|i2,99)} 99 +test_expr expr-1.99 {i1=32, i2=NULL} {coalesce(i1&i2,99)} 99 +test_expr expr-1.100 {i1=1, i2=''} {i1=i2} 0 +test_expr expr-1.101 {i1=0, i2=''} {i1=i2} 0 + +# Check for proper handling of 64-bit integer values. +# +if {[working_64bit_int]} { + test_expr expr-1.102 {i1=40, i2=1} {i2<1} 1 +} + +if {[working_64bit_int]} { + test_realnum_expr expr-1.106 {i1=0} {-9223372036854775808/-1} 9.22337203685478e+18 +} + +test_expr expr-1.107 {i1=0} {-9223372036854775808%-1} 0 +test_expr expr-1.108 {i1=0} {1%0} {{}} +test_expr expr-1.109 {i1=0} {1/0} {{}} + +if {[working_64bit_int]} { + test_expr expr-1.110 {i1=0} {-9223372036854775807/-1} 9223372036854775807 +} + +test_expr expr-1.111 {i1=NULL, i2=8} {i1 IS i2} 0 +test_expr expr-1.111b {i1=NULL, i2=8} {i1 IS NOT DISTINCT FROM i2} 0 +test_expr expr-1.112 {i1=NULL, i2=NULL} {i1 IS i2} 1 +test_expr expr-1.112b {i1=NULL, i2=NULL} {i1 IS NOT DISTINCT FROM i2} 1 +test_expr expr-1.113 {i1=6, i2=NULL} {i1 IS i2} 0 +test_expr expr-1.113b {i1=6, i2=NULL} {i1 IS NOT DISTINCT FROM i2} 0 +test_expr expr-1.114 {i1=6, i2=6} {i1 IS i2} 1 +test_expr expr-1.114b {i1=6, i2=6} {i1 IS NOT DISTINCT FROM i2} 1 +test_expr expr-1.115 {i1=NULL, i2=8} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.115b {i1=NULL, i2=8} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.116 {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.116b {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.117 {i1=6, i2=NULL} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.117b {i1=6, i2=NULL} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.118 {i1=8, i2=8} \ + {CASE WHEN i1 IS i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.118b {i1=8, i2=8} \ + {CASE WHEN i1 IS NOT DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.119 {i1=NULL, i2=8} {i1 IS NOT i2} 1 +test_expr expr-1.119b {i1=NULL, i2=8} {i1 IS DISTINCT FROM i2} 1 +test_expr expr-1.120 {i1=NULL, i2=NULL} {i1 IS NOT i2} 0 +test_expr expr-1.120b {i1=NULL, i2=NULL} {i1 IS DISTINCT FROM i2} 0 +test_expr expr-1.121 {i1=6, i2=NULL} {i1 IS NOT i2} 1 +test_expr expr-1.121b {i1=6, i2=NULL} {i1 IS DISTINCT FROM i2} 1 +test_expr expr-1.122 {i1=6, i2=6} {i1 IS NOT i2} 0 +test_expr expr-1.122b {i1=6, i2=6} {i1 IS DISTINCT FROM i2} 0 +test_expr expr-1.123 {i1=NULL, i2=8} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.123b {i1=NULL, i2=8} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.124 {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.124b {i1=NULL, i2=NULL} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.125 {i1=6, i2=NULL} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.125b {i1=6, i2=NULL} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} yes +test_expr expr-1.126 {i1=8, i2=8} \ + {CASE WHEN i1 IS NOT i2 THEN 'yes' ELSE 'no' END} no +test_expr expr-1.126b {i1=8, i2=8} \ + {CASE WHEN i1 IS DISTINCT FROM i2 THEN 'yes' ELSE 'no' END} no + +do_catchsql_test expr-1.127 { + SELECT 1 IS #1; +} {1 {near "#1": syntax error}} + +ifcapable floatingpoint {if {[working_64bit_int]} { + test_expr expr-1.200\ + {i1=9223372036854775806, i2=1} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.201\ + {i1=9223372036854775806, i2=2} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.202\ + {i1=9223372036854775806, i2=100000} {i1+i2} 9.22337203685488e+18 + test_realnum_expr expr-1.203\ + {i1=9223372036854775807, i2=0} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.204\ + {i1=9223372036854775807, i2=1} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.205\ + {i2=9223372036854775806, i1=1} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.206\ + {i2=9223372036854775806, i1=2} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.207\ + {i2=9223372036854775806, i1=100000} {i1+i2} 9.22337203685488e+18 + test_realnum_expr expr-1.208\ + {i2=9223372036854775807, i1=0} {i1+i2} 9223372036854775807 + test_realnum_expr expr-1.209\ + {i2=9223372036854775807, i1=1} {i1+i2} 9.22337203685478e+18 + test_realnum_expr expr-1.210\ + {i1=-9223372036854775807, i2=-1} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.211\ + {i1=-9223372036854775807, i2=-2} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.212\ + {i1=-9223372036854775807, i2=-100000} {i1+i2} -9.22337203685488e+18 + test_realnum_expr expr-1.213\ + {i1=-9223372036854775808, i2=0} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.214\ + {i1=-9223372036854775808, i2=-1} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.215\ + {i2=-9223372036854775807, i1=-1} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.216\ + {i2=-9223372036854775807, i1=-2} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.217\ + {i2=-9223372036854775807, i1=-100000} {i1+i2} -9.22337203685488e+18 + test_realnum_expr expr-1.218\ + {i2=-9223372036854775808, i1=0} {i1+i2} -9223372036854775808 + test_realnum_expr expr-1.219\ + {i2=-9223372036854775808, i1=-1} {i1+i2} -9.22337203685478e+18 + test_realnum_expr expr-1.220\ + {i1=9223372036854775806, i2=-1} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.221\ + {i1=9223372036854775806, i2=-2} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.222\ + {i1=9223372036854775806, i2=-100000} {i1-i2} 9.22337203685488e+18 + test_realnum_expr expr-1.223\ + {i1=9223372036854775807, i2=0} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.224\ + {i1=9223372036854775807, i2=-1} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.225\ + {i2=-9223372036854775806, i1=1} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.226\ + {i2=-9223372036854775806, i1=2} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.227\ + {i2=-9223372036854775806, i1=100000} {i1-i2} 9.22337203685488e+18 + test_realnum_expr expr-1.228\ + {i2=-9223372036854775807, i1=0} {i1-i2} 9223372036854775807 + test_realnum_expr expr-1.229\ + {i2=-9223372036854775807, i1=1} {i1-i2} 9.22337203685478e+18 + test_realnum_expr expr-1.230\ + {i1=-9223372036854775807, i2=1} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.231\ + {i1=-9223372036854775807, i2=2} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.232\ + {i1=-9223372036854775807, i2=100000} {i1-i2} -9.22337203685488e+18 + test_realnum_expr expr-1.233\ + {i1=-9223372036854775808, i2=0} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.234\ + {i1=-9223372036854775808, i2=1} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.235\ + {i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808 + test_realnum_expr expr-1.236\ + {i2=9223372036854775807, i1=-2} {i1-i2} -9.22337203685478e+18 + test_realnum_expr expr-1.237\ + {i2=9223372036854775807, i1=-100000} {i1-i2} -9.22337203685488e+18 + test_realnum_expr expr-1.238\ + {i2=9223372036854775807, i1=0} {i1-i2} -9223372036854775807 + test_realnum_expr expr-1.239\ + {i2=9223372036854775807, i1=-1} {i1-i2} -9223372036854775808 + + test_realnum_expr expr-1.250\ + {i1=4294967296, i2=2147483648} {i1*i2} 9.22337203685478e+18 + test_realnum_expr expr-1.251\ + {i1=4294967296, i2=2147483647} {i1*i2} 9223372032559808512 + test_realnum_expr expr-1.252\ + {i1=-4294967296, i2=2147483648} {i1*i2} -9223372036854775808 + test_realnum_expr expr-1.253\ + {i1=-4294967296, i2=2147483647} {i1*i2} -9223372032559808512 + test_realnum_expr expr-1.254\ + {i1=4294967296, i2=-2147483648} {i1*i2} -9223372036854775808 + test_realnum_expr expr-1.255\ + {i1=4294967296, i2=-2147483647} {i1*i2} -9223372032559808512 + test_realnum_expr expr-1.256\ + {i1=-4294967296, i2=-2147483648} {i1*i2} 9.22337203685478e+18 + test_realnum_expr expr-1.257\ + {i1=-4294967296, i2=-2147483647} {i1*i2} 9223372032559808512 + + test_realnum_expr expr-1.260\ + {i1=3037000500, i2=3037000500} {i1*i2} 9.22337203700025e+18 + test_realnum_expr expr-1.261\ + {i1=3037000500, i2=-3037000500} {i1*i2} -9.22337203700025e+18 + test_realnum_expr expr-1.262\ + {i1=-3037000500, i2=3037000500} {i1*i2} -9.22337203700025e+18 + test_realnum_expr expr-1.263\ + {i1=-3037000500, i2=-3037000500} {i1*i2} 9.22337203700025e+18 + + test_realnum_expr expr-1.264\ + {i1=3037000500, i2=3037000499} {i1*i2} 9223372033963249500 + test_realnum_expr expr-1.265\ + {i1=3037000500, i2=-3037000499} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.266\ + {i1=-3037000500, i2=3037000499} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.267\ + {i1=-3037000500, i2=-3037000499} {i1*i2} 9223372033963249500 + + test_realnum_expr expr-1.268\ + {i1=3037000499, i2=3037000500} {i1*i2} 9223372033963249500 + test_realnum_expr expr-1.269\ + {i1=3037000499, i2=-3037000500} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.270\ + {i1=-3037000499, i2=3037000500} {i1*i2} -9223372033963249500 + test_realnum_expr expr-1.271\ + {i1=-3037000499, i2=-3037000500} {i1*i2} 9223372033963249500 + +}} + +ifcapable floatingpoint { + test_expr expr-2.1 {r1=1.23, r2=2.34} {r1+r2} 3.57 + test_expr expr-2.2 {r1=1.23, r2=2.34} {r1-r2} -1.11 + test_expr expr-2.3 {r1=1.23, r2=2.34} {r1*r2} 2.8782 +} +set tcl_precision 15 +ifcapable floatingpoint { + test_expr expr-2.4 {r1=1.23, r2=2.34} {r1/r2} 0.525641025641026 + test_expr expr-2.5 {r1=1.23, r2=2.34} {r2/r1} 1.90243902439024 + test_expr expr-2.6 {r1=1.23, r2=2.34} {r2r1} 1 + test_expr expr-2.9 {r1=1.23, r2=2.34} {r2>=r1} 1 + test_expr expr-2.10 {r1=1.23, r2=2.34} {r2!=r1} 1 + test_expr expr-2.11 {r1=1.23, r2=2.34} {r2=r1} 0 + test_expr expr-2.12 {r1=1.23, r2=2.34} {r2<>r1} 1 + test_expr expr-2.13 {r1=1.23, r2=2.34} {r2==r1} 0 + test_expr expr-2.14 {r1=2.34, r2=2.34} {r2r1} 0 + test_expr expr-2.17 {r1=2.34, r2=2.34} {r2>=r1} 1 + test_expr expr-2.18 {r1=2.34, r2=2.34} {r2!=r1} 0 + test_expr expr-2.19 {r1=2.34, r2=2.34} {r2=r1} 1 + test_expr expr-2.20 {r1=2.34, r2=2.34} {r2<>r1} 0 + test_expr expr-2.21 {r1=2.34, r2=2.34} {r2==r1} 1 + test_expr expr-2.22 {r1=1.23, r2=2.34} {min(r1,r2,r1+r2,r1-r2)} {-1.11} + test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57} + test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0 + test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0 + test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 + test_expr expr-2.26b {r1=1e300, r2=-1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0 + test_expr expr-2.27 {r1=1.1, r2=0.0} {r1/r2} {{}} + test_expr expr-2.28 {r1=1.1, r2=0.0} {r1%r2} {{}} +} + +test_expr expr-3.1 {t1='abc', t2='xyz'} {t1t2} 0 +test_expr expr-3.8 {t1='xyz', t2='abc'} {t1>t2} 1 +test_expr expr-3.9 {t1='abc', t2='abc'} {t1>t2} 0 +test_expr expr-3.10 {t1='abc', t2='xyz'} {t1>=t2} 0 +test_expr expr-3.11 {t1='xyz', t2='abc'} {t1>=t2} 1 +test_expr expr-3.12 {t1='abc', t2='abc'} {t1>=t2} 1 +test_expr expr-3.13 {t1='abc', t2='xyz'} {t1=t2} 0 +test_expr expr-3.14 {t1='xyz', t2='abc'} {t1=t2} 0 +test_expr expr-3.15 {t1='abc', t2='abc'} {t1=t2} 1 +test_expr expr-3.16 {t1='abc', t2='xyz'} {t1==t2} 0 +test_expr expr-3.17 {t1='xyz', t2='abc'} {t1==t2} 0 +test_expr expr-3.18 {t1='abc', t2='abc'} {t1==t2} 1 +test_expr expr-3.19 {t1='abc', t2='xyz'} {t1<>t2} 1 +test_expr expr-3.20 {t1='xyz', t2='abc'} {t1<>t2} 1 +test_expr expr-3.21 {t1='abc', t2='abc'} {t1<>t2} 0 +test_expr expr-3.22 {t1='abc', t2='xyz'} {t1!=t2} 1 +test_expr expr-3.23 {t1='xyz', t2='abc'} {t1!=t2} 1 +test_expr expr-3.24 {t1='abc', t2='abc'} {t1!=t2} 0 +test_expr expr-3.25 {t1=NULL, t2='hi'} {t1 isnull} 1 +test_expr expr-3.25b {t1=NULL, t2='hi'} {t1 is null} 1 +test_expr expr-3.26 {t1=NULL, t2='hi'} {t2 isnull} 0 +test_expr expr-3.27 {t1=NULL, t2='hi'} {t1 notnull} 0 +test_expr expr-3.28 {t1=NULL, t2='hi'} {t2 notnull} 1 +test_expr expr-3.28b {t1=NULL, t2='hi'} {t2 is not null} 1 +test_expr expr-3.29 {t1='xyz', t2='abc'} {t1||t2} {xyzabc} +test_expr expr-3.30 {t1=NULL, t2='abc'} {t1||t2} {{}} +test_expr expr-3.31 {t1='xyz', t2=NULL} {t1||t2} {{}} +test_expr expr-3.32 {t1='xyz', t2='abc'} {t1||' hi '||t2} {{xyz hi abc}} +test_expr epxr-3.33 {t1='abc', t2=NULL} {coalesce(t1t2,99)} 99 +test_expr epxr-3.36 {t1='abc', t2=NULL} {coalesce(t2>t1,99)} 99 +test_expr epxr-3.37 {t1='abc', t2=NULL} {coalesce(t1<=t2,99)} 99 +test_expr epxr-3.38 {t1='abc', t2=NULL} {coalesce(t2<=t1,99)} 99 +test_expr epxr-3.39 {t1='abc', t2=NULL} {coalesce(t1>=t2,99)} 99 +test_expr epxr-3.40 {t1='abc', t2=NULL} {coalesce(t2>=t1,99)} 99 +test_expr epxr-3.41 {t1='abc', t2=NULL} {coalesce(t1==t2,99)} 99 +test_expr epxr-3.42 {t1='abc', t2=NULL} {coalesce(t2==t1,99)} 99 +test_expr epxr-3.43 {t1='abc', t2=NULL} {coalesce(t1!=t2,99)} 99 +test_expr epxr-3.44 {t1='abc', t2=NULL} {coalesce(t2!=t1,99)} 99 + +test_expr expr-4.1 {t1='abc', t2='Abc'} {t1t2} 1 +test_expr expr-4.3 {t1='abc', t2='Bbc'} {t1t2} 1 +test_expr expr-4.5 {t1='0', t2='0.0'} {t1==t2} 0 +test_expr expr-4.6 {t1='0.000', t2='0.0'} {t1==t2} 0 +test_expr expr-4.7 {t1=' 0.000', t2=' 0.0'} {t1==t2} 0 +test_expr expr-4.8 {t1='0.0', t2='abc'} {t1r2} 0 + test_expr expr-4.11 {r1='abc', r2='Abc'} {r1r2} 1 + test_expr expr-4.13 {r1='abc', r2='Bbc'} {r1r2} 1 + test_expr expr-4.15 {r1='0', r2='0.0'} {r1==r2} 1 + test_expr expr-4.16 {r1='0.000', r2='0.0'} {r1==r2} 1 + test_expr expr-4.17 {r1=' 0.000', r2=' 0.0'} {r1==r2} 1 + test_expr expr-4.18 {r1='0.0', r2='abc'} {r1r2} 0 +} + +# CSL is true if LIKE is case sensitive and false if not. +# NCSL is the opposite. Use these variables as the result +# on operations where case makes a difference. +set CSL $sqlite_options(casesensitivelike) +set NCSL [expr {!$CSL}] + +test_expr expr-5.1 {t1='abc', t2='xyz'} {t1 LIKE t2} 0 +test_expr expr-5.2a {t1='abc', t2='abc'} {t1 LIKE t2} 1 +test_expr expr-5.2b {t1='abc', t2='ABC'} {t1 LIKE t2} $NCSL +test_expr expr-5.3a {t1='abc', t2='a_c'} {t1 LIKE t2} 1 +test_expr expr-5.3b {t1='abc', t2='A_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.4 {t1='abc', t2='abc_'} {t1 LIKE t2} 0 +test_expr expr-5.5a {t1='abc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5b {t1='abc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.5c {t1='abdc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5d {t1='ac', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.5e {t1='ac', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.6a {t1='abxyzzyc', t2='a%c'} {t1 LIKE t2} 1 +test_expr expr-5.6b {t1='abxyzzyc', t2='A%C'} {t1 LIKE t2} $NCSL +test_expr expr-5.7a {t1='abxyzzy', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.7b {t1='abxyzzy', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8a {t1='abxyzzycx', t2='a%c'} {t1 LIKE t2} 0 +test_expr expr-5.8b {t1='abxyzzycy', t2='a%cx'} {t1 LIKE t2} 0 +test_expr expr-5.8c {t1='abxyzzycx', t2='A%C'} {t1 LIKE t2} 0 +test_expr expr-5.8d {t1='abxyzzycy', t2='A%CX'} {t1 LIKE t2} 0 +test_expr expr-5.9a {t1='abc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.9b {t1='ac', t2='a%_c'} {t1 LIKE t2} 0 +test_expr expr-5.9c {t1='abc', t2='A%_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.9d {t1='ac', t2='A%_C'} {t1 LIKE t2} 0 +test_expr expr-5.10a {t1='abxyzzyc', t2='a%_c'} {t1 LIKE t2} 1 +test_expr expr-5.10b {t1='abxyzzyc', t2='A%_C'} {t1 LIKE t2} $NCSL +test_expr expr-5.11 {t1='abc', t2='xyz'} {t1 NOT LIKE t2} 1 +test_expr expr-5.12a {t1='abc', t2='abc'} {t1 NOT LIKE t2} 0 +test_expr expr-5.12b {t1='abc', t2='ABC'} {t1 NOT LIKE t2} $CSL +test_expr expr-5.13 {t1='A'} {t1 LIKE 'A%_'} 0 +test_expr expr-5.14 {t1='AB'} {t1 LIKE 'A%b' ESCAPE 'b'} 0 + +# The following tests only work on versions of TCL that support Unicode +# +if {"\u1234"!="u1234"} { + test_expr expr-5.13a "t1='a\u0080c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.13b "t1='a\u0080c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.14a "t1='a\u07FFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.14b "t1='a\u07FFc', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.15a "t1='a\u0800c', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.15b "t1='a\u0800c', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.16a "t1='a\uFFFFc', t2='a_c'" {t1 LIKE t2} 1 + test_expr expr-5.16b "t1='a\uFFFFc', t2='A_C'" {t1 LIKE t2} $NCSL + test_expr expr-5.17 "t1='a\u0080', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.18 "t1='a\u07FF', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.19 "t1='a\u0800', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.20 "t1='a\uFFFF', t2='A__'" {t1 LIKE t2} 0 + test_expr expr-5.21a "t1='ax\uABCD', t2='a_\uABCD'" {t1 LIKE t2} 1 + test_expr expr-5.21b "t1='ax\uABCD', t2='A_\uABCD'" {t1 LIKE t2} $NCSL + test_expr expr-5.22a "t1='ax\u1234', t2='a%\u1234'" {t1 LIKE t2} 1 + test_expr expr-5.22b "t1='ax\u1234', t2='A%\u1234'" {t1 LIKE t2} $NCSL + test_expr expr-5.23a "t1='ax\uFEDC', t2='a_%'" {t1 LIKE t2} 1 + test_expr expr-5.23b "t1='ax\uFEDC', t2='A_%'" {t1 LIKE t2} $NCSL + test_expr expr-5.24a "t1='ax\uFEDCy\uFEDC', t2='a%\uFEDC'" {t1 LIKE t2} 1 + test_expr expr-5.24b "t1='ax\uFEDCy\uFEDC', t2='A%\uFEDC'" {t1 LIKE t2} $NCSL +} + +test_expr expr-5.54 {t1='abc', t2=NULL} {t1 LIKE t2} {{}} +test_expr expr-5.55 {t1='abc', t2=NULL} {t1 NOT LIKE t2} {{}} +test_expr expr-5.56 {t1='abc', t2=NULL} {t2 LIKE t1} {{}} +test_expr expr-5.57 {t1='abc', t2=NULL} {t2 NOT LIKE t1} {{}} + +# LIKE expressions that use ESCAPE characters. +test_expr expr-5.58a {t1='abc', t2='a_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.58b {t1='abc', t2='A_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.59a {t1='a_c', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.59b {t1='a_c', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.60a {t1='abc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.60b {t1='abc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61a {t1='a7Xc', t2='a7_c'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.61b {t1='a7Xc', t2='A7_C'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.62a {t1='abcde', t2='a%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.62b {t1='abcde', t2='A%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.63a {t1='abcde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.63b {t1='abcde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64a {t1='a7cde', t2='a7%e'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.64b {t1='a7cde', t2='A7%E'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.65a {t1='a7cde', t2='a77%e'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.65b {t1='a7cde', t2='A77%E'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.66a {t1='abc7', t2='a%77'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.66b {t1='abc7', t2='A%77'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.67a {t1='abc_', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 1 +test_expr expr-5.67b {t1='abc_', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} $NCSL +test_expr expr-5.68a {t1='abc7', t2='a%7_'} {t1 LIKE t2 ESCAPE '7'} 0 +test_expr expr-5.68b {t1='abc7', t2='A%7_'} {t1 LIKE t2 ESCAPE '7'} 0 + +# These are the same test as the block above, but using a multi-byte +# character as the escape character. +if {"\u1234"!="u1234"} { + test_expr expr-5.69a "t1='abc', t2='a_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.69b "t1='abc', t2='A_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.70a "t1='a_c', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.70b "t1='a_c', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.71a "t1='abc', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.71b "t1='abc', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.72a "t1='a\u1234Xc', t2='a\u1234_c'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.72b "t1='a\u1234Xc', t2='A\u1234_C'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.73a "t1='abcde', t2='a%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.73b "t1='abcde', t2='A%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.74a "t1='abcde', t2='a\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.74b "t1='abcde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75a "t1='a\u1234cde', t2='a\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.75b "t1='a\u1234cde', t2='A\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.76a "t1='a\u1234cde', t2='a\u1234\u1234%e'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.76b "t1='a\u1234cde', t2='A\u1234\u1234%E'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.77a "t1='abc\u1234', t2='a%\u1234\u1234'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.77b "t1='abc\u1234', t2='A%\u1234\u1234'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.78a "t1='abc_', t2='a%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 1 + test_expr expr-5.78b "t1='abc_', t2='A%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" $NCSL + test_expr expr-5.79a "t1='abc\u1234', t2='a%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 + test_expr expr-5.79b "t1='abc\u1234', t2='A%\u1234_'" \ + "t1 LIKE t2 ESCAPE '\u1234'" 0 +} + +test_expr expr-6.1 {t1='abc', t2='xyz'} {t1 GLOB t2} 0 +test_expr expr-6.2 {t1='abc', t2='ABC'} {t1 GLOB t2} 0 +test_expr expr-6.3 {t1='abc', t2='A?C'} {t1 GLOB t2} 0 +test_expr expr-6.4 {t1='abc', t2='a?c'} {t1 GLOB t2} 1 +test_expr expr-6.5 {t1='abc', t2='abc?'} {t1 GLOB t2} 0 +test_expr expr-6.6 {t1='abc', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.7 {t1='abc', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.8 {t1='abxyzzyc', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.9 {t1='abxyzzy', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.10 {t1='abxyzzycx', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.11 {t1='abc', t2='xyz'} {t1 NOT GLOB t2} 1 +test_expr expr-6.12 {t1='abc', t2='abc'} {t1 NOT GLOB t2} 0 +test_expr expr-6.13 {t1='abc', t2='a[bx]c'} {t1 GLOB t2} 1 +test_expr expr-6.14 {t1='abc', t2='a[cx]c'} {t1 GLOB t2} 0 +test_expr expr-6.15 {t1='abc', t2='a[a-d]c'} {t1 GLOB t2} 1 +test_expr expr-6.16 {t1='abc', t2='a[^a-d]c'} {t1 GLOB t2} 0 +test_expr expr-6.17 {t1='abc', t2='a[A-Dc]c'} {t1 GLOB t2} 0 +test_expr expr-6.18 {t1='abc', t2='a[^A-Dc]c'} {t1 GLOB t2} 1 +test_expr expr-6.19 {t1='abc', t2='a[]b]c'} {t1 GLOB t2} 1 +test_expr expr-6.20 {t1='abc', t2='a[^]b]c'} {t1 GLOB t2} 0 +test_expr expr-6.21a {t1='abcdefg', t2='a*[de]g'} {t1 GLOB t2} 0 +test_expr expr-6.21b {t1='abcdefg', t2='a*[df]g'} {t1 GLOB t2} 1 +test_expr expr-6.21c {t1='abcdefg', t2='a*[d-h]g'} {t1 GLOB t2} 1 +test_expr expr-6.21d {t1='abcdefg', t2='a*[b-e]g'} {t1 GLOB t2} 0 +test_expr expr-6.22a {t1='abcdefg', t2='a*[^de]g'} {t1 GLOB t2} 1 +test_expr expr-6.22b {t1='abcdefg', t2='a*[^def]g'} {t1 GLOB t2} 0 +test_expr expr-6.23 {t1='abcdefg', t2='a*?g'} {t1 GLOB t2} 1 +test_expr expr-6.24 {t1='ac', t2='a*c'} {t1 GLOB t2} 1 +test_expr expr-6.25 {t1='ac', t2='a*?c'} {t1 GLOB t2} 0 +test_expr expr-6.26 {t1='a*c', t2='a[*]c'} {t1 GLOB t2} 1 +test_expr expr-6.27 {t1='a?c', t2='a[?]c'} {t1 GLOB t2} 1 +test_expr expr-6.28 {t1='a[c', t2='a[[]c'} {t1 GLOB t2} 1 + + +# These tests only work on versions of TCL that support Unicode +# +if {"\u1234"!="u1234"} { + test_expr expr-6.26 "t1='a\u0080c', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.27 "t1='a\u07ffc', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.28 "t1='a\u0800c', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.29 "t1='a\uffffc', t2='a?c'" {t1 GLOB t2} 1 + test_expr expr-6.30 "t1='a\u1234', t2='a?'" {t1 GLOB t2} 1 + test_expr expr-6.31 "t1='a\u1234', t2='a??'" {t1 GLOB t2} 0 + test_expr expr-6.32 "t1='ax\u1234', t2='a?\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.33 "t1='ax\u1234', t2='a*\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.34 "t1='ax\u1234y\u1234', t2='a*\u1234'" {t1 GLOB t2} 1 + test_expr expr-6.35 "t1='a\u1234b', t2='a\[x\u1234y\]b'" {t1 GLOB t2} 1 + test_expr expr-6.36 "t1='a\u1234b', t2='a\[\u1233-\u1235\]b'" {t1 GLOB t2} 1 + test_expr expr-6.37 "t1='a\u1234b', t2='a\[\u1234-\u124f\]b'" {t1 GLOB t2} 1 + test_expr expr-6.38 "t1='a\u1234b', t2='a\[\u1235-\u124f\]b'" {t1 GLOB t2} 0 + test_expr expr-6.39 "t1='a\u1234b', t2='a\[a-\u1235\]b'" {t1 GLOB t2} 1 + test_expr expr-6.40 "t1='a\u1234b', t2='a\[a-\u1234\]b'" {t1 GLOB t2} 1 + test_expr expr-6.41 "t1='a\u1234b', t2='a\[a-\u1233\]b'" {t1 GLOB t2} 0 +} + +test_expr expr-6.51 {t1='ABC', t2='xyz'} {t1 GLOB t2} 0 +test_expr expr-6.52 {t1='ABC', t2='abc'} {t1 GLOB t2} 0 +test_expr expr-6.53 {t1='ABC', t2='a?c'} {t1 GLOB t2} 0 +test_expr expr-6.54 {t1='ABC', t2='A?C'} {t1 GLOB t2} 1 +test_expr expr-6.55 {t1='ABC', t2='abc?'} {t1 GLOB t2} 0 +test_expr expr-6.56 {t1='ABC', t2='a*c'} {t1 GLOB t2} 0 +test_expr expr-6.57 {t1='ABC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.58 {t1='ABxyzzyC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.59 {t1='ABxyzzy', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.60 {t1='ABxyzzyCx', t2='A*C'} {t1 GLOB t2} 0 +test_expr expr-6.61 {t1='ABC', t2='xyz'} {t1 NOT GLOB t2} 1 +test_expr expr-6.62 {t1='ABC', t2='ABC'} {t1 NOT GLOB t2} 0 +test_expr expr-6.63 {t1='ABC', t2='A[Bx]C'} {t1 GLOB t2} 1 +test_expr expr-6.64 {t1='ABC', t2='A[Cx]C'} {t1 GLOB t2} 0 +test_expr expr-6.65 {t1='ABC', t2='A[A-D]C'} {t1 GLOB t2} 1 +test_expr expr-6.66 {t1='ABC', t2='A[^A-D]C'} {t1 GLOB t2} 0 +test_expr expr-6.67 {t1='ABC', t2='A[a-dC]C'} {t1 GLOB t2} 0 +test_expr expr-6.68 {t1='ABC', t2='A[^a-dC]C'} {t1 GLOB t2} 1 +test_expr expr-6.69a {t1='ABC', t2='A[]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.69b {t1='A]C', t2='A[]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.70a {t1='ABC', t2='A[^]B]C'} {t1 GLOB t2} 0 +test_expr expr-6.70b {t1='AxC', t2='A[^]B]C'} {t1 GLOB t2} 1 +test_expr expr-6.70c {t1='A]C', t2='A[^]B]C'} {t1 GLOB t2} 0 +test_expr expr-6.71 {t1='ABCDEFG', t2='A*[DE]G'} {t1 GLOB t2} 0 +test_expr expr-6.72 {t1='ABCDEFG', t2='A*[^DE]G'} {t1 GLOB t2} 1 +test_expr expr-6.73 {t1='ABCDEFG', t2='A*?G'} {t1 GLOB t2} 1 +test_expr expr-6.74 {t1='AC', t2='A*C'} {t1 GLOB t2} 1 +test_expr expr-6.75 {t1='AC', t2='A*?C'} {t1 GLOB t2} 0 + +test_expr expr-6.63 {t1=NULL, t2='a*?c'} {t1 GLOB t2} {{}} +test_expr expr-6.64 {t1='ac', t2=NULL} {t1 GLOB t2} {{}} +test_expr expr-6.65 {t1=NULL, t2='a*?c'} {t1 NOT GLOB t2} {{}} +test_expr expr-6.66 {t1='ac', t2=NULL} {t1 NOT GLOB t2} {{}} + +# Check that the affinity of a CAST expression is calculated correctly. +ifcapable cast { + test_expr expr-6.67 {t1='01', t2=1} {t1 = t2} 0 + test_expr expr-6.68 {t1='1', t2=1} {t1 = t2} 1 + test_expr expr-6.69 {t1='01', t2=1} {CAST(t1 AS INTEGER) = t2} 1 +} + +test_expr expr-case.1 {i1=1, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.2 {i1=2, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} eq +test_expr expr-case.3 {i1=NULL, i2=2} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.4 {i1=2, i2=NULL} \ + {CASE WHEN i1 = i2 THEN 'eq' ELSE 'ne' END} ne +test_expr expr-case.5 {i1=2} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} two +test_expr expr-case.6 {i1=1} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} one +test_expr expr-case.7 {i1=2} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error +test_expr expr-case.8 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN NULL THEN 'two' ELSE 'error' END} error +test_expr expr-case.9 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'error' END} error +test_expr expr-case.10 {i1=3} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' END} {{}} +test_expr expr-case.11 {i1=null} \ + {CASE i1 WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 3 END} 3 +test_expr expr-case.12 {i1=1} \ + {CASE i1 WHEN 1 THEN null WHEN 2 THEN 'two' ELSE 3 END} {{}} +test_expr expr-case.13 {i1=7} \ + { CASE WHEN i1 < 5 THEN 'low' + WHEN i1 < 10 THEN 'medium' + WHEN i1 < 15 THEN 'high' ELSE 'error' END} medium + + +# The sqliteExprIfFalse and sqliteExprIfTrue routines are only +# executed as part of a WHERE clause. Create a table suitable +# for testing these functions. +# +execsql {DROP TABLE test1} +execsql {CREATE TABLE test1(a int, b int);} +for {set i 1} {$i<=20} {incr i} { + execsql "INSERT INTO test1 VALUES($i,[expr {1<<$i}])" +} +execsql "INSERT INTO test1 VALUES(NULL,0)" +do_test expr-7.1 { + execsql {SELECT * FROM test1 ORDER BY a} +} {{} 0 1 2 2 4 3 8 4 16 5 32 6 64 7 128 8 256 9 512 10 1024 11 2048 12 4096 13 8192 14 16384 15 32768 16 65536 17 131072 18 262144 19 524288 20 1048576} + +proc test_expr2 {name expr result} { + do_test $name [format { + execsql {SELECT a FROM test1 WHERE %s ORDER BY a} + } $expr] $result +} + +test_expr2 expr-7.2 {a<10 AND a>8} {9} +test_expr2 expr-7.3 {a<=10 AND a>=8} {8 9 10} +test_expr2 expr-7.4 {a>=8 AND a<=10} {8 9 10} +test_expr2 expr-7.5 {a>=20 OR a<=1} {1 20} +test_expr2 expr-7.6 {b!=4 AND a<=3} {1 3} +test_expr2 expr-7.7 {b==8 OR b==16 OR b==32} {3 4 5} +test_expr2 expr-7.8 {NOT b<>8 OR b==1024} {3 10} +test_expr2 expr-7.9 {b LIKE '10%'} {10 20} +test_expr2 expr-7.10 {b LIKE '_4'} {6} +test_expr2 expr-7.11 {a GLOB '1?'} {10 11 12 13 14 15 16 17 18 19} +test_expr2 expr-7.12 {b GLOB '1*4'} {10 14} +test_expr2 expr-7.13 {b GLOB '*1[456]'} {4} +test_expr2 expr-7.14 {a ISNULL} {{}} +test_expr2 expr-7.15 {a NOTNULL AND a<3} {1 2} +test_expr2 expr-7.16 {a AND a<3} {1 2} +test_expr2 expr-7.17 {NOT a} {} +test_expr2 expr-7.18 {a==11 OR (b>1000 AND b<2000)} {10 11} +test_expr2 expr-7.19 {a<=1 OR a>=20} {1 20} +test_expr2 expr-7.20 {a<1 OR a>20} {} +test_expr2 expr-7.21 {a>19 OR a<1} {20} +test_expr2 expr-7.22 {a!=1 OR a=100} \ + {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +test_expr2 expr-7.23 {(a notnull AND a<4) OR a==8} {1 2 3 8} +test_expr2 expr-7.24 {a LIKE '2_' OR a==8} {8 20} +test_expr2 expr-7.25 {a GLOB '2?' OR a==8} {8 20} +test_expr2 expr-7.26 {a isnull OR a=8} {{} 8} +test_expr2 expr-7.27 {a notnull OR a=8} \ + {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} +test_expr2 expr-7.28 {a<0 OR b=0} {{}} +test_expr2 expr-7.29 {b=0 OR a<0} {{}} +test_expr2 expr-7.30 {a<0 AND b=0} {} +test_expr2 expr-7.31 {b=0 AND a<0} {} +test_expr2 expr-7.32 {a IS NULL AND (a<0 OR b=0)} {{}} +test_expr2 expr-7.33 {a IS NULL AND (b=0 OR a<0)} {{}} +test_expr2 expr-7.34 {a IS NULL AND (a<0 AND b=0)} {} +test_expr2 expr-7.35 {a IS NULL AND (b=0 AND a<0)} {} +test_expr2 expr-7.32 {(a<0 OR b=0) AND a IS NULL} {{}} +test_expr2 expr-7.33 {(b=0 OR a<0) AND a IS NULL} {{}} +test_expr2 expr-7.34 {(a<0 AND b=0) AND a IS NULL} {} +test_expr2 expr-7.35 {(b=0 AND a<0) AND a IS NULL} {} +test_expr2 expr-7.36 {a<2 OR (a<0 OR b=0)} {{} 1} +test_expr2 expr-7.37 {a<2 OR (b=0 OR a<0)} {{} 1} +test_expr2 expr-7.38 {a<2 OR (a<0 AND b=0)} {1} +test_expr2 expr-7.39 {a<2 OR (b=0 AND a<0)} {1} +ifcapable floatingpoint { + test_expr2 expr-7.40 {((a<2 OR a IS NULL) AND b<3) OR b>1e10} {{} 1} +} +test_expr2 expr-7.41 {a BETWEEN -1 AND 1} {1} +test_expr2 expr-7.42 {a NOT BETWEEN 2 AND 100} {1} +test_expr2 expr-7.43 {(b+1234)||'this is a string that is at least 32 characters long' BETWEEN 1 AND 2} {} +test_expr2 expr-7.44 {123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a BETWEEN '123a' AND '123b'} {} +test_expr2 expr-7.45 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123b')<0} {} +test_expr2 expr-7.46 {((123||'xabcdefghijklmnopqrstuvwyxz01234567890'||a) BETWEEN '123a' AND '123z')>0} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20} + +test_expr2 expr-7.50 {((a between 1 and 2 OR 0) AND 1) OR 0} {1 2} +test_expr2 expr-7.51 {((a not between 3 and 100 OR 0) AND 1) OR 0} {1 2} + +ifcapable subquery { + test_expr2 expr-7.52 {((a in (1,2) OR 0) AND 1) OR 0} {1 2} + test_expr2 expr-7.53 \ + {((a not in (3,4,5,6,7,8,9,10) OR 0) AND a<11) OR 0} {1 2} +} +test_expr2 expr-7.54 {((a>0 OR 0) AND a<3) OR 0} {1 2} +ifcapable subquery { + test_expr2 expr-7.55 {((a in (1,2) OR 0) IS NULL AND 1) OR 0} {{}} + test_expr2 expr-7.56 \ + {((a not in (3,4,5,6,7,8,9,10) IS NULL OR 0) AND 1) OR 0} {{}} +} +test_expr2 expr-7.57 {((a>0 IS NULL OR 0) AND 1) OR 0} {{}} + +test_expr2 expr-7.58 {(a||'')<='1'} {1} + +test_expr2 expr-7.59 {LIKE('10%',b)} {10 20} +test_expr2 expr-7.60 {LIKE('_4',b)} {6} +test_expr2 expr-7.61 {GLOB('1?',a)} {10 11 12 13 14 15 16 17 18 19} +test_expr2 expr-7.62 {GLOB('1*4',b)} {10 14} +test_expr2 expr-7.63 {GLOB('*1[456]',b)} {4} +test_expr2 expr-7.64 {b = abs(-2)} {1} +test_expr2 expr-7.65 {b = abs(+-2)} {1} +test_expr2 expr-7.66 {b = abs(++-2)} {1} +test_expr2 expr-7.67 {b = abs(+-+-2)} {1} +test_expr2 expr-7.68 {b = abs(+-++-2)} {1} +test_expr2 expr-7.69 {b = abs(++++-2)} {1} +test_expr2 expr-7.70 {b = 5 - abs(+3)} {1} +test_expr2 expr-7.71 {b = 5 - abs(-3)} {1} +ifcapable floatingpoint { + test_expr2 expr-7.72 {b = abs(-2.0)} {1} +} +test_expr2 expr-7.73 {b = 6 - abs(-a)} {2} +ifcapable floatingpoint { + test_expr2 expr-7.74 {b = abs(8.0)} {3} +} + +# Test the CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP expressions. +# +ifcapable {floatingpoint} { + set sqlite_current_time 1157124849 + do_test expr-8.1 { + execsql {SELECT CURRENT_TIME} + } {15:34:09} + do_test expr-8.2 { + execsql {SELECT CURRENT_DATE} + } {2006-09-01} + do_test expr-8.3 { + execsql {SELECT CURRENT_TIMESTAMP} + } {{2006-09-01 15:34:09}} +} +ifcapable datetime { + do_test expr-8.4 { + execsql {SELECT CURRENT_TIME==time('now');} + } 1 + do_test expr-8.5 { + execsql {SELECT CURRENT_DATE==date('now');} + } 1 + do_test expr-8.6 { + execsql {SELECT CURRENT_TIMESTAMP==datetime('now');} + } 1 +} +set sqlite_current_time 0 + +ifcapable floatingpoint { + do_test expr-9.1 { + execsql {SELECT round(-('-'||'123'))} + } 123.0 +} + +# Test an error message that can be generated by the LIKE expression +do_test expr-10.1 { + catchsql {SELECT 'abc' LIKE 'abc' ESCAPE ''} +} {1 {ESCAPE expression must be a single character}} +do_test expr-10.2 { + catchsql {SELECT 'abc' LIKE 'abc' ESCAPE 'ab'} +} {1 {ESCAPE expression must be a single character}} + +# If we specify an integer constant that is bigger than the largest +# possible integer, code the integer as a real number. +# +do_test expr-11.1 { + execsql {SELECT typeof(9223372036854775807)} +} {integer} +do_test expr-11.2 { + execsql {SELECT typeof(00000009223372036854775807)} +} {integer} +do_test expr-11.3 { + execsql {SELECT typeof(+9223372036854775807)} +} {integer} +do_test expr-11.4 { + execsql {SELECT typeof(+000000009223372036854775807)} +} {integer} +do_test expr-11.5 { + execsql {SELECT typeof(9223372036854775808)} +} {real} +do_test expr-11.6 { + execsql {SELECT typeof(00000009223372036854775808)} +} {real} +do_test expr-11.7 { + execsql {SELECT typeof(+9223372036854775808)} +} {real} +do_test expr-11.8 { + execsql {SELECT typeof(+0000009223372036854775808)} +} {real} +do_test expr-11.11 { + execsql {SELECT typeof(-9223372036854775808)} +} {integer} +do_test expr-11.12 { + execsql {SELECT typeof(-00000009223372036854775808)} +} {integer} +ifcapable floatingpoint { + do_test expr-11.13 { + execsql {SELECT typeof(-9223372036854775809)} + } {real} + do_test expr-11.14 { + execsql {SELECT typeof(-00000009223372036854775809)} + } {real} +} + +# These two statements used to leak memory (because of missing %destructor +# directives in parse.y). +do_test expr-12.1 { + catchsql { + SELECT (CASE a>4 THEN 1 ELSE 0 END) FROM test1; + } +} {1 {near "THEN": syntax error}} +do_test expr-12.2 { + catchsql { + SELECT (CASE WHEN a>4 THEN 1 ELSE 0) FROM test1; + } +} {1 {near ")": syntax error}} + +ifcapable floatingpoint { + do_realnum_test expr-13.1 { + execsql { + SELECT 12345678901234567890; + } + } {1.23456789012346e+19} +} + +# Implicit String->Integer conversion is used when possible. +# +if {[working_64bit_int]} { + do_test expr-13.2 { + execsql { + SELECT 0+'9223372036854775807' + } + } {9223372036854775807} + do_test expr-13.3 { + execsql { + SELECT '9223372036854775807'+0 + } + } {9223372036854775807} +} + +# If the value is too large, use String->Float conversion. +# +ifcapable floatingpoint { + do_realnum_test expr-13.4 { + execsql { + SELECT 0+'9223372036854775808' + } + } {9.22337203685478e+18} + do_realnum_test expr-13.5 { + execsql { + SELECT '9223372036854775808'+0 + } + } {9.22337203685478e+18} +} + +# Use String->float conversion if the value is explicitly a floating +# point value. +# +do_realnum_test expr-13.6 { + execsql { + SELECT 0+'9223372036854775807.0' + } +} {9.22337203685478e+18} +do_realnum_test expr-13.7 { + execsql { + SELECT '9223372036854775807.0'+0 + } +} {9.22337203685478e+18} + +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_execsql_test expr-13.8 { + SELECT "" <= ''; +} {1} +do_execsql_test expr-13.9 { + SELECT '' <= ""; +} {1} + +# 2018-02-26. Ticket https://www.sqlite.org/src/tktview/36fae083b450e3af85 +# +do_execsql_test expr-14.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(0),(1),(NULL),(0.5),('1x'),('0x'); + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (CASE WHEN x THEN 1 ELSE 0 END); +} {0} +do_execsql_test expr-14.2 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (NOT NOT x); +} {0} +do_execsql_test expr-14.3 { + SELECT sum(NOT x) FROM t1 + WHERE x +} {0} +do_execsql_test expr-14.4 { + SELECT sum(CASE WHEN x THEN 0 ELSE 1 END) FROM t1 + WHERE x +} {0} + + +foreach {tn val} [list 1 NaN 2 -NaN 3 NaN0 4 -NaN0 5 Inf 6 -Inf] { + do_execsql_test expr-15.$tn.1 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(x); + INSERT INTO t1 VALUES(0),(1),(NULL),(0.5),('1x'),('0x'); + } + + do_test expr-15.$tn.2 { + set ::STMT [sqlite3_prepare db "INSERT INTO t1 VALUES(?)" -1 TAIL] + sqlite3_bind_double $::STMT 1 $val + sqlite3_step $::STMT + sqlite3_reset $::STMT + sqlite3_finalize $::STMT + } {SQLITE_OK} + + do_execsql_test expr-15.$tn.3 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (CASE WHEN x THEN 1 ELSE 0 END); + } {0} + + do_execsql_test expr-15.$tn.4 { + SELECT count(*) FROM t1 + WHERE (x OR (8==9)) != (NOT NOT x); + } {0} + + do_execsql_test expr-15.$tn.5 { + SELECT sum(NOT x) FROM t1 + WHERE x + } {0} + + do_execsql_test expr-15.$tn.6 { + SELECT sum(CASE WHEN x THEN 0 ELSE 1 END) FROM t1 + WHERE x + } {0} +} + +reset_db +sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db +do_execsql_test expr-16.1 { + CREATE TABLE t1(a,b,c); + CREATE TABLE dual(dummy); + INSERT INTO dual VALUES('X'); +} {} +do_execsql_test expr-16.100 { + SELECT implies_nonnull_row( (b=1 AND 0)>(b=3 AND 0),a) + FROM dual LEFT JOIN t1; +} {0} +do_execsql_test expr-16.101 { + SELECT implies_nonnull_row( (b=1 AND 0)>(b=3 AND a=4),a) + FROM dual LEFT JOIN t1; +} {1} +do_execsql_test expr-16.102 { + SELECT implies_nonnull_row( (b=1 AND a=2)>(b=3 AND a=4),a) + FROM dual LEFT JOIN t1; +} {1} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/expr2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/expr2.test new file mode 100644 index 0000000000000000000000000000000000000000..3dfbadcd900bcf43b22e7001861d9abc6a9b18b9 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/expr2.test @@ -0,0 +1,54 @@ +# 2019 May 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. +# +#*********************************************************************** +# This file implements regression tests for SQLite library. The +# focus of this file is testing expressions. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix expr2 + +do_execsql_test 1.0 { + CREATE TABLE t0(c0); + INSERT INTO t0(c0) VALUES ('val'); +} + +do_execsql_test 1.1 { + SELECT * FROM t0 WHERE ( + ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0 + ) +} {val} + +do_execsql_test 1.2.1 { + SELECT + ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) IS 0 + FROM t0 +} {1} + +do_execsql_test 1.2.2 { + SELECT + ( (0 IS NOT FALSE) OR NOT (0 IS 0 OR (t0.c0 = 1)) ) IS 0 + FROM t0 +} {1} + +do_execsql_test 1.3 { + SELECT ( (0 IS NOT FALSE) OR NOT (0 IS FALSE OR (t0.c0 = 1)) ) FROM t0 +} {0} + +do_execsql_test 1.4.1 { + SELECT (0 IS NOT FALSE) FROM t0 +} {0} +do_execsql_test 1.4.2 { + SELECT NOT (0 IS FALSE OR (t0.c0 = 1)) FROM t0 +} {0} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/exprfault2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/exprfault2.test new file mode 100644 index 0000000000000000000000000000000000000000..acbead59f6b934e6a4e256b055eb2ae8b3766fa2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/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 a100] +} {1 1} + +do_execsql_test fallocate-1.9 { + PRAGMA max_page_count = 100; +} {100} + +#------------------------------------------------------------------------- +# The following tests - fallocate-2.* - test that things work in WAL +# mode as well. +# +set skipwaltests [expr { + [permutation]=="journaltest" || [permutation]=="inmemory_journal" +}] +ifcapable !wal { set skipwaltests 1 } + +if {!$skipwaltests} { + db close + forcedelete test.db + sqlite3 db test.db + file_control_chunksize_test db main [expr 32*1024] + + do_test fallocate-2.1 { + execsql { + PRAGMA page_size = 1024; + PRAGMA journal_mode = WAL; + CREATE TABLE t1(a, b); + } + file size test.db + } [expr 32*1024] + + do_test fallocate-2.2 { + execsql { INSERT INTO t1 VALUES(1, zeroblob(35*1024)) } + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.3 { + execsql { DELETE FROM t1 } + execsql { VACUUM } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.4 { + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 32*1024] + + do_test fallocate-2.5 { + execsql { + INSERT INTO t1 VALUES(2, randomblob(35*1024)); + PRAGMA wal_checkpoint; + INSERT INTO t1 VALUES(3, randomblob(128)); + DELETE FROM t1 WHERE a = 2; + VACUUM; + } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.6 { + sqlite3 db2 test.db + execsql { BEGIN ; SELECT count(a) FROM t1 } db2 + execsql { + INSERT INTO t1 VALUES(4, randomblob(128)); + PRAGMA wal_checkpoint; + } + file size test.db + } [expr 64*1024] + + do_test fallocate-2.7 { + execsql { SELECT count(b) FROM t1 } db2 + } {1} + + do_test fallocate-2.8 { + execsql { COMMIT } db2 + execsql { PRAGMA wal_checkpoint } + file size test.db + } [expr 32*1024] +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/filefmt.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/filefmt.test new file mode 100644 index 0000000000000000000000000000000000000000..b44ef8e29a5f01429e137d0e83ccea76bab882fb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/filefmt.test @@ -0,0 +1,254 @@ +# 2007 April 6 +# +# 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. +# +# This file implements tests to verify database file format. +# +# $Id: filefmt.test,v 1.3 2009/06/18 11:34:43 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Do not use a codec for tests in this file, as the database file is +# manipulated directly using tcl scripts (using the [hexio_write] command). +# +do_not_use_codec + +db close +forcedelete test.db test.db-journal + +# Database begins with valid 16-byte header string. +# +do_test filefmt-1.1 { + sqlite3 db test.db + db eval {CREATE TABLE t1(x)} + db close + hexio_read test.db 0 16 +} {53514C69746520666F726D6174203300} + +# If the 16-byte header is changed, the file will not open +# +do_test filefmt-1.2 { + hexio_write test.db 0 54 + set x [catch {sqlite3 db test.db} err] + lappend x $err +} {0 {}} +do_test filefmt-1.3 { + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} +do_test filefmt-1.4 { + db close + hexio_write test.db 0 53 + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {0 1} + +# The page-size is stored at offset 16 +# +ifcapable pager_pragmas { + foreach pagesize {512 1024 2048 4096 8192 16384 32768} { + if {[info exists SQLITE_MAX_PAGE_SIZE] + && $pagesize>$SQLITE_MAX_PAGE_SIZE} continue + do_test filefmt-1.5.$pagesize.1 { + db close + forcedelete test.db + sqlite3 db test.db + db eval "PRAGMA auto_vacuum=OFF" + db eval "PRAGMA page_size=$pagesize" + db eval {CREATE TABLE t1(x)} + file size test.db + } [expr $pagesize*2] + do_test filefmt-1.5.$pagesize.2 { + hexio_get_int [hexio_read test.db 16 2] + } $pagesize + } +} + +# The page-size must be a power of 2 +# +do_test filefmt-1.6 { + db close + hexio_write test.db 16 [hexio_render_int16 1025] + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} + + +# The page-size must be at least 512 bytes +# +do_test filefmt-1.7 { + db close + hexio_write test.db 16 [hexio_render_int16 256] + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } +} {1 {file is not a database}} + +# Usable space per page (page-size minus unused space per page) +# must be at least 480 bytes +# +ifcapable pager_pragmas { + do_test filefmt-1.8 { + db close + forcedelete test.db + sqlite3 db test.db + db eval {PRAGMA page_size=512; CREATE TABLE t1(x)} + db close + hexio_write test.db 20 21 + sqlite3 db test.db + catchsql { + SELECT count(*) FROM sqlite_master + } + } {1 {file is not a database}} +} + +#------------------------------------------------------------------------- +# The following block of tests - filefmt-2.* - test that versions 3.7.0 +# and later can read and write databases that have been modified or created +# by 3.6.23.1 and earlier. The difference difference is that 3.7.0 stores +# the size of the database in the database file header, whereas 3.6.23.1 +# always derives this from the size of the file. +# +db close +forcedelete test.db + +set a_string_counter 1 +proc a_string {n} { + incr ::a_string_counter + string range [string repeat "${::a_string_counter}." $n] 1 $n +} +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.1.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.1.2 { + hexio_read test.db 28 4 + } {00000009} +} + +do_test filefmt-2.1.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.1.4 { INSERT INTO t2 VALUES(2) } {} +integrity_check filefmt-2.1.5 +do_test filefmt-2.1.6 { hexio_read test.db 28 4 } {00000010} + +db close +forcedelete test.db +sqlite3 db test.db +db func a_string a_string + +do_execsql_test filefmt-2.2.1 { + PRAGMA page_size = 1024; + PRAGMA auto_vacuum = 0; + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(a_string(3000)); + CREATE TABLE t2(a); + INSERT INTO t2 VALUES(1); +} {} +if {![nonzero_reserved_bytes]} { + do_test filefmt-2.2.2 { + hexio_read test.db 28 4 + } {00000009} +} + +do_test filefmt-2.2.3 { + sql36231 { INSERT INTO t1 VALUES(a_string(3000)) } +} {} + +do_execsql_test filefmt-2.2.4 { + PRAGMA integrity_check; + BEGIN; + INSERT INTO t2 VALUES(2); + SAVEPOINT a; + INSERT INTO t2 VALUES(3); + ROLLBACK TO a; +} {ok} + +integrity_check filefmt-2.2.5 +do_execsql_test filefmt-2.2.6 { COMMIT } {} +db close +sqlite3 db test.db +integrity_check filefmt-2.2.7 + +#-------------------------------------------------------------------------- +# Check that ticket 89b8c9ac54 is fixed. Before the fix, the SELECT +# statement would return SQLITE_CORRUPT. The database file was not actually +# corrupted, but SQLite was reporting that it was. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test filefmt-3.1 { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(a, b); +} {} +do_test filefmt-3.2 { + sql36231 { DROP TABLE t1 } +} {} +do_execsql_test filefmt-3.3 { + SELECT * FROM sqlite_master; + PRAGMA integrity_check; +} {ok} + +reset_db +do_execsql_test filefmt-4.1 { + PRAGMA auto_vacuum = 1; + CREATE TABLE t1(x, y); + CREATE TABLE t2(x, y); + + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + INSERT INTO t1 VALUES(randomblob(100), randomblob(100)); + + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; + INSERT INTO t2 SELECT randomblob(100), randomblob(100) FROM t1; +} + +do_test filefmt-4.2 { + sql36231 { INSERT INTO t2 SELECT * FROM t1 } +} {} + +do_test filefmt-4.3 { + forcedelete bak.db + db backup bak.db +} {} + +do_test filefmt-4.4 { + sqlite3 db2 bak.db + db2 eval { PRAGMA integrity_check } +} {ok} +db2 close + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/filter1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/filter1.test new file mode 100644 index 0000000000000000000000000000000000000000..bb36e179b3b3b645504c959091593c5d8020712a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/filter1.test @@ -0,0 +1,237 @@ +# 2018 May 8 +# +# 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 filter1 + +ifcapable !windowfunc { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a); + CREATE INDEX i1 ON t1(a); + INSERT INTO t1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9); +} + +do_execsql_test 1.1 { SELECT sum(a) FROM t1; } 45 +do_execsql_test 1.2 { SELECT sum(a) FILTER( WHERE a<5 ) FROM t1; } 10 + +do_execsql_test 1.3 { + SELECT sum(a) FILTER( WHERE a>9 ), + sum(a) FILTER( WHERE a>8 ), + sum(a) FILTER( WHERE a>7 ), + sum(a) FILTER( WHERE a>6 ), + sum(a) FILTER( WHERE a>5 ), + sum(a) FILTER( WHERE a>4 ), + sum(a) FILTER( WHERE a>3 ), + sum(a) FILTER( WHERE a>2 ), + sum(a) FILTER( WHERE a>1 ), + sum(a) FILTER( WHERE a>0 ) + FROM t1; +} {{} 9 17 24 30 35 39 42 44 45} + +do_execsql_test 1.4 { + SELECT max(a) FILTER (WHERE (a % 2)==0) FROM t1 +} {8} + +do_execsql_test 1.5 { + SELECT min(a) FILTER (WHERE a>4) FROM t1 +} {5} + +do_execsql_test 1.6 { + SELECT count(*) FILTER (WHERE a!=5) FROM t1 +} {8} + +do_execsql_test 1.7 { + SELECT min(a) FILTER (WHERE a>3) FROM t1 GROUP BY (a%2) ORDER BY 1; +} {4 5} + +do_execsql_test 1.8 { + CREATE VIEW vv AS + SELECT sum(a) FILTER( WHERE a>9 ), + sum(a) FILTER( WHERE a>8 ), + sum(a) FILTER( WHERE a>7 ), + sum(a) FILTER( WHERE a>6 ), + sum(a) FILTER( WHERE a>5 ), + sum(a) FILTER( WHERE a>4 ), + sum(a) FILTER( WHERE a>3 ), + sum(a) FILTER( WHERE a>2 ), + sum(a) FILTER( WHERE a>1 ), + sum(a) FILTER( WHERE a>0 ) + FROM t1; + SELECT * FROM vv; +} {{} 9 17 24 30 35 39 42 44 45} + + +#------------------------------------------------------------------------- +# Test some errors: +# +# .1 FILTER on a non-aggregate function, +# .2 Window function in FILTER clause, +# .3 Aggregate function in FILTER clause, +# +reset_db +do_execsql_test 2.0 { + CREATE TABLE t1(a); + INSERT INTO t1 VALUES(1), (2), (3), (4), (5), (6), (7), (8), (9); +} + +do_catchsql_test 2.1 { + SELECT upper(a) FILTER (WHERE a=1) FROM t1 +} {1 {FILTER may not be used with non-aggregate upper()}} + +do_catchsql_test 2.2 { + SELECT sum(a) FILTER (WHERE 1 - max(a) OVER () > 0) FROM t1 +} {1 {misuse of window function max()}} + +do_catchsql_test 2.3 { + SELECT sum(a) FILTER (WHERE 1 - count(a)) FROM t1 +} {1 {misuse of aggregate function count()}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 3.0 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1, 1); +} +do_execsql_test 3.1 { + SELECT b, max(a) FILTER (WHERE b='x') FROM t1; +} {1 {}} + +do_execsql_test 3.2 { + CREATE TABLE t2(a, b, c); + INSERT INTO t2 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 3, 4); + INSERT INTO t2 VALUES(2, 5, 6); + INSERT INTO t2 VALUES(2, 7, 8); +} +do_execsql_test 3.3 { + SELECT a, c, max(b) FILTER (WHERE c='x') FROM t2 GROUP BY a; +} {1 3 {} 2 6 {}} + +do_execsql_test 3.4 { + DELETE FROM t2; + INSERT INTO t2 VALUES(1, 5, 'x'); + INSERT INTO t2 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 4, 'x'); + INSERT INTO t2 VALUES(2, 5, 6); + INSERT INTO t2 VALUES(2, 7, 8); +} +do_execsql_test 3.5 { + SELECT a, c, max(b) FILTER (WHERE c='x') FROM t2 GROUP BY a; +} {1 x 5 2 6 {}} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1(a, b, c); + INSERT INTO t1 VALUES('a', 0, 5); + INSERT INTO t1 VALUES('a', 1, 10); + INSERT INTO t1 VALUES('a', 0, 15); + + INSERT INTO t1 VALUES('b', 0, 5); + INSERT INTO t1 VALUES('b', 1, 1000); + INSERT INTO t1 VALUES('b', 0, 5); + + INSERT INTO t1 VALUES('c', 0, 1); + INSERT INTO t1 VALUES('c', 1, 2); + INSERT INTO t1 VALUES('c', 0, 3); +} + +do_execsql_test 4.1 { + SELECT avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY h; +} {2.0 5.0 10.0} +do_execsql_test 4.2 { + SELECT avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY (h+1.0); +} {2.0 5.0 10.0} +do_execsql_test 4.3 { + SELECT a, avg(c) FILTER (WHERE b!=1) AS h FROM t1 GROUP BY a ORDER BY avg(c); +} {c 2.0 a 10.0 b 5.0} +do_execsql_test 4.4 { + SELECT a, avg(c) FILTER (WHERE b!=1) FROM t1 GROUP BY a ORDER BY 2 +} {c 2.0 b 5.0 a 10.0} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(1, 3); +} + +do_execsql_test 5.1 { + SELECT count(*) FILTER (WHERE b>2) FROM (SELECT * FROM t1) +} {1} + +do_execsql_test 5.2 { + SELECT count(*) FILTER (WHERE b>2) OVER () FROM (SELECT * FROM t1) +} {1 1} + +do_execsql_test 5.3 { + SELECT count(*) FILTER (WHERE b>2) OVER (ORDER BY b) FROM (SELECT * FROM t1) +} {0 1} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 6.0 { + CREATE TABLE t1(a,b); + INSERT INTO t1 VALUES(1,1); + INSERT INTO t1 VALUES(2,2); + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,1); +} + +do_execsql_test 6.1 { + SELECT (SELECT COUNT(a) FILTER(WHERE x) FROM t2) FROM t1; +} {1 1} +do_execsql_test 6.2 { + SELECT (SELECT COUNT(a+x) FROM t2) FROM t1; +} {1 1} +do_execsql_test 6.3 { + SELECT (SELECT COUNT(a) FROM t2) FROM t1; +} {2} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 7.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + INSERT INTO t1 VALUES(321, 100000); + INSERT INTO t1 VALUES(111, 110000); + INSERT INTO t1 VALUES(444, 120000); + INSERT INTO t1 VALUES(222, 130000); +} + +do_execsql_test 7.1 { + SELECT max(a), max(a) FILTER (WHERE b<12345), b FROM t1; +} { + 444 {} 120000 +} + +# 2023-02-17 dbsqlfuzz 4f8e0de6e272bbbb3e1b41cb5aea31e0b47297e3 +# count() with FILTER clause using the COUNTOFVIEW optimization. +# +reset_db +do_execsql_test 8.0 { + CREATE TABLE t0(c0 INT); + CREATE TABLE t1a(a INTEGER PRIMARY KEY, b TEXT); + INSERT INTO t1a VALUES(1,'one'),(2,NULL),(3,'three'); + CREATE TABLE t1b(c INTEGER PRIMARY KEY, d TEXT); + INSERT INTO t1b VALUES(4,'four'),(5,NULL),(6,'six'); + CREATE VIEW t1 AS SELECT a, b FROM t1a UNION ALL SELECT c, d FROM t1b; + SELECT count()FILTER(WHERE b IS NULL) FROM t1; +} 2 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/filter2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/filter2.test new file mode 100644 index 0000000000000000000000000000000000000000..06cfd2a4c32155e1a7708869ae6c7ac29236a3dd --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/filter2.test @@ -0,0 +1,156 @@ +# 2019 July 2 +# +# 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 filter2 + +ifcapable !windowfunc { finish_test ; return } +do_execsql_test 1.0 { + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INTEGER); + INSERT INTO t1 VALUES + (1, 7), (2, 3), (3, 5), (4, 30), (5, 26), (6, 23), (7, 27), + (8, 3), (9, 17), (10, 26), (11, 33), (12, 25), (13, NULL), (14, 47), + (15, 36), (16, 13), (17, 45), (18, 31), (19, 11), (20, 36), (21, 37), + (22, 21), (23, 22), (24, 14), (25, 16), (26, 3), (27, 7), (28, 29), + (29, 50), (30, 38), (31, 3), (32, 36), (33, 12), (34, 4), (35, 46), + (36, 3), (37, 48), (38, 23), (39, NULL), (40, 24), (41, 5), (42, 46), + (43, 11), (44, NULL), (45, 18), (46, 25), (47, 15), (48, 18), (49, 23); +} {} + +do_execsql_test 1.1 { + SELECT sum(b) FROM t1 +} {1041} + +do_execsql_test 1.2 { + SELECT sum(b) FILTER (WHERE a<10) FROM t1 +} {141} + +do_execsql_test 1.3 { + SELECT count(DISTINCT b) FROM t1 +} {31} + +do_execsql_test 1.4 { + SELECT count(DISTINCT b) FILTER (WHERE a!=19) FROM t1 +} {31} + +do_execsql_test 1.5 { + SELECT min(b) FILTER (WHERE a>19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1; +} {3 3 88 85} + +do_execsql_test 1.6 { + SELECT min(b), + min(b), + max(a+b), + max(b+a) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} {3 3 58 58 3 3 66 66 3 3 71 71 3 3 88 88 4 4 61 61 5 5 54 54 + 7 7 85 85 11 11 79 79 16 16 81 81 24 24 68 68} + +do_execsql_test 1.7 { + SELECT min(b) FILTER (WHERE a>19), + min(b) FILTER (WHERE a>0), + max(a+b) FILTER (WHERE a>19), + max(b+a) FILTER (WHERE a BETWEEN 10 AND 40) + FROM t1 + GROUP BY (a%10) + ORDER BY 1, 2, 3, 4; +} {3 3 58 58 3 3 71 39 4 4 38 61 7 7 85 85 11 5 54 45 16 16 81 81 + 18 3 66 61 21 3 88 68 23 11 79 79 24 24 68 68} + +do_execsql_test 1.8 { + SELECT sum(a+b) FILTER (WHERE a=NULL) FROM t1 +} {{}} + +do_execsql_test 1.9 { + SELECT (a%5) FROM t1 GROUP BY (a%5) + HAVING sum(b) FILTER (WHERE b<20) > 34 + ORDER BY 1 +} {3 4} + +do_execsql_test 1.10 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 1 +} {3 49 4 46} + +do_execsql_test 1.11 { + SELECT (a%5), sum(b) FILTER (WHERE b<20) AS bbb + FROM t1 + GROUP BY (a%5) HAVING sum(b) FILTER (WHERE b<20) >34 + ORDER BY 2 +} {4 46 3 49} + +do_execsql_test 1.12 { + SELECT (a%5), + sum(b) FILTER (WHERE b<20) AS bbb, + count(distinct b) FILTER (WHERE b<20 OR a=13) AS ccc + FROM t1 GROUP BY (a%5) + ORDER BY 2 +} {2 25 3 0 34 2 1 34 4 4 46 4 3 49 5} + +do_execsql_test 1.13 { + SELECT + string_agg(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=0), + group_concat(CAST(b AS TEXT), '_') FILTER (WHERE b%2!=1), + count(*) FILTER (WHERE b%2!=0), + count(*) FILTER (WHERE b%2!=1) + FROM t1; +} {7_3_5_23_27_3_17_33_25_47_13_45_31_11_37_21_3_7_29_3_3_23_5_11_25_15_23 30_26_26_36_36_22_14_16_50_38_36_12_4_46_48_24_46_18_18 27 19} + + +do_test 1.14 { + set myres {} + foreach r [db eval {SELECT + avg(b) FILTER (WHERE b>a), + avg(b) FILTER (WHERE b([set r2]+0.0001)} { + error "list element [set i] does not match: got=[set r] expected=[set r2]" + } + incr i + } + set {} {} +} {} + +do_execsql_test 1.15 { + SELECT + a/5, + sum(b) FILTER (WHERE a%5=0), + sum(b) FILTER (WHERE a%5=1), + sum(b) FILTER (WHERE a%5=2), + sum(b) FILTER (WHERE a%5=3), + sum(b) FILTER (WHERE a%5=4) + FROM t1 GROUP BY (a/5) ORDER BY 1; +} {0 {} 7 3 5 30 1 26 23 27 3 17 2 26 33 25 {} 47 3 36 13 45 31 11 + 4 36 37 21 22 14 5 16 3 7 29 50 6 38 3 36 12 4 7 46 3 48 23 {} + 8 24 5 46 11 {} 9 18 25 15 18 23} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/filterfault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/filterfault.test new file mode 100644 index 0000000000000000000000000000000000000000..a8cde1f555ab3394af43b1de6674c85083541471 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/filterfault.test @@ -0,0 +1,44 @@ +# 2018 May 8 +# +# 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 filterfault + +ifcapable !windowfunc { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a, b, c, d); + INSERT INTO t1 VALUES(1, 2, 3, 4); + INSERT INTO t1 VALUES(5, 6, 7, 8); + INSERT INTO t1 VALUES(9, 10, 11, 12); +} +faultsim_save_and_close + +do_faultsim_test 1 -faults oom-t* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT sum(a) FILTER (WHERE b<5), + count() FILTER (WHERE d!=c) + FROM t1 GROUP BY c ORDER BY 1; + } +} -test { + faultsim_test_result {0 {{} 1 {} 1 1 1}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey2.test new file mode 100644 index 0000000000000000000000000000000000000000..6f9bdc2b7c929eeb167f435569a3299426e67358 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey2.test @@ -0,0 +1,2047 @@ +# 2009 September 15 +# +# 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. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!foreignkey||!trigger} { + finish_test + return +} + +#------------------------------------------------------------------------- +# Test structure: +# +# fkey2-1.*: Simple tests to check that immediate and deferred foreign key +# constraints work when not inside a transaction. +# +# fkey2-2.*: Tests to verify that deferred foreign keys work inside +# explicit transactions (i.e that processing really is deferred). +# +# fkey2-3.*: Tests that a statement transaction is rolled back if an +# immediate foreign key constraint is violated. +# +# fkey2-4.*: Test that FK actions may recurse even when recursive triggers +# are disabled. +# +# fkey2-5.*: Check that if foreign-keys are enabled, it is not possible +# to write to an FK column using the incremental blob API. +# +# fkey2-6.*: Test that FK processing is automatically disabled when +# running VACUUM. +# +# fkey2-7.*: Test using an IPK as the key in the child (referencing) table. +# +# fkey2-8.*: Test that enabling/disabling foreign key support while a +# transaction is active is not possible. +# +# fkey2-9.*: Test SET DEFAULT actions. +# +# fkey2-10.*: Test errors. +# +# fkey2-11.*: Test CASCADE actions. +# +# fkey2-12.*: Test RESTRICT actions. +# +# fkey2-13.*: Test that FK processing is performed when a row is REPLACED by +# an UPDATE or INSERT statement. +# +# fkey2-14.*: Test the ALTER TABLE and DROP TABLE commands. +# +# fkey2-15.*: Test that if there are no (known) outstanding foreign key +# constraint violations in the database, inserting into a parent +# table or deleting from a child table does not cause SQLite +# to check if this has repaired an outstanding violation. +# +# fkey2-16.*: Test that rows that refer to themselves may be inserted, +# updated and deleted. +# +# fkey2-17.*: Test that the "count_changes" pragma does not interfere with +# FK constraint processing. +# +# fkey2-18.*: Test that the authorization callback is invoked when processing +# FK constraints. +# +# fkey2-20.*: Test that ON CONFLICT clauses specified as part of statements +# do not affect the operation of FK constraints. +# +# fkey2-genfkey.*: Tests that were used with the shell tool .genfkey +# command. Recycled to test the built-in implementation. +# +# fkey2-dd08e5.*: Tests to verify that ticket dd08e5a988d00decc4a543daa8d +# has been fixed. +# + + +execsql { PRAGMA foreign_keys = on } + +set FkeySimpleSchema { + PRAGMA foreign_keys = on; + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c REFERENCES t1(a) /D/ , d); + + CREATE TABLE t3(a PRIMARY KEY, b); + CREATE TABLE t4(c REFERENCES t3 /D/, d); + + CREATE TABLE t7(a, b INTEGER PRIMARY KEY); + CREATE TABLE t8(c REFERENCES t7 /D/, d); + + CREATE TABLE t9(a REFERENCES nosuchtable, b); + CREATE TABLE t10(a REFERENCES t9(c) /D/, b); +} + + +set FkeySimpleTests { + 1.1 "INSERT INTO t2 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 1.2 "INSERT INTO t1 VALUES(1, 2)" {0 {}} + 1.3 "INSERT INTO t2 VALUES(1, 3)" {0 {}} + 1.4 "INSERT INTO t2 VALUES(2, 4)" {1 {FOREIGN KEY constraint failed}} + 1.5 "INSERT INTO t2 VALUES(NULL, 4)" {0 {}} + 1.6 "UPDATE t2 SET c=2 WHERE d=4" {1 {FOREIGN KEY constraint failed}} + 1.7 "UPDATE t2 SET c=1 WHERE d=4" {0 {}} + 1.9 "UPDATE t2 SET c=1 WHERE d=4" {0 {}} + 1.10 "UPDATE t2 SET c=NULL WHERE d=4" {0 {}} + 1.11 "DELETE FROM t1 WHERE a=1" {1 {FOREIGN KEY constraint failed}} + 1.12 "UPDATE t1 SET a = 2" {1 {FOREIGN KEY constraint failed}} + 1.13 "UPDATE t1 SET a = 1" {0 {}} + + 2.1 "INSERT INTO t4 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 2.2 "INSERT INTO t3 VALUES(1, 2)" {0 {}} + 2.3 "INSERT INTO t4 VALUES(1, 3)" {0 {}} + + 4.1 "INSERT INTO t8 VALUES(1, 3)" {1 {FOREIGN KEY constraint failed}} + 4.2 "INSERT INTO t7 VALUES(2, 1)" {0 {}} + 4.3 "INSERT INTO t8 VALUES(1, 3)" {0 {}} + 4.4 "INSERT INTO t8 VALUES(2, 4)" {1 {FOREIGN KEY constraint failed}} + 4.5 "INSERT INTO t8 VALUES(NULL, 4)" {0 {}} + 4.6 "UPDATE t8 SET c=2 WHERE d=4" {1 {FOREIGN KEY constraint failed}} + 4.7 "UPDATE t8 SET c=1 WHERE d=4" {0 {}} + 4.9 "UPDATE t8 SET c=1 WHERE d=4" {0 {}} + 4.10 "UPDATE t8 SET c=NULL WHERE d=4" {0 {}} + 4.11 "DELETE FROM t7 WHERE b=1" {1 {FOREIGN KEY constraint failed}} + 4.12 "UPDATE t7 SET b = 2" {1 {FOREIGN KEY constraint failed}} + 4.13 "UPDATE t7 SET b = 1" {0 {}} + 4.14 "INSERT INTO t8 VALUES('a', 'b')" {1 {FOREIGN KEY constraint failed}} + 4.15 "UPDATE t7 SET b = 5" {1 {FOREIGN KEY constraint failed}} + 4.16 "UPDATE t7 SET rowid = 5" {1 {FOREIGN KEY constraint failed}} + 4.17 "UPDATE t7 SET a = 10" {0 {}} + + 5.1 "INSERT INTO t9 VALUES(1, 3)" {1 {no such table: main.nosuchtable}} + 5.2 "INSERT INTO t10 VALUES(1, 3)" + {1 {foreign key mismatch - "t10" referencing "t9"}} +} + +do_test fkey2-1.1.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] +} {} +foreach {tn zSql res} $FkeySimpleTests { + do_test fkey2-1.1.$tn.1 { catchsql $zSql } $res + do_test fkey2-1.1.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.1.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.1.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.1.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.1.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.1.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +drop_all_tables + +do_test fkey2-1.2.0 { + execsql [string map {/D/ {DEFERRABLE INITIALLY DEFERRED}} $FkeySimpleSchema] +} {} +foreach {tn zSql res} $FkeySimpleTests { + do_test fkey2-1.2.$tn { catchsql $zSql } $res + do_test fkey2-1.2.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.2.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.2.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.2.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.2.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.2.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +drop_all_tables + +do_test fkey2-1.3.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] + execsql { PRAGMA count_changes = 1 } +} {} +foreach {tn zSql res} $FkeySimpleTests { + if {$res == "0 {}"} { set res {0 1} } + do_test fkey2-1.3.$tn { catchsql $zSql } $res + do_test fkey2-1.3.$tn.2 { execsql {PRAGMA foreign_key_check(t1)} } {} + do_test fkey2-1.3.$tn.3 { execsql {PRAGMA foreign_key_check(t2)} } {} + do_test fkey2-1.3.$tn.4 { execsql {PRAGMA foreign_key_check(t3)} } {} + do_test fkey2-1.3.$tn.5 { execsql {PRAGMA foreign_key_check(t4)} } {} + do_test fkey2-1.3.$tn.6 { execsql {PRAGMA foreign_key_check(t7)} } {} + do_test fkey2-1.3.$tn.7 { execsql {PRAGMA foreign_key_check(t8)} } {} +} +execsql { PRAGMA count_changes = 0 } +drop_all_tables + +do_test fkey2-1.4.0 { + execsql [string map {/D/ {}} $FkeySimpleSchema] + execsql { PRAGMA count_changes = 1 } +} {} +foreach {tn zSql res} $FkeySimpleTests { + if {$res == "0 {}"} { set res {0 1} } + execsql BEGIN + do_test fkey2-1.4.$tn { catchsql $zSql } $res + execsql COMMIT +} +execsql { PRAGMA count_changes = 0 } +drop_all_tables + +# Special test: When the parent key is an IPK, make sure the affinity of +# the IPK is not applied to the child key value before it is inserted +# into the child table. +do_test fkey2-1.5.1 { + execsql { + CREATE TABLE i(i INTEGER PRIMARY KEY); + CREATE TABLE j(j REFERENCES i); + INSERT INTO i VALUES(35); + INSERT INTO j VALUES('35.0'); + SELECT j, typeof(j) FROM j; + } +} {35.0 text} +do_test fkey2-1.5.2 { + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Same test using a regular primary key with integer affinity. +drop_all_tables +do_test fkey2-1.6.1 { + execsql { + CREATE TABLE i(i INT UNIQUE); + CREATE TABLE j(j REFERENCES i(i)); + INSERT INTO i VALUES('35.0'); + INSERT INTO j VALUES('35.0'); + SELECT j, typeof(j) FROM j; + SELECT i, typeof(i) FROM i; + } +} {35.0 text 35 integer} +do_test fkey2-1.6.2 { + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Use a collation sequence on the parent key. +drop_all_tables +do_test fkey2-1.7.1 { + execsql { + CREATE TABLE i(i TEXT COLLATE nocase PRIMARY KEY); + CREATE TABLE j(j TEXT COLLATE binary REFERENCES i(i)); + INSERT INTO i VALUES('SQLite'); + INSERT INTO j VALUES('sqlite'); + } + catchsql { DELETE FROM i } +} {1 {FOREIGN KEY constraint failed}} + +# Use the parent key collation even if it is default and the child key +# has an explicit value. +drop_all_tables +do_test fkey2-1.7.2 { + execsql { + CREATE TABLE i(i TEXT PRIMARY KEY); -- Colseq is "BINARY" + CREATE TABLE j(j TEXT COLLATE nocase REFERENCES i(i)); + INSERT INTO i VALUES('SQLite'); + } + catchsql { INSERT INTO j VALUES('sqlite') } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-1.7.3 { + execsql { + INSERT INTO i VALUES('sqlite'); + INSERT INTO j VALUES('sqlite'); + DELETE FROM i WHERE i = 'SQLite'; + } + catchsql { DELETE FROM i WHERE i = 'sqlite' } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# This section (test cases fkey2-2.*) contains tests to check that the +# deferred foreign key constraint logic works. +# +proc fkey2-2-test {tn nocommit sql {res {}}} { + if {$res eq "FKV"} { + set expected {1 {FOREIGN KEY constraint failed}} + } else { + set expected [list 0 $res] + } + do_test fkey2-2.$tn [list catchsql $sql] $expected + if {$nocommit} { + do_test fkey2-2.${tn}c { + catchsql COMMIT + } {1 {FOREIGN KEY constraint failed}} + } +} + +fkey2-2-test 1 0 { + CREATE TABLE node( + nodeid PRIMARY KEY, + parent REFERENCES node DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE leaf( + cellid PRIMARY KEY, + parent REFERENCES node DEFERRABLE INITIALLY DEFERRED + ); +} + +fkey2-2-test 1 0 "INSERT INTO node VALUES(1, 0)" FKV +fkey2-2-test 2 0 "BEGIN" +fkey2-2-test 3 1 "INSERT INTO node VALUES(1, 0)" +fkey2-2-test 4 0 "UPDATE node SET parent = NULL" +fkey2-2-test 5 0 "COMMIT" +fkey2-2-test 6 0 "SELECT * FROM node" {1 {}} + +fkey2-2-test 7 0 "BEGIN" +fkey2-2-test 8 1 "INSERT INTO leaf VALUES('a', 2)" +fkey2-2-test 9 1 "INSERT INTO node VALUES(2, 0)" +fkey2-2-test 10 0 "UPDATE node SET parent = 1 WHERE nodeid = 2" +fkey2-2-test 11 0 "COMMIT" +fkey2-2-test 12 0 "SELECT * FROM node" {1 {} 2 1} +fkey2-2-test 13 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 14 0 "BEGIN" +fkey2-2-test 15 1 "DELETE FROM node WHERE nodeid = 2" +fkey2-2-test 16 0 "INSERT INTO node VALUES(2, NULL)" +fkey2-2-test 17 0 "COMMIT" +fkey2-2-test 18 0 "SELECT * FROM node" {1 {} 2 {}} +fkey2-2-test 19 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 20 0 "BEGIN" +fkey2-2-test 21 0 "INSERT INTO leaf VALUES('b', 1)" +fkey2-2-test 22 0 "SAVEPOINT save" +fkey2-2-test 23 0 "DELETE FROM node WHERE nodeid = 1" +fkey2-2-test 24 0 "ROLLBACK TO save" +fkey2-2-test 25 0 "COMMIT" +fkey2-2-test 26 0 "SELECT * FROM node" {1 {} 2 {}} +fkey2-2-test 27 0 "SELECT * FROM leaf" {a 2 b 1} + +fkey2-2-test 28 0 "BEGIN" +fkey2-2-test 29 0 "INSERT INTO leaf VALUES('c', 1)" +fkey2-2-test 30 0 "SAVEPOINT save" +fkey2-2-test 31 0 "DELETE FROM node WHERE nodeid = 1" +fkey2-2-test 32 1 "RELEASE save" +fkey2-2-test 33 1 "DELETE FROM leaf WHERE cellid = 'b'" +fkey2-2-test 34 0 "DELETE FROM leaf WHERE cellid = 'c'" +fkey2-2-test 35 0 "COMMIT" +fkey2-2-test 36 0 "SELECT * FROM node" {2 {}} +fkey2-2-test 37 0 "SELECT * FROM leaf" {a 2} + +fkey2-2-test 38 0 "SAVEPOINT outer" +fkey2-2-test 39 1 "INSERT INTO leaf VALUES('d', 3)" +fkey2-2-test 40 1 "RELEASE outer" FKV +fkey2-2-test 41 1 "INSERT INTO leaf VALUES('e', 3)" +fkey2-2-test 42 0 "INSERT INTO node VALUES(3, 2)" +fkey2-2-test 43 0 "RELEASE outer" + +fkey2-2-test 44 0 "SAVEPOINT outer" +fkey2-2-test 45 1 "DELETE FROM node WHERE nodeid=3" +fkey2-2-test 47 0 "INSERT INTO node VALUES(3, 2)" +fkey2-2-test 48 0 "ROLLBACK TO outer" +fkey2-2-test 49 0 "RELEASE outer" + +fkey2-2-test 50 0 "SAVEPOINT outer" +fkey2-2-test 51 1 "INSERT INTO leaf VALUES('f', 4)" +fkey2-2-test 52 1 "SAVEPOINT inner" +fkey2-2-test 53 1 "INSERT INTO leaf VALUES('g', 4)" +fkey2-2-test 54 1 "RELEASE outer" FKV +fkey2-2-test 55 1 "ROLLBACK TO inner" +fkey2-2-test 56 0 "COMMIT" FKV +fkey2-2-test 57 0 "INSERT INTO node VALUES(4, NULL)" +fkey2-2-test 58 0 "RELEASE outer" +fkey2-2-test 59 0 "SELECT * FROM node" {2 {} 3 2 4 {}} +fkey2-2-test 60 0 "SELECT * FROM leaf" {a 2 d 3 e 3 f 4} + +# The following set of tests check that if a statement that affects +# multiple rows violates some foreign key constraints, then strikes a +# constraint that causes the statement-transaction to be rolled back, +# the deferred constraint counter is correctly reset to the value it +# had before the statement-transaction was opened. +# +fkey2-2-test 61 0 "BEGIN" +fkey2-2-test 62 0 "DELETE FROM leaf" +fkey2-2-test 63 0 "DELETE FROM node" +fkey2-2-test 64 1 "INSERT INTO leaf VALUES('a', 1)" +fkey2-2-test 65 1 "INSERT INTO leaf VALUES('b', 2)" +fkey2-2-test 66 1 "INSERT INTO leaf VALUES('c', 1)" +do_test fkey2-2-test-67 { + catchsql "INSERT INTO node SELECT parent, 3 FROM leaf" +} {1 {UNIQUE constraint failed: node.nodeid}} +fkey2-2-test 68 0 "COMMIT" FKV +fkey2-2-test 69 1 "INSERT INTO node VALUES(1, NULL)" +fkey2-2-test 70 0 "INSERT INTO node VALUES(2, NULL)" +fkey2-2-test 71 0 "COMMIT" + +fkey2-2-test 72 0 "BEGIN" +fkey2-2-test 73 1 "DELETE FROM node" +fkey2-2-test 74 0 "INSERT INTO node(nodeid) SELECT DISTINCT parent FROM leaf" +fkey2-2-test 75 0 "COMMIT" + +#------------------------------------------------------------------------- +# Test cases fkey2-3.* test that a program that executes foreign key +# actions (CASCADE, SET DEFAULT, SET NULL etc.) or tests FK constraints +# opens a statement transaction if required. +# +# fkey2-3.1.*: Test UPDATE statements. +# fkey2-3.2.*: Test DELETE statements. +# +drop_all_tables +do_test fkey2-3.1.1 { + execsql { + CREATE TABLE ab(a PRIMARY KEY, b); + CREATE TABLE cd( + c PRIMARY KEY REFERENCES ab ON UPDATE CASCADE ON DELETE CASCADE, + d + ); + CREATE TABLE ef( + e REFERENCES cd ON UPDATE CASCADE, + f, CHECK (e!=5) + ); + } +} {} +do_test fkey2-3.1.2 { + execsql { + INSERT INTO ab VALUES(1, 'b'); + INSERT INTO cd VALUES(1, 'd'); + INSERT INTO ef VALUES(1, 'e'); + } +} {} +do_test fkey2-3.1.3 { + catchsql { UPDATE ab SET a = 5 } +} {1 {CHECK constraint failed: e!=5}} +do_test fkey2-3.1.4 { + execsql { SELECT * FROM ab } +} {1 b} +do_test fkey2-3.1.4 { + execsql BEGIN; + catchsql { UPDATE ab SET a = 5 } +} {1 {CHECK constraint failed: e!=5}} +do_test fkey2-3.1.5 { + execsql COMMIT; + execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef } +} {1 b 1 d 1 e} + +do_test fkey2-3.2.1 { + execsql BEGIN; + catchsql { DELETE FROM ab } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-3.2.2 { + execsql COMMIT + execsql { SELECT * FROM ab; SELECT * FROM cd; SELECT * FROM ef } +} {1 b 1 d 1 e} + +#------------------------------------------------------------------------- +# Test cases fkey2-4.* test that recursive foreign key actions +# (i.e. CASCADE) are allowed even if recursive triggers are disabled. +# +drop_all_tables +do_test fkey2-4.1 { + execsql { + CREATE TABLE t1( + node PRIMARY KEY, + parent REFERENCES t1 ON DELETE CASCADE + ); + CREATE TABLE t2(node PRIMARY KEY, parent); + CREATE TRIGGER t2t AFTER DELETE ON t2 BEGIN + DELETE FROM t2 WHERE parent = old.node; + END; + INSERT INTO t1 VALUES(1, NULL); + INSERT INTO t1 VALUES(2, 1); + INSERT INTO t1 VALUES(3, 1); + INSERT INTO t1 VALUES(4, 2); + INSERT INTO t1 VALUES(5, 2); + INSERT INTO t1 VALUES(6, 3); + INSERT INTO t1 VALUES(7, 3); + INSERT INTO t2 SELECT * FROM t1; + } +} {} +do_test fkey2-4.2 { + execsql { PRAGMA recursive_triggers = off } + execsql { + BEGIN; + DELETE FROM t1 WHERE node = 1; + SELECT node FROM t1; + } +} {} +do_test fkey2-4.3 { + execsql { + DELETE FROM t2 WHERE node = 1; + SELECT node FROM t2; + ROLLBACK; + } +} {4 5 6 7} +do_test fkey2-4.4 { + execsql { PRAGMA recursive_triggers = on } + execsql { + BEGIN; + DELETE FROM t1 WHERE node = 1; + SELECT node FROM t1; + } +} {} +do_test fkey2-4.3 { + execsql { + DELETE FROM t2 WHERE node = 1; + SELECT node FROM t2; + ROLLBACK; + } +} {} + +#------------------------------------------------------------------------- +# Test cases fkey2-5.* verify that the incremental blob API may not +# write to a foreign key column while foreign-keys are enabled. +# +drop_all_tables +ifcapable incrblob { + do_test fkey2-5.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1(a)); + INSERT INTO t1 VALUES('hello', 'world'); + INSERT INTO t2 VALUES('key', 'hello'); + } + } {} + do_test fkey2-5.2 { + set rc [catch { set fd [db incrblob t2 b 1] } msg] + list $rc $msg + } {1 {cannot open foreign key column for writing}} + do_test fkey2-5.3 { + set rc [catch { set fd [db incrblob -readonly t2 b 1] } msg] + close $fd + set rc + } {0} + do_test fkey2-5.4 { + execsql { PRAGMA foreign_keys = off } + set rc [catch { set fd [db incrblob t2 b 1] } msg] + close $fd + set rc + } {0} + do_test fkey2-5.5 { + execsql { PRAGMA foreign_keys = on } + } {} +} + +drop_all_tables +ifcapable vacuum { + do_test fkey2-6.1 { + execsql { + CREATE TABLE t1(a REFERENCES t2(c), b); + CREATE TABLE t2(c UNIQUE, b); + INSERT INTO t2 VALUES(1, 2); + INSERT INTO t1 VALUES(1, 2); + VACUUM; + } + } {} +} + +#------------------------------------------------------------------------- +# Test that it is possible to use an INTEGER PRIMARY KEY as the child key +# of a foreign constraint. +# +drop_all_tables +do_test fkey2-7.1 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c INTEGER PRIMARY KEY REFERENCES t1, b); + } +} {} +do_test fkey2-7.2 { + catchsql { INSERT INTO t2 VALUES(1, 'A'); } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.3 { + execsql { + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t1 VALUES(2, 3); + INSERT INTO t2 VALUES(1, 'A'); + } +} {} +do_test fkey2-7.4 { + execsql { UPDATE t2 SET c = 2 } +} {} +do_test fkey2-7.5 { + catchsql { UPDATE t2 SET c = 3 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.6 { + catchsql { DELETE FROM t1 WHERE a = 2 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.7 { + execsql { DELETE FROM t1 WHERE a = 1 } +} {} +do_test fkey2-7.8 { + catchsql { UPDATE t1 SET a = 3 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-7.9 { + catchsql { UPDATE t2 SET rowid = 3 } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Test that it is not possible to enable/disable FK support while a +# transaction is open. +# +drop_all_tables +proc fkey2-8-test {tn zSql value} { + do_test fkey-2.8.$tn.1 [list execsql $zSql] {} + do_test fkey-2.8.$tn.2 { execsql "PRAGMA foreign_keys" } $value +} +fkey2-8-test 1 { PRAGMA foreign_keys = 0 } 0 +fkey2-8-test 2 { PRAGMA foreign_keys = 1 } 1 +fkey2-8-test 3 { BEGIN } 1 +fkey2-8-test 4 { PRAGMA foreign_keys = 0 } 1 +fkey2-8-test 5 { COMMIT } 1 +fkey2-8-test 6 { PRAGMA foreign_keys = 0 } 0 +fkey2-8-test 7 { BEGIN } 0 +fkey2-8-test 8 { PRAGMA foreign_keys = 1 } 0 +fkey2-8-test 9 { COMMIT } 0 +fkey2-8-test 10 { PRAGMA foreign_keys = 1 } 1 +fkey2-8-test 11 { PRAGMA foreign_keys = off } 0 +fkey2-8-test 12 { PRAGMA foreign_keys = on } 1 +fkey2-8-test 13 { PRAGMA foreign_keys = no } 0 +fkey2-8-test 14 { PRAGMA foreign_keys = yes } 1 +fkey2-8-test 15 { PRAGMA foreign_keys = false } 0 +fkey2-8-test 16 { PRAGMA foreign_keys = true } 1 + +#------------------------------------------------------------------------- +# The following tests, fkey2-9.*, test SET DEFAULT actions. +# +drop_all_tables +do_test fkey2-9.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2( + c INTEGER PRIMARY KEY, + d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT + ); + DELETE FROM t1; + } +} {} +do_test fkey2-9.1.2 { + execsql { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t2 VALUES(1, 2); + SELECT * FROM t2; + DELETE FROM t1 WHERE a = 2; + SELECT * FROM t2; + } +} {1 2 1 1} +do_test fkey2-9.1.3 { + execsql { + INSERT INTO t1 VALUES(2, 'two'); + UPDATE t2 SET d = 2; + DELETE FROM t1 WHERE a = 1; + SELECT * FROM t2; + } +} {1 2} +do_test fkey2-9.1.4 { + execsql { SELECT * FROM t1 } +} {2 two} +do_test fkey2-9.1.5 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey2-9.2.1 { + execsql { + CREATE TABLE pp(a, b, c, PRIMARY KEY(b, c)); + CREATE TABLE cc(d DEFAULT 3, e DEFAULT 1, f DEFAULT 2, + FOREIGN KEY(f, d) REFERENCES pp + ON UPDATE SET DEFAULT + ON DELETE SET NULL + ); + INSERT INTO pp VALUES(1, 2, 3); + INSERT INTO pp VALUES(4, 5, 6); + INSERT INTO pp VALUES(7, 8, 9); + } +} {} +do_test fkey2-9.2.2 { + execsql { + INSERT INTO cc VALUES(6, 'A', 5); + INSERT INTO cc VALUES(6, 'B', 5); + INSERT INTO cc VALUES(9, 'A', 8); + INSERT INTO cc VALUES(9, 'B', 8); + UPDATE pp SET b = 1 WHERE a = 7; + SELECT * FROM cc; + } +} {6 A 5 6 B 5 3 A 2 3 B 2} +do_test fkey2-9.2.3 { + execsql { + DELETE FROM pp WHERE a = 4; + SELECT * FROM cc; + } +} {{} A {} {} B {} 3 A 2 3 B 2} +do_execsql_test fkey2-9.3.0 { + CREATE TABLE t3(x PRIMARY KEY REFERENCES t3 ON DELETE SET NULL); + INSERT INTO t3(x) VALUES(12345); + DROP TABLE t3; +} {} + +#------------------------------------------------------------------------- +# The following tests, fkey2-10.*, test "foreign key mismatch" and +# other errors. +# +set tn 0 +foreach zSql [list { + CREATE TABLE p(a PRIMARY KEY, b); + CREATE TABLE c(x REFERENCES p(c)); +} { + CREATE TABLE c(x REFERENCES v(y)); + CREATE VIEW v AS SELECT x AS y FROM c; +} { + CREATE TABLE p(a, b, PRIMARY KEY(a, b)); + CREATE TABLE c(x REFERENCES p); +} { + CREATE TABLE p(a COLLATE binary, b); + CREATE UNIQUE INDEX i ON p(a COLLATE nocase); + CREATE TABLE c(x REFERENCES p(a)); +}] { + drop_all_tables + do_test fkey2-10.1.[incr tn] { + execsql $zSql + catchsql { INSERT INTO c DEFAULT VALUES } + } {/1 {foreign key mismatch - "c" referencing "."}/} +} + +# "rowid" cannot be used as part of a child or parent key definition +# unless it happens to be the name of an explicitly declared column. +# +do_test fkey2-10.2.1 { + drop_all_tables + catchsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(c, d, FOREIGN KEY(rowid) REFERENCES t1(a)); + } +} {1 {unknown column "rowid" in foreign key definition}} +do_test fkey2-10.2.2 { + drop_all_tables + catchsql { + CREATE TABLE t1(a PRIMARY KEY, b); + CREATE TABLE t2(rowid, d, FOREIGN KEY(rowid) REFERENCES t1(a)); + } +} {0 {}} +do_test fkey2-10.2.1 { + drop_all_tables + catchsql { + CREATE TABLE t1(a, b); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); + INSERT INTO t1(rowid, a, b) VALUES(1, 1, 1); + INSERT INTO t2 VALUES(1, 1); + } +} {1 {foreign key mismatch - "t2" referencing "t1"}} +do_test fkey2-10.2.2 { + drop_all_tables + catchsql { + CREATE TABLE t1(rowid PRIMARY KEY, b); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(rowid)); + INSERT INTO t1(rowid, b) VALUES(1, 1); + INSERT INTO t2 VALUES(1, 1); + } +} {0 {}} + + +#------------------------------------------------------------------------- +# The following tests, fkey2-11.*, test CASCADE actions. +# +drop_all_tables +do_test fkey2-11.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, rowid, _rowid_, oid); + CREATE TABLE t2(c, d, FOREIGN KEY(c) REFERENCES t1(a) ON UPDATE CASCADE); + + INSERT INTO t1 VALUES(10, 100, 'abc', 'def', 'ghi'); + INSERT INTO t2 VALUES(10, 100); + UPDATE t1 SET a = 15; + SELECT * FROM t2; + } +} {15 100} + +#------------------------------------------------------------------------- +# The following tests, fkey2-12.*, test RESTRICT actions. +# +drop_all_tables +do_test fkey2-12.1.1 { + execsql { + CREATE TABLE t1(a, b PRIMARY KEY); + CREATE TABLE t2( + x REFERENCES t1 ON UPDATE RESTRICT DEFERRABLE INITIALLY DEFERRED + ); + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t1 VALUES(3, 'three'); + } +} {} +do_test fkey2-12.1.2 { + execsql "BEGIN" + execsql "INSERT INTO t2 VALUES('two')" +} {} +do_test fkey2-12.1.3 { + execsql "UPDATE t1 SET b = 'four' WHERE b = 'one'" +} {} +do_test fkey2-12.1.4 { + catchsql "UPDATE t1 SET b = 'five' WHERE b = 'two'" +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.1.5 { + execsql "DELETE FROM t1 WHERE b = 'two'" +} {} +do_test fkey2-12.1.6 { + catchsql "COMMIT" +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.1.7 { + execsql { + INSERT INTO t1 VALUES(2, 'two'); + COMMIT; + } +} {} + +drop_all_tables +do_test fkey2-12.2.1 { + execsql { + CREATE TABLE t1(x COLLATE NOCASE PRIMARY KEY); + CREATE TRIGGER tt1 AFTER DELETE ON t1 + WHEN EXISTS ( SELECT 1 FROM t2 WHERE old.x = y ) + BEGIN + INSERT INTO t1 VALUES(old.x); + END; + CREATE TABLE t2(y REFERENCES t1); + INSERT INTO t1 VALUES('A'); + INSERT INTO t1 VALUES('B'); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} +do_test fkey2-12.2.2 { + execsql { DELETE FROM t1 } + execsql { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} +do_test fkey2-12.2.3 { + execsql { + DROP TABLE t2; + CREATE TABLE t2(y REFERENCES t1 ON DELETE RESTRICT); + INSERT INTO t2 VALUES('a'); + INSERT INTO t2 VALUES('b'); + } + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.2.4 { + execsql { + SELECT * FROM t1; + SELECT * FROM t2; + } +} {A B a b} + +drop_all_tables +do_test fkey2-12.3.1 { + execsql { + CREATE TABLE up( + c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, + c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, + c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, + c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, + PRIMARY KEY(c34, c35) + ); + CREATE TABLE down( + c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, + c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, + c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, + c30, c31, c32, c33, c34, c35, c36, c37, c38, c39, + FOREIGN KEY(c39, c38) REFERENCES up ON UPDATE CASCADE + ); + } +} {} +do_test fkey2-12.3.2 { + execsql { + INSERT INTO up(c34, c35) VALUES('yes', 'no'); + INSERT INTO down(c39, c38) VALUES('yes', 'no'); + UPDATE up SET c34 = 'possibly'; + SELECT c38, c39 FROM down; + DELETE FROM down; + } +} {no possibly} +do_test fkey2-12.3.3 { + catchsql { INSERT INTO down(c39, c38) VALUES('yes', 'no') } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.3.4 { + execsql { + INSERT INTO up(c34, c35) VALUES('yes', 'no'); + INSERT INTO down(c39, c38) VALUES('yes', 'no'); + } + catchsql { DELETE FROM up WHERE c34 = 'yes' } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-12.3.5 { + execsql { + DELETE FROM up WHERE c34 = 'possibly'; + SELECT c34, c35 FROM up; + SELECT c39, c38 FROM down; + } +} {yes no yes no} + +#------------------------------------------------------------------------- +# The following tests, fkey2-13.*, test that FK processing is performed +# when rows are REPLACEd. +# +drop_all_tables +do_test fkey2-13.1.1 { + execsql { + CREATE TABLE pp(a UNIQUE, b, c, PRIMARY KEY(b, c)); + CREATE TABLE cc(d, e, f UNIQUE, FOREIGN KEY(d, e) REFERENCES pp); + INSERT INTO pp VALUES(1, 2, 3); + INSERT INTO cc VALUES(2, 3, 1); + } +} {} +foreach {tn stmt} { + 1 "REPLACE INTO pp VALUES(1, 4, 5)" + 2 "REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 3, 4)" +} { + do_test fkey2-13.1.$tn.1 { + catchsql $stmt + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-13.1.$tn.2 { + execsql { + SELECT * FROM pp; + SELECT * FROM cc; + } + } {1 2 3 2 3 1} + do_test fkey2-13.1.$tn.3 { + execsql BEGIN; + catchsql $stmt + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-13.1.$tn.4 { + execsql { + COMMIT; + SELECT * FROM pp; + SELECT * FROM cc; + } + } {1 2 3 2 3 1} +} +do_test fkey2-13.1.3 { + execsql { + REPLACE INTO pp(rowid, a, b, c) VALUES(1, 2, 2, 3); + SELECT rowid, * FROM pp; + SELECT * FROM cc; + } +} {1 2 2 3 2 3 1} +do_test fkey2-13.1.4 { + execsql { + REPLACE INTO pp(rowid, a, b, c) VALUES(2, 2, 2, 3); + SELECT rowid, * FROM pp; + SELECT * FROM cc; + } +} {2 2 2 3 2 3 1} + +#------------------------------------------------------------------------- +# The following tests, fkey2-14.*, test that the "DROP TABLE" and "ALTER +# TABLE" commands work as expected wrt foreign key constraints. +# +# fkey2-14.1*: ALTER TABLE ADD COLUMN +# fkey2-14.2*: ALTER TABLE RENAME TABLE +# fkey2-14.3*: DROP TABLE +# +drop_all_tables +ifcapable altertable { + do_test fkey2-14.1.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + CREATE TABLE t1(a PRIMARY KEY); + CREATE TABLE t2(a, b); + INSERT INTO t2 VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + + # Test the sqlite_rename_parent() function directly. + # + proc test_rename_parent {zCreate zOld zNew} { + db eval {SELECT sqlite_rename_table( + 'main', 'table', 't1', $zCreate, $zOld, $zNew, 0 + )} + } + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2.2.1 { + drop_all_tables + execsql { + CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} + + # Repeat for TEMP tables + # + drop_all_tables + do_test fkey2-14.1tmp.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + CREATE TEMP TABLE t1(a PRIMARY KEY); + CREATE TEMP TABLE t2(a, b); + INSERT INTO temp.t2 VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1tmp.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1tmp.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1tmp.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1tmp.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1tmp.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM temp.sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2tmp.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2tmp.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2tmp.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2tmp.2.1 { + drop_all_tables + execsql { + CREATE TEMP TABLE t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TEMP TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TEMP TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM sqlite_temp_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2tmp.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM temp.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2tmp.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2tmp.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2tmp.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2tmp.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2tmp.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} + + # Repeat for ATTACH-ed tables + # + drop_all_tables + do_test fkey2-14.1aux.1 { + # Adding a column with a REFERENCES clause is not supported. + execsql { + ATTACH ':memory:' AS aux; + CREATE TABLE aux.t1(a PRIMARY KEY); + CREATE TABLE aux.t2(a, b); + INSERT INTO aux.t2(a,b) VALUES(1,2); + } + catchsql { ALTER TABLE t2 ADD COLUMN c REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1aux.2 { + catchsql { ALTER TABLE t2 ADD COLUMN d DEFAULT NULL REFERENCES t1 } + } {0 {}} + do_test fkey2-14.1aux.3 { + catchsql { ALTER TABLE t2 ADD COLUMN e REFERENCES t1 DEFAULT NULL} + } {0 {}} + do_test fkey2-14.1aux.4 { + catchsql { ALTER TABLE t2 ADD COLUMN f REFERENCES t1 DEFAULT 'text'} + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1aux.5 { + catchsql { ALTER TABLE t2 ADD COLUMN g DEFAULT CURRENT_TIME REFERENCES t1 } + } {1 {Cannot add a REFERENCES column with non-NULL default value}} + do_test fkey2-14.1aux.6 { + execsql { + PRAGMA foreign_keys = off; + ALTER TABLE t2 ADD COLUMN h DEFAULT 'text' REFERENCES t1; + PRAGMA foreign_keys = on; + SELECT sql FROM aux.sqlite_master WHERE name='t2'; + } + } {{CREATE TABLE t2(a, b, c REFERENCES t1, d DEFAULT NULL REFERENCES t1, e REFERENCES t1 DEFAULT NULL, h DEFAULT 'text' REFERENCES t1)}} + + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + do_test fkey2-14.2aux.1.1 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + do_test fkey2-14.2aux.1.2 { + test_rename_parent {CREATE TABLE t1(a REFERENCES t2)} t4 t3 + } {{CREATE TABLE t1(a REFERENCES t2)}} + do_test fkey2-14.2aux.1.3 { + test_rename_parent {CREATE TABLE t1(a REFERENCES "t2")} t2 t3 + } {{CREATE TABLE t1(a REFERENCES "t3")}} + sqlite3_test_control SQLITE_TESTCTRL_INTERNAL_FUNCTIONS db + + # Test ALTER TABLE RENAME TABLE a bit. + # + do_test fkey2-14.2aux.2.1 { + drop_all_tables + execsql { + CREATE TABLE aux.t1(a PRIMARY KEY, b REFERENCES t1); + CREATE TABLE aux.t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2); + CREATE TABLE aux.t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1); + } + execsql { SELECT sql FROM aux.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE t1(a PRIMARY KEY, b REFERENCES t1)} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES t1, c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES t1, b REFERENCES t2, c REFERENCES t1)} \ + ] + do_test fkey2-14.2aux.2.2 { + execsql { ALTER TABLE t1 RENAME TO t4 } + execsql { SELECT sql FROM aux.sqlite_master WHERE type = 'table'} + } [list \ + {CREATE TABLE "t4"(a PRIMARY KEY, b REFERENCES "t4")} \ + {CREATE TABLE t2(a PRIMARY KEY, b REFERENCES "t4", c REFERENCES t2)} \ + {CREATE TABLE t3(a REFERENCES "t4", b REFERENCES t2, c REFERENCES "t4")} \ + ] + do_test fkey2-14.2aux.2.3 { + catchsql { INSERT INTO t3 VALUES(1, 2, 3) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2aux.2.4 { + execsql { INSERT INTO t4 VALUES(1, NULL) } + } {} + do_test fkey2-14.2aux.2.5 { + catchsql { UPDATE t4 SET b = 5 } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-14.2aux.2.6 { + catchsql { UPDATE t4 SET b = 1 } + } {0 {}} + do_test fkey2-14.2aux.2.7 { + execsql { INSERT INTO t3 VALUES(1, NULL, 1) } + } {} +} + +do_test fkey-2.14.3.1 { + drop_all_tables + execsql { + CREATE TABLE t1(a, b REFERENCES nosuchtable); + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.2 { + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES('a', 1); + CREATE TABLE t2(x REFERENCES t1); + INSERT INTO t2 VALUES('a'); + } +} {} +do_test fkey-2.14.3.3 { + catchsql { DROP TABLE t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey-2.14.3.4 { + execsql { + DELETE FROM t2; + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.4 { + catchsql { INSERT INTO t2 VALUES('x') } +} {1 {no such table: main.t1}} +do_test fkey-2.14.3.5 { + execsql { + CREATE TABLE t1(x PRIMARY KEY); + INSERT INTO t1 VALUES('x'); + } + execsql { INSERT INTO t2 VALUES('x') } +} {} +do_test fkey-2.14.3.6 { + catchsql { DROP TABLE t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey-2.14.3.7 { + execsql { + DROP TABLE t2; + DROP TABLE t1; + } +} {} +do_test fkey-2.14.3.8 { + execsql { + CREATE TABLE pp(x, y, PRIMARY KEY(x, y)); + CREATE TABLE cc(a, b, FOREIGN KEY(a, b) REFERENCES pp(x, z)); + } + catchsql { INSERT INTO cc VALUES(1, 2) } +} {1 {foreign key mismatch - "cc" referencing "pp"}} +do_test fkey-2.14.3.9 { + execsql { DROP TABLE cc } +} {} +do_test fkey-2.14.3.10 { + execsql { + CREATE TABLE cc(a, b, + FOREIGN KEY(a, b) REFERENCES pp DEFERRABLE INITIALLY DEFERRED + ); + } + execsql { + INSERT INTO pp VALUES('a', 'b'); + INSERT INTO cc VALUES('a', 'b'); + BEGIN; + DROP TABLE pp; + CREATE TABLE pp(a, b, c, PRIMARY KEY(b, c)); + INSERT INTO pp VALUES(1, 'a', 'b'); + COMMIT; + } +} {} +do_test fkey-2.14.3.11 { + execsql { + BEGIN; + DROP TABLE cc; + DROP TABLE pp; + COMMIT; + } +} {} +do_test fkey-2.14.3.12 { + execsql { + CREATE TABLE b1(a, b); + CREATE TABLE b2(a, b REFERENCES b1); + DROP TABLE b1; + } +} {} +do_test fkey-2.14.3.13 { + execsql { + CREATE TABLE b3(a, b REFERENCES b2 DEFERRABLE INITIALLY DEFERRED); + DROP TABLE b2; + } +} {} + +# Test that nothing goes wrong when dropping a table that refers to a view. +# Or dropping a view that an existing FK (incorrectly) refers to. Or either +# of the above scenarios with a virtual table. +drop_all_tables +do_test fkey-2.14.4.1 { + execsql { + CREATE TABLE t1(x REFERENCES v); + CREATE VIEW v AS SELECT * FROM t1; + } +} {} +do_test fkey-2.14.4.2 { + execsql { + DROP VIEW v; + } +} {} +ifcapable vtab { + register_echo_module db + do_test fkey-2.14.4.3 { + execsql { CREATE VIRTUAL TABLE v USING echo(t1) } + } {} + do_test fkey-2.14.4.2 { + execsql { + DROP TABLE v; + } + } {} +} + +#------------------------------------------------------------------------- +# The following tests, fkey2-15.*, test that unnecessary FK related scans +# and lookups are avoided when the constraint counters are zero. +# +drop_all_tables +proc execsqlS {zSql} { + set ::sqlite_search_count 0 + set ::sqlite_found_count 0 + set res [uplevel [list execsql $zSql]] + concat [expr $::sqlite_found_count + $::sqlite_search_count] $res +} +do_test fkey2-15.1.1 { + execsql { + CREATE TABLE pp(a PRIMARY KEY, b); + CREATE TABLE cc(x, y REFERENCES pp DEFERRABLE INITIALLY DEFERRED); + INSERT INTO pp VALUES(1, 'one'); + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES('neung', 1); + INSERT INTO cc VALUES('song', 2); + } +} {} +do_test fkey2-15.1.2 { + execsqlS { INSERT INTO pp VALUES(3, 'three') } +} {0} +do_test fkey2-15.1.3 { + execsql { + BEGIN; + INSERT INTO cc VALUES('see', 4); -- Violates deferred constraint + } + execsqlS { INSERT INTO pp VALUES(5, 'five') } +} {2} +do_test fkey2-15.1.4 { + execsql { DELETE FROM cc WHERE x = 'see' } + execsqlS { INSERT INTO pp VALUES(6, 'six') } +} {0} +do_test fkey2-15.1.5 { + execsql COMMIT +} {} +do_test fkey2-15.1.6 { + execsql BEGIN + execsqlS { + DELETE FROM cc WHERE x = 'neung'; + ROLLBACK; + } +} {1} +do_test fkey2-15.1.7 { + execsql { + BEGIN; + DELETE FROM pp WHERE a = 2; + } + execsqlS { + DELETE FROM cc WHERE x = 'neung'; + ROLLBACK; + } +} {2} + +#------------------------------------------------------------------------- +# This next block of tests, fkey2-16.*, test that rows that refer to +# themselves may be inserted and deleted. +# +foreach {tn zSchema} { + 1 { CREATE TABLE self(a INTEGER PRIMARY KEY, b REFERENCES self(a)) } + 2 { CREATE TABLE self(a PRIMARY KEY, b REFERENCES self(a)) } + 3 { CREATE TABLE self(a UNIQUE, b INTEGER PRIMARY KEY REFERENCES self(a)) } +} { + drop_all_tables + do_test fkey2-16.1.$tn.1 { + execsql $zSchema + execsql { INSERT INTO self VALUES(13, 13) } + } {} + do_test fkey2-16.1.$tn.2 { + execsql { UPDATE self SET a = 14, b = 14 } + } {} + + do_test fkey2-16.1.$tn.3 { + catchsql { UPDATE self SET b = 15 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.4 { + catchsql { UPDATE self SET a = 15 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.5 { + catchsql { UPDATE self SET a = 15, b = 16 } + } {1 {FOREIGN KEY constraint failed}} + + do_test fkey2-16.1.$tn.6 { + catchsql { UPDATE self SET a = 17, b = 17 } + } {0 {}} + + do_test fkey2-16.1.$tn.7 { + execsql { DELETE FROM self } + } {} + do_test fkey2-16.1.$tn.8 { + catchsql { INSERT INTO self VALUES(20, 21) } + } {1 {FOREIGN KEY constraint failed}} +} + +#------------------------------------------------------------------------- +# This next block of tests, fkey2-17.*, tests that if "PRAGMA count_changes" +# is turned on statements that violate immediate FK constraints return +# SQLITE_CONSTRAINT immediately, not after returning a number of rows. +# Whereas statements that violate deferred FK constraints return the number +# of rows before failing. +# +# Also test that rows modified by FK actions are not counted in either the +# returned row count or the values returned by sqlite3_changes(). Like +# trigger related changes, they are included in sqlite3_total_changes() though. +# +drop_all_tables +do_test fkey2-17.1.1 { + execsql { PRAGMA count_changes = 1 } + execsql { + CREATE TABLE one(a, b, c, UNIQUE(b, c)); + CREATE TABLE two(d, e, f, FOREIGN KEY(e, f) REFERENCES one(b, c)); + INSERT INTO one VALUES(1, 2, 3); + } +} {1} +do_test fkey2-17.1.2 { + set STMT [sqlite3_prepare_v2 db "INSERT INTO two VALUES(4, 5, 6)" -1 dummy] + sqlite3_step $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.2b SQLITE_CONSTRAINT_FOREIGNKEY +ifcapable autoreset { + do_test fkey2-17.1.3 { + sqlite3_step $STMT + } {SQLITE_CONSTRAINT} + verify_ex_errcode fkey2-17.1.3b SQLITE_CONSTRAINT_FOREIGNKEY +} else { + do_test fkey2-17.1.3 { + sqlite3_step $STMT + } {SQLITE_MISUSE} +} +do_test fkey2-17.1.4 { + sqlite3_finalize $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.4b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-17.1.5 { + execsql { + INSERT INTO one VALUES(2, 3, 4); + INSERT INTO one VALUES(3, 4, 5); + INSERT INTO two VALUES(1, 2, 3); + INSERT INTO two VALUES(2, 3, 4); + INSERT INTO two VALUES(3, 4, 5); + } +} {1 1 1 1 1} +do_test fkey2-17.1.6 { + catchsql { + BEGIN; + INSERT INTO one VALUES(0, 0, 0); + UPDATE two SET e=e+1, f=f+1; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-17.1.7 { + execsql { SELECT * FROM one } +} {1 2 3 2 3 4 3 4 5 0 0 0} +do_test fkey2-17.1.8 { + execsql { SELECT * FROM two } +} {1 2 3 2 3 4 3 4 5} +do_test fkey2-17.1.9 { + execsql COMMIT +} {} +do_test fkey2-17.1.10 { + execsql { + CREATE TABLE three( + g, h, i, + FOREIGN KEY(h, i) REFERENCES one(b, c) DEFERRABLE INITIALLY DEFERRED + ); + } +} {} +do_test fkey2-17.1.11 { + set STMT [sqlite3_prepare_v2 db "INSERT INTO three VALUES(7, 8, 9)" -1 dummy] + sqlite3_step $STMT +} {SQLITE_ROW} +do_test fkey2-17.1.12 { + sqlite3_column_text $STMT 0 +} {1} +do_test fkey2-17.1.13 { + sqlite3_step $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.13b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-17.1.14 { + sqlite3_finalize $STMT +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-17.1.14b SQLITE_CONSTRAINT_FOREIGNKEY + +drop_all_tables +do_test fkey2-17.2.1 { + execsql { + CREATE TABLE high("a'b!" PRIMARY KEY, b); + CREATE TABLE low( + c, + "d&6" REFERENCES high ON UPDATE CASCADE ON DELETE CASCADE + ); + } +} {} +do_test fkey2-17.2.2 { + execsql { + INSERT INTO high VALUES('a', 'b'); + INSERT INTO low VALUES('b', 'a'); + } + db changes +} {1} +set nTotal [db total_changes] +do_test fkey2-17.2.3 { + execsql { UPDATE high SET "a'b!" = 'c' } +} {1} +do_test fkey2-17.2.4 { + db changes +} {1} +do_test fkey2-17.2.5 { + expr [db total_changes] - $nTotal +} {2} +do_test fkey2-17.2.6 { + execsql { SELECT * FROM high ; SELECT * FROM low } +} {c b b c} +do_test fkey2-17.2.7 { + execsql { DELETE FROM high } +} {1} +do_test fkey2-17.2.8 { + db changes +} {1} +do_test fkey2-17.2.9 { + expr [db total_changes] - $nTotal +} {4} +do_test fkey2-17.2.10 { + execsql { SELECT * FROM high ; SELECT * FROM low } +} {} +execsql { PRAGMA count_changes = 0 } + +#------------------------------------------------------------------------- +# Test that the authorization callback works. +# + +ifcapable auth { + do_test fkey2-18.1 { + execsql { + CREATE TABLE long(a, b PRIMARY KEY, c); + CREATE TABLE short(d, e, f REFERENCES long); + CREATE TABLE mid(g, h, i REFERENCES long DEFERRABLE INITIALLY DEFERRED); + } + } {} + + proc auth {args} {eval lappend ::authargs [lrange $args 0 4]; return SQLITE_OK} + db auth auth + + # An insert on the parent table must read the child key of any deferred + # foreign key constraints. But not the child key of immediate constraints. + set authargs {} + do_test fkey2-18.2 { + execsql { INSERT INTO long VALUES(1, 2, 3) } + set authargs + } {SQLITE_INSERT long {} main {} SQLITE_READ mid i main {}} + + # An insert on the child table of an immediate constraint must read the + # parent key columns (to see if it is a violation or not). + set authargs {} + do_test fkey2-18.3 { + execsql { INSERT INTO short VALUES(1, 3, 2) } + set authargs + } {SQLITE_INSERT short {} main {} SQLITE_READ long b main {}} + + # As must an insert on the child table of a deferred constraint. + set authargs {} + do_test fkey2-18.4 { + execsql { INSERT INTO mid VALUES(1, 3, 2) } + set authargs + } {SQLITE_INSERT mid {} main {} SQLITE_READ long b main {}} + + do_test fkey2-18.5 { + execsql { + CREATE TABLE nought(a, b PRIMARY KEY, c); + CREATE TABLE cross(d, e, f, + FOREIGN KEY(e) REFERENCES nought(b) ON UPDATE CASCADE + ); + } + execsql { INSERT INTO nought VALUES(2, 1, 2) } + execsql { INSERT INTO cross VALUES(0, 1, 0) } + set authargs [list] + execsql { UPDATE nought SET b = 5 } + set authargs + } {SQLITE_UPDATE nought b main {} SQLITE_READ cross e main {} SQLITE_READ cross e main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {} SQLITE_UPDATE cross e main {} SQLITE_READ nought b main {} SQLITE_READ cross e main {} SQLITE_READ nought b main {} SQLITE_READ nought b main {}} + + do_test fkey2-18.6 { + execsql {SELECT * FROM cross} + } {0 5 0} + + do_test fkey2-18.7 { + execsql { + CREATE TABLE one(a INTEGER PRIMARY KEY, b); + CREATE TABLE two(b, c REFERENCES one); + INSERT INTO one VALUES(101, 102); + } + set authargs [list] + execsql { INSERT INTO two VALUES(100, 101); } + set authargs + } {SQLITE_INSERT two {} main {} SQLITE_READ one a main {}} + + # Return SQLITE_IGNORE to requests to read from the parent table. This + # causes inserts of non-NULL keys into the child table to fail. + # + rename auth {} + proc auth {args} { + if {[lindex $args 1] == "long"} {return SQLITE_IGNORE} + return SQLITE_OK + } + do_test fkey2-18.8 { + catchsql { INSERT INTO short VALUES(1, 3, 2) } + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-18.9 { + execsql { INSERT INTO short VALUES(1, 3, NULL) } + } {} + do_test fkey2-18.10 { + execsql { SELECT * FROM short } + } {1 3 2 1 3 {}} + do_test fkey2-18.11 { + catchsql { UPDATE short SET f = 2 WHERE f IS NULL } + } {1 {FOREIGN KEY constraint failed}} + + db auth {} + unset authargs +} + + +do_test fkey2-19.1 { + execsql { + CREATE TABLE main(id INTEGER PRIMARY KEY); + CREATE TABLE sub(id INT REFERENCES main(id)); + INSERT INTO main VALUES(1); + INSERT INTO main VALUES(2); + INSERT INTO sub VALUES(2); + } +} {} +do_test fkey2-19.2 { + set S [sqlite3_prepare_v2 db "DELETE FROM main WHERE id = ?" -1 dummy] + sqlite3_bind_int $S 1 2 + sqlite3_step $S +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-19.2b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-19.3 { + sqlite3_reset $S +} {SQLITE_CONSTRAINT} +verify_ex_errcode fkey2-19.3b SQLITE_CONSTRAINT_FOREIGNKEY +do_test fkey2-19.4 { + sqlite3_bind_int $S 1 1 + sqlite3_step $S +} {SQLITE_DONE} +do_test fkey2-19.4 { + sqlite3_finalize $S +} {SQLITE_OK} + +drop_all_tables +do_test fkey2-20.1 { + execsql { + CREATE TABLE pp(a PRIMARY KEY, b); + CREATE TABLE cc(c PRIMARY KEY, d REFERENCES pp); + } +} {} + +foreach {tn insert} { + 1 "INSERT" + 2 "INSERT OR IGNORE" + 3 "INSERT OR ABORT" + 4 "INSERT OR ROLLBACK" + 5 "INSERT OR REPLACE" + 6 "INSERT OR FAIL" +} { + do_test fkey2-20.2.$tn.1 { + catchsql "$insert INTO cc VALUES(1, 2)" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.2.$tn.2 { + execsql { SELECT * FROM cc } + } {} + do_test fkey2-20.2.$tn.3 { + execsql { + BEGIN; + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES(1, 2); + } + catchsql "$insert INTO cc VALUES(3, 4)" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.2.$tn.4 { + execsql { COMMIT ; SELECT * FROM cc } + } {1 2} + do_test fkey2-20.2.$tn.5 { + execsql { DELETE FROM cc ; DELETE FROM pp } + } {} +} + +foreach {tn update} { + 1 "UPDATE" + 2 "UPDATE OR IGNORE" + 3 "UPDATE OR ABORT" + 4 "UPDATE OR ROLLBACK" + 5 "UPDATE OR REPLACE" + 6 "UPDATE OR FAIL" +} { + do_test fkey2-20.3.$tn.1 { + execsql { + INSERT INTO pp VALUES(2, 'two'); + INSERT INTO cc VALUES(1, 2); + } + } {} + do_test fkey2-20.3.$tn.2 { + catchsql "$update pp SET a = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.3 { + execsql { SELECT * FROM pp } + } {2 two} + do_test fkey2-20.3.$tn.4 { + catchsql "$update cc SET d = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.5 { + execsql { SELECT * FROM cc } + } {1 2} + do_test fkey2-20.3.$tn.6 { + execsql { + BEGIN; + INSERT INTO pp VALUES(3, 'three'); + } + catchsql "$update pp SET a = 1 WHERE a = 2" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.7 { + execsql { COMMIT ; SELECT * FROM pp } + } {2 two 3 three} + do_test fkey2-20.3.$tn.8 { + execsql { + BEGIN; + INSERT INTO cc VALUES(2, 2); + } + catchsql "$update cc SET d = 1 WHERE c = 1" + } {1 {FOREIGN KEY constraint failed}} + do_test fkey2-20.3.$tn.9 { + execsql { COMMIT ; SELECT * FROM cc } + } {1 2 2 2} + do_test fkey2-20.3.$tn.10 { + execsql { DELETE FROM cc ; DELETE FROM pp } + } {} +} + +#------------------------------------------------------------------------- +# The following block of tests, those prefixed with "fkey2-genfkey.", are +# the same tests that were used to test the ".genfkey" command provided +# by the shell tool. So these tests show that the built-in foreign key +# implementation is more or less compatible with the triggers generated +# by genfkey. +# +drop_all_tables +do_test fkey2-genfkey.1.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + CREATE TABLE t2(e REFERENCES t1, f); + CREATE TABLE t3(g, h, i, FOREIGN KEY (h, i) REFERENCES t1(b, c)); + } +} {} +do_test fkey2-genfkey.1.2 { + catchsql { INSERT INTO t2 VALUES(1, 2) } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.3 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t2 VALUES(1, 2); + } +} {} +do_test fkey2-genfkey.1.4 { + execsql { INSERT INTO t2 VALUES(NULL, 3) } +} {} +do_test fkey2-genfkey.1.5 { + catchsql { UPDATE t2 SET e = 5 WHERE e IS NULL } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.6 { + execsql { UPDATE t2 SET e = 1 WHERE e IS NULL } +} {} +do_test fkey2-genfkey.1.7 { + execsql { UPDATE t2 SET e = NULL WHERE f = 3 } +} {} +do_test fkey2-genfkey.1.8 { + catchsql { UPDATE t1 SET a = 10 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.9 { + catchsql { UPDATE t1 SET a = NULL } +} {1 {datatype mismatch}} +do_test fkey2-genfkey.1.10 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.11 { + execsql { UPDATE t2 SET e = NULL } +} {} +do_test fkey2-genfkey.1.12 { + execsql { + UPDATE t1 SET a = 10; + DELETE FROM t1; + DELETE FROM t2; + } +} {} +do_test fkey2-genfkey.1.13 { + execsql { + INSERT INTO t3 VALUES(1, NULL, NULL); + INSERT INTO t3 VALUES(1, 2, NULL); + INSERT INTO t3 VALUES(1, NULL, 3); + } +} {} +do_test fkey2-genfkey.1.14 { + catchsql { INSERT INTO t3 VALUES(3, 1, 4) } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.15 { + execsql { + INSERT INTO t1 VALUES(1, 1, 4); + INSERT INTO t3 VALUES(3, 1, 4); + } +} {} +do_test fkey2-genfkey.1.16 { + catchsql { DELETE FROM t1 } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.17 { + catchsql { UPDATE t1 SET b = 10} +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-genfkey.1.18 { + execsql { UPDATE t1 SET a = 10} +} {} +do_test fkey2-genfkey.1.19 { + catchsql { UPDATE t3 SET h = 'hello' WHERE i = 3} +} {1 {FOREIGN KEY constraint failed}} + +drop_all_tables +do_test fkey2-genfkey.2.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(b, c)); + CREATE TABLE t2(e REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE, f); + CREATE TABLE t3(g, h, i, + FOREIGN KEY (h, i) + REFERENCES t1(b, c) ON UPDATE CASCADE ON DELETE CASCADE + ); + } +} {} +do_test fkey2-genfkey.2.2 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + INSERT INTO t2 VALUES(1, 'one'); + INSERT INTO t2 VALUES(4, 'four'); + } +} {} +do_test fkey2-genfkey.2.3 { + execsql { + UPDATE t1 SET a = 2 WHERE a = 1; + SELECT * FROM t2; + } +} {2 one 4 four} +do_test fkey2-genfkey.2.4 { + execsql { + DELETE FROM t1 WHERE a = 4; + SELECT * FROM t2; + } +} {2 one} + +do_test fkey2-genfkey.2.5 { + execsql { + INSERT INTO t3 VALUES('hello', 2, 3); + UPDATE t1 SET c = 2; + SELECT * FROM t3; + } +} {hello 2 2} +do_test fkey2-genfkey.2.6 { + execsql { + DELETE FROM t1; + SELECT * FROM t3; + } +} {} + +drop_all_tables +do_test fkey2-genfkey.3.1 { + execsql { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(c, b)); + CREATE TABLE t2(e REFERENCES t1 ON UPDATE SET NULL ON DELETE SET NULL, f); + CREATE TABLE t3(g, h, i, + FOREIGN KEY (h, i) + REFERENCES t1(b, c) ON UPDATE SET NULL ON DELETE SET NULL + ); + } +} {} +do_test fkey2-genfkey.3.2 { + execsql { + INSERT INTO t1 VALUES(1, 2, 3); + INSERT INTO t1 VALUES(4, 5, 6); + INSERT INTO t2 VALUES(1, 'one'); + INSERT INTO t2 VALUES(4, 'four'); + } +} {} +do_test fkey2-genfkey.3.3 { + execsql { + UPDATE t1 SET a = 2 WHERE a = 1; + SELECT * FROM t2; + } +} {{} one 4 four} +do_test fkey2-genfkey.3.4 { + execsql { + DELETE FROM t1 WHERE a = 4; + SELECT * FROM t2; + } +} {{} one {} four} +do_test fkey2-genfkey.3.5 { + execsql { + INSERT INTO t3 VALUES('hello', 2, 3); + UPDATE t1 SET c = 2; + SELECT * FROM t3; + } +} {hello {} {}} +do_test fkey2-genfkey.3.6 { + execsql { + UPDATE t3 SET h = 2, i = 2; + DELETE FROM t1; + SELECT * FROM t3; + } +} {hello {} {}} + +#------------------------------------------------------------------------- +# Verify that ticket dd08e5a988d00decc4a543daa8dbbfab9c577ad8 has been +# fixed. +# +do_test fkey2-dd08e5.1.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE tdd08(a INTEGER PRIMARY KEY, b); + CREATE UNIQUE INDEX idd08 ON tdd08(a,b); + INSERT INTO tdd08 VALUES(200,300); + + CREATE TABLE tdd08_b(w,x,y, FOREIGN KEY(x,y) REFERENCES tdd08(a,b)); + INSERT INTO tdd08_b VALUES(100,200,300); + } +} {} +do_test fkey2-dd08e5.1.2 { + catchsql { + DELETE FROM tdd08; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.3 { + execsql { + SELECT * FROM tdd08; + } +} {200 300} +do_test fkey2-dd08e5.1.4 { + catchsql { + INSERT INTO tdd08_b VALUES(400,500,300); + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.5 { + catchsql { + UPDATE tdd08_b SET x=x+1; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-dd08e5.1.6 { + catchsql { + UPDATE tdd08 SET a=a+1; + } +} {1 {FOREIGN KEY constraint failed}} + +#------------------------------------------------------------------------- +# Verify that ticket ce7c133ea6cc9ccdc1a60d80441f80b6180f5eba +# fixed. +# +do_test fkey2-ce7c13.1.1 { + execsql { + CREATE TABLE tce71(a INTEGER PRIMARY KEY, b); + CREATE UNIQUE INDEX ice71 ON tce71(a,b); + INSERT INTO tce71 VALUES(100,200); + CREATE TABLE tce72(w, x, y, FOREIGN KEY(x,y) REFERENCES tce71(a,b)); + INSERT INTO tce72 VALUES(300,100,200); + UPDATE tce71 set b = 200 where a = 100; + SELECT * FROM tce71, tce72; + } +} {100 200 300 100 200} +do_test fkey2-ce7c13.1.2 { + catchsql { + UPDATE tce71 set b = 201 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.3 { + catchsql { + UPDATE tce71 set a = 101 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.4 { + execsql { + CREATE TABLE tce73(a INTEGER PRIMARY KEY, b, UNIQUE(a,b)); + INSERT INTO tce73 VALUES(100,200); + CREATE TABLE tce74(w, x, y, FOREIGN KEY(x,y) REFERENCES tce73(a,b)); + INSERT INTO tce74 VALUES(300,100,200); + UPDATE tce73 set b = 200 where a = 100; + SELECT * FROM tce73, tce74; + } +} {100 200 300 100 200} +do_test fkey2-ce7c13.1.5 { + catchsql { + UPDATE tce73 set b = 201 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} +do_test fkey2-ce7c13.1.6 { + catchsql { + UPDATE tce73 set a = 101 where a = 100; + } +} {1 {FOREIGN KEY constraint failed}} + +# 2015-04-16: Foreign key errors propagate back up to the parser. +# +do_test fkey2-20150416-100 { + db close + sqlite3 db :memory: + catchsql { + PRAGMA foreign_keys=1; + CREATE TABLE t1(x PRIMARY KEY); + CREATE TABLE t(y REFERENCES t0(x)ON DELETE SET DEFAULT); + CREATE TABLE t0(y REFERENCES t1 ON DELETE SET NULL); + REPLACE INTO t1 SELECT(0);CREATE TABLE t2(x);CREATE TABLE t3; + } +} {1 {foreign key mismatch - "t" referencing "t0"}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey3.test new file mode 100644 index 0000000000000000000000000000000000000000..a8d038202074c5723177fa12d680fe1dca8fd01b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey3.test @@ -0,0 +1,186 @@ +# 2009 September 15 +# +# 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. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable {!foreignkey||!trigger} { + finish_test + return +} + +set testprefix fkey3 + +# Create a table and some data to work with. +# +do_test fkey3-1.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(101); + CREATE TABLE t2(y INTEGER REFERENCES t1 (x)); + INSERT INTO t2 VALUES(100); + INSERT INTO t2 VALUES(101); + SELECT 1, x FROM t1; + SELECT 2, y FROM t2; + } +} {1 100 1 101 2 100 2 101} + +do_test fkey3-1.2 { + catchsql { + DELETE FROM t1 WHERE x=100; + } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey3-1.3 { + catchsql { + DROP TABLE t1; + } +} {1 {FOREIGN KEY constraint failed}} + +do_test fkey3-1.4 { + execsql { + DROP TABLE t2; + } +} {} + +do_test fkey3-1.5 { + execsql { + DROP TABLE t1; + } +} {} + +do_test fkey3-2.1 { + execsql { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + INSERT INTO t1 VALUES(100); + INSERT INTO t1 VALUES(101); + CREATE TABLE t2(y INTEGER PRIMARY KEY REFERENCES t1 (x) ON UPDATE SET NULL); + } + execsql { + INSERT INTO t2 VALUES(100); + INSERT INTO t2 VALUES(101); + SELECT 1, x FROM t1; + SELECT 2, y FROM t2; + } +} {1 100 1 101 2 100 2 101} + + +#------------------------------------------------------------------------- +# The following tests - fkey-3.* - test some edge cases to do with +# inserting rows into tables that have foreign keys where the parent +# table is the same as the child table. Especially cases where the +# new row being inserted matches itself. +# +do_execsql_test 3.1.1 { + CREATE TABLE t3(a, b, c, d, + UNIQUE(a, b), + FOREIGN KEY(c, d) REFERENCES t3(a, b) + ); + INSERT INTO t3 VALUES(1, 2, 1, 2); +} {} +do_catchsql_test 3.1.2 { + INSERT INTO t3 VALUES(NULL, 2, 5, 2); +} {1 {FOREIGN KEY constraint failed}} +do_catchsql_test 3.1.3 { + INSERT INTO t3 VALUES(NULL, 3, 5, 2); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.2.1 { + CREATE TABLE t4(a UNIQUE, b REFERENCES t4(a)); +} +do_catchsql_test 3.2.2 { + INSERT INTO t4 VALUES(NULL, 1); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.3.1 { + CREATE TABLE t5(a INTEGER PRIMARY KEY, b REFERENCES t5(a)); + INSERT INTO t5 VALUES(NULL, 1); +} {} +do_catchsql_test 3.3.2 { + INSERT INTO t5 VALUES(NULL, 3); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.4.1 { + CREATE TABLE t6(a INTEGER PRIMARY KEY, b, c, d, + FOREIGN KEY(c, d) REFERENCES t6(a, b) + ); + CREATE UNIQUE INDEX t6i ON t6(b, a); +} +do_execsql_test 3.4.2 { INSERT INTO t6 VALUES(NULL, 'a', 1, 'a'); } {} +do_execsql_test 3.4.3 { INSERT INTO t6 VALUES(2, 'a', 2, 'a'); } {} +do_execsql_test 3.4.4 { INSERT INTO t6 VALUES(NULL, 'a', 1, 'a'); } {} +do_execsql_test 3.4.5 { INSERT INTO t6 VALUES(5, 'a', 2, 'a'); } {} +do_catchsql_test 3.4.6 { + INSERT INTO t6 VALUES(NULL, 'a', 65, 'a'); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 3.4.7 { + INSERT INTO t6 VALUES(100, 'one', 100, 'one'); + DELETE FROM t6 WHERE a = 100; +} +do_execsql_test 3.4.8 { + INSERT INTO t6 VALUES(100, 'one', 100, 'one'); + UPDATE t6 SET c = 1, d = 'a' WHERE a = 100; + DELETE FROM t6 WHERE a = 100; +} + +do_execsql_test 3.5.1 { + CREATE TABLE t7(a, b, c, d INTEGER PRIMARY KEY, + FOREIGN KEY(c, d) REFERENCES t7(a, b) + ); + CREATE UNIQUE INDEX t7i ON t7(a, b); +} +do_execsql_test 3.5.2 { INSERT INTO t7 VALUES('x', 1, 'x', NULL) } {} +do_execsql_test 3.5.3 { INSERT INTO t7 VALUES('x', 2, 'x', 2) } {} +do_catchsql_test 3.5.4 { + INSERT INTO t7 VALUES('x', 450, 'x', NULL); +} {1 {FOREIGN KEY constraint failed}} +do_catchsql_test 3.5.5 { + INSERT INTO t7 VALUES('x', 450, 'x', 451); +} {1 {FOREIGN KEY constraint failed}} + + +do_execsql_test 3.6.1 { + CREATE TABLE t8(a, b, c, d, e, FOREIGN KEY(c, d) REFERENCES t8(a, b)); + CREATE UNIQUE INDEX t8i1 ON t8(a, b); + CREATE UNIQUE INDEX t8i2 ON t8(c); + INSERT INTO t8 VALUES(1, 1, 1, 1, 1); +} +do_catchsql_test 3.6.2 { + UPDATE t8 SET d = 2; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.6.3 { UPDATE t8 SET d = 1; } +do_execsql_test 3.6.4 { UPDATE t8 SET e = 2; } + +do_catchsql_test 3.6.5 { + CREATE TABLE TestTable ( + id INTEGER PRIMARY KEY, + name text, + source_id integer not null, + parent_id integer, + + foreign key(source_id, parent_id) references TestTable(source_id, id) + ); + CREATE UNIQUE INDEX testindex on TestTable(source_id, id); + PRAGMA foreign_keys=1; + INSERT INTO TestTable VALUES (1, 'parent', 1, null); + INSERT INTO TestTable VALUES (2, 'child', 1, 1); + UPDATE TestTable SET parent_id=1000 where id=2; +} {1 {FOREIGN KEY constraint failed}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey5.test new file mode 100644 index 0000000000000000000000000000000000000000..d467a64281dc43f250cff466b81cdbaf910d0cf7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey5.test @@ -0,0 +1,492 @@ +# 2012 December 17 +# +# 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. +# +# This file tests the PRAGMA foreign_key_check command. +# +# EVIDENCE-OF: R-15402-03103 PRAGMA schema.foreign_key_check; PRAGMA +# schema.foreign_key_check(table-name); +# +# EVIDENCE-OF: R-41653-15278 The foreign_key_check pragma checks the +# database, or the table called "table-name", for foreign key +# constraints that are violated. The foreign_key_check pragma returns +# one row output for each foreign key violation. + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey5 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_test fkey5-1.1 { + db eval { + CREATE TABLE p1(a INTEGER PRIMARY KEY); INSERT INTO p1 VALUES(88),(89); + CREATE TABLE p2(a INT PRIMARY KEY); INSERT INTO p2 VALUES(77),(78); + CREATE TABLE p3(a TEXT PRIMARY KEY); + INSERT INTO p3 VALUES(66),(67),('alpha'),('BRAVO'); + CREATE TABLE p4(a TEXT PRIMARY KEY COLLATE nocase); + INSERT INTO p4 VALUES('alpha'),('BRAVO'),('55'),('Delta'),('ECHO'); + CREATE TABLE p5(a INTEGER PRIMARY KEY, b, c, UNIQUE(b,c)); + INSERT INTO p5 VALUES(1,'Alpha','abc'),(2,'beta','def'); + CREATE TABLE p6(a INTEGER PRIMARY KEY, b TEXT COLLATE nocase, + c TEXT COLLATE rtrim, UNIQUE(b,c)); + INSERT INTO p6 VALUES(1,'Alpha','abc '),(2,'bETA','def '); + + CREATE TABLE c1(x INTEGER PRIMARY KEY references p1); + CREATE TABLE c2(x INTEGER PRIMARY KEY references p2); + CREATE TABLE c3(x INTEGER PRIMARY KEY references p3); + CREATE TABLE c4(x INTEGER PRIMARY KEY references p4); + CREATE TABLE c5(x INT references p1); + CREATE TABLE c6(x INT references p2); + CREATE TABLE c7(x INT references p3); + CREATE TABLE c8(x INT references p4); + CREATE TABLE c9(x TEXT UNIQUE references p1); + CREATE TABLE c10(x TEXT UNIQUE references p2); + CREATE TABLE c11(x TEXT UNIQUE references p3); + CREATE TABLE c12(x TEXT UNIQUE references p4); + CREATE TABLE c13(x TEXT COLLATE nocase references p3); + CREATE TABLE c14(x TEXT COLLATE nocase references p4); + CREATE TABLE c15(x, y, FOREIGN KEY(x,y) REFERENCES p5(b,c)); + CREATE TABLE c16(x, y, FOREIGN KEY(x,y) REFERENCES p5(c,b)); + CREATE TABLE c17(x, y, FOREIGN KEY(x,y) REFERENCES p6(b,c)); + CREATE TABLE c18(x, y, FOREIGN KEY(x,y) REFERENCES p6(c,b)); + CREATE TABLE c19(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p5(b,c)); + CREATE TABLE c20(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p5(c,b)); + CREATE TABLE c21(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p6(b,c)); + CREATE TABLE c22(x TEXT COLLATE nocase, y TEXT COLLATE rtrim, + FOREIGN KEY(x,y) REFERENCES p6(c,b)); + + PRAGMA foreign_key_check; + } +} {} +do_test fkey5-1.2 { + db eval { + INSERT INTO c1 VALUES(90),(87),(88); + PRAGMA foreign_key_check; + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.2b { + db eval { + PRAGMA main.foreign_key_check; + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.2c { + db eval { + PRAGMA temp.foreign_key_check; + } +} {} +do_test fkey5-1.3 { + db eval { + PRAGMA foreign_key_check(c1); + } +} {c1 87 p1 0 c1 90 p1 0} +do_test fkey5-1.4 { + db eval { + PRAGMA foreign_key_check(c2); + } +} {} +do_test fkey5-1.5 { + db eval { + PRAGMA main.foreign_key_check(c2); + } +} {} +do_test fkey5-1.6 { + catchsql { + PRAGMA temp.foreign_key_check(c2); + } +} {1 {no such table: temp.c2}} + +# EVIDENCE-OF: R-45728-08709 There are four columns in each result row. +# +# EVIDENCE-OF: R-55672-01620 The first column is the name of the table +# that contains the REFERENCES clause. +# +# EVIDENCE-OF: R-00471-55166 The second column is the rowid of the row +# that contains the invalid REFERENCES clause, or NULL if the child +# table is a WITHOUT ROWID table. +# +# The second clause in the previous is tested by fkey5-10.3. +# +# EVIDENCE-OF: R-40482-20265 The third column is the name of the table +# that is referred to. +# +# EVIDENCE-OF: R-62839-07969 The fourth column is the index of the +# specific foreign key constraint that failed. +# +do_test fkey5-2.0 { + db eval { + INSERT INTO c5 SELECT x FROM c1; + DELETE FROM c1; + PRAGMA foreign_key_check; + } +} {c5 1 p1 0 c5 3 p1 0} +do_test fkey5-2.1 { + db eval { + PRAGMA foreign_key_check(c5); + } +} {c5 1 p1 0 c5 3 p1 0} +do_test fkey5-2.2 { + db eval { + PRAGMA foreign_key_check(c1); + } +} {} +do_execsql_test fkey5-2.3 { + PRAGMA foreign_key_list(c5); +} {0 0 p1 x {} {NO ACTION} {NO ACTION} NONE} + +do_test fkey5-3.0 { + db eval { + INSERT INTO c9 SELECT x FROM c5; + DELETE FROM c5; + PRAGMA foreign_key_check; + } +} {c9 1 p1 0 c9 3 p1 0} +do_test fkey5-3.1 { + db eval { + PRAGMA foreign_key_check(c9); + } +} {c9 1 p1 0 c9 3 p1 0} +do_test fkey5-3.2 { + db eval { + PRAGMA foreign_key_check(c5); + } +} {} + +do_test fkey5-4.0 { + db eval { + DELETE FROM c9; + INSERT INTO c2 VALUES(79),(77),(76); + PRAGMA foreign_key_check; + } +} {c2 76 p2 0 c2 79 p2 0} +do_test fkey5-4.1 { + db eval { + PRAGMA foreign_key_check(c2); + } +} {c2 76 p2 0 c2 79 p2 0} +do_test fkey5-4.2 { + db eval { + INSERT INTO c6 SELECT x FROM c2; + DELETE FROM c2; + PRAGMA foreign_key_check; + } +} {c6 1 p2 0 c6 3 p2 0} +do_test fkey5-4.3 { + db eval { + PRAGMA foreign_key_check(c6); + } +} {c6 1 p2 0 c6 3 p2 0} +do_test fkey5-4.4 { + db eval { + INSERT INTO c10 SELECT x FROM c6; + DELETE FROM c6; + PRAGMA foreign_key_check; + } +} {c10 1 p2 0 c10 3 p2 0} +do_test fkey5-4.5 { + db eval { + PRAGMA foreign_key_check(c10); + } +} {c10 1 p2 0 c10 3 p2 0} + +do_test fkey5-5.0 { + db eval { + DELETE FROM c10; + INSERT INTO c3 VALUES(68),(67),(65); + PRAGMA foreign_key_check; + } +} {c3 65 p3 0 c3 68 p3 0} +do_test fkey5-5.1 { + db eval { + PRAGMA foreign_key_check(c3); + } +} {c3 65 p3 0 c3 68 p3 0} +do_test fkey5-5.2 { + db eval { + INSERT INTO c7 SELECT x FROM c3; + INSERT INTO c7 VALUES('Alpha'),('alpha'),('foxtrot'); + DELETE FROM c3; + PRAGMA foreign_key_check; + } +} {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} +do_test fkey5-5.3 { + db eval { + PRAGMA foreign_key_check(c7); + } +} {c7 1 p3 0 c7 3 p3 0 c7 4 p3 0 c7 6 p3 0} +do_test fkey5-5.4 { + db eval { + INSERT INTO c11 SELECT x FROM c7; + DELETE FROM c7; + PRAGMA foreign_key_check; + } +} {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} +do_test fkey5-5.5 { + db eval { + PRAGMA foreign_key_check(c11); + } +} {c11 1 p3 0 c11 3 p3 0 c11 4 p3 0 c11 6 p3 0} + +do_test fkey5-6.0 { + db eval { + DELETE FROM c11; + INSERT INTO c4 VALUES(54),(55),(56); + PRAGMA foreign_key_check; + } +} {c4 54 p4 0 c4 56 p4 0} +do_test fkey5-6.1 { + db eval { + PRAGMA foreign_key_check(c4); + } +} {c4 54 p4 0 c4 56 p4 0} +do_test fkey5-6.2 { + db eval { + INSERT INTO c8 SELECT x FROM c4; + INSERT INTO c8 VALUES('Alpha'),('ALPHA'),('foxtrot'); + DELETE FROM c4; + PRAGMA foreign_key_check; + } +} {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} +do_test fkey5-6.3 { + db eval { + PRAGMA foreign_key_check(c8); + } +} {c8 1 p4 0 c8 3 p4 0 c8 6 p4 0} +do_test fkey5-6.4 { + db eval { + INSERT INTO c12 SELECT x FROM c8; + DELETE FROM c8; + PRAGMA foreign_key_check; + } +} {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} +do_test fkey5-6.5 { + db eval { + PRAGMA foreign_key_check(c12); + } +} {c12 1 p4 0 c12 3 p4 0 c12 6 p4 0} + +do_test fkey5-7.1 { + set res {} + db eval { + INSERT OR IGNORE INTO c13 SELECT * FROM c12; + INSERT OR IGNORE INTO C14 SELECT * FROM c12; + DELETE FROM c12; + PRAGMA foreign_key_check; + } { + lappend res [list $table $rowid $fkid $parent] + } + lsort $res +} {{c13 1 0 p3} {c13 2 0 p3} {c13 3 0 p3} {c13 4 0 p3} {c13 5 0 p3} {c13 6 0 p3} {c14 1 0 p4} {c14 3 0 p4} {c14 6 0 p4}} +do_test fkey5-7.2 { + db eval { + PRAGMA foreign_key_check(c14); + } +} {c14 1 p4 0 c14 3 p4 0 c14 6 p4 0} +do_test fkey5-7.3 { + db eval { + PRAGMA foreign_key_check(c13); + } +} {c13 1 p3 0 c13 2 p3 0 c13 3 p3 0 c13 4 p3 0 c13 5 p3 0 c13 6 p3 0} + +do_test fkey5-8.0 { + db eval { + DELETE FROM c13; + DELETE FROM c14; + INSERT INTO c19 VALUES('alpha','abc'); + PRAGMA foreign_key_check(c19); + } +} {c19 1 p5 0} +do_test fkey5-8.1 { + db eval { + DELETE FROM c19; + INSERT INTO c19 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c19); + } +} {} +do_test fkey5-8.2 { + db eval { + INSERT INTO c20 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c20); + } +} {c20 1 p5 0} +do_test fkey5-8.3 { + db eval { + DELETE FROM c20; + INSERT INTO c20 VALUES('abc','Alpha'); + PRAGMA foreign_key_check(c20); + } +} {} +do_test fkey5-8.4 { + db eval { + INSERT INTO c21 VALUES('alpha','abc '); + PRAGMA foreign_key_check(c21); + } +} {} +do_test fkey5-8.5 { + db eval { + DELETE FROM c21; + INSERT INTO c19 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c21); + } +} {} +do_test fkey5-8.6 { + db eval { + INSERT INTO c22 VALUES('Alpha','abc'); + PRAGMA foreign_key_check(c22); + } +} {c22 1 p6 0} +do_test fkey5-8.7 { + db eval { + DELETE FROM c22; + INSERT INTO c22 VALUES('abc ','ALPHA'); + PRAGMA foreign_key_check(c22); + } +} {} + + +#------------------------------------------------------------------------- +# Tests 9.* verify that missing parent tables are handled correctly. +# +do_execsql_test 9.1.1 { + CREATE TABLE k1(x REFERENCES s1); + PRAGMA foreign_key_check(k1); +} {} +do_execsql_test 9.1.2 { + INSERT INTO k1 VALUES(NULL); + PRAGMA foreign_key_check(k1); +} {} +do_execsql_test 9.1.3 { + INSERT INTO k1 VALUES(1); + PRAGMA foreign_key_check(k1); +} {k1 2 s1 0} + +do_execsql_test 9.2.1 { + CREATE TABLE k2(x, y, FOREIGN KEY(x, y) REFERENCES s1(a, b)); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.2 { + INSERT INTO k2 VALUES(NULL, 'five'); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.3 { + INSERT INTO k2 VALUES('one', NULL); + PRAGMA foreign_key_check(k2); +} {} +do_execsql_test 9.4 { + INSERT INTO k2 VALUES('six', 'seven'); + PRAGMA foreign_key_check(k2); +} {k2 3 s1 0} + +#------------------------------------------------------------------------- +# Test using a WITHOUT ROWID table as the child table with an INTEGER +# PRIMARY KEY as the parent key. +# +reset_db +do_execsql_test 10.1 { + CREATE TABLE p30 (id INTEGER PRIMARY KEY); + CREATE TABLE IF NOT EXISTS c30 ( + line INTEGER, + master REFERENCES p30(id), + PRIMARY KEY(master) + ) WITHOUT ROWID; + + INSERT INTO p30 (id) VALUES (1); + INSERT INTO c30 (master, line) VALUES (1, 999); +} +do_execsql_test 10.2 { + PRAGMA foreign_key_check; +} +# EVIDENCE-OF: R-00471-55166 The second column is the rowid of the row +# that contains the invalid REFERENCES clause, or NULL if the child +# table is a WITHOUT ROWID table. +do_execsql_test 10.3 { + INSERT INTO c30 VALUES(45, 45); + PRAGMA foreign_key_check; +} {c30 {} p30 0} + +#------------------------------------------------------------------------- +# Test "foreign key mismatch" errors. +# +reset_db +do_execsql_test 11.0 { + CREATE TABLE tt(y); + CREATE TABLE c11(x REFERENCES tt(y)); +} +do_catchsql_test 11.1 { + PRAGMA foreign_key_check; +} {1 {foreign key mismatch - "c11" referencing "tt"}} + +# 2020-07-03 Bug in foreign_key_check discovered while working on the +# forum reports that pragma_foreign_key_check does not accept an argument: +# If two separate schemas seem to reference one another, that causes +# problems for foreign_key_check. +# +reset_db +do_execsql_test 12.0 { + ATTACH ':memory:' as aux; + CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b TEXT REFERENCES t2); + CREATE TABLE main.t2(x TEXT PRIMARY KEY, y INT); + INSERT INTO main.t2 VALUES('abc',11),('def',22),('xyz',99); + INSERT INTO aux.t1 VALUES(5,'abc'),(7,'xyz'),(9,'oops'); + PRAGMA foreign_key_check=t1; +} {t1 5 t2 0 t1 7 t2 0 t1 9 t2 0} +do_execsql_test 12.1 { + CREATE TABLE aux.t2(x TEXT PRIMARY KEY, y INT); + INSERT INTO aux.t2 VALUES('abc',11),('def',22),('xyz',99); + PRAGMA foreign_key_check=t1; +} {t1 9 t2 0} + +# 2020-07-03: the pragma_foreign_key_check virtual table should +# accept arguments for the table name and/or schema name. +# +ifcapable vtab { + do_execsql_test 13.0 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1'); + } {t1 9 t2 0 x} + do_catchsql_test 13.1 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1','main'); + } {1 {no such table: main.t1}} + do_execsql_test 13.2 { + SELECT *, 'x' FROM pragma_foreign_key_check('t1','aux'); + } {t1 9 t2 0 x} +} + +ifcapable vtab { + reset_db + do_execsql_test 13.10 { + PRAGMA foreign_keys=OFF; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT REFERENCES t2); + CREATE TABLE t2(x TEXT PRIMARY KEY, y INT); + CREATE TABLE t3(w TEXT, z INT REFERENCES t1); + INSERT INTO t2 VALUES('abc',11),('def',22),('xyz',99); + INSERT INTO t1 VALUES(5,'abc'),(7,'xyz'),(9,'oops'); + INSERT INTO t3 VALUES(11,7),(22,19); + } {} + do_execsql_test 13.11 { + SELECT x.*, '|' + FROM sqlite_schema, pragma_foreign_key_check(name) AS x + WHERE type='table' + ORDER BY x."table"; + } {t1 9 t2 0 | t3 2 t1 0 |} + do_execsql_test 13.12 { + SELECT *, '|' + FROM pragma_foreign_key_check AS x + ORDER BY x."table"; + } {t1 9 t2 0 | t3 2 t1 0 |} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey6.test new file mode 100644 index 0000000000000000000000000000000000000000..b658f20fea19665ef32cf00ea13ab1c9fa4edbdc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey6.test @@ -0,0 +1,229 @@ +# 2012 December 17 +# +# 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. +# +# This file tests the PRAGMA defer_foreign_keys and +# SQLITE_DBSTATUS_DEFERRED_FKS +# +# EVIDENCE-OF: R-18981-16292 When the defer_foreign_keys PRAGMA is on, +# enforcement of all foreign key constraints is delayed until the +# outermost transaction is committed. +# +# EVIDENCE-OF: R-28911-57501 The defer_foreign_keys pragma defaults to +# OFF so that foreign key constraints are only deferred if they are +# created as "DEFERRABLE INITIALLY DEFERRED". + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey6 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_execsql_test fkey6-1.0 { + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-1.1 { + PRAGMA foreign_keys=ON; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + CREATE TABLE t2(y INTEGER PRIMARY KEY, + z INTEGER REFERENCES t1(x) DEFERRABLE INITIALLY DEFERRED); + CREATE INDEX t2z ON t2(z); + CREATE TABLE t3(u INTEGER PRIMARY KEY, v INTEGER REFERENCES t1(x)); + CREATE INDEX t3v ON t3(v); + INSERT INTO t1 VALUES(1),(2),(3),(4),(5); + INSERT INTO t2 VALUES(1,1),(2,2); + INSERT INTO t3 VALUES(3,3),(4,4); +} {} +do_test fkey6-1.2 { + catchsql {DELETE FROM t1 WHERE x=2;} +} {1 {FOREIGN KEY constraint failed}} +do_test fkey6-1.3 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.4 { + execsql { + BEGIN; + DELETE FROM t1 WHERE x=1; + } +} {} +do_test fkey6-1.5.1 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 1 +} {0 1 0} +do_test fkey6-1.5.2 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} +do_test fkey6-1.6 { + execsql { + ROLLBACK; + } +} {} +do_test fkey6-1.7 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.8 { + execsql { + PRAGMA defer_foreign_keys=ON; + BEGIN; + DELETE FROM t1 WHERE x=3; + } +} {} +do_test fkey6-1.9 { + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} + +# EVIDENCE-OF: R-21752-26913 The defer_foreign_keys pragma is +# automatically switched off at each COMMIT or ROLLBACK. Hence, the +# defer_foreign_keys pragma must be separately enabled for each +# transaction. +do_execsql_test fkey6-1.10.1 { + PRAGMA defer_foreign_keys; + ROLLBACK; + PRAGMA defer_foreign_keys; + BEGIN; + PRAGMA defer_foreign_keys=ON; + PRAGMA defer_foreign_keys; + COMMIT; + PRAGMA defer_foreign_keys; + BEGIN; +} {1 0 1 0} +do_test fkey6-1.10.2 { + catchsql {DELETE FROM t1 WHERE x=3} +} {1 {FOREIGN KEY constraint failed}} +db eval {ROLLBACK} + +do_test fkey6-1.20 { + execsql { + BEGIN; + DELETE FROM t1 WHERE x=1; + } + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 1 0} +do_test fkey6-1.21 { + execsql { + DELETE FROM t2 WHERE y=1; + } + sqlite3_db_status db DBSTATUS_DEFERRED_FKS 0 +} {0 0 0} +do_test fkey6-1.22 { + execsql { + COMMIT; + } +} {} + +do_execsql_test fkey6-2.1 { + CREATE TABLE p1(a PRIMARY KEY); + INSERT INTO p1 VALUES('one'), ('two'); + CREATE TABLE c1(x REFERENCES p1); + INSERT INTO c1 VALUES('two'), ('one'); +} + +do_execsql_test fkey6-2.2 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p1; + ROLLBACK; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.3 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DROP TABLE p1; + PRAGMA vdbe_trace = 0; + ROLLBACK; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p1; + DROP TABLE c1; + COMMIT; + PRAGMA defer_foreign_keys; +} {0} + +do_execsql_test fkey6-2.5 { + DROP TABLE p1; + CREATE TABLE p1(a PRIMARY KEY); + INSERT INTO p1 VALUES('one'), ('two'); + CREATE TABLE c1(x REFERENCES p1); + INSERT INTO c1 VALUES('two'), ('one'); +} + +do_execsql_test fkey6-2.6 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + INSERT INTO c1 VALUES('three'); + DROP TABLE c1; + COMMIT; + PRAGMA defer_foreign_keys; +} {0} + +#-------------------------------------------------------------------------- +# Test that defer_foreign_keys disables RESTRICT. +# +do_execsql_test 3.1 { + CREATE TABLE p2(a PRIMARY KEY, b); + CREATE TABLE c2(x, y REFERENCES p2 ON DELETE RESTRICT ON UPDATE RESTRICT); + INSERT INTO p2 VALUES(1, 'one'); + INSERT INTO p2 VALUES(2, 'two'); + INSERT INTO c2 VALUES('i', 1); +} + +do_catchsql_test 3.2.1 { + BEGIN; + UPDATE p2 SET a=a-1; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.2.2 { COMMIT } + +do_execsql_test 3.2.3 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + UPDATE p2 SET a=a-1; + COMMIT; +} + +do_execsql_test 3.2.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + UPDATE p2 SET a=a-1; +} +do_catchsql_test 3.2.5 { + COMMIT; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.2.6 { ROLLBACK } + +do_execsql_test 3.3.1 { + CREATE TRIGGER p2t AFTER DELETE ON p2 BEGIN + INSERT INTO p2 VALUES(old.a, 'deleted!'); + END; +} +do_catchsql_test 3.3.2 { + BEGIN; + DELETE FROM p2 WHERE a=1; +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 3.3.3 { COMMIT } + +do_execsql_test 3.3.4 { + BEGIN; + PRAGMA defer_foreign_keys = 1; + DELETE FROM p2 WHERE a=1; + COMMIT; + SELECT * FROM p2; +} {0 one 1 deleted!} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey7.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey7.test new file mode 100644 index 0000000000000000000000000000000000000000..77870a7505a377536c866e56a31143483f890d46 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey7.test @@ -0,0 +1,121 @@ +# 2001 September 15 +# +# 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. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey7 + +ifcapable {!foreignkey} { + finish_test + return +} + +do_execsql_test 1.1 { + PRAGMA foreign_keys = 1; + + CREATE TABLE s1(a PRIMARY KEY, b); + CREATE TABLE par(a, b REFERENCES s1, c UNIQUE, PRIMARY KEY(a)); + + CREATE TABLE c1(a, b REFERENCES par); + CREATE TABLE c2(a, b REFERENCES par); + CREATE TABLE c3(a, b REFERENCES par(c)); +} + +proc auth {op tbl args} { + if {$op == "SQLITE_READ"} { set ::tbls($tbl) 1 } + return "SQLITE_OK" +} +db auth auth +db cache size 0 +proc do_tblsread_test {tn sql tbllist} { + array unset ::tbls + uplevel [list execsql $sql] + uplevel [list do_test $tn {lsort [array names ::tbls]} $tbllist] +} + +do_tblsread_test 1.2 { UPDATE par SET b=? WHERE a=? } {par s1} +do_tblsread_test 1.3 { UPDATE par SET a=? WHERE b=? } {c1 c2 par} +do_tblsread_test 1.4 { UPDATE par SET c=? WHERE b=? } {c3 par} +do_tblsread_test 1.5 { UPDATE par SET a=?,b=?,c=? WHERE b=? } {c1 c2 c3 par s1} + +ifcapable incrblob { + do_execsql_test 2.0 { + CREATE TABLE pX(x PRIMARY KEY); + CREATE TABLE cX(a INTEGER PRIMARY KEY, b REFERENCES pX); + } + + do_catchsql_test 2.1 { + INSERT INTO cX VALUES(11, zeroblob(40)); + } {1 {FOREIGN KEY constraint failed}} + + do_test 2.2 { + set stmt [sqlite3_prepare_v2 db "INSERT INTO cX VALUES(11, ?)" -1] + sqlite3_bind_zeroblob $stmt 1 45 + sqlite3_step $stmt + sqlite3_finalize $stmt + } {SQLITE_CONSTRAINT} +} + +ifcapable stat4 { + do_execsql_test 3.0 { + CREATE TABLE p4 (id INTEGER NOT NULL PRIMARY KEY); + INSERT INTO p4 VALUES(1), (2), (3); + + CREATE TABLE c4(x INTEGER REFERENCES p4(id) DEFERRABLE INITIALLY DEFERRED); + CREATE INDEX c4_x ON c4(x); + INSERT INTO c4 VALUES(1), (2), (3); + + ANALYZE; + INSERT INTO p4(id) VALUES(4); + } +} + + +do_execsql_test 4.0 { + PRAGMA foreign_keys = true; + CREATE TABLE parent( + p PRIMARY KEY + ); + CREATE TABLE child( + c UNIQUE REFERENCES parent(p) + ); +} + +do_catchsql_test 4.1 { + INSERT OR FAIL INTO child VALUES(123), (123); +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 4.2 { + SELECT * FROM child; +} {} + +do_execsql_test 4.3 { + PRAGMA foreign_key_check; +} {} + +do_catchsql_test 4.4 { + INSERT INTO parent VALUES(123); + INSERT OR FAIL INTO child VALUES(123), (123); +} {1 {UNIQUE constraint failed: child.c}} + +do_execsql_test 4.5 { + SELECT * FROM child; +} {123} + +do_execsql_test 4.6 { + PRAGMA foreign_key_check; +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey8.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey8.test new file mode 100644 index 0000000000000000000000000000000000000000..2d72f6fcf0c84b4225b4535eb114b7b3411004ae --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey8.test @@ -0,0 +1,253 @@ +# 2001 September 15 +# +# 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. +# +# This file implements tests for foreign keys. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fkey8 + +ifcapable {!foreignkey} { + finish_test + return +} +do_execsql_test 1.0 { PRAGMA foreign_keys = 1; } + + +foreach {tn use_stmt sql schema} { + 1 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1); + } + + 2.1 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE); + } + 2.2 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE SET NULL); + } + 2.3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE SET DEFAULT); + } + + 3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE); + CREATE TRIGGER ct1 AFTER DELETE ON c1 BEGIN + INSERT INTO p1 VALUES('x'); + END; + } + + 4 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1); + } + + 5.1 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE CASCADE); + } + 5.2 0 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET NULL); + } + 5.3 1 "DELETE FROM p1" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON DELETE CASCADE, c PRIMARY KEY); + CREATE TABLE cc1(d REFERENCES c1 ON DELETE SET DEFAULT); + } + + 6.1 1 "UPDATE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c); + } + 6.2 0 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE SET NULL, c); + } + 6.3 1 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b REFERENCES p1 ON UPDATE CASCADE, c); + } + 6.4 1 "UPDATE OR IGNORE p1 SET a = ?" { + CREATE TABLE p1(a PRIMARY KEY); + CREATE TABLE c1(b NOT NULL REFERENCES p1 ON UPDATE SET NULL, c); + } + +} { + drop_all_tables + do_test 1.$tn { + execsql $schema + set stmt [sqlite3_prepare_v2 db $sql -1 dummy] + set ret [uses_stmt_journal $stmt] + sqlite3_finalize $stmt + set ret + } $use_stmt +} + +#------------------------------------------------------------------------- +# The following tests check that foreign key constaint counters are +# correctly updated for any implicit DELETE operations that occur +# when a REPLACE command is executed against a WITHOUT ROWID table +# that has no triggers or auxiliary indexes. +# +reset_db +do_execsql_test 2.1.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p1(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE TABLE c1(x REFERENCES p1 DEFERRABLE INITIALLY DEFERRED); + + INSERT INTO p1 VALUES(1, 'one'); + INSERT INTO p1 VALUES(2, 'two'); + INSERT INTO c1 VALUES(1); + INSERT INTO c1 VALUES(2); +} + +do_catchsql_test 2.1.2 { + BEGIN; + DELETE FROM p1 WHERE a=1; + INSERT OR REPLACE INTO p1 VALUES(2, 'two'); + COMMIT; +} {1 {FOREIGN KEY constraint failed}} + +reset_db +do_execsql_test 2.2.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p2(a PRIMARY KEY, b); + CREATE TABLE c2( + x PRIMARY KEY, + y REFERENCES p2 DEFERRABLE INITIALLY DEFERRED + ) WITHOUT ROWID; +} + +do_catchsql_test 2.2.1 { + BEGIN; + INSERT INTO c2 VALUES(13, 13); + INSERT OR REPLACE INTO c2 VALUES(13, 13); + DELETE FROM c2; + COMMIT; +} {0 {}} + +reset_db +do_execsql_test 2.3.0 { + PRAGMA foreign_keys = on; + CREATE TABLE p3(a PRIMARY KEY, b) WITHOUT ROWID; + CREATE TABLE c3(x REFERENCES p3); + + INSERT INTO p3 VALUES(1, 'one'); + INSERT INTO p3 VALUES(2, 'two'); + INSERT INTO c3 VALUES(1); + INSERT INTO c3 VALUES(2); + + CREATE TRIGGER p3d AFTER DELETE ON p3 WHEN old.a=1 BEGIN + INSERT OR REPLACE INTO p3 VALUES(2, 'three'); + END; +} + +do_catchsql_test 2.3.1 { + DELETE FROM p3 WHERE a=1 +} {1 {FOREIGN KEY constraint failed}} + + +do_execsql_test 3.0 { + PRAGMA foreign_keys=ON; + CREATE TABLE t2( + a PRIMARY KEY, b, c, d, e, + FOREIGN KEY(b, c) REFERENCES t2(d, e) + ) WITHOUT ROWID; + CREATE UNIQUE INDEX idx ON t2(d, e); + + INSERT INTO t2 VALUES(1, 'one', 'one', 'one', 'one'); -- row is parent of self + INSERT INTO t2 VALUES(2, 'one', 'one', 'one', NULL); -- parent is row 1 +} + +do_catchsql_test 3.1 { + DELETE FROM t2 WHERE a=1; +} {1 {FOREIGN KEY constraint failed}} + +do_execsql_test 4.0 { + CREATE TABLE t1 ( + c1 PRIMARY KEY, + c2 NUMERIC, + FOREIGN KEY(c1) REFERENCES t1(c2) + ) WITHOUT ROWID ; + CREATE INDEX t1c1 ON t1(c1); + CREATE UNIQUE INDEX t1c1unique ON t1(c2); +} +do_catchsql_test 4.1 { + INSERT OR REPLACE INTO t1 VALUES(10000, 20000); +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test 4.2 { + INSERT OR REPLACE INTO t1 VALUES(20000, 20000); +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 5.0 { + PRAGMA foreign_keys = true; + CREATE TABLE parent( + p TEXT PRIMARY KEY + ); + CREATE TABLE child( + c INTEGER UNIQUE, + FOREIGN KEY(c) REFERENCES parent(p) DEFERRABLE INITIALLY DEFERRED + ); + BEGIN; + INSERT INTO child VALUES(123); + INSERT INTO parent VALUES('123'); + COMMIT; +} +do_execsql_test 5.1 { + PRAGMA integrity_check; +} {ok} + +do_execsql_test 5.2 { + INSERT INTO parent VALUES(1200); + BEGIN; + INSERT INTO child VALUES(456); + UPDATE parent SET p = '456' WHERE p=1200; + COMMIT; +} +do_execsql_test 5.3 { + PRAGMA integrity_check; +} {ok} + +#------------------------------------------------------------------------- +reset_db +forcedelete test.db2 +do_execsql_test 6.1 { + PRAGMA foreign_keys = on; + CREATE TABLE c1(b); + INSERT INTO c1 VALUES(123); +} + +do_execsql_test 6.2 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.p1(a INTEGER PRIMARY KEY); + CREATE TABLE aux.c1(b REFERENCES p1(a) ON DELETE RESTRICT); + + INSERT INTO aux.p1 VALUES(123); +} + +do_execsql_test 6.3 { + DELETE FROM aux.p1 WHERE a=123; +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey_malloc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey_malloc.test new file mode 100644 index 0000000000000000000000000000000000000000..382e6f67d95384ad09d871536453ae84fce887dc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fkey_malloc.test @@ -0,0 +1,134 @@ +# 2009 September 22 +# +# 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 + +ifcapable !foreignkey||!trigger { + finish_test + return +} +source $testdir/malloc_common.tcl + +do_malloc_test fkey_malloc-1 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a PRIMARY KEY, b UNIQUE); + CREATE TABLE t2(x REFERENCES t1 ON UPDATE CASCADE ON DELETE CASCADE); +} -sqlbody { + INSERT INTO t1 VALUES('aaa', 1); + INSERT INTO t2 VALUES('aaa'); + UPDATE t1 SET a = 'bbb'; + DELETE FROM t1; + PRAGMA foreign_key_check; +} + +do_malloc_test fkey_malloc-2 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a, b, UNIQUE(a, b)); +} -sqlbody { + CREATE TABLE t2(x, y, + FOREIGN KEY(x, y) REFERENCES t1(a, b) DEFERRABLE INITIALLY DEFERRED + ); + BEGIN; + INSERT INTO t2 VALUES('a', 'b'); + INSERT INTO t1 VALUES('a', 'b'); + UPDATE t1 SET a = 'c'; + DELETE FROM t2; + INSERT INTO t2 VALUES('d', 'b'); + UPDATE t2 SET x = 'c'; + COMMIT; +} + +do_malloc_test fkey_malloc-3 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x INTEGER PRIMARY KEY); + CREATE TABLE t2(y DEFAULT 14 REFERENCES t1(x) ON UPDATE SET DEFAULT); + CREATE TABLE t3(y REFERENCES t1 ON UPDATE SET NULL); + INSERT INTO t1 VALUES(13); + INSERT INTO t2 VALUES(13); + INSERT INTO t3 VALUES(13); +} -sqlbody { + UPDATE t1 SET x = 14; +} + +proc catch_fk_error {zSql} { + set rc [catch {db eval $zSql} msg] + if {$rc==0} { + return $msg + } + if {[string match {*foreign key*} $msg]} { + return "" + } + if {$msg eq "out of memory" + || $msg eq "FOREIGN KEY constraint failed" + || $msg eq "constraint failed" + } { + error 1 + } + error $msg +} + +do_malloc_test fkey_malloc-4 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x INTEGER PRIMARY KEY, y UNIQUE); + CREATE TABLE t2(z REFERENCES t1(x), a REFERENCES t1(y)); + CREATE TABLE t3(x); + CREATE TABLE t4(z REFERENCES t3); + CREATE TABLE t5(x, y); + CREATE TABLE t6(z REFERENCES t5(x)); + CREATE INDEX i51 ON t5(x); + CREATE INDEX i52 ON t5(y, x); + INSERT INTO t1 VALUES(1, 2); +} -tclbody { + catch_fk_error {INSERT INTO t2 VALUES(1, 3)} + catch_fk_error {INSERT INTO t4 VALUES(2)} + catch_fk_error {INSERT INTO t6 VALUES(2)} +} + +do_malloc_test fkey_malloc-5 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(x, y, PRIMARY KEY(x, y)); + CREATE TABLE t2(a, b, FOREIGN KEY(a, b) REFERENCES t1 ON UPDATE CASCADE); + INSERT INTO t1 VALUES(1, 2); + INSERT INTO t2 VALUES(1, 2); +} -sqlbody { + UPDATE t1 SET x = 5; +} + +do_malloc_test fkey_malloc-6 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE t1( + x PRIMARY KEY, + y REFERENCES t1 ON DELETE RESTRICT ON UPDATE SET DEFAULT + ); + INSERT INTO t1 VALUES('abc', 'abc'); + INSERT INTO t1 VALUES('def', 'def'); +} -sqlbody { + INSERT INTO t1 VALUES('ghi', 'ghi'); + DELETE FROM t1 WHERE rowid>1; + UPDATE t1 SET x='jkl', y='jkl'; +} + +do_malloc_test fkey_malloc-7 -sqlprep { + PRAGMA foreign_keys = 1; + CREATE TABLE x(a, b, PRIMARY KEY(a, b)); + CREATE TABLE y(c, d, + FOREIGN KEY(d, c) REFERENCES x DEFERRABLE INITIALLY DEFERRED + ); + CREATE TABLE z(e, f, FOREIGN KEY(e, f) REFERENCES x); +} -sqlbody { + DROP TABLE y; + DROP TABLE x; +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fordelete.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fordelete.test new file mode 100644 index 0000000000000000000000000000000000000000..39c0c3585e2a4b995b8cb2be790ad5e6c49c0dc6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fordelete.test @@ -0,0 +1,209 @@ +# 2001 September 15 +# +# 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. The +# focus of this file is testing the SELECT statement. +# +# $Id: select1.test,v 1.70 2009/05/28 01:00:56 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fordelete + +# This function returns a list of the tables or indexes opened with +# OP_OpenWrite instructions when the SQL statement passed as the only +# argument is executed. If the OPFLAG_FORDELETE flag is specified on +# the OP_OpenWrite, an asterix is appended to the object name. The list +# is sorted in [lsort] order before it is returned. +# +proc analyze_delete_program {sql} { + # Build a map from root page to table/index name. + db eval { + SELECT name, rootpage FROM sqlite_master + } { + set T($rootpage) $name + } + + # For each OpenWrite instruction generated for the proposed DELETE + # statement, add the following array entries: + # + # $M() -> + # $O() -> "*" | "" + # + # The O() entry is set to "*" if the BTREE_FORDELETE flag is specified, + # or "" otherwise. + # + db eval "EXPLAIN $sql" R { + if {$R(opcode)=="OpenWrite"} { + set root $R(p2) + set csr $R(p1) + if {[info exists T($root)]} { set M($csr) $T($root) } + + set obj $T($root) + set O($obj) "" + if {$R(p5) & 0x08} { + set O($obj) * + } else { + set O($obj) "" + } + } + } + + db eval "EXPLAIN $sql" R { + if {$R(opcode) == "Delete"} { + set csr $R(p1) + if {[info exists M($csr)]} { + set idxdelete [expr {("0x$R(p5)" & 0x04) ? 1 : 0}] + if {$idxdelete} { + append O($M($csr)) "+" + } + } + } + } + + set res [list] + foreach {k v} [array get O] { + lappend res "${k}${v}" + } + + lsort $res +} + +proc do_adp_test {tn sql res} { + uplevel [list do_test $tn [list analyze_delete_program $sql] [list {*}$res]] +} + +do_execsql_test 1.0 { + CREATE TABLE t1(a PRIMARY KEY, b); +} + +foreach {tn sql res} { + 1 { DELETE FROM t1 WHERE a=?} { sqlite_autoindex_t1_1 t1*+ } + 2 { DELETE FROM t1 WHERE a=? AND b=? } { sqlite_autoindex_t1_1 t1+ } + 3 { DELETE FROM t1 WHERE a>? } { sqlite_autoindex_t1_1 t1*+ } + 4 { DELETE FROM t1 WHERE rowid=? } { sqlite_autoindex_t1_1* t1 } +} { + do_adp_test 1.$tn $sql $res +} + +do_execsql_test 2.0 { + CREATE TABLE t2(a, b, c); + CREATE INDEX t2a ON t2(a); + CREATE INDEX t2b ON t2(b); + CREATE INDEX t2c ON t2(c); +} +foreach {tn sql res} { + 1 { DELETE FROM t2 WHERE a=?} { t2*+ t2a t2b* t2c* } + 2 { DELETE FROM t2 WHERE a=? AND +b=?} { t2+ t2a t2b* t2c* } + 3 { DELETE FROM t2 WHERE a=? OR b=?} { t2 t2a* t2b* t2c* } + 4 { DELETE FROM t2 WHERE +a=? } { t2 t2a* t2b* t2c* } + 5 { DELETE FROM t2 WHERE rowid=? } { t2 t2a* t2b* t2c* } +} { + do_adp_test 2.$tn $sql $res +} + +#------------------------------------------------------------------------- +# Test that a record that consists of the bytes: +# +# 0x01 0x00 +# +# is interpreted by OP_Column as a vector of NULL values (assuming the +# default column values are NULL). Also test that: +# +# 0x00 +# +# is handled in the same way. +# +do_execsql_test 3.0 { + CREATE TABLE x1(a INTEGER PRIMARY KEY, b, c, d); + CREATE TABLE x2(a INTEGER PRIMARY KEY, b, c, d); +} + +do_test 3.1 { + set root [db one { SELECT rootpage FROM sqlite_master WHERE name = 'x1' }] + db eval { + BEGIN IMMEDIATE; + } + set bt [btree_from_db db] + set csr [btree_cursor $bt $root 1] + btree_insert $csr 5 "\000" + btree_close_cursor $csr + db eval { COMMIT } + + db eval { + SELECT * FROM x1; + } +} {5 {} {} {}} + +do_test 3.2 { + set root [db one { SELECT rootpage FROM sqlite_master WHERE name = 'x2' }] + db eval { + BEGIN IMMEDIATE; + } + set bt [btree_from_db db] + set csr [btree_cursor $bt $root 1] + btree_insert $csr 6 "\000" + btree_close_cursor $csr + db eval { COMMIT } + + db eval { + SELECT * FROM x2; + } +} {6 {} {} {}} + + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 4.0 { + CREATE TABLE log(x); + CREATE TABLE p1(one PRIMARY KEY, two); + + CREATE TRIGGER tr_bd BEFORE DELETE ON p1 BEGIN + INSERT INTO log VALUES('delete'); + END; + INSERT INTO p1 VALUES('a', 'A'), ('b', 'B'), ('c', 'C'); + DELETE FROM p1 WHERE one = 'a'; +} + +reset_db +do_execsql_test 4.1 { + BEGIN TRANSACTION; + CREATE TABLE tbl(a PRIMARY KEY, b, c); + CREATE TABLE log(a, b, c); + INSERT INTO "tbl" VALUES(1,2,3); + CREATE TRIGGER the_trigger BEFORE DELETE ON tbl BEGIN + INSERT INTO log VALUES(1, 2,3); + END; + COMMIT; + DELETE FROM tbl WHERE a=1; +} + +reset_db +do_execsql_test 5.1 { + PRAGMA foreign_keys = 1; + CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t2( + c INTEGER PRIMARY KEY, + d INTEGER DEFAULT 1 REFERENCES t1 ON DELETE SET DEFAULT + ); +} {} +do_execsql_test 5.2 { + INSERT INTO t1 VALUES(1, 'one'); + INSERT INTO t1 VALUES(2, 'two'); + INSERT INTO t2 VALUES(1, 2); + SELECT * FROM t2; +} {1 2} +do_execsql_test 5.3 { + DELETE FROM t1 WHERE a = 2; +} {} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fp-speed-1.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/fp-speed-1.c new file mode 100644 index 0000000000000000000000000000000000000000..cb4e0409c3a8ef6a82e5ff6d016b9dca645f1294 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fp-speed-1.c @@ -0,0 +1,154 @@ +/* +** Performance testing of floating-point binary-to-decimal conversion for +** SQLite versus the standard library. +** +** To compile: +** +** make sqlite3.c +** gcc -Os -c sqlite3.c +** gcc -I. -Os test/fp-speed-1.c sqlite3.o -ldl -lm -lpthread +** +** To run the test: +** +** time ./a.out 0 10000000 <-- standard library +** time ./a.out 1 10000000 <-- SQLite +*/ +static double aVal[] = { + -1.0163830486285643089e+063, + +0.0049243807391586981e-019, + +7.3818732407343994867e-095, + +7.0678595219225717143e+000, + +9.2807266319850025655e+120, + +5.8871050861933394663e+135, + -2.2998023621259662805e-168, + -1.5903581924910847482e+181, + +2.4313441816844978216e-001, + -3.8290987328945399091e-147, + +1.8787914062744001349e-009, + +0.7270653560487146653e-014, + +0.0639577697913183665e+107, + +5.2292338879315861930e-103, + +6.3747682672872231319e-021, + +8.6972339538329106984e-129, + -9.5074486051597691937e-026, + -8.6480257845368753018e-005, + -3.5657595775797470332e+017, + -7.8323106179731761351e+161, + +7.7813875274120800372e+077, + -1.8739718928360196596e-050, + +8.6898145915593357218e-051, + +6.0566766359877837871e+002, + +4.1703379217148160678e+199, + +2.1283871288746651560e+150, + -6.8395236083891810637e+128, + -6.2114299763939529155e-147, + -2.0753525742614637350e-149, + +5.8727459803944290257e-007, + +8.5888991062002101817e+010, + +6.8624461031355917632e+026, + -3.3053986756670905167e-075, + -4.3596843152763444945e-108, + +0.0834139520104099673e+098, + -8.8581986548904222440e-192, + -3.6622095428727698202e+038, + -6.6965852297025063260e+005, + +1.8204169347406488441e-054, + +6.5234508038649000384e-065, + +1.5923006018219011453e+083, + +1.7362555291656389480e+018, + +7.2875431976854785882e+160, + +1.2835880105958926748e-146, + +8.0516253320320819420e-113, + +6.6324633399381145440e-030, + -1.7126500070280062058e-149, + +1.6995738341583712335e+042, + +7.6048766923738663725e-112, + +0.6159117235449455043e-004, + +5.7544894355415943289e-135, + +8.2970228592690581890e-023, + -6.5531925360163067447e+020, + +5.8321334606187030050e+120, + +5.6557166509571891727e+095, + +0.3322789708438408704e-114, + -7.1210648776698686623e-050, + -9.6721262526706343301e+179, + -3.4583916571377395084e-106, + +4.7896094323214750793e-172, + -9.6926028040004137875e-056, + +7.0683848275381385483e-198, + -5.2970114182162961964e-007, + -4.4287021200905393271e-170, + +0.0728891155732808799e-189, + -9.1855462025879447465e+175, + +3.7294126234131007796e+015, + +2.6857421882792719241e+003, + -4.7070607333624685339e+039, + +7.2175820768279334274e+136, + -8.3678412534261163481e-115, + +2.2174844304241822163e+019, + +0.1949824588606861016e+112, + -9.7334052955672071912e+151, + -9.7793887766936999879e-142, + -5.1561164587416931561e+139, + -7.5048993577765174789e-022, + +7.3556076568687784568e+107, + -5.0681628575533599865e-144, + +1.5209705642027747811e+165, + -7.5989782535048296040e-101, + +1.3654137203389775871e-016, + -1.6441720554651372066e+087, + -4.9042433196141125923e+000, + -7.7063611961649130777e+118, + +0.1699427460930766201e+174, + +8.3374317849572216870e-145, + -5.2355330480469580072e+081, + -3.8510045942194147919e+141, + -6.3513622544326339887e-147, + +2.3869303484454428988e+049, + +3.8352715871620360268e-165, + -3.1263120493136887902e+035, + -5.5794797002556490823e+051, + -8.8109874479595604379e+142, + -4.3727360120203216922e+070, + -3.1109951189668539974e+170, + -9.4841878031704268232e+011, + -3.7398451668304407277e+067, + +4.8984042008915959963e-091, +}; +#define NN (sizeof(aVal)/sizeof(aVal[0])) + +#include "sqlite3.h" +#include +#include + +int main(int argc, char **argv){ + int i; + int cnt; + int fg; + char zBuf[1000]; + + if( argc!=3 ){ + fprintf(stderr, "Usage: %s FLAG COUNT\n", argv[0]); + return 1; + } + cnt = atoi(argv[2]); + fg = atoi(argv[1]); + + switch( fg % 3 ){ + case 0: { + printf("Doing %d calls to C-lib sprintf()\n", cnt); + for(i=0; i 10000} {error "n must be <= 10000"} + db eval "CREATE VIRTUAL TABLE t1 USING $opts(-module) (x, y)" + + set xwords [list zero one two three four five six seven eight nine ten] + set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa] + + for {set i 0} {$i < $n} {incr i} { + set x "" + set y "" + + set x [list] + lappend x [lindex $xwords [expr ($i / 1000) % 10]] + lappend x [lindex $xwords [expr ($i / 100) % 10]] + lappend x [lindex $xwords [expr ($i / 10) % 10]] + lappend x [lindex $xwords [expr ($i / 1) % 10]] + + set y [list] + lappend y [lindex $ywords [expr ($i / 1000) % 10]] + lappend y [lindex $ywords [expr ($i / 100) % 10]] + lappend y [lindex $ywords [expr ($i / 10) % 10]] + lappend y [lindex $ywords [expr ($i / 1) % 10]] + + db eval { INSERT INTO t1(docid, x, y) VALUES($i, $x, $y) } + } +} + +#------------------------------------------------------------------------- +# USAGE: fts3_build_db_2 N ARGS +# +# Build a sample FTS table in the database opened by database connection +# [db]. The name of the new table is "t2". +# +proc fts3_build_db_2 {args} { + + set default(-module) fts4 + set default(-extra) "" + + set nArg [llength $args] + if {($nArg%2)==0} { + error "wrong # args: should be \"fts3_build_db_1 ?switches? n\"" + } + + set n [lindex $args [expr $nArg-1]] + array set opts [array get default] + array set opts [lrange $args 0 [expr $nArg-2]] + foreach k [array names opts] { + if {0==[info exists default($k)]} { error "unknown option: $k" } + } + + if {$n > 100000} {error "n must be <= 100000"} + + set sql "CREATE VIRTUAL TABLE t2 USING $opts(-module) (content" + if {$opts(-extra) != ""} { + append sql ", " $opts(-extra) + } + append sql ")" + db eval $sql + + set chars [list a b c d e f g h i j k l m n o p q r s t u v w x y z ""] + + for {set i 0} {$i < $n} {incr i} { + set word "" + set nChar [llength $chars] + append word [lindex $chars [expr {($i / 1) % $nChar}]] + append word [lindex $chars [expr {($i / $nChar) % $nChar}]] + append word [lindex $chars [expr {($i / ($nChar*$nChar)) % $nChar}]] + + db eval { INSERT INTO t2(docid, content) VALUES($i, $word) } + } +} + +#------------------------------------------------------------------------- +# USAGE: fts3_integrity_check TBL +# +# This proc is used to verify that the full-text index is consistent with +# the contents of the fts3 table. In other words, it checks that the +# data in the %_contents table matches that in the %_segdir and %_segments +# tables. +# +# This is not an efficient procedure. It uses a lot of memory and a lot +# of CPU. But it is better than not checking at all. +# +# The procedure is: +# +# 1) Read the entire full-text index from the %_segdir and %_segments +# tables into memory. For each entry in the index, the following is +# done: +# +# set C($iDocid,$iCol,$iPosition) $zTerm +# +# 2) Iterate through each column of each row of the %_content table. +# Tokenize all documents, and check that for each token there is +# a corresponding entry in the $C array. After checking a token, +# [unset] the $C array entry. +# +# 3) Check that array $C is now empty. +# +# +proc fts3_integrity_check {tbl} { + + fts3_read2 $tbl 1 A + + foreach zTerm [array names A] { + #puts $zTerm + foreach doclist $A($zTerm) { + set docid 0 + while {[string length $doclist]>0} { + set iCol 0 + set iPos 0 + set lPos [list] + set lCol [list] + + # First varint of a doclist-entry is the docid. Delta-compressed + # with respect to the docid of the previous entry. + # + incr docid [gobble_varint doclist] + if {[info exists D($zTerm,$docid)]} { + while {[set iDelta [gobble_varint doclist]] != 0} {} + continue + } + set D($zTerm,$docid) 1 + + # Gobble varints until the 0x00 that terminates the doclist-entry + # is found. + while {[set iDelta [gobble_varint doclist]] > 0} { + if {$iDelta == 1} { + set iCol [gobble_varint doclist] + set iPos 0 + } else { + incr iPos $iDelta + incr iPos -2 + set C($docid,$iCol,$iPos) $zTerm + } + } + } + } + } + + foreach key [array names C] { + #puts "$key -> $C($key)" + } + + + db eval "SELECT * FROM ${tbl}_content" E { + set iCol 0 + set iDoc $E(docid) + foreach col [lrange $E(*) 1 end] { + set c $E($col) + set sql {SELECT fts3_tokenizer_test('simple', $c)} + + foreach {pos term dummy} [db one $sql] { + if {![info exists C($iDoc,$iCol,$pos)]} { + set es "Error at docid=$iDoc col=$iCol pos=$pos. Index is missing" + lappend errors $es + } else { + if {[string compare $C($iDoc,$iCol,$pos) $term]} { + set es "Error at docid=$iDoc col=$iCol pos=$pos. Index " + append es "has \"$C($iDoc,$iCol,$pos)\", document has \"$term\"" + lappend errors $es + } + unset C($iDoc,$iCol,$pos) + } + } + incr iCol + } + } + + foreach c [array names C] { + lappend errors "Bad index entry: $c -> $C($c)" + } + + if {[info exists errors]} { return [join $errors "\n"] } + return "ok" +} + +# USAGE: fts3_terms TBL WHERE +# +# Argument TBL must be the name of an FTS3 table. Argument WHERE is an +# SQL expression that will be used as the WHERE clause when scanning +# the %_segdir table. As in the following query: +# +# "SELECT * FROM ${TBL}_segdir WHERE ${WHERE}" +# +# This function returns a list of all terms present in the segments +# selected by the statement above. +# +proc fts3_terms {tbl where} { + fts3_read $tbl $where a + return [lsort [array names a]] +} + + +# USAGE: fts3_doclist TBL TERM WHERE +# +# Argument TBL must be the name of an FTS3 table. TERM is a term that may +# or may not be present in the table. Argument WHERE is used to select a +# subset of the b-tree segments in the associated full-text index as +# described above for [fts3_terms]. +# +# This function returns the results of merging the doclists associated +# with TERM in the selected segments. Each doclist is an element of the +# returned list. Each doclist is formatted as follows: +# +# [$docid ?$col[$off1 $off2...]?...] +# +# The formatting is odd for a Tcl command in order to be compatible with +# the original C-language implementation. If argument WHERE is "1", then +# any empty doclists are omitted from the returned list. +# +proc fts3_doclist {tbl term where} { + fts3_read $tbl $where a + + + foreach doclist $a($term) { + set docid 0 + + while {[string length $doclist]>0} { + set iCol 0 + set iPos 0 + set lPos [list] + set lCol [list] + incr docid [gobble_varint doclist] + + while {[set iDelta [gobble_varint doclist]] > 0} { + if {$iDelta == 1} { + lappend lCol [list $iCol $lPos] + set iPos 0 + set lPos [list] + set iCol [gobble_varint doclist] + } else { + incr iPos $iDelta + incr iPos -2 + lappend lPos $iPos + } + } + + if {[llength $lPos]>0} { + lappend lCol [list $iCol $lPos] + } + + if {$where != "1" || [llength $lCol]>0} { + set ret($docid) $lCol + } else { + unset -nocomplain ret($docid) + } + } + } + + set lDoc [list] + foreach docid [lsort -integer [array names ret]] { + set lCol [list] + set cols "" + foreach col $ret($docid) { + foreach {iCol lPos} $col {} + append cols " $iCol\[[join $lPos { }]\]" + } + lappend lDoc "\[${docid}${cols}\]" + } + + join $lDoc " " +} + +########################################################################### + +proc gobble_varint {varname} { + upvar $varname blob + set n [read_fts3varint $blob ret] + set blob [string range $blob $n end] + return $ret +} +proc gobble_string {varname nLength} { + upvar $varname blob + set ret [string range $blob 0 [expr $nLength-1]] + set blob [string range $blob $nLength end] + return $ret +} + +# The argument is a blob of data representing an FTS3 segment leaf. +# Return a list consisting of alternating terms (strings) and doclists +# (blobs of data). +# +proc fts3_readleaf {blob} { + set zPrev "" + set terms [list] + + while {[string length $blob] > 0} { + set nPrefix [gobble_varint blob] + set nSuffix [gobble_varint blob] + + set zTerm [string range $zPrev 0 [expr $nPrefix-1]] + append zTerm [gobble_string blob $nSuffix] + set nDoclist [gobble_varint blob] + set doclist [gobble_string blob $nDoclist] + + lappend terms $zTerm $doclist + set zPrev $zTerm + } + + return $terms +} + +proc fts3_read2 {tbl where varname} { + upvar $varname a + array unset a + db eval " SELECT start_block, leaves_end_block, root + FROM ${tbl}_segdir WHERE $where + ORDER BY level ASC, idx DESC + " { + set c 0 + binary scan $root c c + if {$c==0} { + foreach {t d} [fts3_readleaf $root] { lappend a($t) $d } + } else { + db eval " SELECT block + FROM ${tbl}_segments + WHERE blockid>=$start_block AND blockid<=$leaves_end_block + ORDER BY blockid + " { + foreach {t d} [fts3_readleaf $block] { lappend a($t) $d } + } + } + } +} + +proc fts3_read {tbl where varname} { + upvar $varname a + array unset a + db eval " SELECT start_block, leaves_end_block, root + FROM ${tbl}_segdir WHERE $where + ORDER BY level DESC, idx ASC + " { + if {$start_block == 0} { + foreach {t d} [fts3_readleaf $root] { lappend a($t) $d } + } else { + db eval " SELECT block + FROM ${tbl}_segments + WHERE blockid>=$start_block AND blockid<$leaves_end_block + ORDER BY blockid + " { + foreach {t d} [fts3_readleaf $block] { lappend a($t) $d } + + } + } + } +} + +########################################################################## + diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aa.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aa.test new file mode 100644 index 0000000000000000000000000000000000000000..cb1bde74a46650c0381292ae8af41d20ef661d44 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aa.test @@ -0,0 +1,265 @@ +# 2006 September 9 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3aa + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing five keywords: +# one, two, three, four, and five, in various combinations. The +# rowid for each will be a bitmask for the elements it contains. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1(content) VALUES('one'); + INSERT INTO t1(content) VALUES('two'); + INSERT INTO t1(content) VALUES('one two'); + INSERT INTO t1(content) VALUES('three'); + INSERT INTO t1(content) VALUES('one three'); + INSERT INTO t1(content) VALUES('two three'); + INSERT INTO t1(content) VALUES('one two three'); + INSERT INTO t1(content) VALUES('four'); + INSERT INTO t1(content) VALUES('one four'); + INSERT INTO t1(content) VALUES('two four'); + INSERT INTO t1(content) VALUES('one two four'); + INSERT INTO t1(content) VALUES('three four'); + INSERT INTO t1(content) VALUES('one three four'); + INSERT INTO t1(content) VALUES('two three four'); + INSERT INTO t1(content) VALUES('one two three four'); + INSERT INTO t1(content) VALUES('five'); + INSERT INTO t1(content) VALUES('one five'); + INSERT INTO t1(content) VALUES('two five'); + INSERT INTO t1(content) VALUES('one two five'); + INSERT INTO t1(content) VALUES('three five'); + INSERT INTO t1(content) VALUES('one three five'); + INSERT INTO t1(content) VALUES('two three five'); + INSERT INTO t1(content) VALUES('one two three five'); + INSERT INTO t1(content) VALUES('four five'); + INSERT INTO t1(content) VALUES('one four five'); + INSERT INTO t1(content) VALUES('two four five'); + INSERT INTO t1(content) VALUES('one two four five'); + INSERT INTO t1(content) VALUES('three four five'); + INSERT INTO t1(content) VALUES('one three four five'); + INSERT INTO t1(content) VALUES('two three four five'); + INSERT INTO t1(content) VALUES('one two three four five'); +} + +do_test fts3aa-1.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-1.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-1.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-1.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'} +} {7 15 23 31} +do_test fts3aa-1.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'} +} {7 15 23 31} +do_test fts3aa-1.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'} +} {7 15 23 31} +do_test fts3aa-1.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'} +} {7 15 23 31} +do_test fts3aa-1.8 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'} +} {7 15 23 31} +do_test fts3aa-1.9 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'} +} {7 15 23 31} +do_test fts3aa-1.10 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'} +} {7 15 23 31} +do_test fts3aa-1.11 { + execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '} +} {7 15 23 31} + +do_test fts3aa-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one"'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'} +} {3 7 11 15 19 23 27 31} +do_test fts3aa-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'} +} {} +do_test fts3aa-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'} +} {7 15 23 31} +do_test fts3aa-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'} +} {} +do_test fts3aa-2.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'} +} {15 31} +do_test fts3aa-2.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'} +} {} +do_test fts3aa-2.8 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'} +} {21} +do_test fts3aa-2.9 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'} +} {21 29} +do_test fts3aa-2.10 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'} +} {21 29} +do_test fts3aa-2.11 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'} +} {29} +do_test fts3aa-2.12 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'} +} {29} +do_test fts3aa-2.13 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'} +} {29} + +do_test fts3aa-3.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3aa-3.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'} +} {1 5 9 13 17 21 25 29} +do_test fts3aa-3.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'} +} {1 5 9 13 17 21 25 29} + +do_test fts3aa-4.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one OR two'} +} {1 2 3 5 6 7 9 10 11 13 14 15 17 18 19 21 22 23 25 26 27 29 30 31} +do_test fts3aa-4.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two" OR three'} +} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} +do_test fts3aa-4.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR "one two"'} +} {3 4 5 6 7 11 12 13 14 15 19 20 21 22 23 27 28 29 30 31} +do_test fts3aa-4.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three'} +} {3 5 7 11 13 15 19 21 23 27 29 31} +do_test fts3aa-4.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three OR two one'} +} {3 5 7 11 13 15 19 21 23 27 29 31} +do_test fts3aa-4.6 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two OR three OR four'} +} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} +do_test fts3aa-4.7 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two OR three OR four one'} +} {3 5 7 9 11 13 15 19 21 23 25 27 29 31} + +# Test the ability to handle NULL content +# +do_test fts3aa-5.1 { + execsql {INSERT INTO t1(content) VALUES(NULL)} +} {} +do_test fts3aa-5.2 { + set rowid [db last_insert_rowid] + execsql {SELECT content FROM t1 WHERE rowid=$rowid} +} {{}} +do_test fts3aa-5.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH NULL} +} {} + +# Test the ability to handle non-positive rowids +# +do_test fts3aa-6.0 { + execsql {INSERT INTO t1(rowid, content) VALUES(0, 'four five')} +} {} +do_test fts3aa-6.1 { + execsql {SELECT content FROM t1 WHERE rowid = 0} +} {{four five}} +do_test fts3aa-6.2 { + execsql {INSERT INTO t1(rowid, content) VALUES(-1, 'three four')} +} {} +do_test fts3aa-6.3 { + execsql {SELECT content FROM t1 WHERE rowid = -1} +} {{three four}} +do_test fts3aa-6.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'four'} +} {-1 0 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31} + +# Test creation of FTS3 and FTS4 tables with columns that contain +# an "=" character. +# +do_execsql_test fts3aa-7.1 { + CREATE VIRTUAL TABLE t2 USING fts3(xyz=abc); + SELECT xyz FROM t2; +} {} +do_catchsql_test fts3aa-7.2 { + CREATE VIRTUAL TABLE t3 USING fts4(xyz=abc); +} {1 {unrecognized parameter: xyz=abc}} +do_catchsql_test fts3aa-7.3 { + CREATE VIRTUAL TABLE t3 USING fts4(xyz = abc); +} {1 {unrecognized parameter: xyz = abc}} + +do_execsql_test fts3aa-7.4 { + CREATE VIRTUAL TABLE t3 USING fts3(tokenize=simple, tokenize=simple); + SELECT tokenize FROM t3; +} {} +do_catchsql_test fts3aa-7.5 { + CREATE VIRTUAL TABLE t4 USING fts4(tokenize=simple, tokenize=simple); +} {1 {unrecognized parameter: tokenize=simple}} + +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t0 USING fts4(order=desc); + BEGIN; + INSERT INTO t0(rowid, content) VALUES(1, 'abc'); + UPDATE t0 SET docid=5 WHERE docid=1; + INSERT INTO t0(rowid, content) VALUES(6, 'abc'); +} +do_execsql_test 8.1 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.2 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} +do_execsql_test 8.3 { COMMIT } +do_execsql_test 8.4 { + SELECT docid FROM t0 WHERE t0 MATCH 'abc'; +} {6 5} +do_execsql_test 8.5 { + SELECT docid FROM t0 WHERE t0 MATCH '"abc abc"'; +} {} + +do_execsql_test 9.1 { + CREATE VIRTUAL TABLE t9 USING fts4(a, "", '---'); +} +do_execsql_test 9.2 { + CREATE VIRTUAL TABLE t10 USING fts3(<, b, c); +} + +do_execsql_test 10.0 { + CREATE VIRTUAL TABLE z1 USING fts3; + INSERT INTO z1 VALUES('one two three'),('four one five'),('six two five'); + CREATE TRIGGER z1r1 AFTER DELETE ON z1_content BEGIN + DELETE FROM z1; + END; +} +do_catchsql_test 10.1 { + DELETE FROM z1; +} {1 {SQL logic error}} + +expand_all_sql db +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ab.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ab.test new file mode 100644 index 0000000000000000000000000000000000000000..86124f78c4b44dac97d19106546321e47b4c3d27 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ab.test @@ -0,0 +1,147 @@ +# 2006 September 13 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3ab.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Fill the full-text index "t1" with phrases in english, spanish, +# and german. For the i-th row, fill in the names for the bits +# that are set in the value of i. The least significant bit is +# 1. For example, the value 5 is 101 in binary which will be +# converted to "one three" in english. +# +proc fill_multilanguage_fulltext_t1 {} { + set english {one two three four five} + set spanish {un dos tres cuatro cinco} + set german {eine zwei drei vier funf} + + for {set i 1} {$i<=31} {incr i} { + set cmd "INSERT INTO t1 VALUES" + set vset {} + foreach lang {english spanish german} { + set words {} + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { + if {$k&$i} {lappend words [lindex [set $lang] $j]} + } + lappend vset "'$words'" + } + set sql "INSERT INTO t1(english,spanish,german) VALUES([join $vset ,])" + # puts $sql + db eval $sql + } +} + +# Construct a full-text search table containing five keywords: +# one, two, three, four, and five, in various combinations. The +# rowid for each will be a bitmask for the elements it contains. +# +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(english,spanish,german); +} +fill_multilanguage_fulltext_t1 + +do_test fts3ab-1.1 { + execsql {SELECT rowid FROM t1 WHERE english MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3ab-1.2 { + execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'} +} {} +do_test fts3ab-1.3 { + execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'} +} {} +do_test fts3ab-1.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one'} +} {1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31} +do_test fts3ab-1.5 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one dos drei'} +} {7 15 23 31} +do_test fts3ab-1.6 { + execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1} +} {one un eine} +do_test fts3ab-1.7 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"one un"'} +} {} + +do_test fts3ab-2.1 { + execsql { + CREATE VIRTUAL TABLE t2 USING fts3(from,to); + INSERT INTO t2([from],[to]) VALUES ('one two three', 'four five six'); + SELECT [from], [to] FROM t2 + } +} {{one two three} {four five six}} + + +# Compute an SQL string that contains the words one, two, three,... to +# describe bits set in the value $i. Only the lower 5 bits are examined. +# +proc wordset {i} { + set x {} + for {set j 0; set k 1} {$j<5} {incr j; incr k $k} { + if {$k&$i} {lappend x [lindex {one two three four five} $j]} + } + return '$x' +} + +# Create a new FTS table with three columns: +# +# norm: words for the bits of rowid +# plusone: words for the bits of rowid+1 +# invert: words for the bits of ~rowid +# +db eval { + CREATE VIRTUAL TABLE t4 USING fts3([norm],'plusone',"invert"); +} +for {set i 1} {$i<=15} {incr i} { + set vset [list [wordset $i] [wordset [expr {$i+1}]] [wordset [expr {~$i}]]] + db eval "INSERT INTO t4(norm,plusone,invert) VALUES([join $vset ,]);" +} + +do_test fts3ab-4.1 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.2 { + execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.3 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'one'} +} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15} +do_test fts3ab-4.4 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:one'} +} {2 4 6 8 10 12 14} +do_test fts3ab-4.5 { + execsql {SELECT rowid FROM t4 WHERE plusone MATCH 'one'} +} {2 4 6 8 10 12 14} +do_test fts3ab-4.6 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one plusone:two'} +} {1 5 9 13} +do_test fts3ab-4.7 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one two'} +} {1 3 5 7 9 11 13 15} +do_test fts3ab-4.8 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:two norm:one'} +} {1 5 9 13} +do_test fts3ab-4.9 { + execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'two norm:one'} +} {1 3 5 7 9 11 13 15} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ac.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ac.test new file mode 100644 index 0000000000000000000000000000000000000000..84da924b6e8aee8613e17c842ffd1b68646f1ceb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ac.test @@ -0,0 +1,1219 @@ +# 2006 September 14 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3ac.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create a table of sample email data. The data comes from email +# archives of Enron executives that was published as part of the +# litigation against that company. +# +do_test fts3ac-1.1 { + db eval { + CREATE VIRTUAL TABLE email USING fts3([from],[to],subject,body); + BEGIN TRANSACTION; +INSERT INTO email([from],[to],subject,body) VALUES('savita.puthigai@enron.com', 'traders.eol@enron.com, traders.eol@enron.com', 'EnronOnline- Change to Autohedge', 'Effective Monday, October 22, 2001 the following changes will be made to the Autohedge functionality on EnronOnline. + +The volume on the hedge will now respect the minimum volume and volume increment settings on the parent product. See rules below: + +? If the transaction volume on the child is less than half of the parent''s minimum volume no hedge will occur. +? If the transaction volume on the child is more than half the parent''s minimum volume but less than half the volume increment on the parent, the hedge will volume will be the parent''s minimum volume. +? For all other volumes, the same rounding rules will apply based on the volume increment on the parent product. + +Please see example below: + +Parent''s Settings: +Minimum: 5000 +Increment: 1000 + +Volume on Autohedge transaction Volume Hedged +1 - 2499 0 +2500 - 5499 5000 +5500 - 6499 6000'); +INSERT INTO email([from],[to],subject,body) VALUES('dana.davis@enron.com', 'laynie.east@enron.com, lisa.king@enron.com, lisa.best@enron.com,', 'Leaving Early', 'FYI: +If it''s ok with everyone''s needs, I would like to leave @4pm. If you think +you will need my assistance past the 4 o''clock hour just let me know; I''ll +be more than willing to stay.'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'louise.kitchen@enron.com', '<> - CC02.06.02', 'The following expense report is ready for approval: + +Employee Name: Christopher F. Calger +Status last changed by: Mollie E. Gustafson Ms +Expense Report Name: CC02.06.02 +Report Total: $3,972.93 +Amount Due Employee: $3,972.93 + + +To approve this expense report, click on the following link for Concur Expense. +http://expensexms.enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('jeff.duff@enron.com', 'julie.johnson@enron.com', 'Work request', 'Julie, + +Could you print off the current work request report by 1:30 today? + +Gentlemen, + +I''d like to review this today at 1:30 in our office. Also, could you provide +me with your activity reports so I can have Julie enter this information. + +JD'); +INSERT INTO email([from],[to],subject,body) VALUES('v.weldon@enron.com', 'gary.l.carrier@usa.dupont.com, scott.joyce@bankofamerica.com', 'Enron News', 'This could turn into something big.... +http://biz.yahoo.com/rf/010129/n29305829.html'); +INSERT INTO email([from],[to],subject,body) VALUES('mark.haedicke@enron.com', 'paul.simons@enron.com', 'Re: First Polish Deal!', 'Congrats! Things seem to be building rapidly now on the Continent. Mark'); +INSERT INTO email([from],[to],subject,body) VALUES('e..carter@enron.com', 't..robinson@enron.com', 'FW: Producers Newsletter 9-24-2001', ' +The producer lumber pricing sheet. + -----Original Message----- +From: Johnson, Jay +Sent: Tuesday, October 16, 2001 3:42 PM +To: Carter, Karen E. +Subject: FW: Producers Newsletter 9-24-2001 + + + + -----Original Message----- +From: Daigre, Sergai +Sent: Friday, September 21, 2001 8:33 PM +Subject: Producers Newsletter 9-24-2001 + + '); +INSERT INTO email([from],[to],subject,body) VALUES('david.delainey@enron.com', 'kenneth.lay@enron.com', 'Greater Houston Partnership', 'Ken, in response to the letter from Mr Miguel San Juan, my suggestion would +be to offer up the Falcon for their use; however, given the tight time frame +and your recent visit with Mr. Fox that it would be difficult for either you +or me to participate. + +I spoke to Max and he agrees with this approach. + +I hope this meets with your approval. + +Regards +Delainey'); +INSERT INTO email([from],[to],subject,body) VALUES('lachandra.fenceroy@enron.com', 'lindy.donoho@enron.com', 'FW: Bus Applications Meeting Follow Up', 'Lindy, + +Here is the original memo we discussed earlier. Please provide any information that you may have. + +Your cooperation is greatly appreciated. + +Thanks, + +lachandra.fenceroy@enron.com +713.853.3884 +877.498.3401 Pager + + -----Original Message----- +From: Bisbee, Joanne +Sent: Wednesday, September 26, 2001 7:50 AM +To: Fenceroy, LaChandra +Subject: FW: Bus Applications Meeting Follow Up + +Lachandra, Please get with David Duff today and see what this is about. Who are our TW accounting business users? + + -----Original Message----- +From: Koh, Wendy +Sent: Tuesday, September 25, 2001 2:41 PM +To: Bisbee, Joanne +Subject: Bus Applications Meeting Follow Up + +Lisa brought up a TW change effective Nov 1. It involves eliminating a turnback surcharge. I have no other information, but you might check with the business folks for any system changes required. + +Wendy'); +INSERT INTO email([from],[to],subject,body) VALUES('danny.mccarty@enron.com', 'fran.fagan@enron.com', 'RE: worksheets', 'Fran, + If Julie''s merit needs to be lump sum, just move it over to that column. Also, send me Eric Gadd''s sheets as well. Thanks. +Dan + + -----Original Message----- +From: Fagan, Fran +Sent: Thursday, December 20, 2001 11:10 AM +To: McCarty, Danny +Subject: worksheets + +As discussed, attached are your sheets for bonus and merit. + +Thanks, + +Fran Fagan +Sr. HR Rep +713.853.5219 + + + << File: McCartyMerit.xls >> << File: mccartyBonusCommercial_UnP.xls >> + +'); +INSERT INTO email([from],[to],subject,body) VALUES('bert.meyers@enron.com', 'shift.dl-portland@enron.com', 'OCTOBER SCHEDULE', 'TEAM, + +PLEASE SEND ME ANY REQUESTS THAT YOU HAVE FOR OCTOBER. SO FAR I HAVE THEM FOR LEAF. I WOULD LIKE TO HAVE IT DONE BY THE 15TH OF THE MONTH. ANY QUESTIONS PLEASE GIVE ME A CALL. + +BERT'); +INSERT INTO email([from],[to],subject,body) VALUES('errol.mclaughlin@enron.com', 'john.arnold@enron.com, bilal.bajwa@enron.com, john.griffith@enron.com,', 'TRV Notification: (NG - PROPT P/L - 09/27/2001)', 'The report named: NG - PROPT P/L , published as of 09/27/2001 is now available for viewing on the website.'); +INSERT INTO email([from],[to],subject,body) VALUES('patrice.mims@enron.com', 'calvin.eakins@enron.com', 'Re: Small business supply assistance', 'Hi Calvin + + +I spoke with Rickey (boy, is he long-winded!!). Gave him the name of our +credit guy, Russell Diamond. + +Thank for your help!'); +INSERT INTO email([from],[to],subject,body) VALUES('legal <.hall@enron.com>', 'stephanie.panus@enron.com', 'Termination update', 'City of Vernon and Salt River Project terminated their contracts. I will fax these notices to you.'); +INSERT INTO email([from],[to],subject,body) VALUES('d..steffes@enron.com', 'richard.shapiro@enron.com', 'EES / ENA Government Affairs Staffing & Outside Services', 'Rick -- + +Here is the information on staffing and outside services. Call if you need anything else. + +Jim + + '); +INSERT INTO email([from],[to],subject,body) VALUES('gelliott@industrialinfo.com', 'pcopello@industrialinfo.com', 'ECAAR (Gavin), WSCC (Diablo Canyon), & NPCC (Seabrook)', 'Dear Power Outage Database Customer, +Attached you will find an excel document. The outages contained within are forced or rescheduled outages. Your daily delivery will still contain these outages. +In addition to the two excel documents, there is a dbf file that is formatted like your daily deliveries you receive nightly. This will enable you to load the data into your regular database. Any questions please let me know. Thanks. +Greg Elliott +IIR, Inc. +713-783-5147 x 3481 +outages@industrialinfo.com +THE INFORMATION CONTAINED IN THIS E-MAIL IS LEGALLY PRIVILEGED AND CONFIDENTIAL INFORMATION INTENDED ONLY FOR THE USE OF THE INDIVIDUAL OR ENTITY NAMED ABOVE. YOU ARE HEREBY NOTIFIED THAT ANY DISSEMINATION, DISTRIBUTION, OR COPY OF THIS E-MAIL TO UNAUTHORIZED ENTITIES IS STRICTLY PROHIBITED. IF YOU HAVE RECEIVED THIS +E-MAIL IN ERROR, PLEASE DELETE IT. + - OUTAGE.dbf + - 111201R.xls + - 111201.xls '); +INSERT INTO email([from],[to],subject,body) VALUES('enron.announcements@enron.com', 'all_ena_egm_eim@enron.com', 'EWS Brown Bag', 'MARK YOUR LUNCH CALENDARS NOW ! + +You are invited to attend the EWS Brown Bag Lunch Series + +Featuring: RAY BOWEN, COO + +Topic: Enron Industrial Markets + +Thursday, March 15, 2001 +11:30 am - 12:30 pm +EB 5 C2 + + +You bring your lunch, Limited Seating +We provide drinks and dessert. RSVP x 3-9610'); +INSERT INTO email([from],[to],subject,body) VALUES('chris.germany@enron.com', 'ingrid.immer@williams.com', 'Re: About St Pauls', 'Sounds good to me. I bet this is next to the Warick?? Hotel. + + + + +"Immer, Ingrid" on 12/21/2000 11:48:47 AM +To: "''chris.germany@enron.com''" +cc: +Subject: About St Pauls + + + + + <> +? +?http://www.stpaulshouston.org/about.html + +Chris, + +I like the looks of this place.? What do you think about going here Christmas +eve?? They have an 11:00 a.m. service and a candlelight service at 5:00 p.m., +among others. + +Let me know.?? ii + + - About St Pauls.url + +'); +INSERT INTO email([from],[to],subject,body) VALUES('nas@cpuc.ca.gov', 'skatz@sempratrading.com, kmccrea@sablaw.com, thompson@wrightlaw.com,', 'Reply Brief filed July 31, 2000', ' - CPUC01-#76371-v1-Revised_Reply_Brief__Due_today_7_31_.doc'); +INSERT INTO email([from],[to],subject,body) VALUES('gascontrol@aglresources.com', 'dscott4@enron.com, lcampbel@enron.com', 'Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder', 'Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder +As discussed in the Winter Operations Meeting on Sept.29,2000, +E-Gas(Emergency Gas) will not be offered this winter as a service from AGLC. +Marketers and Poolers can receive gas via Peaking and IBSS nominations(daisy +chain) from other marketers up to the 6 p.m. Same Day 2 nomination cycle. +'); +INSERT INTO email([from],[to],subject,body) VALUES('dutch.quigley@enron.com', 'rwolkwitz@powermerchants.com', '', ' + +Here is a goody for you'); +INSERT INTO email([from],[to],subject,body) VALUES('ryan.o''rourke@enron.com', 'k..allen@enron.com, randy.bhatia@enron.com, frank.ermis@enron.com,', 'TRV Notification: (West VaR - 11/07/2001)', 'The report named: West VaR , published as of 11/07/2001 is now available for viewing on the website.'); +INSERT INTO email([from],[to],subject,body) VALUES('mjones7@txu.com', 'cstone1@txu.com, ggreen2@txu.com, timpowell@txu.com,', 'Enron / HPL Actuals for July 10, 2000', 'Teco Tap 10.000 / Enron ; 110.000 / HPL IFERC + +LS HPL LSK IC 30.000 / Enron +'); +INSERT INTO email([from],[to],subject,body) VALUES('susan.pereira@enron.com', 'kkw816@aol.com', 'soccer practice', 'Kathy- + +Is it safe to assume that practice is cancelled for tonight?? + +Susan Pereira'); +INSERT INTO email([from],[to],subject,body) VALUES('mark.whitt@enron.com', 'barry.tycholiz@enron.com', 'Huber Internal Memo', 'Please look at this. I didn''t know how deep to go with the desk. Do you think this works. + + '); +INSERT INTO email([from],[to],subject,body) VALUES('m..forney@enron.com', 'george.phillips@enron.com', '', 'George, +Give me a call and we will further discuss opportunities on the 13st floor. + +Thanks, +JMForney +3-7160'); +INSERT INTO email([from],[to],subject,body) VALUES('brad.mckay@enron.com', 'angusmcka@aol.com', 'Re: (no subject)', 'not yet'); +INSERT INTO email([from],[to],subject,body) VALUES('adam.bayer@enron.com', 'jonathan.mckay@enron.com', 'FW: Curve Fetch File', 'Here is the curve fetch file sent to me. It has plenty of points in it. If you give me a list of which ones you need we may be able to construct a secondary worksheet to vlookup the values. + +adam +35227 + + + -----Original Message----- +From: Royed, Jeff +Sent: Tuesday, September 25, 2001 11:37 AM +To: Bayer, Adam +Subject: Curve Fetch File + +Let me know if it works. It may be required to have a certain version of Oracle for it to work properly. + + + +Jeff Royed +Enron +Energy Operations +Phone: 713-853-5295'); +INSERT INTO email([from],[to],subject,body) VALUES('matt.smith@enron.com', 'yan.wang@enron.com', 'Report Formats', 'Yan, + +The merged reports look great. I believe the only orientation changes are to +"unmerge" the following six reports: + +31 Keystone Receipts +15 Questar Pipeline +40 Rockies Production +22 West_2 +23 West_3 +25 CIG_WIC + +The orientation of the individual reports should be correct. Thanks. + +Mat + +PS. Just a reminder to add the "*" by the title of calculated points.'); +INSERT INTO email([from],[to],subject,body) VALUES('michelle.lokay@enron.com', 'jimboman@bigfoot.com', 'Egyptian Festival', '---------------------- Forwarded by Michelle Lokay/ET&S/Enron on 09/07/2000 +10:08 AM --------------------------- + + +"Karkour, Randa" on 09/07/2000 09:01:04 AM +To: "''Agheb (E-mail)" , "Leila Mankarious (E-mail)" +, "''Marymankarious (E-mail)" +, "Michelle lokay (E-mail)" , "Ramy +Mankarious (E-mail)" +cc: + +Subject: Egyptian Festival + + + <> + + http://www.egyptianfestival.com/ + + - Egyptian Festival.url +'); +INSERT INTO email([from],[to],subject,body) VALUES('errol.mclaughlin@enron.com', 'sherry.dawson@enron.com', 'Urgent!!! --- New EAST books', 'This has to be done.................................. + +Thanks +---------------------- Forwarded by Errol McLaughlin/Corp/Enron on 12/20/2000 +08:39 AM --------------------------- + + + + From: William Kelly @ ECT 12/20/2000 08:31 AM + + +To: Kam Keiser/HOU/ECT@ECT, Darron C Giron/HOU/ECT@ECT, David +Baumbach/HOU/ECT@ECT, Errol McLaughlin/Corp/Enron@ENRON +cc: Kimat Singla/HOU/ECT@ECT, Kulvinder Fowler/NA/Enron@ENRON, Kyle R +Lilly/HOU/ECT@ECT, Jeff Royed/Corp/Enron@ENRON, Alejandra +Chavez/NA/Enron@ENRON, Crystal Hyde/HOU/ECT@ECT + +Subject: New EAST books + +We have new book names in TAGG for our intramonth portfolios and it is +extremely important that any deal booked to the East is communicated quickly +to someone on my team. I know it will take some time for the new names to +sink in and I do not want us to miss any positions or P&L. + +Thanks for your help on this. + +New: +Scott Neal : East Northeast +Dick Jenkins: East Marketeast + +WK +'); +INSERT INTO email([from],[to],subject,body) VALUES('david.forster@enron.com', 'eol.wide@enron.com', 'Change to Stack Manager', 'Effective immediately, there is a change to the Stack Manager which will +affect any Inactive Child. + +An inactive Child with links to Parent products will not have their +calculated prices updated until the Child product is Activated. + +When the Child Product is activated, the price will be recalculated and +updated BEFORE it is displayed on the web. + +This means that if you are inputting a basis price on a Child product, you +will not see the final, calculated price until you Activate the product, at +which time the customer will also see it. + +If you have any questions, please contact the Help Desk on: + +Americas: 713 853 4357 +Europe: + 44 (0) 20 7783 7783 +Asia/Australia: +61 2 9229 2300 + +Dave'); +INSERT INTO email([from],[to],subject,body) VALUES('vince.kaminski@enron.com', 'jhh1@email.msn.com', 'Re: Light reading - see pieces beginning on page 7', 'John, + +I saw it. Very interesting. + +Vince + + + + + +"John H Herbert" on 07/28/2000 08:38:08 AM +To: "Vince J Kaminski" +cc: +Subject: Light reading - see pieces beginning on page 7 + + +Cheers and have a nice weekend, + + +JHHerbert + + + + + - gd000728.pdf + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('matthew.lenhart@enron.com', 'mmmarcantel@equiva.com', 'RE:', 'i will try to line up a pig for you '); +INSERT INTO email([from],[to],subject,body) VALUES('jae.black@enron.com', 'claudette.harvey@enron.com, chaun.roberts@enron.com, judy.martinez@enron.com,', 'Disaster Recovery Equipment', 'As a reminder...there are several pieces of equipment that are set up on the 30th Floor, as well as on our floor, for the Disaster Recovery Team. PLEASE DO NOT TAKE, BORROW OR USE this equipment. Should you need to use another computer system, other than yours, or make conference calls please work with your Assistant to help find or set up equipment for you to use. + +Thanks for your understanding in this matter. + +T.Jae Black +East Power Trading +Assistant to Kevin Presto +off. 713-853-5800 +fax 713-646-8272 +cell 713-539-4760'); +INSERT INTO email([from],[to],subject,body) VALUES('eric.bass@enron.com', 'dale.neuner@enron.com', '5 X 24', 'Dale, + +Have you heard anything more on the 5 X 24s? We would like to get this +product out ASAP. + + +Thanks, + +Eric'); +INSERT INTO email([from],[to],subject,body) VALUES('messenger@smartreminders.com', 'm..tholt@enron.com', '10% Coupon - PrintPal Printer Cartridges - 100% Guaranteed', '[IMAGE] +[IMAGE][IMAGE][IMAGE] +Dear SmartReminders Member, + [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] [IMAGE] + + + + + + + + + + + + + + + + + + + + + +We respect your privacy and are a Certified Participant of the BBBOnLine + Privacy Program. To be removed from future offers,click here. +SmartReminders.com is a permission based service. To unsubscribe click here . '); +INSERT INTO email([from],[to],subject,body) VALUES('benjamin.rogers@enron.com', 'mark.bernstein@enron.com', '', 'The guy you are talking about left CIN under a "cloud of suspicion" sort of +speak. He was the one who got into several bad deals and PPA''s in California +for CIN, thus he left on a bad note. Let me know if you need more detail +than that, I felt this was the type of info you were looking for. Thanks! +Ben'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'michelle.cash@enron.com', 'Expense Report Receipts Not Received', 'Employee Name: Michelle Cash +Report Name: Houston Cellular 8-11-01 +Report Date: 12/13/01 +Report ID: 594D37C9ED2111D5B452 +Submitted On: 12/13/01 + +You are only allowed 2 reports with receipts outstanding. Your expense reports will not be paid until you meet this requirement.'); +INSERT INTO email([from],[to],subject,body) VALUES('susan.mara@enron.com', 'ray.alvarez@enron.com, mark.palmer@enron.com, karen.denne@enron.com,', 'CAISO Emergency Motion -- to discontinue market-based rates for', 'FYI. the latest broadside against the generators. + +Sue Mara +Enron Corp. +Tel: (415) 782-7802 +Fax:(415) 782-7854 +----- Forwarded by Susan J Mara/NA/Enron on 06/08/2001 12:24 PM ----- + + + "Milner, Marcie" 06/08/2001 11:13 AM To: "''smara@enron.com''" cc: Subject: CAISO Emergency Motion + + +Sue, did you see this emergency motion the CAISO filed today? Apparently +they are requesting that FERC discontinue market-based rates immediately and +grant refunds plus interest on the difference between cost-based rates and +market revenues received back to May 2000. They are requesting the +commission act within 14 days. Have you heard anything about what they are +doing? + +Marcie + +http://www.caiso.com/docs/2001/06/08/200106081005526469.pdf +'); +INSERT INTO email([from],[to],subject,body) VALUES('fletcher.sturm@enron.com', 'eloy.escobar@enron.com', 'Re: General Brinks Position Meeting', 'Eloy, + +Who is General Brinks? + +Fletch'); +INSERT INTO email([from],[to],subject,body) VALUES('nailia.dindarova@enron.com', 'richard.shapiro@enron.com', 'Documents for Mark Frevert (on EU developments and lessons from', 'Rick, + +Here are the documents that Peter has prepared for Mark Frevert. + +Nailia +---------------------- Forwarded by Nailia Dindarova/LON/ECT on 25/06/2001 +16:36 --------------------------- + + +Nailia Dindarova +25/06/2001 15:36 +To: Michael Brown/Enron@EUEnronXGate +cc: Ross Sankey/Enron@EUEnronXGate, Eric Shaw/ENRON@EUEnronXGate, Peter +Styles/LON/ECT@ECT + +Subject: Documents for Mark Frevert (on EU developments and lessons from +California) + +Michael, + + +These are the documents that Peter promised to give to you for Mark Frevert. +He has now handed them to him in person but asked me to transmit them +electronically to you, as well as Eric and Ross. + +Nailia + + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('peggy.a.kostial@accenture.com', 'dave.samuels@enron.com', 'EOL-Accenture Deal Sheet', 'Dave - + +Attached are our comments and suggested changes. Please call to review. + +On the time line for completion, we have four critical steps to complete: + Finalize market analysis to refine business case, specifically + projected revenue stream + Complete counterparty surveying, including targeting 3 CPs for letters + of intent + Review Enron asset base for potential reuse/ licensing + Contract negotiations + +Joe will come back to us with an updated time line, but it is my +expectation that we are still on the same schedule (we just begun week +three) with possibly a week or so slippage.....contract negotiations will +probably be the critical path. + +We will send our cut at the actual time line here shortly. Thanks, + +Peggy + +(See attached file: accenture-dealpoints v2.doc) + - accenture-dealpoints v2.doc '); +INSERT INTO email([from],[to],subject,body) VALUES('thomas.martin@enron.com', 'thomas.martin@enron.com', 'Re: Guadalupe Power Partners LP', '---------------------- Forwarded by Thomas A Martin/HOU/ECT on 03/20/2001 +03:49 PM --------------------------- + + +Thomas A Martin +10/11/2000 03:55 PM +To: Patrick Wade/HOU/ECT@ECT +cc: +Subject: Re: Guadalupe Power Partners LP + +The deal is physically served at Oasis Waha or Oasis Katy and is priced at +either HSC, Waha or Katytailgate GD at buyers option three days prior to +NYMEX close. + +'); +INSERT INTO email([from],[to],subject,body) VALUES('judy.townsend@enron.com', 'dan.junek@enron.com, chris.germany@enron.com', 'Columbia Distribution''s Capacity Available for Release - Sum', '---------------------- Forwarded by Judy Townsend/HOU/ECT on 03/09/2001 11:04 +AM --------------------------- + + +agoddard@nisource.com on 03/08/2001 09:16:57 AM +To: " - *Koch, Kent" , " - +*Millar, Debra" , " - *Burke, Lynn" + +cc: " - *Heckathorn, Tom" +Subject: Columbia Distribution''s Capacity Available for Release - Sum + + +Attached is Columbia Distribution''s notice of capacity available for release +for +the summer of 2001 (Apr. 2001 through Oct. 2001). + +Please note that the deadline for bids is 3:00pm EST on March 20, 2001. + +If you have any questions, feel free to contact any of the representatives +listed +at the bottom of the attachment. + +Aaron Goddard + + + + + - 2001Summer.doc +'); +INSERT INTO email([from],[to],subject,body) VALUES('rhonda.denton@enron.com', 'tim.belden@enron.com, dana.davis@enron.com, genia.fitzgerald@enron.com,', 'Split Rock Energy LLC', 'We have received the executed EEI contract from this CP dated 12/12/2000. +Copies will be distributed to Legal and Credit.'); +INSERT INTO email([from],[to],subject,body) VALUES('kerrymcelroy@dwt.com', 'jack.speer@alcoa.com, crow@millernash.com, michaelearly@earthlink.net,', 'Oral Argument Request', ' - Oral Argument Request.doc'); +INSERT INTO email([from],[to],subject,body) VALUES('mike.carson@enron.com', 'rlmichaelis@hormel.com', '', 'Did you come in town this wk end..... My new number at our house is : +713-668-3712...... my cell # is 281-381-7332 + +the kid'); +INSERT INTO email([from],[to],subject,body) VALUES('cooper.richey@enron.com', 'trycooper@hotmail.com', 'FW: Contact Info', ' + +-----Original Message----- +From: Punja, Karim +Sent: Thursday, December 13, 2001 2:35 PM +To: Richey, Cooper +Subject: Contact Info + + +Cooper, + +Its been a real pleasure working with you (even though it was for only a small amount of time) +I hope we can stay in touch. + +Home# 234-0249 +email: kpunja@hotmail.com + +Take Care, + +Karim. + '); +INSERT INTO email([from],[to],subject,body) VALUES('bjm30@earthlink.net', 'mcguinn.k@enron.com, mcguinn.ian@enron.com, mcguinn.stephen@enron.com,', 'email address change', 'Hello all. + +I haven''t talked to many of you via email recently but I do want to give you +my new address for your email file: + + bjm30@earthlink.net + +I hope all is well. + +Brian McGuinn'); +INSERT INTO email([from],[to],subject,body) VALUES('shelley.corman@enron.com', 'steve.hotte@enron.com', 'Flat Panels', 'Can you please advise what is going on with the flat panels that we had planned to distribute to our gas logistics team. It was in the budget and we had the okay, but now I''m hearing there is some hold-up & the units are stored on 44. + +Shelley'); +INSERT INTO email([from],[to],subject,body) VALUES('sara.davidson@enron.com', 'john.schwartzenburg@enron.com, scott.dieball@enron.com, recipients@enron.com,', '2001 Enron Law Conference (Distribution List 2)', ' Enron Law Conference + +San Antonio, Texas May 2-4, 2001 Westin Riverwalk + + See attached memo for more details!! + + +? Registration for the law conference this year will be handled through an +Online RSVP Form on the Enron Law Conference Website at +http://lawconference.corp.enron.com. The website is still under construction +and will not be available until Thursday, March 15, 2001. + +? We will send you another e-mail to confirm when the Law Conference Website +is operational. + +? Please complete the Online RSVP Form as soon as it is available and submit +it no later than Friday, March 30th. + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('tori.kuykendall@enron.com', 'heath.b.taylor@accenture.com', 'Re:', 'hey - thats funny about john - he definitely remembers him - i''ll call pat +and let him know - we are coming on saturday - i just havent had a chance to +call you guys back -- looking forward to it -- i probably need the +directions again though'); +INSERT INTO email([from],[to],subject,body) VALUES('darron.giron@enron.com', 'bryce.baxter@enron.com', 'Re: Feedback for Audrey Cook', 'Bryce, + +I''ll get it done today. + +DG 3-9573 + + + + + + From: Bryce Baxter 06/12/2000 07:15 PM + + +To: Darron C Giron/HOU/ECT@ECT +cc: +Subject: Feedback for Audrey Cook + +You were identified as a reviewer for Audrey Cook. If possible, could you +complete her feedback by end of business Wednesday? It will really help me +in the PRC process to have your input. Thanks. + +'); +INSERT INTO email([from],[to],subject,body) VALUES('casey.evans@enron.com', 'stephanie.sever@enron.com', 'Gas EOL ID', 'Stephanie, + +In conjunction with the recent movement of several power traders, they are changing the names of their gas books as well. The names of the new gas books and traders are as follows: + +PWR-NG-LT-SPP: Mike Carson +PWR-NG-LT-SERC: Jeff King + +If you need to know their power desk to map their ID to their gas books, those desks are as follows: + +EPMI-LT-SPP: Mike Carson +EPMI-LT-SERC: Jeff King + +I will be in training this afternoon, but will be back when class is over. Let me know if you have any questions. + +Thanks for your help! +Casey'); +INSERT INTO email([from],[to],subject,body) VALUES('darrell.schoolcraft@enron.com', 'david.roensch@enron.com, kimberly.watson@enron.com, michelle.lokay@enron.com,', 'Postings', 'Please see the attached. + + +ds + + + + + '); +INSERT INTO email([from],[to],subject,body) VALUES('mcominsky@aol.com', 'cpatman@bracepatt.com, james_derrick@enron.com', 'Jurisprudence Luncheon', 'Carrin & Jim -- + +It was an honor and a pleasure to meet both of you yesterday. I know we will +have fun working together on this very special event. + +Jeff left the jurisprudence luncheon lists for me before he left on vacation. + I wasn''t sure whether he transmitted them to you as well. Would you please +advise me if you would like them sent to you? I can email the MS Excel files +or I can fax the hard copies to you. Please advise what is most convenient. + +I plan to be in town through the holidays and can be reached by phone, email, +or cell phone at any time. My cell phone number is 713/705-4829. + +Thanks again for your interest in the ADL''s work. Martin. + +Martin B. Cominsky +Director, Southwest Region +Anti-Defamation League +713/627-3490, ext. 122 +713/627-2011 (fax) +MCominsky@aol.com'); +INSERT INTO email([from],[to],subject,body) VALUES('phillip.love@enron.com', 'todagost@utmb.edu, gbsonnta@utmb.edu', 'New President', 'I had a little bird put a word in my ear. Is there any possibility for Ben +Raimer to be Bush''s secretary of HHS? Just curious about that infamous UTMB +rumor mill. Hope things are well, happy holidays. +PL'); +INSERT INTO email([from],[to],subject,body) VALUES('marie.heard@enron.com', 'ehamilton@fna.com', 'ISDA Master Agreement', 'Erin: + +Pursuant to your request, attached are the Schedule to the ISDA Master Agreement, together with Paragraph 13 to the ISDA Credit Support Annex. Please let me know if you need anything else. We look forward to hearing your comments. + +Marie + +Marie Heard +Senior Legal Specialist +Enron North America Corp. +Phone: (713) 853-3907 +Fax: (713) 646-3490 +marie.heard@enron.com + + '); +INSERT INTO email([from],[to],subject,body) VALUES('andrea.ring@enron.com', 'beverly.beaty@enron.com', 'Re: Tennessee Buy - Louis Dreyfus', 'Beverly - once again thanks so much for your help on this. + + + + '); +INSERT INTO email([from],[to],subject,body) VALUES('karolyn.criado@enron.com', 'j..bonin@enron.com, felicia.case@enron.com, b..clapp@enron.com,', 'Price List week of Oct. 8-9, 2001', ' +Please contact me if you have any questions regarding last weeks prices. + +Thank you, +Karolyn Criado +3-9441 + + + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('kevin.presto@enron.com', 'edward.baughman@enron.com, billy.braddock@enron.com', 'Associated', 'Please begin working on filling our Associated short position in 02. I would like to take this risk off the books. + +In addition, please find out what a buy-out of VEPCO would cost us. With Rogers transitioning to run our retail risk management, I would like to clean up our customer positions. + +We also need to continue to explore a JEA buy-out. + +Thanks.'); +INSERT INTO email([from],[to],subject,body) VALUES('stacy.dickson@enron.com', 'gregg.penman@enron.com', 'RE: Constellation TC 5-7-01', 'Gregg, + +I am at home with a sick baby. (Lots of fun!) I will call you about this +tomorrow. + +Stacy'); +INSERT INTO email([from],[to],subject,body) VALUES('joe.quenet@enron.com', 'dfincher@utilicorp.com', '', 'hey big guy.....check this out..... + + w ww.gorelieberman-2000.com/'); +INSERT INTO email([from],[to],subject,body) VALUES('k..allen@enron.com', 'jacqestc@aol.com', '', 'Jacques, + +I sent you a fax of Kevin Kolb''s comments on the release. The payoff on the note would be $36,248 ($36090(principal) + $158 (accrued interest)). +This is assuming we wrap this up on Tuesday. + +Please email to confirm that their changes are ok so I can set up a meeting on Tuesday to reach closure. + +Phillip'); +INSERT INTO email([from],[to],subject,body) VALUES('kourtney.nelson@enron.com', 'mike.swerzbin@enron.com', 'Adjusted L/R Balance', 'Mike, + +I placed the adjusted L/R Balance on the Enronwest site. It is under the "Staff/Kourtney Nelson". There are two links: + +1) "Adj L_R" is the same data/format from the weekly strategy meeting. +2) "New Gen 2001_2002" link has all of the supply side info that is used to calculate the L/R balance + -Please note the Data Flag column, a value of "3" indicates the project was cancelled, on hold, etc and is not included in the calc. + +Both of these sheets are interactive Excel spreadsheets and thus you can play around with the data as you please. Also, James Bruce is working to get his gen report on the web. That will help with your access to information on new gen. + +Please let me know if you have any questions or feedback, + +Kourtney + + + +Kourtney Nelson +Fundamental Analysis +Enron North America +(503) 464-8280 +kourtney.nelson@enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('d..thomas@enron.com', 'naveed.ahmed@enron.com', 'FW: Current Enron TCC Portfolio', ' + +-----Original Message----- +From: Grace, Rebecca M. +Sent: Monday, December 17, 2001 9:44 AM +To: Thomas, Paul D. +Cc: Cashion, Jim; Allen, Thresa A.; May, Tom +Subject: RE: Current Enron TCC Portfolio + + +Paul, + +I reviewed NY''s list. I agree with all of their contracts numbers and mw amounts. + +Call if you have any more questions. + +Rebecca + + + + -----Original Message----- +From: Thomas, Paul D. +Sent: Monday, December 17, 2001 9:08 AM +To: Grace, Rebecca M. +Subject: FW: Current Enron TCC Portfolio + + << File: enrontccs.xls >> +Rebecca, +Let me know if you see any differences. + +Paul +X 3-0403 +-----Original Message----- +From: Thomas, Paul D. +Sent: Monday, December 17, 2001 9:04 AM +To: Ahmed, Naveed +Subject: FW: Current Enron TCC Portfolio + + + + +-----Original Message----- +From: Thomas, Paul D. +Sent: Thursday, December 13, 2001 10:01 AM +To: Baughman, Edward D. +Subject: Current Enron TCC Portfolio + + +'); +INSERT INTO email([from],[to],subject,body) VALUES('stephanie.panus@enron.com', 'william.bradford@enron.com, debbie.brackett@enron.com,', 'Coastal Merchant Energy/El Paso Merchant Energy', 'Coastal Merchant Energy, L.P. merged with and into El Paso Merchant Energy, +L.P., effective February 1, 2001, with the surviving entity being El Paso +Merchant Energy, L.P. We currently have ISDA Master Agreements with both +counterparties. Please see the attached memo regarding the existing Masters +and let us know which agreement should be terminated. + +Thanks, +Stephanie +'); +INSERT INTO email([from],[to],subject,body) VALUES('kam.keiser@enron.com', 'c..kenne@enron.com', 'RE: What about this too???', ' + + -----Original Message----- +From: Kenne, Dawn C. +Sent: Wednesday, February 06, 2002 11:50 AM +To: Keiser, Kam +Subject: What about this too??? + + + << File: Netco Trader Matrix.xls >> + '); +INSERT INTO email([from],[to],subject,body) VALUES('chris.meyer@enron.com', 'joe.parks@enron.com', 'Centana', 'Talked to Chip. We do need Cash Committe approval given the netting feature of your deal, which means Batch Funding Request. Please update per my previous e-mail and forward. + +Thanks + +chris +x31666'); +INSERT INTO email([from],[to],subject,body) VALUES('debra.perlingiere@enron.com', 'jworman@academyofhealth.com', '', 'Have a great weekend! Happy Fathers Day! + + +Debra Perlingiere +Enron North America Corp. +1400 Smith Street, EB 3885 +Houston, Texas 77002 +dperlin@enron.com +Phone 713-853-7658 +Fax 713-646-3490'); +INSERT INTO email([from],[to],subject,body) VALUES('outlook.team@enron.com', '', 'Demo by Martha Janousek of Dashboard & Pipeline Profile / Julia &', 'CALENDAR ENTRY: APPOINTMENT + +Description: + Demo by Martha Janousek of Dashboard & Pipeline Profile / Julia & Dir Rpts. - 4102 + +Date: 1/5/2001 +Time: 9:00 AM - 10:00 AM (Central Standard Time) + +Chairperson: Outlook Migration Team + +Detailed Description:'); +INSERT INTO email([from],[to],subject,body) VALUES('diana.seifert@enron.com', 'mark.taylor@enron.com', 'Guest access Chile', 'Hello Mark, + +Justin Boyd told me that your can help me with questions regarding Chile. +We got a request for guest access through MG. +The company is called Escondida and is a subsidiary of BHP Australia. + +Please advise if I can set up a guest account or not. +F.Y.I.: MG is planning to put a "in w/h Chile" contract for Copper on-line as +soon as Enron has done the due diligence for this country. +Thanks ! + + +Best regards + +Diana Seifert +EOL PCG'); +INSERT INTO email([from],[to],subject,body) VALUES('enron_update@concureworkplace.com', 'mark.whitt@enron.com', '<> - 121001', 'The Approval status has changed on the following report: + +Status last changed by: Barry L. Tycholiz +Expense Report Name: 121001 +Report Total: $198.98 +Amount Due Employee: $198.98 +Amount Approved: $198.98 +Amount Paid: $0.00 +Approval Status: Approved +Payment Status: Pending + + +To review this expense report, click on the following link for Concur Expense. +http://expensexms.enron.com'); +INSERT INTO email([from],[to],subject,body) VALUES('kevin.hyatt@enron.com', '', 'Technical Support', 'Outside the U.S., please refer to the list below: + +Australia: +1800 678-515 +support@palm-au.com + +Canada: +1905 305-6530 +support@palm.com + +New Zealand: +0800 446-398 +support@palm-nz.com + +U.K.: +0171 867 0108 +eurosupport@palm.3com.com + +Please refer to the Worldwide Customer Support card for a complete technical support contact list.'); +INSERT INTO email([from],[to],subject,body) VALUES('geoff.storey@enron.com', 'dutch.quigley@enron.com', 'RE:', 'duke contact? + + -----Original Message----- +From: Quigley, Dutch +Sent: Wednesday, October 31, 2001 10:14 AM +To: Storey, Geoff +Subject: RE: + +bp corp Albert LaMore 281-366-4962 + +running the reports now + + + -----Original Message----- +From: Storey, Geoff +Sent: Wednesday, October 31, 2001 10:10 AM +To: Quigley, Dutch +Subject: RE: + +give me a contact over there too +BP + + + -----Original Message----- +From: Quigley, Dutch +Sent: Wednesday, October 31, 2001 9:42 AM +To: Storey, Geoff +Subject: + +Coral Jeff Whitnah 713-767-5374 +Relaint Steve McGinn 713-207-4000'); +INSERT INTO email([from],[to],subject,body) VALUES('pete.davis@enron.com', 'pete.davis@enron.com', 'Start Date: 4/22/01; HourAhead hour: 3; ', 'Start Date: 4/22/01; HourAhead hour: 3; No ancillary schedules awarded. +Variances detected. +Variances detected in Load schedule. + + LOG MESSAGES: + +PARSING FILE -->> O:\Portland\WestDesk\California Scheduling\ISO Final +Schedules\2001042203.txt + +---- Load Schedule ---- +$$$ Variance found in table tblLoads. + Details: (Hour: 3 / Preferred: 1.92 / Final: 1.89) + TRANS_TYPE: FINAL + LOAD_ID: PGE4 + MKT_TYPE: 2 + TRANS_DATE: 4/22/01 + SC_ID: EPMI + +'); +INSERT INTO email([from],[to],subject,body) VALUES('john.postlethwaite@enron.com', 'john.zufferli@enron.com', 'Reference', 'John, hope things are going well up there for you. The big day is almost here for you and Jessica. I was wondering if I could use your name as a job reference if need be. I am just trying to get everything in order just in case something happens. + +John'); +INSERT INTO email([from],[to],subject,body) VALUES('jeffrey.shankman@enron.com', 'lschiffm@jonesday.com', 'Re:', 'I saw you called on the cell this a.m. Sorry I missed you. (I was in the +shower). I have had a shitty week--I suspect my silence (not only to you, +but others) after our phone call is a result of the week. I''m seeing Glen at +11:15....talk to you'); +INSERT INTO email([from],[to],subject,body) VALUES('litebytz@enron.com', '', 'Lite Bytz RSVP', ' +This week''s Lite Bytz presentation will feature the following TOOLZ speaker: + +Richard McDougall +Solaris 8 +Thursday, June 7, 2001 + +If you have not already signed up, please RSVP via email to litebytz@enron.com by the end of the day Tuesday, June 5, 2001. + +*Remember: this is now a Brown Bag Event--so bring your lunch and we will provide cookies and drinks. + +Click below for more details. + +http://home.enron.com:84/messaging/litebytztoolzprint.jpg'); + COMMIT; + } +} {} + +############################################################################### +# Everything above just builds an interesting test database. The actual +# tests come after this comment. +############################################################################### + +do_test fts3ac-1.2 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark' + } +} {6 17 25 38 40 42 73 74} +do_test fts3ac-1.3 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'susan' + } +} {24 40} +do_test fts3ac-1.4 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark susan' + } +} {40} +do_test fts3ac-1.5 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'susan mark' + } +} {40} +do_test fts3ac-1.6 { + execsql { + SELECT rowid FROM email WHERE email MATCH '"mark susan"' + } +} {} +do_test fts3ac-1.7 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark -susan' + } +} {6 17 25 38 42 73 74} +do_test fts3ac-1.8 { + execsql { + SELECT rowid FROM email WHERE email MATCH '-mark susan' + } +} {24} +do_test fts3ac-1.9 { + execsql { + SELECT rowid FROM email WHERE email MATCH 'mark OR susan' + } +} {6 17 24 25 38 40 42 73 74} + +# Some simple tests of the automatic "offsets(email)" column. In the sample +# data set above, only one message, number 20, contains the words +# "gas" and "reminder" in both body and subject. +# +do_test fts3ac-2.1 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'gas reminder' + } +} {20 {2 0 42 3 2 1 54 8 3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} +do_test fts3ac-2.2 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'subject:gas reminder' + } +} {20 {2 0 42 3 2 1 54 8 3 1 54 8}} +do_test fts3ac-2.3 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE email MATCH 'body:gas reminder' + } +} {20 {2 1 54 8 3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} +do_test fts3ac-2.4 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE subject MATCH 'gas reminder' + } +} {20 {2 0 42 3 2 1 54 8}} +do_test fts3ac-2.5 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH 'gas reminder' + } +} {20 {3 0 42 3 3 1 54 8 3 0 129 3 3 0 143 3 3 0 240 3}} + +# Document 32 contains 5 instances of the world "child". But only +# 3 of them are paired with "product". Make sure only those instances +# that match the phrase appear in the offsets(email) list. +# +do_test fts3ac-3.1 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH 'child product' AND +rowid=32 + } +} {32 {3 0 94 5 3 0 114 5 3 0 207 5 3 1 213 7 3 0 245 5 3 1 251 7 3 0 409 5 3 1 415 7 3 1 493 7}} +do_test fts3ac-3.2 { + execsql { + SELECT rowid, offsets(email) FROM email + WHERE body MATCH '"child product"' + } +} {32 {3 0 207 5 3 1 213 7 3 0 245 5 3 1 251 7 3 0 409 5 3 1 415 7}} + +# Snippet generator tests +# +do_test fts3ac-4.1 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'subject:gas reminder' + } +} {{Alert Posted 10:00 AM November 20,2000: E-GAS Request Reminder}} +do_test fts3ac-4.2 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'christmas candlelight' + } +} {{...here Christmas +eve?? They have an 11:00 a.m. service and a candlelight service...}} + +do_test fts3ac-4.3 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'deal sheet potential reuse' + } +} {{EOL-Accenture Deal Sheet...asset base for potential reuse/ licensing + Contract negotiations...}} +do_test fts3ac-4.4 { + execsql { + SELECT snippet(email,'<<<','>>>',' ') FROM email + WHERE email MATCH 'deal sheet potential reuse' + } +} {{EOL-Accenture <<>> <<>> asset base for <<>> <<>>/ licensing + Contract negotiations }} +do_test fts3ac-4.5 { + execsql { + SELECT snippet(email,'<<<','>>>',' ') FROM email + WHERE email MATCH 'first things' + } +} {{Re: <<>> Polish Deal! Congrats! <<>> seem to be building rapidly now }} +do_test fts3ac-4.6 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'chris is here' + } +} {{...chris.germany@enron.com'" <chris...bet this is next to...about going here Christmas +eve...}} +do_test fts3ac-4.7 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH '"pursuant to"' + } +} {{Erin: + +Pursuant to your request, attached are the Schedule to the ISDA Master Agreement, together...}} +do_test fts3ac-4.8 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'ancillary load davis' + } +} {{pete.davis@enron.com...3; No ancillary schedules awarded...detected in Load schedule. + + LOG...}} + +# Combinations of AND and OR operators: +# +do_test fts3ac-5.1 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'questar enron OR com' + } +} {{matt.smith@enron.com...31 Keystone Receipts +15 Questar Pipeline +40 Rockies...}} + +do_test fts3ac-5.2 { + execsql { + SELECT snippet(email) FROM email + WHERE email MATCH 'enron OR com questar' + } +} {{matt.smith@enron.com...31 Keystone Receipts +15 Questar Pipeline +40 Rockies...}} + +#------------------------------------------------------------------------- +# Test a problem reported on the mailing list. +# +do_test fts3ac-6.1 { + execsql { + CREATE VIRTUAL TABLE ft USING fts3(one, two); + INSERT INTO ft VALUES('', 'foo'); + INSERT INTO ft VALUES('foo', 'foo'); + SELECT offsets(ft) FROM ft WHERE ft MATCH 'foo'; + } +} {{1 0 0 3} {0 0 0 3 1 0 0 3}} +do_test fts3ac-6.2 { + execsql { + DELETE FROM ft WHERE one = 'foo'; + SELECT offsets(ft) FROM ft WHERE ft MATCH 'foo'; + } +} {{1 0 0 3}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ad.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ad.test new file mode 100644 index 0000000000000000000000000000000000000000..e373339d4e74b10991efac46192c1e00c397a475 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ad.test @@ -0,0 +1,106 @@ +# 2006 October 1 +# +# 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. The +# focus of this script is testing the FTS3 module, and in particular +# the Porter stemmer. +# +# $Id: fts3ad.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_test fts3ad-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-1.2 { + execsql { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'run jump'; + } +} {{running and jumping}} +do_test fts3ad-1.3 { + execsql { + INSERT INTO t1(rowid, content) + VALUES(2, 'abcdefghijklmnopqrstuvwyxz'); + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijqrstuvwyxz' + } +} {2 abcdefghijklmnopqrstuvwyxz} +do_test fts3ad-1.4 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijXXXXqrstuvwyxz' + } +} {2 abcdefghijklmnopqrstuvwyxz} +do_test fts3ad-1.5 { + execsql { + INSERT INTO t1(rowid, content) + VALUES(3, 'The value is 123456789'); + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH '123789' + } +} {3 {The value is 123456789}} +do_test fts3ad-1.6 { + execsql { + SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH '123000000789' + } +} {3 {The value is 123456789}} + +do_test fts3ad-2.1 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.2 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.3 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= simple); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {} +do_test fts3ad-2.4 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize= porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} +do_test fts3ad-2.5 { + execsql { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(content, tokenize = porter); + INSERT INTO t1(rowid, content) VALUES(1, 'running and jumping'); + SELECT rowid FROM t1 WHERE content MATCH 'run jump'; + } +} {1} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ae.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ae.test new file mode 100644 index 0000000000000000000000000000000000000000..b87268897df8ea00f9294aa291e1fb768af0c902 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ae.test @@ -0,0 +1,85 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing deletions in the FTS3 module. +# +# $Id: fts3ae.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing keywords which are the +# ordinal numbers of the bit positions set for a sequence of integers, +# which are used for the rowid. There are a total of 30 INSERT and +# DELETE statements, so that we'll test both the segmentMerge() merge +# (over the first 16) and the termSelect() merge (over the level-1 +# segment and 14 level-0 segments). +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'one'); + INSERT INTO t1 (rowid, content) VALUES(2, 'two'); + INSERT INTO t1 (rowid, content) VALUES(3, 'one two'); + INSERT INTO t1 (rowid, content) VALUES(4, 'three'); + DELETE FROM t1 WHERE rowid = 1; + INSERT INTO t1 (rowid, content) VALUES(5, 'one three'); + INSERT INTO t1 (rowid, content) VALUES(6, 'two three'); + INSERT INTO t1 (rowid, content) VALUES(7, 'one two three'); + DELETE FROM t1 WHERE rowid = 4; + INSERT INTO t1 (rowid, content) VALUES(8, 'four'); + INSERT INTO t1 (rowid, content) VALUES(9, 'one four'); + INSERT INTO t1 (rowid, content) VALUES(10, 'two four'); + DELETE FROM t1 WHERE rowid = 7; + INSERT INTO t1 (rowid, content) VALUES(11, 'one two four'); + INSERT INTO t1 (rowid, content) VALUES(12, 'three four'); + INSERT INTO t1 (rowid, content) VALUES(13, 'one three four'); + DELETE FROM t1 WHERE rowid = 10; + INSERT INTO t1 (rowid, content) VALUES(14, 'two three four'); + INSERT INTO t1 (rowid, content) VALUES(15, 'one two three four'); + INSERT INTO t1 (rowid, content) VALUES(16, 'five'); + DELETE FROM t1 WHERE rowid = 13; + INSERT INTO t1 (rowid, content) VALUES(17, 'one five'); + INSERT INTO t1 (rowid, content) VALUES(18, 'two five'); + INSERT INTO t1 (rowid, content) VALUES(19, 'one two five'); + DELETE FROM t1 WHERE rowid = 16; + INSERT INTO t1 (rowid, content) VALUES(20, 'three five'); + INSERT INTO t1 (rowid, content) VALUES(21, 'one three five'); + INSERT INTO t1 (rowid, content) VALUES(22, 'two three five'); + DELETE FROM t1 WHERE rowid = 19; + DELETE FROM t1 WHERE rowid = 22; +} + +do_test fts3ae-1.1 { + execsql {SELECT COUNT(*) FROM t1} +} {14} + +do_test fts3ae-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {3 5 9 11 15 17 21} + +do_test fts3ae-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'} +} {2 3 6 11 14 15 18} + +do_test fts3ae-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'} +} {5 6 12 14 15 20 21} + +do_test fts3ae-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'} +} {8 9 11 12 14 15} + +do_test fts3ae-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'} +} {17 18 20 21} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3af.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3af.test new file mode 100644 index 0000000000000000000000000000000000000000..221ac4c3bcab5b1f8ec821bab8fbd788189c9e92 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3af.test @@ -0,0 +1,90 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing updates in the FTS3 module. +# +# $Id: fts3af.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Construct a full-text search table containing keywords which are the +# ordinal numbers of the bit positions set for a sequence of integers, +# which are used for the rowid. There are a total of 31 INSERT, +# UPDATE, and DELETE statements, so that we'll test both the +# segmentMerge() merge (over the first 16) and the termSelect() merge +# (over the level-1 segment and 15 level-0 segments). +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'one'); + INSERT INTO t1 (rowid, content) VALUES(2, 'two'); + INSERT INTO t1 (rowid, content) VALUES(3, 'one two'); + INSERT INTO t1 (rowid, content) VALUES(4, 'three'); + INSERT INTO t1 (rowid, content) VALUES(5, 'one three'); + INSERT INTO t1 (rowid, content) VALUES(6, 'two three'); + INSERT INTO t1 (rowid, content) VALUES(7, 'one two three'); + DELETE FROM t1 WHERE rowid = 4; + INSERT INTO t1 (rowid, content) VALUES(8, 'four'); + UPDATE t1 SET content = 'update one three' WHERE rowid = 1; + INSERT INTO t1 (rowid, content) VALUES(9, 'one four'); + INSERT INTO t1 (rowid, content) VALUES(10, 'two four'); + DELETE FROM t1 WHERE rowid = 7; + INSERT INTO t1 (rowid, content) VALUES(11, 'one two four'); + INSERT INTO t1 (rowid, content) VALUES(12, 'three four'); + INSERT INTO t1 (rowid, content) VALUES(13, 'one three four'); + DELETE FROM t1 WHERE rowid = 10; + INSERT INTO t1 (rowid, content) VALUES(14, 'two three four'); + INSERT INTO t1 (rowid, content) VALUES(15, 'one two three four'); + UPDATE t1 SET content = 'update two five' WHERE rowid = 8; + INSERT INTO t1 (rowid, content) VALUES(16, 'five'); + DELETE FROM t1 WHERE rowid = 13; + INSERT INTO t1 (rowid, content) VALUES(17, 'one five'); + INSERT INTO t1 (rowid, content) VALUES(18, 'two five'); + INSERT INTO t1 (rowid, content) VALUES(19, 'one two five'); + DELETE FROM t1 WHERE rowid = 16; + INSERT INTO t1 (rowid, content) VALUES(20, 'three five'); + INSERT INTO t1 (rowid, content) VALUES(21, 'one three five'); + INSERT INTO t1 (rowid, content) VALUES(22, 'two three five'); + DELETE FROM t1 WHERE rowid = 19; + UPDATE t1 SET content = 'update' WHERE rowid = 15; +} + +do_test fts3af-1.1 { + execsql {SELECT COUNT(*) FROM t1} +} {16} + +do_test fts3af-2.0 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'update'} +} {1 8 15} + +do_test fts3af-2.1 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'} +} {1 3 5 9 11 17 21} + +do_test fts3af-2.2 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'} +} {2 3 6 8 11 14 18 22} + +do_test fts3af-2.3 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'} +} {1 5 6 12 14 20 21 22} + +do_test fts3af-2.4 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'} +} {9 11 12 14} + +do_test fts3af-2.5 { + execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'} +} {8 17 18 20 21 22} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ag.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ag.test new file mode 100644 index 0000000000000000000000000000000000000000..9b658d19df3dbf6e4825ce098f68684bbcb7b0fc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ag.test @@ -0,0 +1,93 @@ +# 2006 October 19 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing handling of edge cases for various doclist +# merging functions in the FTS3 module query logic. +# +# $Id: fts3ag.test,v 1.2 2007/11/16 00:23:08 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'this is a test'); + INSERT INTO t1 (rowid, content) VALUES(2, 'also a test'); +} + +# No hits at all. Returns empty doclists from termSelect(). +do_test fts3ag-1.1 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'} +} {} + +# Empty left in docListExceptMerge(). +do_test fts3ag-1.2 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this something'} +} {} + +# Empty right in docListExceptMerge(). +do_test fts3ag-1.3 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this -something'} +} {1} + +# Empty left in docListPhraseMerge(). +do_test fts3ag-1.4 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"this something"'} +} {} + +# Empty right in docListPhraseMerge(). +do_test fts3ag-1.5 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"something is"'} +} {} + +# Empty left in docListOrMerge(). +do_test fts3ag-1.6 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR this'} +} {1} + +# Empty right in docListOrMerge(). +do_test fts3ag-1.7 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR something'} +} {1} + +# Empty left in docListAndMerge(). +do_test fts3ag-1.8 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something this'} +} {} + +# Empty right in docListAndMerge(). +do_test fts3ag-1.9 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this something'} +} {} + +# No support for all-except queries. +do_test fts3ag-1.10 { + catchsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this -something'} +} {1 {malformed MATCH expression: [-this -something]}} + +# Test that docListOrMerge() correctly handles reaching the end of one +# doclist before it reaches the end of the other. +do_test fts3ag-1.11 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR also'} +} {1 2} +do_test fts3ag-1.12 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'also OR this'} +} {1 2} + +# Empty left and right in docListOrMerge(). Each term matches neither +# row, and when combined there was an assertion failure. +do_test fts3ag-1.13 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR nothing'} +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ah.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ah.test new file mode 100644 index 0000000000000000000000000000000000000000..3810ec37b5c8c5bd35683c5537520b6b1f59d299 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ah.test @@ -0,0 +1,71 @@ +# 2006 October 31 +# +# 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. The focus +# here is testing correct handling of very long terms. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Generate a document of bigterms based on characters from the list +# chars. +proc bigtermdoc {chars len} { + set doc "" + foreach char $chars { + append doc " " [string repeat $char $len] + } + return $doc +} + +set len 5000 +set doc1 [bigtermdoc {a b c d} $len] +set doc2 [bigtermdoc {b d e f} $len] +set doc3 [bigtermdoc {a c e} $len] + +set aterm [string repeat a $len] +set bterm [string repeat b $len] +set xterm [string repeat x $len] + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, $doc1); + INSERT INTO t1 (rowid, content) VALUES(2, $doc2); + INSERT INTO t1 (rowid, content) VALUES(3, $doc3); +} + +# No hits at all. Returns empty doclists from termSelect(). +do_test fts3ah-1.1 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'} +} {} + +do_test fts3ah-1.2 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH $aterm} +} {1 3} + +do_test fts3ah-1.3 { + execsql {SELECT rowid FROM t1 WHERE t1 MATCH $xterm} +} {} + +do_test fts3ah-1.4 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '$aterm -$xterm'" +} {1 3} + +do_test fts3ah-1.5 { + execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"$aterm $bterm\"'" +} {1} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ai.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ai.test new file mode 100644 index 0000000000000000000000000000000000000000..b17b5bdd553d91993341463f17de60a30a521002 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ai.test @@ -0,0 +1,92 @@ +# 2007 January 17 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite fts3 library. The +# focus here is testing handling of UPDATE when using UTF-16-encoded +# databases. +# +# $Id: fts3ai.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +ifcapable !utf16 { + finish_test + return +} + +# Return the UTF-16 representation of the supplied UTF-8 string $str. +# If $nt is true, append two 0x00 bytes as a nul terminator. +# NOTE(shess) Copied from capi3.test. +proc utf16 {str {nt 1}} { + set r [encoding convertto unicode $str] + if {$nt} { + append r "\x00\x00" + } + return $r +} + +db eval { + PRAGMA encoding = "UTF-16le"; + CREATE VIRTUAL TABLE t1 USING fts3(content); +} + +do_test fts3ai-1.0 { + execsql {PRAGMA encoding} +} {UTF-16le} + +do_test fts3ai-1.1 { + execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')} + execsql {SELECT content FROM t1 WHERE rowid = 1} +} {one} + +do_test fts3ai-1.2 { + set sql "INSERT INTO t1 (rowid, content) VALUES(2, 'two')" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 2} +} {two} + +do_test fts3ai-1.3 { + set sql "INSERT INTO t1 (rowid, content) VALUES(3, 'three')" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + set sql "UPDATE t1 SET content = 'trois' WHERE rowid = 3" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 3} +} {trois} + +do_test fts3ai-1.4 { + set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(4, 'four')}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 4} +} {four} + +do_test fts3ai-1.5 { + set sql16 [utf16 {INSERT INTO t1 (rowid, content) VALUES(5, 'five')}] + set STMT [sqlite3_prepare16 $DB $sql16 -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + set sql "UPDATE t1 SET content = 'cinq' WHERE rowid = 5" + set STMT [sqlite3_prepare $DB $sql -1 TAIL] + sqlite3_step $STMT + sqlite3_finalize $STMT + execsql {SELECT content FROM t1 WHERE rowid = 5} +} {cinq} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ak.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ak.test new file mode 100644 index 0000000000000000000000000000000000000000..080efe52b57a6b080c9ff43432d4b0d3763bb3f3 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3ak.test @@ -0,0 +1,105 @@ +# 2007 March 9 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. These +# make sure that fts3 insertion buffering is fully transparent when +# using transactions. +# +# $Id: fts3ak.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1 (rowid, content) VALUES(1, 'hello world'); + INSERT INTO t1 (rowid, content) VALUES(2, 'hello there'); + INSERT INTO t1 (rowid, content) VALUES(3, 'cruel world'); +} + +# Test that possibly-buffered inserts went through after commit. +do_test fts3ak-1.1 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(4, 'false world'); + INSERT INTO t1 (rowid, content) VALUES(5, 'false door'); + COMMIT TRANSACTION; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4} + +# Test that buffered inserts are seen by selects in the same +# transaction. +do_test fts3ak-1.2 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(6, 'another world'); + INSERT INTO t1 (rowid, content) VALUES(7, 'another test'); + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + COMMIT TRANSACTION; + } +} {1 3 4 6} + +# Test that buffered inserts are seen within a transaction. This is +# really the same test as 1.2. +do_test fts3ak-1.3 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(8, 'second world'); + INSERT INTO t1 (rowid, content) VALUES(9, 'second sight'); + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + ROLLBACK TRANSACTION; + } +} {1 3 4 6 8} + +# Double-check that the previous result doesn't persist past the +# rollback! +do_test fts3ak-1.4 { + execsql { + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4 6} + +# Test it all together. +do_test fts3ak-1.5 { + execsql { + BEGIN TRANSACTION; + INSERT INTO t1 (rowid, content) VALUES(10, 'second world'); + INSERT INTO t1 (rowid, content) VALUES(11, 'second sight'); + ROLLBACK TRANSACTION; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; + } +} {1 3 4 6} + +# Test that the obvious case works. +do_test fts3ak-1.6 { + execsql { + BEGIN; + INSERT INTO t1 (rowid, content) VALUES(12, 'third world'); + COMMIT; + SELECT rowid FROM t1 WHERE t1 MATCH 'third'; + } +} {12} + +# This is exactly the same as the previous test, except that older +# code loses the INSERT due to an SQLITE_SCHEMA error. +do_test fts3ak-1.7 { + execsql { + BEGIN; + INSERT INTO t1 (rowid, content) VALUES(13, 'third dimension'); + CREATE TABLE x (c); + COMMIT; + SELECT rowid FROM t1 WHERE t1 MATCH 'dimension'; + } +} {13} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3al.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3al.test new file mode 100644 index 0000000000000000000000000000000000000000..02cc0d1695297c7394e97be5bb971e8b1b619973 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3al.test @@ -0,0 +1,73 @@ +# 2007 March 28 +# +# The author disclaims copyright to this source code. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing isspace/isalnum/tolower problems with the +# FTS3 module. Unfortunately, this code isn't a really principled set +# of tests, because it is impossible to know where new uses of these +# functions might appear. +# +# $Id: fts3al.test,v 1.2 2007/12/13 21:54:11 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Tests that startsWith() (calls isspace, tolower, isalnum) can handle +# hi-bit chars. parseSpec() also calls isalnum here. +do_test fts3al-1.1 { + execsql "CREATE VIRTUAL TABLE t1 USING fts3(content, \x80)" +} {} + +# Additionally tests isspace() call in getToken(), and isalnum() call +# in tokenListToIdList(). +do_test fts3al-1.2 { + catch { + execsql "CREATE VIRTUAL TABLE t2 USING fts3(content, tokenize \x80)" + } + sqlite3_errmsg $DB +} "unknown tokenizer: \x80" + +# Additionally test final isalnum() in startsWith(). +do_test fts3al-1.3 { + execsql "CREATE VIRTUAL TABLE t3 USING fts3(content, tokenize\x80)" +} {} + +# The snippet-generation code has calls to isspace() which are sort of +# hard to get to. It finds convenient breakpoints by starting ~40 +# chars before and after the matched term, and scanning ~10 chars +# around that position for isspace() characters. The long word with +# embedded hi-bit chars causes one of these isspace() calls to be +# exercised. The version with a couple extra spaces should cause the +# other isspace() call to be exercised. [Both cases have been tested +# in the debugger, but I'm hoping to continue to catch it if simple +# constant changes change things slightly. +# +# The trailing and leading hi-bit chars help with code which tests for +# isspace() to coalesce multiple spaces. +# +# UPDATE: The above is no longer true; there is no such code in fts3. +# But leave the test in just the same. +# + +set word "\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80xxxxx\x80" +set phrase1 "$word $word $word target $word $word $word" +set phrase2 "$word $word $word target $word $word $word" + +db eval {CREATE VIRTUAL TABLE t4 USING fts3(content)} +db eval "INSERT INTO t4 (content) VALUES ('$phrase1')" +db eval "INSERT INTO t4 (content) VALUES ('$phrase2')" + +do_test fts3al-1.4 { + execsql {SELECT rowid, length(snippet(t4)) FROM t4 WHERE t4 MATCH 'target'} +} {1 241 2 247} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3auto.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3auto.test new file mode 100644 index 0000000000000000000000000000000000000000..19193973d9eca4637a9aee168b55089e8afe87ac --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3auto.test @@ -0,0 +1,717 @@ +# 2011 June 10 +# +# 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 + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +set testprefix fts3auto +set sfep $sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 + +#-------------------------------------------------------------------------- +# Start of Tcl infrastructure used by tests. The entry points are: +# +# do_fts3query_test +# fts3_make_deferrable +# fts3_zero_long_segments +# + +# +# do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR +# +# This proc runs several test cases on FTS3/4 table $TABLE using match +# expression $MATCHEXPR. All documents in $TABLE must be formatted so that +# they can be "tokenized" using the Tcl list commands (llength, lindex etc.). +# The name and column names used by $TABLE must not require any quoting or +# escaping when used in SQL statements. +# +# $MATCHINFO may be any expression accepted by the FTS4 MATCH operator, +# except that the ":token" syntax is not supported. Tcl list +# commands are used to tokenize the expression. Any parenthesis must appear +# either as separate list elements, or as the first (for opening) or last +# (for closing) character of a list element. i.e. the expression "(a OR b)c" +# will not be parsed correctly, but "( a OR b) c" will. +# +# Available OPTIONS are: +# +# -deferred TOKENLIST +# +# If the "deferred" option is supplied, it is passed a list of tokens that +# are deferred by FTS and result in the relevant matchinfo() stats being an +# approximation. +# +set sqlite_fts3_enable_parentheses 1 +proc do_fts3query_test {tn args} { + + set nArg [llength $args] + if {$nArg < 2 || ($nArg % 2)} { + set cmd do_fts3query_test + error "wrong # args: should be \"$cmd ?-deferred LIST? TABLE MATCHEXPR\"" + } + set tbl [lindex $args [expr $nArg-2]] + set match [lindex $args [expr $nArg-1]] + set deferred [list] + + foreach {k v} [lrange $args 0 [expr $nArg-3]] { + switch -- $k { + -deferred { + ifcapable fts4_deferred { set deferred $v } + } + default { + error "bad option \"$k\": must be -deferred" + } + } + } + + get_near_results $tbl $match $deferred aHit + get_near_results $tbl [string map {AND OR} $match] $deferred aMatchinfo + + set matchinfo_asc [list] + foreach docid [lsort -integer -incr [array names aHit]] { + lappend matchinfo_asc $docid $aMatchinfo($docid) + } + set matchinfo_desc [list] + foreach docid [lsort -integer -decr [array names aHit]] { + lappend matchinfo_desc $docid $aMatchinfo($docid) + } + + set title "(\"$match\" -> [llength [array names aHit]] rows)" + + do_execsql_test $tn$title.1 " + SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC + " [lsort -integer -incr [array names aHit]] + + do_execsql_test $tn$title.2 " + SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC + " [lsort -integer -decr [array names aHit]] + + do_execsql_test $tn$title.3 " + SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl + WHERE $tbl MATCH '$match' ORDER BY docid DESC + " $matchinfo_desc + + do_execsql_test $tn$title.4 " + SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl + WHERE $tbl MATCH '$match' ORDER BY docid ASC + " $matchinfo_asc +} + +# fts3_make_deferrable TABLE TOKEN ?NROW? +# +proc fts3_make_deferrable {tbl token {nRow 0}} { + + set stmt [sqlite3_prepare db "SELECT * FROM $tbl" -1 dummy] + set name [sqlite3_column_name $stmt 0] + sqlite3_finalize $stmt + + if {$nRow==0} { + set nRow [db one "SELECT count(*) FROM $tbl"] + } + set pgsz [db one "PRAGMA page_size"] + execsql BEGIN + for {set i 0} {$i < ($nRow * $pgsz * 1.2)/100} {incr i} { + set doc [string repeat "$token " 100] + execsql "INSERT INTO $tbl ($name) VALUES(\$doc)" + } + execsql "INSERT INTO $tbl ($name) VALUES('aaaaaaa ${token}aaaaa')" + execsql COMMIT + + return [expr $nRow*$pgsz] +} + +# fts3_zero_long_segments TABLE ?LIMIT? +# +proc fts3_zero_long_segments {tbl limit} { + sqlite3_db_config db DEFENSIVE 0 + execsql " + UPDATE ${tbl}_segments + SET block = zeroblob(length(block)) + WHERE length(block)>$limit + " + return [db changes] +} + + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +proc fix_phrase_expr {cols expr colfiltervar} { + upvar $colfiltervar iColFilter + + set out [list] + foreach t $expr { + if {[string match *:* $t]} { + set col [lindex [split $t :] 0] + set t [lindex [split $t :] 1] + set iCol [lsearch $cols $col] + if {$iCol<0} { error "unknown column: $col" } + if {$iColFilter < 0} { + set iColFilter $iCol + } elseif {$iColFilter != $iCol} { + set iColFilter [llength $cols] + } + } + lappend out $t + } + + return $out +} + +proc fix_near_expr {cols expr colfiltervar} { + upvar $colfiltervar iColFilter + + set iColFilter -1 + + set out [list] + lappend out [fix_phrase_expr $cols [lindex $expr 0] iColFilter] + foreach {a b} [lrange $expr 1 end] { + if {[string match -nocase near $a]} { set a 10 } + if {[string match -nocase near/* $a]} { set a [string range $a 5 end] } + lappend out $a + lappend out [fix_phrase_expr $cols $b iColFilter] + } + return $out +} + +proc get_single_near_results {tbl expr deferred arrayvar nullvar} { + upvar $arrayvar aMatchinfo + upvar $nullvar nullentry + catch {array unset aMatchinfo} + + set cols [list] + set miss [list] + db eval "PRAGMA table_info($tbl)" A { lappend cols $A(name) ; lappend miss 0 } + set expr [fix_near_expr $cols $expr iColFilter] + + # Calculate the expected results using [fts3_near_match]. The following + # loop populates the "hits" and "counts" arrays as follows: + # + # 1. For each document in the table that matches the NEAR expression, + # hits($docid) is set to 1. The set of docids that match the expression + # can therefore be found using [array names hits]. + # + # 2. For each column of each document in the table, counts($docid,$iCol) + # is set to the -phrasecountvar output. + # + set res [list] + catch { array unset hits } + db eval "SELECT docid, * FROM $tbl" d { + set iCol 0 + foreach col [lrange $d(*) 1 end] { + set docid $d(docid) + if {$iColFilter<0 || $iCol==$iColFilter} { + set hit [fts3_near_match $d($col) $expr -p counts($docid,$iCol)] + if {$hit} { set hits($docid) 1 } + } else { + set counts($docid,$iCol) $miss + } + incr iCol + } + } + set nPhrase [expr ([llength $expr]+1)/2] + set nCol $iCol + + # This block populates the nHit and nDoc arrays. For each phrase/column + # in the query/table, array elements are set as follows: + # + # nHit($iPhrase,$iCol) - Total number of hits for phrase $iPhrase in + # column $iCol. + # + # nDoc($iPhrase,$iCol) - Number of documents with at least one hit for + # phrase $iPhrase in column $iCol. + # + for {set iPhrase 0} {$iPhrase < $nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol < $nCol} {incr iCol} { + set nHit($iPhrase,$iCol) 0 + set nDoc($iPhrase,$iCol) 0 + } + } + foreach key [array names counts] { + set iCol [lindex [split $key ,] 1] + set iPhrase 0 + foreach c $counts($key) { + if {$c>0} { incr nDoc($iPhrase,$iCol) 1 } + incr nHit($iPhrase,$iCol) $c + incr iPhrase + } + } + + if {[llength $deferred] && [llength $expr]==1} { + set phrase [lindex $expr 0] + set rewritten [list] + set partial 0 + foreach tok $phrase { + if {[lsearch $deferred $tok]>=0} { + lappend rewritten * + } else { + lappend rewritten $tok + set partial 1 + } + } + if {$partial==0} { + set tblsize [db one "SELECT count(*) FROM $tbl"] + for {set iCol 0} {$iCol < $nCol} {incr iCol} { + set nHit(0,$iCol) $tblsize + set nDoc(0,$iCol) $tblsize + } + } elseif {$rewritten != $phrase} { + while {[lindex $rewritten end] == "*"} { + set rewritten [lrange $rewritten 0 end-1] + } + while {[lindex $rewritten 0] == "*"} { + set rewritten [lrange $rewritten 1 end] + } + get_single_near_results $tbl [list $rewritten] {} aRewrite nullentry + foreach docid [array names hits] { + set aMatchinfo($docid) $aRewrite($docid) + } + return + } + } + + # Set up the aMatchinfo array. For each document, set aMatchinfo($docid) to + # contain the output of matchinfo('x') for the document. + # + foreach docid [array names hits] { + set mi [list] + for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol<$nCol} {incr iCol} { + lappend mi [lindex $counts($docid,$iCol) $iPhrase] + lappend mi $nHit($iPhrase,$iCol) + lappend mi $nDoc($iPhrase,$iCol) + } + } + set aMatchinfo($docid) $mi + } + + # Set up the nullentry output. + # + set nullentry [list] + for {set iPhrase 0} {$iPhrase<$nPhrase} {incr iPhrase} { + for {set iCol 0} {$iCol<$nCol} {incr iCol} { + lappend nullentry 0 $nHit($iPhrase,$iCol) $nDoc($iPhrase,$iCol) + } + } +} + + +proc matching_brackets {expr} { + if {[string range $expr 0 0]!="(" || [string range $expr end end] !=")"} { + return 0 + } + + set iBracket 1 + set nExpr [string length $expr] + for {set i 1} {$iBracket && $i < $nExpr} {incr i} { + set c [string range $expr $i $i] + if {$c == "("} {incr iBracket} + if {$c == ")"} {incr iBracket -1} + } + + return [expr ($iBracket==0 && $i==$nExpr)] +} + +proc get_near_results {tbl expr deferred arrayvar {nullvar ""}} { + upvar $arrayvar aMatchinfo + if {$nullvar != ""} { upvar $nullvar nullentry } + + set expr [string trim $expr] + while { [matching_brackets $expr] } { + set expr [string trim [string range $expr 1 end-1]] + } + + set prec(NOT) 1 + set prec(AND) 2 + set prec(OR) 3 + + set currentprec 0 + set iBracket 0 + set expr_length [llength $expr] + for {set i 0} {$i < $expr_length} {incr i} { + set op [lindex $expr $i] + if {$iBracket==0 && [info exists prec($op)] && $prec($op)>=$currentprec } { + set opidx $i + set currentprec $prec($op) + } else { + for {set j 0} {$j < [string length $op]} {incr j} { + set c [string range $op $j $j] + if {$c == "("} { incr iBracket +1 } + if {$c == ")"} { incr iBracket -1 } + } + } + } + if {$iBracket!=0} { error "mismatched brackets in: $expr" } + + if {[info exists opidx]==0} { + get_single_near_results $tbl $expr $deferred aMatchinfo nullentry + } else { + set eLeft [lrange $expr 0 [expr $opidx-1]] + set eRight [lrange $expr [expr $opidx+1] end] + + get_near_results $tbl $eLeft $deferred aLeft nullleft + get_near_results $tbl $eRight $deferred aRight nullright + + switch -- [lindex $expr $opidx] { + "NOT" { + foreach hit [array names aLeft] { + if {0==[info exists aRight($hit)]} { + set aMatchinfo($hit) $aLeft($hit) + } + } + set nullentry $nullleft + } + + "AND" { + foreach hit [array names aLeft] { + if {[info exists aRight($hit)]} { + set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)] + } + } + set nullentry [concat $nullleft $nullright] + } + + "OR" { + foreach hit [array names aLeft] { + if {[info exists aRight($hit)]} { + set aMatchinfo($hit) [concat $aLeft($hit) $aRight($hit)] + unset aRight($hit) + } else { + set aMatchinfo($hit) [concat $aLeft($hit) $nullright] + } + } + foreach hit [array names aRight] { + set aMatchinfo($hit) [concat $nullleft $aRight($hit)] + } + + set nullentry [concat $nullleft $nullright] + } + } + } +} + + +# End of test procs. Actual tests are below this line. +#-------------------------------------------------------------------------- + +#-------------------------------------------------------------------------- +# The following test cases - fts3auto-1.* - focus on testing the Tcl +# command [fts3_near_match], which is used by other tests in this file. +# +proc test_fts3_near_match {tn doc expr res} { + fts3_near_match $doc $expr -phrasecountvar p + uplevel do_test [list $tn] [list [list set {} $p]] [list $res] +} + +test_fts3_near_match 1.1.1 {a b c a b} a {2} +test_fts3_near_match 1.1.2 {a b c a b} {a 5 b 6 c} {2 2 1} +test_fts3_near_match 1.1.3 {a b c a b} {"a b"} {2} +test_fts3_near_match 1.1.4 {a b c a b} {"b c"} {1} +test_fts3_near_match 1.1.5 {a b c a b} {"c c"} {0} + +test_fts3_near_match 1.2.1 "a b c d e f g" {b 2 f} {0 0} +test_fts3_near_match 1.2.2 "a b c d e f g" {b 3 f} {1 1} +test_fts3_near_match 1.2.3 "a b c d e f g" {f 2 b} {0 0} +test_fts3_near_match 1.2.4 "a b c d e f g" {f 3 b} {1 1} +test_fts3_near_match 1.2.5 "a b c d e f g" {"a b" 2 "f g"} {0 0} +test_fts3_near_match 1.2.6 "a b c d e f g" {"a b" 3 "f g"} {1 1} + +set A "a b c d e f g h i j k l m n o p q r s t u v w x y z" +test_fts3_near_match 1.3.1 $A {"c d" 5 "i j" 1 "e f"} {0 0 0} +test_fts3_near_match 1.3.2 $A {"c d" 5 "i j" 2 "e f"} {1 1 1} + +#-------------------------------------------------------------------------- +# Test cases fts3auto-2.* run some simple tests using the +# [do_fts3query_test] proc. +# +foreach {tn create} { + 1 "fts4(a, b)" + 2 "fts4(a, b, order=DESC)" + 3 "fts4(a, b, order=ASC)" + 4 "fts4(a, b, prefix=1)" + 5 "fts4(a, b, order=DESC, prefix=1)" + 6 "fts4(a, b, order=ASC, prefix=1)" +} { + do_test 2.$tn.1 { + catchsql { DROP TABLE t1 } + execsql "CREATE VIRTUAL TABLE t1 USING $create" + for {set i 0} {$i<32} {incr i} { + set doc [list] + if {$i&0x01} {lappend doc one} + if {$i&0x02} {lappend doc two} + if {$i&0x04} {lappend doc three} + if {$i&0x08} {lappend doc four} + if {$i&0x10} {lappend doc five} + execsql { INSERT INTO t1 VALUES($doc, null) } + } + } {} + + foreach {tn2 expr} { + 1 {one} + 2 {one NEAR/1 five} + 3 {t*} + 4 {t* NEAR/0 five} + 5 {o* NEAR/1 f*} + 6 {one NEAR five NEAR two NEAR four NEAR three} + 7 {one NEAR xyz} + 8 {one OR two} + 9 {one AND two} + 10 {one NOT two} + 11 {one AND two OR three} + 12 {three OR one AND two} + 13 {(three OR one) AND two} + 14 {(three OR one) AND two NOT (five NOT four)} + 15 {"one two"} + 16 {"one two" NOT "three four"} + } { + do_fts3query_test 2.$tn.2.$tn2 t1 $expr + } +} + +#-------------------------------------------------------------------------- +# Some test cases involving deferred tokens. +# + +foreach {tn create} { + 1 "fts4(x)" + 2 "fts4(x, order=DESC)" +} { + catchsql { DROP TABLE t1 } + execsql "CREATE VIRTUAL TABLE t1 USING $create" + do_execsql_test 3.$tn.1 { + INSERT INTO t1(docid, x) VALUES(-2, 'a b c d e f g h i j k'); + INSERT INTO t1(docid, x) VALUES(-1, 'b c d e f g h i j k a'); + INSERT INTO t1(docid, x) VALUES(0, 'c d e f g h i j k a b'); + INSERT INTO t1(docid, x) VALUES(1, 'd e f g h i j k a b c'); + INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d'); + INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e'); + INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k'); + INSERT INTO t1(docid, x) VALUES(5, 'a d g j'); + INSERT INTO t1(docid, x) VALUES(6, 'c a b'); + } + + set limit [fts3_make_deferrable t1 c] + + do_fts3query_test 3.$tn.2.1 t1 {a OR c} + + ifcapable fts4_deferred { + do_test 3.$tn.3 { fts3_zero_long_segments t1 $limit } {1} + } + + foreach {tn2 expr def} { + 1 {a NEAR c} {} + 2 {a AND c} c + 3 {"a c"} c + 4 {"c a"} c + 5 {"a c" NEAR/1 g} {} + 6 {"a c" NEAR/0 g} {} + } { + do_fts3query_test 3.$tn.4.$tn2 -deferred $def t1 $expr + } +} + +#-------------------------------------------------------------------------- +# +foreach {tn create} { + 1 "fts4(x, y)" + 2 "fts4(x, y, order=DESC)" + 3 "fts4(x, y, order=DESC, prefix=2)" +} { + + execsql [subst { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING $create; + INSERT INTO t1 VALUES('one two five four five', ''); + INSERT INTO t1 VALUES('', 'one two five four five'); + INSERT INTO t1 VALUES('one two', 'five four five'); + }] + + do_fts3query_test 4.$tn.1.1 t1 {one AND five} + do_fts3query_test 4.$tn.1.2 t1 {one NEAR five} + do_fts3query_test 4.$tn.1.3 t1 {one NEAR/1 five} + do_fts3query_test 4.$tn.1.4 t1 {one NEAR/2 five} + do_fts3query_test 4.$tn.1.5 t1 {one NEAR/3 five} + + do_test 4.$tn.2 { + set limit [fts3_make_deferrable t1 five] + execsql { INSERT INTO t1(t1) VALUES('optimize') } + ifcapable fts4_deferred { + expr {[fts3_zero_long_segments t1 $limit]>0} + } else { + expr 1 + } + } {1} + + do_fts3query_test 4.$tn.3.1 -deferred five t1 {one AND five} + do_fts3query_test 4.$tn.3.2 -deferred five t1 {one NEAR five} + do_fts3query_test 4.$tn.3.3 -deferred five t1 {one NEAR/1 five} + do_fts3query_test 4.$tn.3.4 -deferred five t1 {one NEAR/2 five} + + do_fts3query_test 4.$tn.3.5 -deferred five t1 {one NEAR/3 five} + + do_fts3query_test 4.$tn.4.1 -deferred fi* t1 {on* AND fi*} + do_fts3query_test 4.$tn.4.2 -deferred fi* t1 {on* NEAR fi*} + do_fts3query_test 4.$tn.4.3 -deferred fi* t1 {on* NEAR/1 fi*} + do_fts3query_test 4.$tn.4.4 -deferred fi* t1 {on* NEAR/2 fi*} + do_fts3query_test 4.$tn.4.5 -deferred fi* t1 {on* NEAR/3 fi*} + + ifcapable fts4_deferred { + db eval {UPDATE t1_stat SET value=x'' WHERE id=0} + do_catchsql_test 4.$tn.4.6 { + SELECT docid FROM t1 WHERE t1 MATCH 'on* NEAR/3 fi*' + } {1 {database disk image is malformed}} + } +} + +#-------------------------------------------------------------------------- +# The following test cases - fts3auto-5.* - focus on using prefix indexes. +# +set chunkconfig [fts3_configure_incr_load 1 1] +foreach {tn create pending} { + 1 "fts4(a, b)" 1 + 2 "fts4(a, b, order=ASC, prefix=1)" 1 + 3 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0 + 4 "fts4(a, b, order=DESC, prefix=\"2,4\")" 0 + 5 "fts4(a, b, order=DESC, prefix=\"1\")" 0 + 6 "fts4(a, b, order=ASC, prefix=\"1,3\")" 0 +} { + + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + if {$pending} {execsql BEGIN} + + foreach {a b} { + "the song of songs which is solomons" + "let him kiss me with the kisses of his mouth for thy love is better than wine" + "because of the savour of thy good ointments thy name is as ointment poured forth therefore do the virgins love thee" + "draw me we will run after thee the king hath brought me into his chambers we will be glad and rejoice in thee we will remember thy love more than wine the upright love thee" + "i am black but comely o ye daughters of jerusalem as the tents of kedar as the curtains of solomon" + "look not upon me because i am black because the sun hath looked upon me my mothers children were angry with me they made me the keeper of the vineyards but mine own vineyard have i not kept" + "tell me o thou whom my soul loveth where thou feedest where thou makest thy flock to rest at noon for why should i be as one that turneth aside by the flocks of thy companions?" + "if thou know not o thou fairest among women go thy way forth by the footsteps of the flock and feed thy kids beside the shepherds tents" + "i have compared thee o my love to a company of horses in pharaohs chariots" + "thy cheeks are comely with rows of jewels thy neck with chains of gold" + "we will make thee borders of gold with studs of silver" + "while the king sitteth at his table my spikenard sendeth forth the smell thereof" + "a bundle of myrrh is my wellbeloved unto me he shall lie all night betwixt my breasts" + "my beloved is unto me as a cluster of camphire in the vineyards of en gedi" + "behold thou art fair my love behold thou art fair thou hast doves eyes" + "behold thou art fair my beloved yea pleasant also our bed is green" + "the beams of our house are cedar and our rafters of fir" + } { + execsql {INSERT INTO t1(a, b) VALUES($a, $b)} + } + + + do_fts3query_test 5.$tn.1.1 t1 {s*} + do_fts3query_test 5.$tn.1.2 t1 {so*} + do_fts3query_test 5.$tn.1.3 t1 {"s* o*"} + do_fts3query_test 5.$tn.1.4 t1 {b* NEAR/3 a*} + do_fts3query_test 5.$tn.1.5 t1 {a*} + do_fts3query_test 5.$tn.1.6 t1 {th* NEAR/5 a* NEAR/5 w*} + do_fts3query_test 5.$tn.1.7 t1 {"b* th* art* fair*"} + + if {$pending} {execsql COMMIT} +} +eval fts3_configure_incr_load $chunkconfig + +foreach {tn pending create} { + 1 0 "fts4(a, b, c, d)" + 2 1 "fts4(a, b, c, d)" + 3 0 "fts4(a, b, c, d, order=DESC)" + 4 1 "fts4(a, b, c, d, order=DESC)" +} { + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + + if {$pending} { execsql BEGIN } + + foreach {a b c d} { + "A B C" "D E F" "G H I" "J K L" + "B C D" "E F G" "H I J" "K L A" + "C D E" "F G H" "I J K" "L A B" + "D E F" "G H I" "J K L" "A B C" + "E F G" "H I J" "K L A" "B C D" + "F G H" "I J K" "L A B" "C D E" + } { + execsql { INSERT INTO t1 VALUES($a, $b, $c, $d) } + } + + do_fts3query_test 6.$tn.1 t1 {b:G} + do_fts3query_test 6.$tn.2 t1 {b:G AND c:I} + do_fts3query_test 6.$tn.3 t1 {b:G NEAR c:I} + do_fts3query_test 6.$tn.4 t1 {a:C OR b:G OR c:K OR d:C} + + do_fts3query_test 6.$tn.5 t1 {a:G OR b:G} + + catchsql { COMMIT } +} + +foreach {tn create} { + 1 "fts4(x)" + 2 "fts4(x, order=DESC)" +} { + execsql [subst { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING $create; + }] + + foreach {x} { + "F E N O T K X V A X I E X A P G Q V H U" + "R V A E T C V Q N I E L O N U G J K L U" + "U Y I G W M V F J L X I D C H F P J Q B" + "S G D Z X R P G S S Y B K A S G A I L L" + "L S I C H T Z S R Q P R N K J X L F M J" + "C C C D P X B Z C M A D A C X S B T X V" + "W Y J M D R G V R K B X S A W R I T N C" + "P K L W T M S P O Y Y V V O E H Q A I R" + "C D Y I C Z F H J C O Y A Q F L S B D K" + "P G S C Y C Y V I M B D S Z D D Y W I E" + "Z K Z U E E S F Y X T U A L W O U J C Q" + "P A T Z S W L P L Q V Y Y I P W U X S S" + "I U I H U O F Z F R H R F T N D X A G M" + "N A B M S H K X S O Y D T X S B R Y H Z" + "L U D A S K I L S V Z J P U B E B Y H M" + } { + execsql { INSERT INTO t1 VALUES($x) } + } + + # Add extra documents to the database such that token "B" will be considered + # deferrable if considering the other tokens means that 2 or fewer documents + # will be loaded into memory. + # + fts3_make_deferrable t1 B 2 + + # B is not deferred in either of the first two tests below, since filtering + # on "M" or "D" returns 10 documents or so. But filtering on "M * D" only + # returns 2, so B is deferred in this case. + # + do_fts3query_test 7.$tn.1 t1 {"M B"} + do_fts3query_test 7.$tn.2 t1 {"B D"} + do_fts3query_test 7.$tn.3 -deferred B t1 {"M B D"} +} + +set sqlite_fts3_enable_parentheses $sfep +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aux1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aux1.test new file mode 100644 index 0000000000000000000000000000000000000000..1524d6d30f3616cb88030dad3f65f06aaf5c55bd --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3aux1.test @@ -0,0 +1,531 @@ +# 2011 January 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 regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3aux1 + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4; + INSERT INTO t1 VALUES('one two three four'); + INSERT INTO t1 VALUES('three four five six'); + INSERT INTO t1 VALUES('one three five seven'); + + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} { + five 2 2 four 2 2 one 2 2 seven 1 1 + six 1 1 three 3 3 two 1 1 +} + +do_execsql_test 1.2 { + INSERT INTO t1 VALUES('one one one three three three'); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} { + five 2 2 four 2 2 one 3 5 seven 1 1 + six 1 1 three 4 6 two 1 1 +} + +do_execsql_test 1.3.1 { DELETE FROM t1; } +do_execsql_test 1.3.2 { + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} + +do_execsql_test 1.4 { + INSERT INTO t1 VALUES('a b a b a b a'); + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + INSERT INTO t1 SELECT * FROM t1; + SELECT term, documents, occurrences FROM terms WHERE col = '*'; +} {a 256 1024 b 256 768} + +#------------------------------------------------------------------------- +# The following tests verify that the fts4aux module uses the full-text +# index to reduce the number of rows scanned in the following circumstances: +# +# * when there is equality comparison against the term column using the +# BINARY collating sequence. +# +# * when there is a range constraint on the term column using the BINARY +# collating sequence. +# +# And also uses the full-text index to optimize ORDER BY clauses of the +# form "ORDER BY term ASC" or equivalent. +# +# Test organization is: +# +# fts3aux1-2.1.*: equality constraints. +# fts3aux1-2.2.*: range constraints. +# fts3aux1-2.3.*: ORDER BY optimization. +# + +do_execsql_test 2.0 { + DROP TABLE t1; + DROP TABLE terms; + + CREATE VIRTUAL TABLE x1 USING fts4(x); + INSERT INTO x1(x1) VALUES('nodesize=24'); + CREATE VIRTUAL TABLE terms USING fts4aux(x1); + + CREATE VIEW terms_v AS + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + + INSERT INTO x1 VALUES('braes brag bragged bragger bragging'); + INSERT INTO x1 VALUES('brags braid braided braiding braids'); + INSERT INTO x1 VALUES('brain brainchild brained braining brains'); + INSERT INTO x1 VALUES('brainstem brainstems brainstorm brainstorms'); +} + +proc rec {varname x} { + global $varname + incr $varname + return 1 +} +db func rec rec + +# Use EQP to show that the WHERE expression "term='braid'" uses a different +# index number (1) than "+term='braid'" (0). +# +do_execsql_test 2.1.1.1 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term='braid' +} {/*SCAN terms VIRTUAL TABLE INDEX 1:*/} +do_execsql_test 2.1.1.2 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term='braid' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +# Now show that using "term='braid'" means the virtual table returns +# only 1 row to SQLite, but "+term='braid'" means all 19 are returned. +# +do_test 2.1.2.1 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='braid' } + set cnt +} {1} +do_test 2.1.2.2 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND +term='braid' } + set cnt +} {19} + +# Similar to the test immediately above, but using a term ("breakfast") that +# is not featured in the dataset. +# +do_test 2.1.3.1 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND term='breakfast' } + set cnt +} {0} +do_test 2.1.3.2 { + set cnt 0 + execsql { SELECT * FROM terms_v WHERE rec('cnt', term) AND +term='breakfast' } + set cnt +} {19} + +do_execsql_test 2.1.4.1 { SELECT * FROM terms_v WHERE term='braid' } {braid 1 1} +do_execsql_test 2.1.4.2 { SELECT * FROM terms_v WHERE +term='braid'} {braid 1 1} +do_execsql_test 2.1.4.3 { SELECT * FROM terms_v WHERE term='breakfast' } {} +do_execsql_test 2.1.4.4 { SELECT * FROM terms_v WHERE +term='breakfast' } {} + +do_execsql_test 2.1.4.5 { SELECT * FROM terms_v WHERE term='cba' } {} +do_execsql_test 2.1.4.6 { SELECT * FROM terms_v WHERE +term='cba' } {} +do_execsql_test 2.1.4.7 { SELECT * FROM terms_v WHERE term='abc' } {} +do_execsql_test 2.1.4.8 { SELECT * FROM terms_v WHERE +term='abc' } {} + +# Special case: term=NULL +# +do_execsql_test 2.1.5 { SELECT * FROM terms WHERE term=NULL } {} + +do_execsql_test 2.2.1.1 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term>'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 2:*/} +do_execsql_test 2.2.1.2 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term>'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_execsql_test 2.2.1.3 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term<'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 4:*/} +do_execsql_test 2.2.1.4 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term<'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_execsql_test 2.2.1.5 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE term BETWEEN 'brags' AND 'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 6:*/} +do_execsql_test 2.2.1.6 { + EXPLAIN QUERY PLAN SELECT * FROM terms WHERE +term BETWEEN 'brags' AND 'brain' +} {/*SCAN terms VIRTUAL TABLE INDEX 0:*/} + +do_test 2.2.2.1 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term>'brain' } + set cnt +} {18} +do_test 2.2.2.2 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term>'brain' } + set cnt +} {38} +do_execsql_test 2.2.2.3 { + SELECT term, documents, occurrences FROM terms_v WHERE term>'brain' +} { + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.4 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>'brain' +} { + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.5 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brain' +} { + brain 1 1 + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.6 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>='brain' +} { + brain 1 1 + brainchild 1 1 brained 1 1 braining 1 1 brains 1 1 + brainstem 1 1 brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} + +do_execsql_test 2.2.2.7 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='abc' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 + bragging 1 1 brags 1 1 braid 1 1 braided 1 1 + braiding 1 1 braids 1 1 brain 1 1 brainchild 1 1 + brained 1 1 braining 1 1 brains 1 1 brainstem 1 1 + brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} +do_execsql_test 2.2.2.8 { + SELECT term, documents, occurrences FROM terms_v WHERE +term>='abc' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 + bragging 1 1 brags 1 1 braid 1 1 braided 1 1 + braiding 1 1 braids 1 1 brain 1 1 brainchild 1 1 + brained 1 1 braining 1 1 brains 1 1 brainstem 1 1 + brainstems 1 1 brainstorm 1 1 brainstorms 1 1 +} + +do_execsql_test 2.2.2.9 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brainstorms' +} {brainstorms 1 1} +do_execsql_test 2.2.2.10 { + SELECT term, documents, occurrences FROM terms_v WHERE term>='brainstorms' +} {brainstorms 1 1} +do_execsql_test 2.2.2.11 { SELECT * FROM terms_v WHERE term>'brainstorms' } {} +do_execsql_test 2.2.2.12 { SELECT * FROM terms_v WHERE term>'brainstorms' } {} + +do_execsql_test 2.2.2.13 { SELECT * FROM terms_v WHERE term>'cba' } {} +do_execsql_test 2.2.2.14 { SELECT * FROM terms_v WHERE term>'cba' } {} + +do_test 2.2.3.1 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND term<'brain' } + set cnt +} {22} +do_test 2.2.3.2 { + set cnt 0 + execsql { SELECT * FROM terms WHERE rec('cnt', term) AND +term<'brain' } + set cnt +} {38} +do_execsql_test 2.2.3.3 { + SELECT term, documents, occurrences FROM terms_v WHERE term<'brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.3.4 { + SELECT term, documents, occurrences FROM terms_v WHERE +term<'brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.3.5 { + SELECT term, documents, occurrences FROM terms_v WHERE term<='brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 + brain 1 1 +} +do_execsql_test 2.2.3.6 { + SELECT term, documents, occurrences FROM terms_v WHERE +term<='brain' +} { + braes 1 1 brag 1 1 bragged 1 1 bragger 1 1 bragging 1 1 + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 + brain 1 1 +} + +do_test 2.2.4.1 { + set cnt 0 + execsql { + SELECT term, documents, occurrences FROM terms + WHERE rec('cnt', term) AND term BETWEEN 'brags' AND 'brain' + } + set cnt +} {12} +do_test 2.2.4.2 { + set cnt 0 + execsql { + SELECT term, documents, occurrences FROM terms + WHERE rec('cnt', term) AND +term BETWEEN 'brags' AND 'brain' + } + set cnt +} {38} +do_execsql_test 2.2.4.3 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND term BETWEEN 'brags' AND 'brain' +} { + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 brain 1 1 +} +do_execsql_test 2.2.4.4 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND +term BETWEEN 'brags' AND 'brain' +} { + brags 1 1 braid 1 1 braided 1 1 braiding 1 1 braids 1 1 brain 1 1 +} +do_execsql_test 2.2.4.5 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND term > 'brags' AND term < 'brain' +} { + braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} +do_execsql_test 2.2.4.6 { + SELECT term, documents, occurrences FROM terms_v + WHERE rec('cnt', term) AND +term > 'brags' AND +term < 'brain' +} { + braid 1 1 braided 1 1 braiding 1 1 braids 1 1 +} + +# Check that "ORDER BY term ASC" and equivalents are sorted by the +# virtual table implementation. Any other ORDER BY clause requires +# SQLite to sort results using a temporary b-tree. +# +foreach {tn sort orderby} { + 1 0 "ORDER BY term ASC" + 2 0 "ORDER BY term" + 3 1 "ORDER BY term DESC" + 4 1 "ORDER BY documents ASC" + 5 1 "ORDER BY documents" + 6 1 "ORDER BY documents DESC" + 7 1 "ORDER BY occurrences ASC" + 8 1 "ORDER BY occurrences" + 9 1 "ORDER BY occurrences DESC" +} { + + set res {SCAN terms VIRTUAL TABLE INDEX 0:} + if {$sort} { append res {*USE TEMP B-TREE FOR ORDER BY} } + set res "/*$res*/" + + set sql "SELECT * FROM terms $orderby" + do_execsql_test 2.3.1.$tn "EXPLAIN QUERY PLAN $sql" $res +} + +#------------------------------------------------------------------------- +# The next set of tests, fts3aux1-3.*, test error conditions in the +# fts4aux module. Except, fault injection testing (OOM, IO error etc.) is +# done in fts3fault2.test +# + +do_execsql_test 3.1.1 { + CREATE VIRTUAL TABLE t2 USING fts4; +} + +do_catchsql_test 3.1.2 { + CREATE VIRTUAL TABLE terms2 USING fts4aux; +} {1 {invalid arguments to fts4aux constructor}} +do_catchsql_test 3.1.3 { + CREATE VIRTUAL TABLE terms2 USING fts4aux(t2, t2); +} {1 {invalid arguments to fts4aux constructor}} + +do_execsql_test 3.2.1 { + CREATE VIRTUAL TABLE terms3 USING fts4aux(does_not_exist) +} +do_catchsql_test 3.2.2 { + SELECT * FROM terms3 +} {1 {SQL logic error}} +do_catchsql_test 3.2.3 { + SELECT * FROM terms3 WHERE term = 'abc' +} {1 {SQL logic error}} + +do_catchsql_test 3.3.1 { + INSERT INTO terms VALUES(1,2,3); +} {1 {table terms may not be modified}} +do_catchsql_test 3.3.2 { + DELETE FROM terms +} {1 {table terms may not be modified}} +do_catchsql_test 3.3.3 { + UPDATE terms set documents = documents+1; +} {1 {table terms may not be modified}} + + +#------------------------------------------------------------------------- +# The following tests - fts4aux-4.* - test that joins work with fts4aux +# tables. And that fts4aux provides reasonably sane cost information via +# xBestIndex to the query planner. +# +db close +forcedelete test.db +sqlite3 db test.db +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE x1 USING fts4(x); + CREATE VIRTUAL TABLE terms USING fts4aux(x1); + CREATE TABLE x2(y); + CREATE TABLE x3(y); + CREATE INDEX i1 ON x3(y); + + INSERT INTO x1 VALUES('a b c d e'); + INSERT INTO x1 VALUES('f g h i j'); + INSERT INTO x1 VALUES('k k l l a'); + + INSERT INTO x2 SELECT term FROM terms WHERE col = '*'; + INSERT INTO x3 SELECT term FROM terms WHERE col = '*'; +} + +proc do_plansql_test {tn sql r1 r2} { + do_eqp_test $tn.eqp $sql $r1 + do_execsql_test $tn $sql $r2 +} + +do_plansql_test 4.2 { + SELECT y FROM x2, terms WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN x2 + `--SCAN terms VIRTUAL TABLE INDEX 1: +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.3 { + SELECT y FROM terms, x2 WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN x2 + `--SCAN terms VIRTUAL TABLE INDEX 1: +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.4 { + SELECT y FROM x3, terms WHERE y = term AND col = '*' +} { + QUERY PLAN + |--SCAN terms VIRTUAL TABLE INDEX 0: + `--SEARCH x3 USING COVERING INDEX i1 (y=?) +} { + a b c d e f g h i j k l +} + +do_plansql_test 4.5 { + SELECT y FROM terms, x3 WHERE y = term AND occurrences>1 AND col = '*' +} { + QUERY PLAN + |--SCAN terms VIRTUAL TABLE INDEX 0: + `--SEARCH x3 USING COVERING INDEX i1 (y=?) +} { + a k l +} + +#------------------------------------------------------------------------- +# The following tests check that fts4aux can handle an fts table with an +# odd name (one that requires quoting for use in SQL statements). And that +# the argument to the fts4aux constructor is properly dequoted before use. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE "abc '!' def" USING fts4(x, y); + INSERT INTO "abc '!' def" VALUES('XX', 'YY'); + + CREATE VIRTUAL TABLE terms3 USING fts4aux("abc '!' def"); + SELECT * FROM terms3; +} {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} + +do_execsql_test 5.2 { + CREATE VIRTUAL TABLE "%%^^%%" USING fts4aux('abc ''!'' def'); + SELECT * FROM "%%^^%%"; +} {xx * 1 1 xx 0 1 1 yy * 1 1 yy 1 1 1} + +#------------------------------------------------------------------------- +# Test that we can create an fts4aux table in the temp database. +# +forcedelete test.db2 +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE ft1 USING fts4(x, y); + INSERT INTO ft1 VALUES('a b', 'c d'); + INSERT INTO ft1 VALUES('e e', 'c d'); + INSERT INTO ft1 VALUES('a a', 'b b'); + CREATE VIRTUAL TABLE temp.aux1 USING fts4aux(main, ft1); + SELECT * FROM aux1; +} { + a * 2 3 a 0 2 3 + b * 2 3 b 0 1 1 b 1 1 2 + c * 2 2 c 1 2 2 + d * 2 2 d 1 2 2 + e * 1 2 e 0 1 2 +} + +do_execsql_test 6.2 { + ATTACH 'test.db2' AS att; + CREATE VIRTUAL TABLE att.ft1 USING fts4(x, y); + INSERT INTO att.ft1 VALUES('v w', 'x y'); + INSERT INTO att.ft1 VALUES('z z', 'x y'); + INSERT INTO att.ft1 VALUES('v v', 'w w'); + CREATE VIRTUAL TABLE temp.aux2 USING fts4aux(att, ft1); + SELECT * FROM aux2; +} { + v * 2 3 v 0 2 3 + w * 2 3 w 0 1 1 w 1 1 2 + x * 2 2 x 1 2 2 + y * 2 2 y 1 2 2 + z * 1 2 z 0 1 2 +} + +foreach {tn q res1 res2} { + 1 { SELECT * FROM %%% WHERE term = 'a' } {a * 2 3 a 0 2 3} {} + 2 { SELECT * FROM %%% WHERE term = 'x' } {} {x * 2 2 x 1 2 2} + + 3 { SELECT * FROM %%% WHERE term >= 'y' } + {} {y * 2 2 y 1 2 2 z * 1 2 z 0 1 2} + + 4 { SELECT * FROM %%% WHERE term <= 'c' } + {a * 2 3 a 0 2 3 b * 2 3 b 0 1 1 b 1 1 2 c * 2 2 c 1 2 2} {} +} { + set sql1 [string map {%%% aux1} $q] + set sql2 [string map {%%% aux2} $q] + + do_execsql_test 7.$tn.1 $sql1 $res1 + do_execsql_test 7.$tn.2 $sql2 $res2 +} + +do_test 8.1 { + catchsql { CREATE VIRTUAL TABLE att.aux3 USING fts4aux(main, ft1) } +} {1 {invalid arguments to fts4aux constructor}} + +do_test 8.2 { + execsql {DETACH att} + catchsql { SELECT * FROM aux2 } +} {1 {SQL logic error}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3c.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3c.test new file mode 100644 index 0000000000000000000000000000000000000000..6b63264a680c0df378d394abebc020ffac3c4aa7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3c.test @@ -0,0 +1,255 @@ +# 2008 June 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. +# +#************************************************************************* +# This file exercises some new testing functions in the FTS3 module, +# and then uses them to do some basic tests that FTS3 is internally +# working as expected. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Utility function to check for the expected terms in the segment +# level/index. _all version does same but for entire index. +proc check_terms {test level index terms} { + set where "level = $level AND idx = $index" + do_test $test.terms [list fts3_terms t1 $where] $terms +} +proc check_terms_all {test terms} { + do_test $test.terms [list fts3_terms t1 1] $terms +} + +# Utility function to check for the expected doclist for the term in +# segment level/index. _all version does same for entire index. +proc check_doclist {test level index term doclist} { + set where "level = $level AND idx = $index" + do_test $test [list fts3_doclist t1 $term $where] $doclist +} +proc check_doclist_all {test term doclist} { + do_test $test [list fts3_doclist t1 $term 1] $doclist +} + +#************************************************************************* +# Test the segments resulting from straight-forward inserts. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); +} + +# Check for expected segments and expected matches. +do_test fts3c-1.0.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2} +do_test fts3c-1.0.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +# Check the specifics of the segments constructed. +# Logical view of entire index. +check_terms_all fts3c-1.0.1 {a is test that this was} +check_doclist_all fts3c-1.0.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3c-1.0.1.2 is {[1 0[1]] [3 0[1]]} +check_doclist_all fts3c-1.0.1.3 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3c-1.0.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.0.1.5 this {[1 0[0]] [3 0[0]]} +check_doclist_all fts3c-1.0.1.6 was {[2 0[1]]} + +# Segment 0,0 +check_terms fts3c-1.0.2 0 0 {a is test this} +check_doclist fts3c-1.0.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.0.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.0.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.0.2.4 0 0 this {[1 0[0]]} + +# Segment 0,1 +check_terms fts3c-1.0.3 0 1 {a test that was} +check_doclist fts3c-1.0.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.0.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.0.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.0.3.4 0 1 was {[2 0[1]]} + +# Segment 0,2 +check_terms fts3c-1.0.4 0 2 {a is test this} +check_doclist fts3c-1.0.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.0.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.0.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.0.4.4 0 2 this {[3 0[0]]} + +#************************************************************************* +# Test the segments resulting from inserts followed by a delete. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid = 1; +} + +do_test fts3c-1.1.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2 0 3} +do_test fts3c-1.1.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}} + +check_terms_all fts3c-1.1.1 {a is test that this was} +check_doclist_all fts3c-1.1.1.1 a {[2 0[2]] [3 0[2]]} +check_doclist_all fts3c-1.1.1.2 is {[3 0[1]]} +check_doclist_all fts3c-1.1.1.3 test {[2 0[3]] [3 0[3]]} +check_doclist_all fts3c-1.1.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.1.1.5 this {[3 0[0]]} +check_doclist_all fts3c-1.1.1.6 was {[2 0[1]]} + +check_terms fts3c-1.1.2 0 0 {a is test this} +check_doclist fts3c-1.1.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.1.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.1.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.1.2.4 0 0 this {[1 0[0]]} + +check_terms fts3c-1.1.3 0 1 {a test that was} +check_doclist fts3c-1.1.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.1.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.1.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.1.3.4 0 1 was {[2 0[1]]} + +check_terms fts3c-1.1.4 0 2 {a is test this} +check_doclist fts3c-1.1.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.1.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.1.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.1.4.4 0 2 this {[3 0[0]]} + +check_terms fts3c-1.1.5 0 3 {a is test this} +check_doclist fts3c-1.1.5.1 0 3 a {[1]} +check_doclist fts3c-1.1.5.2 0 3 is {[1]} +check_doclist fts3c-1.1.5.3 0 3 test {[1]} +check_doclist fts3c-1.1.5.4 0 3 this {[1]} + +#************************************************************************* +# Test results when all references to certain tokens are deleted. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); +} + +# Still 4 segments because 0,3 will contain deletes for docid 1 and 3. +do_test fts3c-1.2.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 0 2 0 3} +do_test fts3c-1.2.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3c-1.2.1 {a is test that this was} +check_doclist_all fts3c-1.2.1.1 a {[2 0[2]]} +check_doclist_all fts3c-1.2.1.2 is {} +check_doclist_all fts3c-1.2.1.3 test {[2 0[3]]} +check_doclist_all fts3c-1.2.1.4 that {[2 0[0]]} +check_doclist_all fts3c-1.2.1.5 this {} +check_doclist_all fts3c-1.2.1.6 was {[2 0[1]]} + +check_terms fts3c-1.2.2 0 0 {a is test this} +check_doclist fts3c-1.2.2.1 0 0 a {[1 0[2]]} +check_doclist fts3c-1.2.2.2 0 0 is {[1 0[1]]} +check_doclist fts3c-1.2.2.3 0 0 test {[1 0[3]]} +check_doclist fts3c-1.2.2.4 0 0 this {[1 0[0]]} + +check_terms fts3c-1.2.3 0 1 {a test that was} +check_doclist fts3c-1.2.3.1 0 1 a {[2 0[2]]} +check_doclist fts3c-1.2.3.2 0 1 test {[2 0[3]]} +check_doclist fts3c-1.2.3.3 0 1 that {[2 0[0]]} +check_doclist fts3c-1.2.3.4 0 1 was {[2 0[1]]} + +check_terms fts3c-1.2.4 0 2 {a is test this} +check_doclist fts3c-1.2.4.1 0 2 a {[3 0[2]]} +check_doclist fts3c-1.2.4.2 0 2 is {[3 0[1]]} +check_doclist fts3c-1.2.4.3 0 2 test {[3 0[3]]} +check_doclist fts3c-1.2.4.4 0 2 this {[3 0[0]]} + +check_terms fts3c-1.2.5 0 3 {a is test this} +check_doclist fts3c-1.2.5.1 0 3 a {[1] [3]} +check_doclist fts3c-1.2.5.2 0 3 is {[1] [3]} +check_doclist fts3c-1.2.5.3 0 3 test {[1] [3]} +check_doclist fts3c-1.2.5.4 0 3 this {[1] [3]} + +#************************************************************************* +# Test results when everything is optimized manually. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + DROP TABLE IF EXISTS t1old; + ALTER TABLE t1 RENAME TO t1old; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) SELECT docid, c FROM t1old; + DROP TABLE t1old; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3c-1.3.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3c-1.3.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3c-1.3.1 {a test that was} +check_doclist_all fts3c-1.3.1.1 a {[2 0[2]]} +check_doclist_all fts3c-1.3.1.2 test {[2 0[3]]} +check_doclist_all fts3c-1.3.1.3 that {[2 0[0]]} +check_doclist_all fts3c-1.3.1.4 was {[2 0[1]]} + +check_terms fts3c-1.3.2 0 0 {a test that was} +check_doclist fts3c-1.3.2.1 0 0 a {[2 0[2]]} +check_doclist fts3c-1.3.2.2 0 0 test {[2 0[3]]} +check_doclist fts3c-1.3.2.3 0 0 that {[2 0[0]]} +check_doclist fts3c-1.3.2.4 0 0 was {[2 0[1]]} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3comp1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3comp1.test new file mode 100644 index 0000000000000000000000000000000000000000..9f13aaa64ea59748dcad5ecd26c736ffda1be442 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3comp1.test @@ -0,0 +1,115 @@ +# 2011 January 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 regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3comp1 + +# Create a pretend compression system. +# +# Each time the [zip] function is called, an entry is added to the ::strings +# array mapping from an integer key to the string argument to zip. The key +# is returned. Later on, when the key is passed to [unzip], the original +# string is retrieved from the ::strings array and returned. +# +set next_x 0 +proc zip {x} { + incr ::next_x + set ::strings($::next_x) $x + return $::next_x +} +proc unzip {x} { + return $::strings($x) +} + +foreach {tn zip unzip} { + 1 zip unzip + 2 {z.i.p!!} {un "zip"} +} { + + set next_x 0 + catch {db close} + forcedelete test.db + sqlite3 db test.db + db func $zip zip + db func $unzip unzip + + # Create a table that uses zip/unzip. Check that content inserted into + # the table can be read back (using a full-scan query). Check that the + # underlying %_content table contains the compressed (integer) values. + # + do_execsql_test 1.$tn.0 " + CREATE VIRTUAL TABLE t1 USING fts4( + a, b, + compress='$zip', uncompress='$unzip' + ); + " + do_execsql_test 1.$tn.1 { + INSERT INTO t1 VALUES('one two three', 'two four six'); + SELECT a, b FROM t1; + } {{one two three} {two four six}} + do_execsql_test 1.$tn.2 { + SELECT c0a, c1b FROM t1_content; + } {1 2} + + # Insert another row and check that it can be read back. Also that the + # %_content table still contains all compressed content. This time, try + # full-text index and by-docid queries too. + # + do_execsql_test 1.$tn.3 { + INSERT INTO t1 VALUES('three six nine', 'four eight twelve'); + SELECT a, b FROM t1; + } {{one two three} {two four six} {three six nine} {four eight twelve}} + do_execsql_test 1.$tn.4 { + SELECT c0a, c1b FROM t1_content; + } {1 2 3 4} + + do_execsql_test 1.$tn.5 { + SELECT a, b FROM t1 WHERE docid = 2 + } {{three six nine} {four eight twelve}} + do_execsql_test 1.$tn.6 { + SELECT a, b FROM t1 WHERE t1 MATCH 'two' + } {{one two three} {two four six}} + + # Delete a row and check that the full-text index is correctly updated. + # Inspect the full-text index using an fts4aux table. + # + do_execsql_test 1.$tn.7 { + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + } { + eight 1 1 four 2 2 nine 1 1 one 1 1 + six 2 2 three 2 2 twelve 1 1 two 1 2 + } + do_execsql_test 1.$tn.8 { + DELETE FROM t1 WHERE docid = 1; + SELECT term, documents, occurrences FROM terms WHERE col = '*'; + } { + eight 1 1 four 1 1 nine 1 1 + six 1 1 three 1 1 twelve 1 1 + } + do_execsql_test 1.$tn.9 { SELECT c0a, c1b FROM t1_content } {3 4} +} + +# Test that is an error to specify just one of compress and uncompress. +# +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x, compress=zip) +} {1 {missing uncompress parameter in fts4 constructor}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t2 USING fts4(x, uncompress=unzip) +} {1 {missing compress parameter in fts4 constructor}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3conf.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3conf.test new file mode 100644 index 0000000000000000000000000000000000000000..cd48290195d8d517a9e723d2203763e51d2e7e89 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3conf.test @@ -0,0 +1,256 @@ +# 2011 April 25 +# +# 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. The +# focus of this script is testing the FTS3 module. + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3conf + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + + +proc fts3_integrity {tn db tbl} { + + if {[sqlite3_get_autocommit $db]==0} { + error "fts3_integrity does not work with an open transaction" + } + + set sql [db one {SELECT sql FROM sqlite_master WHERE name = $tbl}] + regexp -nocase {[^(]* using (.*)} $sql -> tail + set cols [list] + $db eval "PRAGMA table_info($tbl)" { + lappend cols $name + } + set cols [join [concat docid $cols] ,] + + $db eval [subst { + CREATE VIRTUAL TABLE fts3check USING fts4term($tbl); + CREATE VIRTUAL TABLE temp.fts3check2 USING $tail; + INSERT INTO temp.fts3check2($cols) SELECT docid, * FROM $tbl; + CREATE VIRTUAL TABLE temp.fts3check3 USING fts4term(fts3check2); + }] + + set m1 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check}] + set m2 [$db one {SELECT md5sum(term, docid, col, pos) FROM fts3check3}] + + $db eval { + DROP TABLE fts3check; + DROP TABLE temp.fts3check2; + DROP TABLE temp.fts3check3; + } + + uplevel [list do_test $tn [list set {} $m1] $m2] +} + +do_execsql_test 1.0.1 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1(rowid, x) VALUES(1, 'a b c d'); + INSERT INTO t1(rowid, x) VALUES(2, 'e f g h'); + + CREATE TABLE source(a, b); + INSERT INTO source VALUES(4, 'z'); + INSERT INTO source VALUES(2, 'y'); +} +db_save_and_close + +set T1 "INTO t1(rowid, x) VALUES(1, 'x')" +set T2 "INTO t1(rowid, x) SELECT * FROM source" + +set T3 "t1 SET docid = 2 WHERE docid = 1" +set T4 "t1 SET docid = CASE WHEN docid = 1 THEN 4 ELSE 3 END WHERE docid <=2" + +foreach {tn sql uses constraint data} [subst { + 1 "INSERT OR ROLLBACK $T1" 0 1 {{a b c d} {e f g h}} + 2 "INSERT OR ABORT $T1" 0 1 {{a b c d} {e f g h} {i j k l}} + 3 "INSERT OR FAIL $T1" 0 1 {{a b c d} {e f g h} {i j k l}} + 4 "INSERT OR IGNORE $T1" 0 0 {{a b c d} {e f g h} {i j k l}} + 5 "INSERT OR REPLACE $T1" 0 0 {x {e f g h} {i j k l}} + + 6 "INSERT OR ROLLBACK $T2" 1 1 {{a b c d} {e f g h}} + 7 "INSERT OR ABORT $T2" 1 1 {{a b c d} {e f g h} {i j k l}} + 8 "INSERT OR FAIL $T2" 1 1 {{a b c d} {e f g h} {i j k l} z} + 9 "INSERT OR IGNORE $T2" 1 0 {{a b c d} {e f g h} {i j k l} z} + 10 "INSERT OR REPLACE $T2" 1 0 {{a b c d} y {i j k l} z} + + 11 "UPDATE OR ROLLBACK $T3" 0 1 {{a b c d} {e f g h}} + 12 "UPDATE OR ABORT $T3" 0 1 {{a b c d} {e f g h} {i j k l}} + 13 "UPDATE OR FAIL $T3" 0 1 {{a b c d} {e f g h} {i j k l}} + 14 "UPDATE OR IGNORE $T3" 0 0 {{a b c d} {e f g h} {i j k l}} + 15 "UPDATE OR REPLACE $T3" 0 0 {{a b c d} {i j k l}} + + 16 "UPDATE OR ROLLBACK $T4" 1 1 {{a b c d} {e f g h}} + 17 "UPDATE OR ABORT $T4" 1 1 {{a b c d} {e f g h} {i j k l}} + 18 "UPDATE OR FAIL $T4" 1 1 {{e f g h} {i j k l} {a b c d}} + 19 "UPDATE OR IGNORE $T4" 1 0 {{e f g h} {i j k l} {a b c d}} + 20 "UPDATE OR REPLACE $T4" 1 0 {{e f g h} {a b c d}} +}] { + db_restore_and_reopen + execsql { + BEGIN; + INSERT INTO t1(rowid, x) VALUES(3, 'i j k l'); + } + set R(0) {0 {}} + set R(1) {1 {constraint failed}} + do_catchsql_test 1.$tn.1 $sql $R($constraint) + do_catchsql_test 1.$tn.2 { SELECT * FROM t1 } [list 0 $data] + catchsql COMMIT + + fts3_integrity 1.$tn.3 db t1 + + do_test 1.$tn.4 [list sql_uses_stmt db $sql] $uses +} + +do_execsql_test 2.1.1 { + DELETE FROM t1; + BEGIN; + INSERT INTO t1 VALUES('a b c'); + SAVEPOINT a; + INSERT INTO t1 VALUES('x y z'); + ROLLBACK TO a; + COMMIT; +} +fts3_integrity 2.1.2 db t1 + +do_catchsql_test 2.2.1 { + DELETE FROM t1; + BEGIN; + INSERT INTO t1(docid, x) VALUES(0, 'a b c'); + INSERT INTO t1(docid, x) VALUES(1, 'a b c'); + REPLACE INTO t1(docid, x) VALUES('zero', 'd e f'); +} {1 {datatype mismatch}} +do_execsql_test 2.2.2 { COMMIT } +do_execsql_test 2.2.3 { SELECT * FROM t1 } {{a b c} {a b c}} +fts3_integrity 2.2.4 db t1 + +if {$tcl_platform(byteOrder)=="littleEndian"} { + do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t3 USING fts4; + REPLACE INTO t3(docid, content) VALUES (1, 'one two'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0100000002000000'} + + do_execsql_test 3.2 { + REPLACE INTO t3(docid, content) VALUES (2, 'one two three four'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'four' + } {X'0200000003000000'} + + do_execsql_test 3.3 { + REPLACE INTO t3(docid, content) VALUES (1, 'one two three four five six'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0200000005000000'} + + do_execsql_test 3.4 { + UPDATE OR REPLACE t3 SET docid = 2 WHERE docid=1; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0100000006000000'} + + do_execsql_test 3.5 { + UPDATE OR REPLACE t3 SET docid = 3 WHERE docid=2; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'six' + } {X'0100000006000000'} + + do_execsql_test 3.6 { + REPLACE INTO t3(docid, content) VALUES (3, 'one two'); + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0100000002000000'} + + do_execsql_test 3.7 { + REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four'); + REPLACE INTO t3(docid, content) VALUES(NULL,'one two three four five six'); + SELECT docid FROM t3; + } {3 4 5} + + do_execsql_test 3.8 { + UPDATE OR REPLACE t3 SET docid = 5, content='three four' WHERE docid = 4; + SELECT quote(matchinfo(t3, 'na')) FROM t3 WHERE t3 MATCH 'one' + } {X'0200000002000000'} +} + +#------------------------------------------------------------------------- +# Test that the xSavepoint is invoked correctly if the first write +# operation within a transaction is to a virtual table. +# +do_catchsql_test 4.1.1 { + CREATE VIRTUAL TABLE t0 USING fts4; + BEGIN; + INSERT INTO t0(rowid, content) SELECT + 1, 'abc' UNION ALL SELECT + 2, 'def' UNION ALL SELECT + 1, 'ghi'; +} {1 {constraint failed}} +do_execsql_test 4.1.2 { + COMMIT; +} +do_execsql_test 4.1.3 { + SELECT * FROM t0 WHERE t0 MATCH 'abc'; + INSERT INTO t0(t0) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} + +do_execsql_test 4.2.1 { + CREATE VIRTUAL TABLE t01 USING fts4; + BEGIN; + SAVEPOINT abc; + INSERT INTO t01 VALUES('a b c'); + ROLLBACK TO abc; + COMMIT; +} +do_execsql_test 4.2.2 { + SELECT * FROM t01 WHERE t01 MATCH 'b'; + INSERT INTO t01(t01) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} + +do_execsql_test 4.3.1 { + CREATE VIRTUAL TABLE t02 USING fts4; + INSERT INTO t01 VALUES('1 1 1'); + INSERT INTO t02 VALUES('2 2 2'); + BEGIN; + SAVEPOINT abc; + INSERT INTO t01 VALUES('a b c'); + INSERT INTO t02 VALUES('a b c'); + ROLLBACK TO abc; + COMMIT; +} +do_execsql_test 4.3.2 { + SELECT * FROM t01 WHERE t01 MATCH 'b'; + INSERT INTO t01(t01) VALUES('integrity-check'); +} {} + +do_execsql_test 4.4.1 { + CREATE TABLE A(ID INTEGER PRIMARY KEY, AnotherID INTEGER, Notes TEXT); + CREATE VIRTUAL TABLE AFTS USING FTS4 (Notes); + CREATE TRIGGER A_DeleteTrigger AFTER DELETE ON A FOR EACH ROW BEGIN + DELETE FROM AFTS WHERE rowid=OLD.ID; + END; + CREATE TABLE B(ID INTEGER PRIMARY KEY,Notes TEXT); + CREATE VIRTUAL TABLE BFTS USING FTS3 (Notes); + CREATE TRIGGER B_DeleteTrigger AFTER DELETE ON B FOR EACH ROW BEGIN + DELETE FROM BFTS WHERE rowid=OLD.ID; + END; +} + +do_execsql_test 4.4.2 { + BEGIN TRANSACTION; + DELETE FROM A WHERE AnotherID=1; + DELETE FROM B WHERE ID=1; + COMMIT; +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt.test new file mode 100644 index 0000000000000000000000000000000000000000..69d5030be91eedd4ff240f002049d8dbffa0ef05 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt.test @@ -0,0 +1,234 @@ +# 2010 October 27 +# +# 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. +# +#*********************************************************************** +# Test that the FTS3 extension does not crash when it encounters a +# corrupt data structure on disk. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts3corrupt + + +# Test that a doclist with a length field that indicates that the doclist +# extends past the end of the node on which it resides is correctly identified +# as database corruption. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1 VALUES('hello'); +} {} +do_test fts3corrupt-1.1 { + set blob [db one {SELECT root from t1_segdir}] + set blob [binary format a7ca* $blob 24 [string range $blob 8 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_test fts3corrupt-1.2 { + foreach w {a b c d e f g h i j k l m n o} { + execsql { INSERT INTO t1 VALUES($w) } + } +} {} +do_catchsql_test 1.3 { + INSERT INTO t1 VALUES('world'); +} {1 {database disk image is malformed}} +do_test 1.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB +do_execsql_test 1.4 { + DROP TABLE t1; +} + +# This block of tests checks that corruption is correctly detected if the +# length field of a term on a leaf node indicates that the term extends past +# the end of the node on which it resides. There are two cases: +# +# 1. The first term on the node. +# 2. The second or subsequent term on the node (prefix compressed term). +# +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + BEGIN; + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('hello'); + COMMIT; +} {} +do_test fts3corrupt-2.1 { + set blob [db one {SELECT root from t1_segdir}] + set blob [binary format a*a* "\x00\x7F" [string range $blob 2 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_catchsql_test 2.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'hello' +} {1 {database disk image is malformed}} +do_test 2.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +do_execsql_test 3.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3; + BEGIN; + INSERT INTO t1 VALUES('hello'); + INSERT INTO t1 VALUES('world'); + COMMIT; +} {} +do_test fts3corrupt-3.1 { + set blob [db one {SELECT quote(root) from t1_segdir}] + set blob [binary format a11a*a* $blob "\x7F" [string range $blob 12 end]] + execsql { UPDATE t1_segdir SET root = $blob } +} {} +do_catchsql_test 3.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'world' +} {1 {database disk image is malformed}} +do_test 3.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + + +do_execsql_test 4.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1(t1) VALUES('nodesize=24'); +} +do_test fts3corrupt-4.1 { + execsql BEGIN + foreach s { + "amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm" + "ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul" + "amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu" + "apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou" + "aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt" + } { + execsql { INSERT INTO t1 VALUES($s) } + } + execsql COMMIT +} {} + +do_catchsql_test 4.2 { + UPDATE t1_segdir SET root = X'FFFFFFFFFFFFFFFF'; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; +} {1 {database disk image is malformed}} +do_test 4.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +set blob [binary format cca*cca*cca*cca*cca*cca*cca*cca*cca*cca*a* \ + 22 120 [string repeat a 120] \ + 22 120 [string repeat b 120] \ + 22 120 [string repeat c 120] \ + 22 120 [string repeat d 120] \ + 22 120 [string repeat e 120] \ + 22 120 [string repeat f 120] \ + 22 120 [string repeat g 120] \ + 22 120 [string repeat h 120] \ + 22 120 [string repeat i 120] \ + 22 120 [string repeat j 120] \ + "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF" +] + +do_catchsql_test 4.3 { + UPDATE t1_segdir SET root = $blob; + SELECT rowid FROM t1 WHERE t1 MATCH 'world'; +} {1 {database disk image is malformed}} +do_test 4.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +# Test a special kind of corruption, where the %_stat table contains +# an invalid entry. At one point this could lead to a division-by-zero +# error in fts4. +# +do_execsql_test 5.0 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4; +} +do_test 5.1 { + db func nn nn + execsql BEGIN + execsql { INSERT INTO t1 VALUES('one') } + execsql { INSERT INTO t1 VALUES('two') } + execsql { INSERT INTO t1 VALUES('three') } + execsql { INSERT INTO t1 VALUES('four') } + execsql COMMIT +} {} +do_catchsql_test 5.2 { + UPDATE t1_stat SET value = X'0000'; + SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*'; +} {1 {database disk image is malformed}} +do_test 5.2.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB +do_catchsql_test 5.3 { + UPDATE t1_stat SET value = NULL; + SELECT matchinfo(t1, 'nxa') FROM t1 WHERE t1 MATCH 't*'; +} {1 {database disk image is malformed}} +do_test 5.3.1 { sqlite3_extended_errcode db } SQLITE_CORRUPT_VTAB + +# 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467 +# bug1 +db close +sqlite3 db :memory: +do_catchsql_test 6.10 { + CREATE VIRTUAL TABLE f using fts3(a,b); + CREATE TABLE f_stat(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f_segdir VALUES (2000, 0,0,0, '16', ''); + INSERT INTO f_segdir VALUES (1999, 0,0,0, '0 18', + x'000131030102000103323334050101010200'); + INSERT INTO f_segments (blockid) values (16); + INSERT INTO f_segments values (0, x''); + INSERT INTO f_stat VALUES (1,x'cf0f01'); + INSERT INTO f(f) VALUES ('merge=1'); +} {1 {database disk image is malformed}} + +# 2020-03-02 https://bugs.chromium.org/p/chromium/issues/detail?id=1057441 +# The ticket complains of use of an uninitialized value. That part is harmless. +# The only reason to fix this is the failure to detect a subtly corrupt +# inverted index. +# +reset_db +do_catchsql_test 7.10 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + INSERT INTO f_segdir VALUES (0,0,1,0,'0 0',x'01010101020101'); + SELECT matchinfo( f , 'pcx') FROM f WHERE b MATCH x'c533'; +} {1 {database disk image is malformed}} + +reset_db +sqlite3_fts3_may_be_corrupt 1 +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE f USING fts3(a); + INSERT INTO f(f) VALUES('nodesize=24'); + BEGIN; + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + COMMIT; + BEGIN; + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz0123456789'); + + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + INSERT INTO f VALUES('abcdefghijklmnopqrstuvwxyz012345678X'); + COMMIT; + + SELECT count(*) FROM f_segments; +} {4} + +do_execsql_test 8.2 { + UPDATE f_segments SET block = ( + SELECT block FROM f_segments WHERE blockid=1 + ) WHERE blockid=2 +} + +do_catchsql_test 8.3 { + INSERT INTO f(f) VALUES('merge=2,2'); +} {1 {database disk image is malformed}} +sqlite3_fts3_may_be_corrupt 0 + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt6.test new file mode 100644 index 0000000000000000000000000000000000000000..a3c5fd8da6936d35004dac43acab7e97ce7740a0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3corrupt6.test @@ -0,0 +1,79 @@ +# 2020 June 8 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts3corrupt6 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::saved_sqlite_fts3_enable_parentheses $::sqlite_fts3_enable_parentheses +set sqlite_fts3_enable_parentheses 1 +sqlite3_fts3_may_be_corrupt 1 +database_may_be_corrupt + +do_execsql_test 1.0 { + BEGIN TRANSACTION; + CREATE TABLE t_content(col0 INTEGER); + PRAGMA writable_schema=ON; + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0_content VALUES(0,NULL,NULL,NULL,NULL); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'000131030102000103323334050101010200000461616161050101020200000462626262050101030200'); + COMMIT; +} + +do_execsql_test 1.1 { + SELECT 0+matchinfo(t0,'yxyyxy') FROM t0 WHERE t0 MATCH CAST( x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d' AS TEXT); +} {0} + +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE t1 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t1_content VALUES(0,NULL,NULL,NULL,NULL); + INSERT INTO t1_segdir VALUES(0,0,0,0,'0 42',X'000131030102000103323334050101010200000461616161050101020200000462626262050101030200'); +} + +do_execsql_test 1.3 { + SELECT 42+matchinfo(t1,'yxyyxy') FROM t1 WHERE t1 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; +} {42} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t0 USING fts3(a); + INSERT INTO t0_segdir VALUES(0,0,0,0,'0 42',X'000131030782000103323334050100fff200010461616161050101020200000462626262050101030200'); +} +do_execsql_test 2.1 { + SELECT count(*) FROM t0 WHERE t0 MATCH '(1 NEAR 1) AND (aaaa OR 1)'; +} 1 + +#------------------------------------------------------------------------- +reset_db +breakpoint +do_catchsql_test 3.0 { + CREATE VIRTUAL TABLE main.Table0 USING fts3(); + INSERT INTO Table0 VALUES (1), (printf('%8.1280000X') ), (1), (printf('%8.1280000X') ), (1) ; + INSERT INTO Table0 VALUES (0), (printf('%8.1280000X%8.1280000X') ), (1), (printf('%1280000.1280000X%#1280000.1280000E%8.1280000X') ), (1) ; + INSERT INTO Table0 VALUES (1) ; + UPDATE Table0_segdir SET start_block = 1; + INSERT INTO Table0 VALUES (1) ; + INSERT INTO Table0(Table0) VALUES('merge=6,8'); +} {1 {database disk image is malformed}} + +set sqlite_fts3_enable_parentheses $saved_sqlite_fts3_enable_parentheses +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3cov.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3cov.test new file mode 100644 index 0000000000000000000000000000000000000000..5d838365764ed246a046aa6d260f0d2f030b9755 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3cov.test @@ -0,0 +1,434 @@ +# 2009 December 03 +# +# 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. +# +#*********************************************************************** +# +# The tests in this file are structural coverage tests for FTS3. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If this build does not include FTS3, skip the tests in this file. +# +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl +source $testdir/malloc_common.tcl + +set DO_MALLOC_TEST 0 +set testprefix fts3cov + +#-------------------------------------------------------------------------- +# When it first needs to read a block from the %_segments table, the FTS3 +# module compiles an SQL statement for that purpose. The statement is +# stored and reused each subsequent time a block is read. This test case +# tests the effects of an OOM error occuring while compiling the statement. +# +# Similarly, when FTS3 first needs to scan through a set of segment leaves +# to find a set of documents that matches a term, it allocates a string +# containing the text of the required SQL, and compiles one or more +# statements to traverse the leaves. This test case tests that OOM errors +# that occur while allocating this string and statement are handled correctly +# also. +# +do_test fts3cov-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1(t1) VALUES('nodesize=24'); + BEGIN; + INSERT INTO t1 VALUES('Is the night chilly and dark?'); + INSERT INTO t1 VALUES('The night is chilly, but not dark.'); + INSERT INTO t1 VALUES('The thin gray cloud is spread on high,'); + INSERT INTO t1 VALUES('It covers but not hides the sky.'); + COMMIT; + SELECT count(*)>0 FROM t1_segments; + } +} {1} + +set DO_MALLOC_TEST 1 +do_restart_select_test fts3cov-1.2 { + SELECT docid FROM t1 WHERE t1 MATCH 'chilly'; +} {1 2} +set DO_MALLOC_TEST 0 + +#-------------------------------------------------------------------------- +# When querying the full-text index, if an expected internal node block is +# missing from the %_segments table, or if a NULL value is stored in the +# %_segments table instead of a binary blob, database corruption should be +# reported. +# +# Even with tiny 24 byte nodes, it takes a fair bit of data to produce a +# segment b-tree that uses the %_segments table to store internal nodes. +# +do_test fts3cov-2.1 { + execsql { + INSERT INTO t1(t1) VALUES('nodesize=24'); + BEGIN; + INSERT INTO t1 VALUES('The moon is behind, and at the full;'); + INSERT INTO t1 VALUES('And yet she looks both small and dull.'); + INSERT INTO t1 VALUES('The night is chill, the cloud is gray:'); + INSERT INTO t1 VALUES('''T is a month before the month of May,'); + INSERT INTO t1 VALUES('And the Spring comes slowly up this way.'); + INSERT INTO t1 VALUES('The lovely lady, Christabel,'); + INSERT INTO t1 VALUES('Whom her father loves so well,'); + INSERT INTO t1 VALUES('What makes her in the wood so late,'); + INSERT INTO t1 VALUES('A furlong from the castle gate?'); + INSERT INTO t1 VALUES('She had dreams all yesternight'); + INSERT INTO t1 VALUES('Of her own betrothed knight;'); + INSERT INTO t1 VALUES('And she in the midnight wood will pray'); + INSERT INTO t1 VALUES('For the weal of her lover that''s far away.'); + COMMIT; + } + execsql { + INSERT INTO t1(t1) VALUES('optimize'); + SELECT substr(hex(root), 1, 2) FROM t1_segdir; + } +} {03} + +# Test the "missing entry" case: +sqlite3_db_config db DEFENSIVE 0 +do_test fts3cov-2.2 { + set root [db one {SELECT root FROM t1_segdir}] + read_fts3varint [string range $root 1 end] left_child + execsql { DELETE FROM t1_segments WHERE blockid = $left_child } +} {} +do_error_test fts3cov-2.3 { + SELECT * FROM t1 WHERE t1 MATCH 'c*' +} {database disk image is malformed} + +# Test the "replaced with NULL" case: +do_test fts3cov-2.4 { + execsql { INSERT INTO t1_segments VALUES($left_child, NULL) } +} {} +do_error_test fts3cov-2.5 { + SELECT * FROM t1 WHERE t1 MATCH 'cloud' +} {database disk image is malformed} + +#-------------------------------------------------------------------------- +# The following tests are to test the effects of OOM errors while storing +# terms in the pending-hash table. Specifically, while creating doclist +# blobs to store in the table. More specifically, to test OOM errors while +# appending column numbers to doclists. For example, if a doclist consists +# of: +# +# 0x01 +# +# The following tests check that malloc errors encountered while appending +# the "0x01 " data to the dynamically growable blob used to +# accumulate the doclist in memory are handled correctly. +# +do_test fts3cov-3.1 { + set cols [list] + set vals [list] + for {set i 0} {$i < 120} {incr i} { + lappend cols "col$i" + lappend vals "'word'" + } + execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])" +} {} +set DO_MALLOC_TEST 1 +do_write_test fts3cov-3.2 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(1, [join $vals ,]) +" +do_write_test fts3cov-3.3 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(200, [join $vals ,]) +" +do_write_test fts3cov-3.4 t2_content " + INSERT INTO t2(docid, [join $cols ,]) VALUES(60000, [join $vals ,]) +" + +#------------------------------------------------------------------------- +# If too much data accumulates in the pending-terms hash table, it is +# flushed to the database automatically, even if the transaction has not +# finished. The following tests check the effects of encountering an OOM +# while doing this. +# +do_test fts3cov-4.1 { + execsql { + CREATE VIRTUAL TABLE t3 USING fts3(x); + INSERT INTO t3(t3) VALUES('nodesize=24'); + INSERT INTO t3(t3) VALUES('maxpending=100'); + } +} {} +set DO_MALLOC_TEST 1 +do_write_test fts3cov-4.2 t3_content { + INSERT INTO t3(docid, x) + SELECT 1, 'Then Christabel stretched forth her hand,' UNION ALL + SELECT 3, 'And comforted fair Geraldine:' UNION ALL + SELECT 4, '''O well, bright dame, may you command' UNION ALL + SELECT 5, 'The service of Sir Leoline;' UNION ALL + SELECT 2, 'And gladly our stout chivalry' UNION ALL + SELECT 7, 'Will he send forth, and friends withal,' UNION ALL + SELECT 8, 'To guide and guard you safe and free' UNION ALL + SELECT 6, 'Home to your noble father''s hall.''' +} + +#------------------------------------------------------------------------- +# When building the internal tree structure for each segment b-tree, FTS3 +# assumes that the content of each internal node will be less than +# $nodesize bytes, where $nodesize is the advisory node size. If this turns +# out to be untrue, then an extra buffer must be malloc'd for each term. +# This test case tests these paths and the effects of said mallocs failing +# by inserting insert a document with some fairly large terms into a +# full-text table with a very small node-size. +# +# Test this handling of large terms in three contexts: +# +# 1. When flushing the pending-terms table. +# 2. When optimizing the data structures using the INSERT syntax. +# 2. When optimizing the data structures using the deprecated SELECT syntax. +# +do_test fts3cov-5.1 { + execsql { + CREATE VIRTUAL TABLE t4 USING fts3(x); + INSERT INTO t4(t4) VALUES('nodesize=24'); + } +} {} +set DO_MALLOC_TEST 1 + +# Test when flushing pending-terms table. +do_write_test fts3cov-5.2 t4_content { + INSERT INTO t4 + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeAA' UNION ALL + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeBB' UNION ALL + SELECT 'ItisanancientMarinerAndhestoppethoneofthreeCC' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstAA' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstBB' UNION ALL + SELECT 'BythylonggreybeardandglitteringeyeNowwhereforestoppstCC' +} + +# Test when optimizing via INSERT. +do_test fts3cov-5.3 { execsql { INSERT INTO t4 VALUES('extra!') } } {} +do_write_test fts3cov-5.2 t4_segments { INSERT INTO t4(t4) VALUES('optimize') } + +# Test when optimizing via SELECT. +do_test fts3cov-5.5 { execsql { INSERT INTO t4 VALUES('more extra!') } } {} +do_write_test fts3cov-5.6 t4_segments { + SELECT * FROM (SELECT optimize(t4) FROM t4 LIMIT 1) + EXCEPT SELECT 'Index optimized' +} + +#------------------------------------------------------------------------- +# When merging all segments at a given level to create a single segment +# at level+1, FTS3 runs a query of the form: +# +# SELECT count(*) FROM %_segdir WHERE level = ? +# +# The query is compiled the first time this operation is required and +# reused thereafter. This test aims to test the effects of an OOM while +# preparing and executing this query for the first time. +# +# Then, keep inserting rows into the table so that the effects of an OOM +# while re-executing the same query can also be tested. +# +do_test fts3cov-6.1 { + execsql { CREATE VIRTUAL TABLE t5 USING fts3(x) } + for {set i 0} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" } + execsql { SELECT count(*) FROM t5_segdir } +} {16} + +# First time. +db close +sqlite3 db test.db +do_write_test fts3cov-6.2 t5_content { + INSERT INTO t5 VALUES('segment number 16!'); +} + +# Second time. +do_test fts3cov-6.3 { + for {set i 1} {$i<16} {incr i} { execsql "INSERT INTO t5 VALUES('term$i')" } + execsql { SELECT count(*) FROM t5_segdir } +} {17} +do_write_test fts3cov-6.4 t5_content { + INSERT INTO t5 VALUES('segment number 16!'); +} + +#------------------------------------------------------------------------- +# Update the docid of a row. Test this in two scenarios: +# +# 1. When the row being updated is the only row in the table. +# 2. When it is not. +# +# The two cases above take different paths because in case 1 all data +# structures can simply be emptied before inserting the new row record. +# In case 2, the data structures actually have to be updated. +# +do_test fts3cov-7.1 { + execsql { + CREATE VIRTUAL TABLE t7 USING fts3(a, b, c); + INSERT INTO t7 VALUES('A', 'B', 'C'); + UPDATE t7 SET docid = 5; + SELECT docid, * FROM t7; + } +} {5 A B C} +do_test fts3cov-7.2 { + execsql { + INSERT INTO t7 VALUES('D', 'E', 'F'); + UPDATE t7 SET docid = 1 WHERE docid = 6; + SELECT docid, * FROM t7; + } +} {1 D E F 5 A B C} + +#------------------------------------------------------------------------- +# If a set of documents are modified within a transaction, the +# pending-terms table must be flushed each time a document with a docid +# less than or equal to the previous docid is modified. +# +# This test checks the effects of an OOM error occuring when the +# pending-terms table is flushed for this reason as part of a DELETE +# statement. +# +do_malloc_test fts3cov-8 -sqlprep { + BEGIN; + CREATE VIRTUAL TABLE t8 USING fts3; + INSERT INTO t8 VALUES('the output of each batch run'); + INSERT INTO t8 VALUES('(possibly a day''s work)'); + INSERT INTO t8 VALUES('was written to two separate disks'); + COMMIT; +} -sqlbody { + BEGIN; + DELETE FROM t8 WHERE rowid = 3; + DELETE FROM t8 WHERE rowid = 2; + DELETE FROM t8 WHERE rowid = 1; + COMMIT; +} + +#------------------------------------------------------------------------- +# Test some branches in the code that handles "special" inserts like: +# +# INSERT INTO t1(t1) VALUES('optimize'); +# +# Also test that an optimize (INSERT method) works on an empty table. +# +set DO_MALLOC_TEST 0 +do_test fts3cov-9.1 { + execsql { CREATE VIRTUAL TABLE xx USING fts3 } +} {} +do_error_test fts3cov-9.2 { + INSERT INTO xx(xx) VALUES('optimise'); -- British spelling +} {SQL logic error} +do_error_test fts3cov-9.3 { + INSERT INTO xx(xx) VALUES('short'); +} {SQL logic error} +do_error_test fts3cov-9.4 { + INSERT INTO xx(xx) VALUES('waytoolongtobecorrect'); +} {SQL logic error} +do_test fts3cov-9.5 { + execsql { INSERT INTO xx(xx) VALUES('optimize') } +} {} + +#------------------------------------------------------------------------- +# Test that a table can be optimized in the middle of a transaction when +# the pending-terms table is non-empty. This case involves some extra +# branches because data must be read not only from the database, but +# also from the pending-terms table. +# +do_malloc_test fts3cov-10 -sqlprep { + CREATE VIRTUAL TABLE t10 USING fts3; + INSERT INTO t10 VALUES('Optimising images for the web is a tricky business'); + BEGIN; + INSERT INTO t10 VALUES('You have to get the right balance between'); +} -sqlbody { + INSERT INTO t10(t10) VALUES('optimize'); +} + +#------------------------------------------------------------------------- +# Test a full-text query for a term that was once in the index, but is +# no longer. +# +do_test fts3cov-11.1 { + execsql { + CREATE VIRTUAL TABLE xx USING fts3; + INSERT INTO xx VALUES('one two three'); + INSERT INTO xx VALUES('four five six'); + DELETE FROM xx WHERE docid = 1; + } + execsql { SELECT * FROM xx WHERE xx MATCH 'two' } +} {} + + +do_malloc_test fts3cov-12 -sqlprep { + CREATE VIRTUAL TABLE t12 USING fts3; + INSERT INTO t12 VALUES('is one of the two togther'); + BEGIN; + INSERT INTO t12 VALUES('one which was appropriate at the time'); +} -sqlbody { + SELECT * FROM t12 WHERE t12 MATCH 'one' +} + +do_malloc_test fts3cov-13 -sqlprep { + PRAGMA encoding = 'UTF-16'; + CREATE VIRTUAL TABLE t13 USING fts3; + INSERT INTO t13 VALUES('two scalar functions'); + INSERT INTO t13 VALUES('scalar two functions'); + INSERT INTO t13 VALUES('functions scalar two'); +} -sqlbody { + SELECT snippet(t13, '%%', '%%', '#') FROM t13 WHERE t13 MATCH 'two'; + SELECT snippet(t13, '%%', '%%') FROM t13 WHERE t13 MATCH 'two'; + SELECT snippet(t13, '%%') FROM t13 WHERE t13 MATCH 'two'; +} + +do_execsql_test 14.0 { + CREATE VIRTUAL TABLE t14 USING fts4(a, b); + INSERT INTO t14 VALUES('one two three', 'one three four'); + INSERT INTO t14 VALUES('a b c', 'd e a'); +} +do_execsql_test 14.1 { + SELECT rowid FROM t14 WHERE t14 MATCH '"one two three"' +} {1} +do_execsql_test 14.2 { + SELECT rowid FROM t14 WHERE t14 MATCH '"one four"' +} {} +do_execsql_test 14.3 { + SELECT rowid FROM t14 WHERE t14 MATCH '"e a"' +} {2} +do_execsql_test 14.5 { + SELECT rowid FROM t14 WHERE t14 MATCH '"e b"' +} {} +do_catchsql_test 14.6 { + SELECT rowid FROM t14 WHERE rowid MATCH 'one' +} {1 {unable to use function MATCH in the requested context}} +do_catchsql_test 14.7 { + SELECT rowid FROM t14 WHERE docid MATCH 'one' +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 15.0 { + CREATE VIRTUAL TABLE t15 USING fts4(a, b, c); + INSERT INTO t15 VALUES('abc def ghi', 'abc2 def2 ghi2', 'abc3 def3 ghi3'); + INSERT INTO t15 VALUES('abc2 def2 ghi2', 'abc2 def2 ghi2', 'abc def3 ghi3'); +} +do_execsql_test 15.1 { + SELECT rowid FROM t15 WHERE t15 MATCH '"abc* def2"' +} {1 2} + +# Test a corruption case. +# +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 16.1 { + CREATE VIRTUAL TABLE t16 USING fts4; + INSERT INTO t16 VALUES('theoretical work to examine the relationship'); + INSERT INTO t16 VALUES('solution of our problems on the invisible'); + DELETE FROM t16_content WHERE rowid = 2; +} +do_catchsql_test 16.2 { + SELECT * FROM t16 WHERE t16 MATCH 'invisible' +} {1 {database disk image is malformed}} + +# And another corruption test case. +# +do_execsql_test 17.1 { + CREATE VIRTUAL TABLE t17 USING fts4; + INSERT INTO t17(content) VALUES('one one one'); + UPDATE t17_segdir SET root = X'00036F6E65FFFFFFFFFFFFFFFFFFFFFF02030300' +} {} +do_catchsql_test 17.2 { + SELECT * FROM t17 WHERE t17 MATCH 'one' +} {1 {database disk image is malformed}} + + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3d.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3d.test new file mode 100644 index 0000000000000000000000000000000000000000..b0547ce7abc00d710a54967239587eb84b988886 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3d.test @@ -0,0 +1,372 @@ +# 2008 June 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing the FTS3 module's optimize() function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Utility function to check for the expected terms in the segment +# level/index. _all version does same but for entire index. +proc check_terms {test level index terms} { + set where "level = $level AND idx = $index" + do_test $test.terms [list fts3_terms t1 $where] $terms +} +proc check_terms_all {test terms} { + do_test $test.terms [list fts3_terms t1 1] $terms +} + +# Utility function to check for the expected doclist for the term in +# segment level/index. _all version does same for entire index. +proc check_doclist {test level index term doclist} { + set where "level = $level AND idx = $index" + do_test $test.doclist [list fts3_doclist t1 $term $where] $doclist +} +proc check_doclist_all {test term doclist} { + do_test $test.doclist [list fts3_doclist t1 $term 1] $doclist +} + +#************************************************************************* +# Test results when all rows are deleted and one is added back. +# Previously older segments would continue to exist, but now the index +# should be dropped when the table is empty. The results should look +# exactly like we never added the earlier rows in the first place. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE 1=1; -- Delete each row rather than dropping table. + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); +} + +# Should be a single initial segment. +do_test fts3d-1.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-1.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}} + +check_terms_all fts3d-1.1 {a is test this} +check_doclist_all fts3d-1.1.1 a {[1 0[2]]} +check_doclist_all fts3d-1.1.2 is {[1 0[1]]} +check_doclist_all fts3d-1.1.3 test {[1 0[3]]} +check_doclist_all fts3d-1.1.4 this {[1 0[0]]} + +check_terms fts3d-1.2 0 0 {a is test this} +check_doclist fts3d-1.2.1 0 0 a {[1 0[2]]} +check_doclist fts3d-1.2.2 0 0 is {[1 0[1]]} +check_doclist fts3d-1.2.3 0 0 test {[1 0[3]]} +check_doclist fts3d-1.2.4 0 0 this {[1 0[0]]} + +#************************************************************************* +# Test results when everything is optimized manually. +# NOTE(shess): This is a copy of fts3c-1.3. I've pulled a copy here +# because fts3d-2 and fts3d-3 should have identical results. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + DROP TABLE IF EXISTS t1old; + ALTER TABLE t1 RENAME TO t1old; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) SELECT docid, c FROM t1old; + DROP TABLE t1old; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3d-2.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-2.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3d-2.1 {a test that was} +check_doclist_all fts3d-2.1.1 a {[2 0[2]]} +check_doclist_all fts3d-2.1.2 test {[2 0[3]]} +check_doclist_all fts3d-2.1.3 that {[2 0[0]]} +check_doclist_all fts3d-2.1.4 was {[2 0[1]]} + +check_terms fts3d-2.2 0 0 {a test that was} +check_doclist fts3d-2.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-2.2.2 0 0 test {[2 0[3]]} +check_doclist fts3d-2.2.3 0 0 that {[2 0[0]]} +check_doclist fts3d-2.2.4 0 0 was {[2 0[1]]} + +#************************************************************************* +# Test results when everything is optimized via optimize(). +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); + DELETE FROM t1 WHERE docid IN (1,3); + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; +} + +# Should be a single optimal segment with the same logical results. +do_test fts3d-3.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0} +do_test fts3d-3.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} {{0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4}} + +check_terms_all fts3d-3.1 {a test that was} +check_doclist_all fts3d-3.1.1 a {[2 0[2]]} +check_doclist_all fts3d-3.1.2 test {[2 0[3]]} +check_doclist_all fts3d-3.1.3 that {[2 0[0]]} +check_doclist_all fts3d-3.1.4 was {[2 0[1]]} + +check_terms fts3d-3.2 0 0 {a test that was} +check_doclist fts3d-3.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-3.2.2 0 0 test {[2 0[3]]} +check_doclist fts3d-3.2.3 0 0 that {[2 0[0]]} +check_doclist fts3d-3.2.4 0 0 was {[2 0[1]]} + +#************************************************************************* +# Test optimize() against a table involving segment merges. +# NOTE(shess): Since there's no transaction, each of the INSERT/UPDATE +# statements generates a segment. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + + INSERT INTO t1 (rowid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (rowid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (rowid, c) VALUES (3, 'This is a test'); + + UPDATE t1 SET c = 'This is a test one' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test one' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test one' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test two' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test two' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test two' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test three' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test three' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test three' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test four' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test four' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test four' WHERE rowid = 3; + + UPDATE t1 SET c = 'This is a test' WHERE rowid = 1; + UPDATE t1 SET c = 'That was a test' WHERE rowid = 2; + UPDATE t1 SET c = 'This is a test' WHERE rowid = 3; +} + +# 2 segments in level 0, 1 in level 1 (18 segments created, 16 +# merged). +do_test fts3d-4.segments { + execsql { + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {0 0 0 1 1 0} + +do_test fts3d-4.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +db eval {SELECT c FROM t1 } +check_terms_all fts3d-4.1 {a four is test that this was} +check_doclist_all fts3d-4.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3d-4.1.2 four {} +check_doclist_all fts3d-4.1.3 is {[1 0[1]] [3 0[1]]} +#check_doclist_all fts3d-4.1.4 one {} +check_doclist_all fts3d-4.1.5 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3d-4.1.6 that {[2 0[0]]} +check_doclist_all fts3d-4.1.7 this {[1 0[0]] [3 0[0]]} +#check_doclist_all fts3d-4.1.8 three {} +#check_doclist_all fts3d-4.1.9 two {} +check_doclist_all fts3d-4.1.10 was {[2 0[1]]} + +check_terms fts3d-4.2 0 0 {a four test that was} +check_doclist fts3d-4.2.1 0 0 a {[2 0[2]]} +check_doclist fts3d-4.2.2 0 0 four {[2]} +check_doclist fts3d-4.2.3 0 0 test {[2 0[3]]} +check_doclist fts3d-4.2.4 0 0 that {[2 0[0]]} +check_doclist fts3d-4.2.5 0 0 was {[2 0[1]]} + +check_terms fts3d-4.3 0 1 {a four is test this} +check_doclist fts3d-4.3.1 0 1 a {[3 0[2]]} +check_doclist fts3d-4.3.2 0 1 four {[3]} +check_doclist fts3d-4.3.3 0 1 is {[3 0[1]]} +check_doclist fts3d-4.3.4 0 1 test {[3 0[3]]} +check_doclist fts3d-4.3.5 0 1 this {[3 0[0]]} + +check_terms fts3d-4.4 1 0 {a four is test that this was} +check_doclist fts3d-4.4.1 1 0 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist fts3d-4.4.2 1 0 four {[2 0[4]] [3 0[4]]} +check_doclist fts3d-4.4.3 1 0 is {[1 0[1]] [3 0[1]]} +#check_doclist fts3d-4.4.4 1 0 one {[1] [2] [3]} +check_doclist fts3d-4.4.5 1 0 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist fts3d-4.4.6 1 0 that {[2 0[0]]} +check_doclist fts3d-4.4.7 1 0 this {[1 0[0]] [3 0[0]]} +#check_doclist fts3d-4.4.8 1 0 three {[1] [2] [3]} +#check_doclist fts3d-4.4.9 1 0 two {[1] [2] [3]} +check_doclist fts3d-4.4.10 1 0 was {[2 0[1]]} + +# Optimize should leave the result in the level of the highest-level +# prior segment. +do_test fts3d-4.5 { + execsql { + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index optimized} 1 0} + +# Identical to fts3d-4.matches. +do_test fts3d-4.5.matches { + execsql { + SELECT OFFSETS(t1) FROM t1 + WHERE t1 MATCH 'this OR that OR was OR a OR is OR test' ORDER BY docid; + } +} [list {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4} \ + {0 1 0 4 0 2 5 3 0 3 9 1 0 5 11 4} \ + {0 0 0 4 0 4 5 2 0 3 8 1 0 5 10 4}] + +check_terms_all fts3d-4.5.1 {a is test that this was} +check_doclist_all fts3d-4.5.1.1 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist_all fts3d-4.5.1.2 is {[1 0[1]] [3 0[1]]} +check_doclist_all fts3d-4.5.1.3 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist_all fts3d-4.5.1.4 that {[2 0[0]]} +check_doclist_all fts3d-4.5.1.5 this {[1 0[0]] [3 0[0]]} +check_doclist_all fts3d-4.5.1.6 was {[2 0[1]]} + +check_terms fts3d-4.5.2 1 0 {a is test that this was} +check_doclist fts3d-4.5.2.1 1 0 a {[1 0[2]] [2 0[2]] [3 0[2]]} +check_doclist fts3d-4.5.2.2 1 0 is {[1 0[1]] [3 0[1]]} +check_doclist fts3d-4.5.2.3 1 0 test {[1 0[3]] [2 0[3]] [3 0[3]]} +check_doclist fts3d-4.5.2.4 1 0 that {[2 0[0]]} +check_doclist fts3d-4.5.2.5 1 0 this {[1 0[0]] [3 0[0]]} +check_doclist fts3d-4.5.2.6 1 0 was {[2 0[1]]} + +# Re-optimizing does nothing. +do_test fts3d-5.0 { + execsql { + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index already optimal} 1 0} + +# Even if we move things around, still does nothing. +sqlite3_db_config db DEFENSIVE 0 +do_test fts3d-5.1 { + execsql { + UPDATE t1_segdir SET level = 2 WHERE level = 1 AND idx = 0; + SELECT OPTIMIZE(t1) FROM t1 LIMIT 1; + SELECT level, idx FROM t1_segdir ORDER BY level, idx; + } +} {{Index already optimal} 2 0} + + +# ALTER TABLE RENAME should work regardless of the database encoding. +# +do_test fts3d-6.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF8; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.1 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} +do_test fts3d-6.2 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF16le; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.3 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} +do_test fts3d-6.4 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA encoding=UTF16be; + CREATE VIRTUAL TABLE fts USING fts3(a,b,c); + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {fts_content fts_segdir fts_segments} +do_test fts3d-6.5 { + db eval { + ALTER TABLE fts RENAME TO xyz; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {xyz_content xyz_segdir xyz_segments} + +# ALTER TABLE RENAME on an FTS3 table following an incr-merge op. +# +do_test fts3d-6.6 { + execsql { INSERT INTO xyz(xyz) VALUES('merge=2,2') } + sqlite3 db test.db + execsql { + ALTER TABLE xyz RENAME TO ott; + SELECT name FROM sqlite_master WHERE name GLOB '???_*' ORDER BY 1; + } +} {ott_content ott_segdir ott_segments ott_stat} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer2.test new file mode 100644 index 0000000000000000000000000000000000000000..51d2afc49fd63ed4db916af2493193f02f880a7e --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer2.test @@ -0,0 +1,193 @@ +# 2010 October 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3||!fts4_deferred { + finish_test + return +} + +set testprefix fts3defer2 + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +#----------------------------------------------------------------------------- +# This block of tests - fts3defer2-1.* - test the interaction of deferred NEAR +# expressions and the snippet, offsets and matchinfo functions. +# +do_execsql_test 1.1.1 { + CREATE VIRTUAL TABLE t1 USING fts4; +} +do_execsql_test 1.1.2 "INSERT INTO t1 VALUES('[string repeat {a } 20000]')" +do_execsql_test 1.1.3 "INSERT INTO t1 VALUES('[string repeat {z } 20000]')" +do_execsql_test 1.1.4 { + INSERT INTO t1 VALUES('a b c d e f a x y'); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1 VALUES(''); + INSERT INTO t1(t1) VALUES('optimize'); +} +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.1.4 { + SELECT count(*) FROM t1_segments WHERE length(block)>10000; + UPDATE t1_segments SET block = zeroblob(length(block)) WHERE length(block)>10000; +} {2} + +do_execsql_test 1.2.0 { + SELECT content FROM t1 WHERE t1 MATCH 'f (e a)'; +} {{a b c d e f a x y}} + +do_execsql_test 1.2.1 { + SELECT content FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; +} {{a b c d e f a x y}} + + +do_execsql_test 1.2.2 { + SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) + FROM t1 WHERE t1 MATCH 'f (e NEAR/2 a)'; +} [list \ + {a b c d [e] [f] [a] x y} \ + {0 1 8 1 0 0 10 1 0 2 12 1} \ + [list 3 1 1 1 1 1 1 1 1 1 1 8 5001 9] +] + +do_execsql_test 1.2.3 { + SELECT snippet(t1, '[', ']'), offsets(t1), mit(matchinfo(t1, 'pcxnal')) + FROM t1 WHERE t1 MATCH 'f (e NEAR/3 a)'; +} [list \ + {[a] b c d [e] [f] [a] x y} \ + {0 2 0 1 0 1 8 1 0 0 10 1 0 2 12 1} \ + [list 3 1 1 1 1 1 1 1 2 2 1 8 5001 9] +] + +do_execsql_test 1.3.1 { DROP TABLE t1 } + +#----------------------------------------------------------------------------- +# Test cases fts3defer2-2.* focus specifically on the matchinfo function. +# +do_execsql_test 2.1.1 "CREATE VIRTUAL TABLE t2 USING fts4" +do_execsql_test 2.1.2 "INSERT INTO t2 VALUES('[string repeat {a } 10000]')" +do_execsql_test 2.1.3 "INSERT INTO t2 VALUES('b [string repeat {z } 10000]')" +do_execsql_test 2.1.4 [string repeat "INSERT INTO t2 VALUES('x');" 50] +do_execsql_test 2.1.5 { + INSERT INTO t2 VALUES('a b c d e f g z'); + INSERT INTO t2 VALUES('a b c d e f g'); +} +foreach {tn sql} { + 1 {} + 2 { INSERT INTO t2(t2) VALUES('optimize') } + 3 { UPDATE t2_segments SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} { + sqlite3_db_config db DEFENSIVE 0 + execsql $sql + + do_execsql_test 2.2.$tn.1 { + SELECT mit(matchinfo(t2, 'pcxnal')) FROM t2 WHERE t2 MATCH 'a b'; + } [list \ + [list 2 1 1 54 54 1 3 3 54 372 8] \ + [list 2 1 1 54 54 1 3 3 54 372 7] \ + ] + + do_execsql_test 2.2.$tn.2 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g z'; + } [list \ + [list 1 2 2 1 54 54] \ + ] + + set sqlite_fts3_enable_parentheses 1 + do_execsql_test 2.2.$tn.3 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'g OR (g z)'; + } [list \ + [list 1 2 2 1 2 2 1 54 54] \ + [list 1 2 2 1 2 2 0 54 54] \ + ] + set sqlite_fts3_enable_parentheses 0 + + do_execsql_test 2.2.$tn.4 { + SELECT mit(matchinfo(t2, 'x')) FROM t2 WHERE t2 MATCH 'e "g z"'; + } [list \ + [list 1 2 2 1 2 2] \ + ] +} + +do_execsql_test 2.3.1 { + CREATE VIRTUAL TABLE t3 USING fts4; + INSERT INTO t3 VALUES('a b c d e f'); + INSERT INTO t3 VALUES('x b c d e f'); + INSERT INTO t3 VALUES('d e f a b c'); + INSERT INTO t3 VALUES('b c d e f'); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); + INSERT INTO t3 VALUES(''); +} +do_execsql_test 2.3.2 " + INSERT INTO t3 VALUES('f e d c b [string repeat {a } 10000]') +" +foreach {tn sql} { + 1 {} + 2 { INSERT INTO t3(t3) VALUES('optimize') } + 3 { UPDATE t3_segments SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} { + sqlite3_db_config db DEFENSIVE 0 + execsql $sql + do_execsql_test 2.4.$tn { + SELECT docid, mit(matchinfo(t3, 'pcxnal')) FROM t3 WHERE t3 MATCH '"a b c"'; + } {1 {1 1 1 4 4 11 912 6} 3 {1 1 1 4 4 11 912 6}} +} + +do_execsql_test 2.5 { + INSERT INTO t3(t3) VALUES('rebuild'); +} +do_execsql_test 2.6 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)'; +} {11 228929} +do_execsql_test 2.7 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)'; +} {1 23 3 23 11 205} +do_execsql_test 2.8 { + SELECT rowid, length(offsets(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)'; +} {1 15 3 15 11 106} + +do_execsql_test 2.9 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR a)'; +} {11 32} +do_execsql_test 2.10 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b NEAR a)' +} {1 44 3 44 11 44} +do_execsql_test 2.11 { + SELECT rowid, length(matchinfo(t3)) FROM t3 WHERE t3 MATCH '(a NEAR b)'; +} {1 32 3 32 11 32} + +do_execsql_test 2.12 { + SELECT rowid, length(matchinfo(t3)) FROM t3 + WHERE t3 MATCH '(a NEAR b NEAR a NEAR b NEAR a)' +} {1 68 3 68 11 68} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer3.test new file mode 100644 index 0000000000000000000000000000000000000000..a795e92bcf1ab8fcde102113258920c289a9e10c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3defer3.test @@ -0,0 +1,84 @@ +# 2010 October 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 contains a very simple test to show that the deferred tokens +# optimization is doing something. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3||!fts4_deferred { + finish_test + return +} +set testprefix fts3defer3 + +set nDoclist 3204 +set nDoc 800 + +# Set up a database that contains 800 rows. Each row contains the document +# "b b", except for the row with docid=200, which contains "a b". Hence +# token "b" is extremely common and token "a" is not. +# +do_test 1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4; + BEGIN; + } + for {set i 1} {$i <= $nDoc} {incr i} { + set document "b b" + if {$i==200} { set document "a b" } + execsql { INSERT INTO t1 (docid, content) VALUES($i, $document) } + } + execsql COMMIT +} {} + +# Check that the db contains two doclists. A small one for "a" and a +# larger one for "b". +# +do_execsql_test 1.2 { + SELECT blockid, length(block) FROM t1_segments; +} [list 1 8 2 $nDoclist] + +# Query for 'a b'. Although this test doesn't prove so, token "b" will +# be deferred because of the very large associated doclist. +# +do_execsql_test 1.3 { + SELECT docid, content FROM t1 WHERE t1 MATCH 'a b'; +} {200 {a b}} + +# Zero out the doclist for token "b" within the database file. Now the +# only queries that use token "b" that will work are those that defer +# it. Any query that tries to use the doclist belonging to token "b" +# will fail. +# +do_test 1.4 { + set fd [db incrblob t1_segments block 2] + puts -nonewline $fd [string repeat "\00" $nDoclist] + close $fd +} {} + +# The first two queries succeed, as they defer token "b". The last one +# fails, as it tries to load the corrupt doclist. +# +do_execsql_test 1.5 { + SELECT docid, content FROM t1 WHERE t1 MATCH 'a b'; +} {200 {a b}} +do_execsql_test 1.6 { + SELECT count(*) FROM t1 WHERE t1 MATCH 'a b'; +} {1} +do_catchsql_test 1.7 { + SELECT count(*) FROM t1 WHERE t1 MATCH 'b'; +} {1 {database disk image is malformed}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3drop.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3drop.test new file mode 100644 index 0000000000000000000000000000000000000000..8b76eafec01b2170e8817c8a5fb579ce0472f194 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3drop.test @@ -0,0 +1,61 @@ +# 2011 October 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS3 module. More specifically, +# that DROP TABLE commands can co-exist with savepoints inside transactions. +# See ticket [48f299634a] for details. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3drop + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE f1 USING fts3; + INSERT INTO f1 VALUES('a b c'); +} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO f1 VALUES('d e f'); + SAVEPOINT one; + INSERT INTO f1 VALUES('g h i'); + DROP TABLE f1; + ROLLBACK TO one; + COMMIT; +} + +do_execsql_test 1.3 { + SELECT * FROM f1; +} {{a b c} {d e f}} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO f1 VALUES('g h i'); + SAVEPOINT one; + INSERT INTO f1 VALUES('j k l'); + DROP TABLE f1; + RELEASE one; + ROLLBACK; +} + +do_execsql_test 1.5 { + SELECT * FROM f1; +} {{a b c} {d e f}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3dropmod.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3dropmod.test new file mode 100644 index 0000000000000000000000000000000000000000..d6b1677ac2e12d57c228b80bf783662a52fac7a5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3dropmod.test @@ -0,0 +1,44 @@ +# 2021 December 16 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3dropmod + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_drop_modules db fts3 +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(x); +} +do_catchsql_test 1.1 { + CREATE VIRTUAL TABLE t2 USING fts4(x); +} {1 {no such module: fts4}} + +reset_db +sqlite3_drop_modules db fts4 +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts4(x); +} +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts3(x); +} {1 {no such module: fts3}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3e.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3e.test new file mode 100644 index 0000000000000000000000000000000000000000..03caaf85f23686db63c5aafa554c5ffbf73c69db --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3e.test @@ -0,0 +1,125 @@ +# 2008 July 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. +# +#************************************************************************* +# These tests exercise the various types of fts3 cursors. +# +# $Id: fts3e.test,v 1.1 2008/07/29 20:24:46 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#************************************************************************* +# Test table scan (QUERY_GENERIC). This kind of query happens for +# queries with no WHERE clause, or for WHERE clauses which cannot be +# satisfied by an index. +db eval { + DROP TABLE IF EXISTS t1; + CREATE VIRTUAL TABLE t1 USING fts3(c); + INSERT INTO t1 (docid, c) VALUES (1, 'This is a test'); + INSERT INTO t1 (docid, c) VALUES (2, 'That was a test'); + INSERT INTO t1 (docid, c) VALUES (3, 'This is a test'); +} + +do_test fts3e-1.1 { + execsql { + SELECT docid FROM t1 ORDER BY docid; + } +} {1 2 3} + +do_test fts3e-1.2 { + execsql { + SELECT docid FROM t1 WHERE c LIKE '%test' ORDER BY docid; + } +} {1 2 3} + +do_test fts3e-1.3 { + execsql { + SELECT docid FROM t1 WHERE c LIKE 'That%' ORDER BY docid; + } +} {2} + +#************************************************************************* +# Test lookup by docid (QUERY_DOCID). This kind of query happens for +# queries which select by the docid/rowid implicit index. +db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t1 USING fts3(c); + CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); + INSERT INTO t2 VALUES (null, 10); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); + INSERT INTO t2 VALUES (null, 5); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); + INSERT INTO t2 VALUES (null, 20); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); +} + +# TODO(shess): This actually is doing QUERY_GENERIC? I'd have +# expected QUERY_DOCID in this case, as for a very large table the +# full scan is less efficient. +do_test fts3e-2.1 { + execsql { + SELECT docid FROM t1 WHERE docid in (1, 2, 10); + SELECT rowid FROM t1 WHERE rowid in (1, 2, 10); + } +} {1 2 1 2} + +do_test fts3e-2.2 { + execsql { + SELECT docid, weight FROM t1, t2 WHERE t2.id = t1.docid ORDER BY weight; + SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight; + } +} {2 5 1 10 3 20 2 5 1 10 3 20} + +do_test fts3e-2.3 { + execsql { + SELECT docid, weight FROM t1, t2 + WHERE t2.weight>5 AND t2.id = t1.docid ORDER BY weight; + SELECT t1.rowid, weight FROM t1, t2 + WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight; + } +} {1 10 3 20 1 10 3 20} + +#************************************************************************* +# Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index. +db eval { + DROP TABLE IF EXISTS t1; + DROP TABLE IF EXISTS t2; + CREATE VIRTUAL TABLE t1 USING fts3(c); + CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE); + INSERT INTO t2 VALUES (null, 10); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); + INSERT INTO t2 VALUES (null, 5); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'That was a test'); + INSERT INTO t2 VALUES (null, 20); + INSERT INTO t1 (docid, c) VALUES (last_insert_rowid(), 'This is a test'); +} + +do_test fts3e-3.1 { + execsql { + SELECT docid FROM t1 WHERE t1 MATCH 'this' ORDER BY docid; + } +} {1 3} + +do_test fts3e-3.2 { + execsql { + SELECT docid, weight FROM t1, t2 + WHERE t1 MATCH 'this' AND t1.docid = t2.id ORDER BY weight; + } +} {1 10 3 20} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr.test new file mode 100644 index 0000000000000000000000000000000000000000..2fd19201b62d6a66910b24798a2eff5b286dd3dc --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr.test @@ -0,0 +1,521 @@ +# 2006 September 9 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3expr.test,v 1.9 2009/07/28 16:44:26 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc test_fts3expr {expr} { + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} +} + +do_test fts3expr-1.0 { + test_fts3expr "abcd" +} {PHRASE 3 0 abcd} +do_test fts3expr-1.1 { + test_fts3expr " tag " +} {PHRASE 3 0 tag} + +do_test fts3expr-1.2 { + test_fts3expr "ab AND cd" +} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.2.1 { + test_fts3expr "ab cd" +} {AND {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.3 { + test_fts3expr "ab OR cd" +} {OR {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.4 { + test_fts3expr "ab NOT cd" +} {NOT {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.5 { + test_fts3expr "ab NEAR cd" +} {NEAR/10 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.1 { + test_fts3expr "ab NEAR/5 cd" +} {NEAR/5 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.2 { + test_fts3expr "ab NEAR/87654321 cd" +} {NEAR/87654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.3 { + test_fts3expr "ab NEAR/7654321 cd" +} {NEAR/7654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.4 { + test_fts3expr "ab NEAR/654321 cd" +} {NEAR/654321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.5 { + test_fts3expr "ab NEAR/54321 cd" +} {NEAR/54321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.6 { + test_fts3expr "ab NEAR/4321 cd" +} {NEAR/4321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.7 { + test_fts3expr "ab NEAR/321 cd" +} {NEAR/321 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} +do_test fts3expr-1.6.8 { + test_fts3expr "ab NEAR/21 cd" +} {NEAR/21 {PHRASE 3 0 ab} {PHRASE 3 0 cd}} + +do_test fts3expr-1.7 { + test_fts3expr {"one two three"} +} {PHRASE 3 0 one two three} +do_test fts3expr-1.8.1 { + test_fts3expr {zero "one two three" four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.2 { + test_fts3expr {zero AND "one two three" four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.3 { + test_fts3expr {zero "one two three" AND four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.8.4 { + test_fts3expr {zero AND "one two three" AND four} +} {AND {AND {PHRASE 3 0 zero} {PHRASE 3 0 one two three}} {PHRASE 3 0 four}} +do_test fts3expr-1.9.1 { + test_fts3expr {"one* two three"} +} {PHRASE 3 0 one+ two three} +do_test fts3expr-1.9.2 { + test_fts3expr {"one two* three"} +} {PHRASE 3 0 one two+ three} +do_test fts3expr-1.9.3 { + test_fts3expr {"one* two* three"} +} {PHRASE 3 0 one+ two+ three} +do_test fts3expr-1.9.4 { + test_fts3expr {"one two three*"} +} {PHRASE 3 0 one two three+} +do_test fts3expr-1.9.5 { + test_fts3expr {"one* two three*"} +} {PHRASE 3 0 one+ two three+} +do_test fts3expr-1.9.6 { + test_fts3expr {"one two* three*"} +} {PHRASE 3 0 one two+ three+} +do_test fts3expr-1.9.7 { + test_fts3expr {"one* two* three*"} +} {PHRASE 3 0 one+ two+ three+} + +do_test fts3expr-1.10 { + test_fts3expr {one* two} +} {AND {PHRASE 3 0 one+} {PHRASE 3 0 two}} +do_test fts3expr-1.11 { + test_fts3expr {one two*} +} {AND {PHRASE 3 0 one} {PHRASE 3 0 two+}} + +do_test fts3expr-1.14 { + test_fts3expr {a:one two} +} {AND {PHRASE 0 0 one} {PHRASE 3 0 two}} +do_test fts3expr-1.15.1 { + test_fts3expr {one b:two} +} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}} +do_test fts3expr-1.15.2 { + test_fts3expr {one B:two} +} {AND {PHRASE 3 0 one} {PHRASE 1 0 two}} + +do_test fts3expr-1.16 { + test_fts3expr {one AND two AND three AND four AND five} +} [list AND \ + [list AND \ + [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + {PHRASE 3 0 three} \ + ] \ + {PHRASE 3 0 four} \ + ] \ + {PHRASE 3 0 five} \ + ] +do_test fts3expr-1.17 { + test_fts3expr {(one AND two) AND ((three AND four) AND five)} +} [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.18 { + test_fts3expr {(one AND two) OR ((three AND four) AND five)} +} [list OR \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.19 { + test_fts3expr {(one AND two) AND ((three AND four) OR five)} +} [list AND \ + [list AND {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list OR \ + [list AND {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.20 { + test_fts3expr {(one OR two) AND ((three OR four) AND five)} +} [list AND \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.21 { + test_fts3expr {(one OR two) AND ((three NOT four) AND five)} +} [list AND \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list NOT {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.22 { + test_fts3expr {(one OR two) NOT ((three OR four) AND five)} +} [list NOT \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.23 { + test_fts3expr {(((((one OR two))))) NOT (((((three OR four))) AND five))} +} [list NOT \ + [list OR {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.24 { + test_fts3expr {one NEAR two} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.25 { + test_fts3expr {(one NEAR two)} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.26 { + test_fts3expr {((((((one NEAR two))))))} +} [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] +do_test fts3expr-1.27 { + test_fts3expr {(one NEAR two) OR ((three OR four) AND five)} +} [list OR \ + [list NEAR/10 {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] +do_test fts3expr-1.28 { + test_fts3expr {(one NEAR/321 two) OR ((three OR four) AND five)} +} [list OR \ + [list NEAR/321 {PHRASE 3 0 one} {PHRASE 3 0 two}] \ + [list AND \ + [list OR {PHRASE 3 0 three} {PHRASE 3 0 four}] \ + {PHRASE 3 0 five} \ + ] \ + ] + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [lrange $L 3 end] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} + ] +} +do_test fts3expr-2.1 { + test_fts3expr2 "ab OR cd AND ef" +} {OR ab {AND cd ef}} +do_test fts3expr-2.2 { + test_fts3expr2 "cd AND ef OR ab" +} {OR {AND cd ef} ab} +do_test fts3expr-2.3 { + test_fts3expr2 "ab AND cd AND ef OR gh" +} {OR {AND {AND ab cd} ef} gh} +do_test fts3expr-2.4 { + test_fts3expr2 "ab AND cd OR ef AND gh" +} {OR {AND ab cd} {AND ef gh}} +do_test fts3expr-2.5 { + test_fts3expr2 "ab cd" +} {AND ab cd} + +do_test fts3expr-3.1 { + test_fts3expr2 "(ab OR cd) AND ef" +} {AND {OR ab cd} ef} +do_test fts3expr-3.2 { + test_fts3expr2 "ef AND (ab OR cd)" +} {AND ef {OR ab cd}} +do_test fts3expr-3.3 { + test_fts3expr2 "(ab OR cd)" +} {OR ab cd} +do_test fts3expr-3.4 { + test_fts3expr2 "(((ab OR cd)))" +} {OR ab cd} + +do_test fts3expr-3.5 { + test_fts3expr2 "one AND (two NEAR three)" +} {AND one {NEAR/10 two three}} +do_test fts3expr-3.6 { + test_fts3expr2 "one (two NEAR three)" +} {AND one {NEAR/10 two three}} +do_test fts3expr-3.7 { + test_fts3expr2 "(two NEAR three) one" +} {AND {NEAR/10 two three} one} +do_test fts3expr-3.8 { + test_fts3expr2 "(two NEAR three) AND one" +} {AND {NEAR/10 two three} one} +do_test fts3expr-3.9 { + test_fts3expr2 "(two NEAR three) (four five)" +} {AND {NEAR/10 two three} {AND four five}} +do_test fts3expr-3.10 { + test_fts3expr2 "(two NEAR three) AND (four five)" +} {AND {NEAR/10 two three} {AND four five}} +do_test fts3expr-3.11 { + test_fts3expr2 "(two NEAR three) (four NEAR five)" +} {AND {NEAR/10 two three} {NEAR/10 four five}} +do_test fts3expr-3.12 { + test_fts3expr2 "(two NEAR three) OR (four NEAR five)" +} {OR {NEAR/10 two three} {NEAR/10 four five}} + +do_test fts3expr-3.13 { + test_fts3expr2 "(two NEAR/1a three)" +} {AND {AND {AND two near} 1a} three} + +do_test fts3expr-3.14 { + test_fts3expr2 "(two NEAR// three)" +} {AND {AND two near} three} +do_test fts3expr-3.15 { + test_fts3expr2 "(two NEAR/: three)" +} {AND {AND two near} three} + +do_test fts3expr-3.16 { + test_fts3expr2 "(two NEAR three)OR(four NEAR five)" +} {OR {NEAR/10 two three} {NEAR/10 four five}} +do_test fts3expr-3.17 { + test_fts3expr2 "(two NEAR three)OR\"four five\"" +} {OR {NEAR/10 two three} {four five}} +do_test fts3expr-3.18 { + test_fts3expr2 "one \u0080wo" +} "AND one \u0080wo" + + + +#------------------------------------------------------------------------ +# The following tests, fts3expr-4.*, test the parsers response to syntax +# errors in query expressions. This is done using a real fts3 table and +# MATCH clauses, not the parser test interface. +# +do_test fts3expr-4.1 { + execsql { CREATE VIRTUAL TABLE t1 USING fts3(a, b, c) } +} {} + +# Mismatched parenthesis: +do_test fts3expr-4.2.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world))' } +} {1 {malformed MATCH expression: [example AND (hello OR world))]}} +do_test fts3expr-4.2.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example AND (hello OR world' } +} {1 {malformed MATCH expression: [example AND (hello OR world]}} +do_test fts3expr-4.2.3 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello' } +} {1 {malformed MATCH expression: [(hello]}} +do_test fts3expr-4.2.4 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(' } +} {1 {malformed MATCH expression: [(]}} +do_test fts3expr-4.2.5 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH ')' } +} {1 {malformed MATCH expression: [)]}} + +do_test fts3expr-4.2.6 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example (hello world' } +} {1 {malformed MATCH expression: [example (hello world]}} + +# Unterminated quotation marks: +do_test fts3expr-4.3.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR "hello world' } +} {1 {malformed MATCH expression: [example OR "hello world]}} +do_test fts3expr-4.3.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'example OR hello world"' } +} {1 {malformed MATCH expression: [example OR hello world"]}} + +# Binary operators without the required operands. +do_test fts3expr-4.4.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'OR hello world' } +} {1 {malformed MATCH expression: [OR hello world]}} +do_test fts3expr-4.4.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'hello world OR' } +} {1 {malformed MATCH expression: [hello world OR]}} +do_test fts3expr-4.4.3 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (hello world OR) two' } +} {1 {malformed MATCH expression: [one (hello world OR) two]}} +do_test fts3expr-4.4.4 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one (OR hello world) two' } +} {1 {malformed MATCH expression: [one (OR hello world) two]}} + +# NEAR operators with something other than phrases as arguments. +do_test fts3expr-4.5.1 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH '(hello OR world) NEAR one' } +} {1 {malformed MATCH expression: [(hello OR world) NEAR one]}} +do_test fts3expr-4.5.2 { + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'one NEAR (hello OR world)' } +} {1 {malformed MATCH expression: [one NEAR (hello OR world)]}} + +#------------------------------------------------------------------------ +# The following OOM tests are designed to cover cases in fts3_expr.c. +# +source $testdir/malloc_common.tcl +do_malloc_test fts3expr-malloc-1 -sqlbody { + SELECT fts3_exprtest('simple', 'a b c "d e f"', 'a', 'b', 'c') +} +do_malloc_test fts3expr-malloc-2 -tclprep { + set sqlite_fts3_enable_parentheses 0 +} -sqlbody { + SELECT fts3_exprtest('simple', 'a -b', 'a', 'b', 'c') +} -cleanup { + set sqlite_fts3_enable_parentheses 1 +} + +#------------------------------------------------------------------------ +# The following tests are not very important. They cover error handling +# cases in the test code, which makes test coverage easier to measure. +# +do_test fts3expr-5.1 { + catchsql { SELECT fts3_exprtest('simple', 'a b') } +} {1 {Usage: fts3_exprtest(tokenizer, expr, col1, ...}} +do_test fts3expr-5.2 { + catchsql { SELECT fts3_exprtest('doesnotexist', 'a b', 'c') } +} {1 {unknown tokenizer: doesnotexist}} +do_test fts3expr-5.3 { + catchsql { SELECT fts3_exprtest('simple', 'a b OR', 'c') } +} {1 {Error parsing expression}} + +#------------------------------------------------------------------------ +# The next set of tests verifies that things actually work as they are +# supposed to when using the new syntax. +# +do_test fts3expr-6.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts3(a); + } + for {set ii 1} {$ii < 32} {incr ii} { + set v [list] + if {$ii & 1} { lappend v one } + if {$ii & 2} { lappend v two } + if {$ii & 4} { lappend v three } + if {$ii & 8} { lappend v four } + if {$ii & 16} { lappend v five } + execsql { INSERT INTO t1 VALUES($v) } + } + + execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'five four one' ORDER BY rowid} +} {25 27 29 31} + +foreach {id expr res} { + + 2 "five four NOT one" {24 26 28 30} + + 3 "five AND four OR one" + {1 3 5 7 9 11 13 15 17 19 21 23 24 25 26 27 28 29 30 31} + + 4 "five AND (four OR one)" {17 19 21 23 24 25 26 27 28 29 30 31} + + 5 "five NOT (four OR one)" {16 18 20 22} + + 6 "(five NOT (four OR one)) OR (five AND (four OR one))" + {16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 7 "(five OR one) AND two AND three" {7 15 22 23 30 31} + + 8 "five OR one AND two AND three" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 9 "five OR one two three" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 10 "five OR \"one two three\"" + {7 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31} + + 11 "one two OR four five NOT three" {3 7 11 15 19 23 24 25 26 27 31} + + 12 "(one two OR four five) NOT three" {3 11 19 24 25 26 27} + + 13 "((((((one two OR four five)))))) NOT three" {3 11 19 24 25 26 27} + +} { + do_test fts3expr-6.1.$id { + execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid } + } $res +} + +set sqlite_fts3_enable_parentheses 0 +foreach {id expr res} { + 1 "one -two three" {5 13 21 29} + 2 "-two one three" {5 13 21 29} + 3 "one three -two" {5 13 21 29} + 4 "-one -two three" {4 12 20 28} + 5 "three -one -two" {4 12 20 28} + 6 "-one three -two" {4 12 20 28} +} { + do_test fts3expr-6.2.$id { + execsql { SELECT rowid FROM t1 WHERE t1 MATCH $expr ORDER BY rowid } + } $res +} +set sqlite_fts3_enable_parentheses 1 + +do_test fts3expr-7.1 { + execsql { + CREATE VIRTUAL TABLE test USING fts3 (keyword); + INSERT INTO test VALUES ('abc'); + SELECT * FROM test WHERE keyword MATCH '""'; + } +} {} + + +do_test fts3expr-8.0 { test_fts3expr "(blah)" } {PHRASE 3 0 blah} +do_test fts3expr-8.1 { test_fts3expr "(blah.)" } {PHRASE 3 0 blah} +do_test fts3expr-8.2 { test_fts3expr "(blah,)" } {PHRASE 3 0 blah} +do_test fts3expr-8.3 { test_fts3expr "(blah!)" } {PHRASE 3 0 blah} +do_test fts3expr-8.4 { test_fts3expr "(blah-)" } {PHRASE 3 0 blah} + +do_test fts3expr-8.5 { test_fts3expr "((blah.))" } {PHRASE 3 0 blah} +do_test fts3expr-8.6 { test_fts3expr "(((blah,)))" } {PHRASE 3 0 blah} +do_test fts3expr-8.7 { test_fts3expr "((((blah!))))" } {PHRASE 3 0 blah} + +do_test fts3expr-8.8 { test_fts3expr "(,(blah-),)" } {PHRASE 3 0 blah} + +set sqlite_fts3_enable_parentheses 0 + +do_test fts3expr-9.1 { + test_fts3expr "f (e NEAR/2 a)" +} {AND {PHRASE 3 0 f} {NEAR/2 {PHRASE 3 0 e} {PHRASE 3 0 a}}} + +do_test fts3expr-10.1 { test_fts3expr "abc *" } {PHRASE 3 0 abc} +do_test fts3expr-10.2 { test_fts3expr "*" } {} +do_test fts3expr-10.3 { test_fts3expr "abc*" } {PHRASE 3 0 abc+} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr2.test new file mode 100644 index 0000000000000000000000000000000000000000..c3d161730b47f9c0e9e11263555d2d6090ed4e62 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr2.test @@ -0,0 +1,166 @@ +# 2009 January 1 +# +# 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. The +# focus of this script is testing the FTS3 module syntax parser. +# +# $Id: fts3expr2.test,v 1.2 2009/06/05 17:09:12 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Test overview: +# +# The tests in this file are pseudo-randomly generated. They test +# the fts3 match expression parser via the test interface +# SQL function "fts3_exprtest" (see comments in fts3_expr.c). +# +# Each test case works as follows: +# +# 1. A random expression tree is generated using proc [random_expr_tree]. +# 2. The expression tree is converted to the text of an equivalent +# fts3 expression using proc [tree_to_expr]. +# 3. The test SQL function "fts3_exprtest" is used to parse the +# expression text generated in step (2), returning a parsed expression +# tree. +# 4. Test that the tree returned in step (3) matches that generated in +# step (1). +# +# In step (2), 4 different fts3 expressions are created from each +# expression tree by varying the following boolean properties: +# +# * Whether or not superflous parenthesis are included. i.e. if +# "a OR b AND (c OR d)" or "a OR (b AND (c OR d))" is generated. +# +# * Whether or not explict AND operators are used. i.e. if +# "a OR b AND c" or "a OR b c" is generated. +# + +set sqlite_fts3_enable_parentheses 1 + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [list P [lrange $L 3 end]] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} + ] +} + +proc rnd {nMax} { expr {int(rand()*$nMax)} } + +proc random_phrase {} { + set phrases [list one two three four "one two" "three four"] + list P [lindex $phrases [rnd [llength $phrases]]] +} + +# Generate and return a pseudo-random expression tree. Using the same +# format returned by the [test_fts3expr2] proc. +# +proc random_expr_tree {iHeight} { + if {$iHeight==0 || [rnd 3]==0} { + return [random_phrase] + } + + set operators [list NEAR NOT AND OR] + set op [lindex $operators [rnd 4]] + + if {$op eq "NEAR"} { + set iDistance [rnd 15] + return [list $op/$iDistance [random_phrase] [random_phrase]] + } + + set iNH [expr {$iHeight - 1}] + return [list $op [random_expr_tree $iNH] [random_expr_tree $iNH]] +} + +# Given an expression tree, generate a corresponding expression. +# +proc tree_to_expr {tree all_brackets implicit_and} { + set prec(NOT) 2 + set prec(AND) 3 + set prec() 3 + set prec(OR) 4 + + set op [lindex $tree 0] + + if {$op eq "P"} { + set phrase [lindex $tree 1] + if {[llength $phrase]>1} { + return "\"$phrase\"" + } else { + return $phrase + } + } + + if {$op eq "NEAR/10"} { + set op "NEAR" + } + if {$op eq "AND" && $implicit_and} { + set op "" + } + + set lhs [lindex $tree 1] + set rhs [lindex $tree 2] + set zLeft [tree_to_expr $lhs $all_brackets $implicit_and] + set zRight [tree_to_expr $rhs $all_brackets $implicit_and] + + set iPrec 5 + set iLeftPrec 0 + set iRightPrec 0 + + catch {set iPrec $prec($op)} + catch {set iLeftPrec $prec([lindex $lhs 0])} + catch {set iRightPrec $prec([lindex $rhs 0])} + + if {$iLeftPrec > $iPrec || $all_brackets} { + set zLeft "($zLeft)" + } + if {$iRightPrec >= $iPrec || $all_brackets} { + set zRight "($zRight)" + } + + return "$zLeft $op $zRight" +} + +proc do_exprparse_test {name expr tree} { + uplevel do_test $name [list "test_fts3expr2 {$expr}"] [list $tree] +} + +for {set iTest 1} {$iTest<500} {incr iTest} { + set t [random_expr_tree 4] + + set e1 [tree_to_expr $t 0 0] + set e2 [tree_to_expr $t 0 1] + set e3 [tree_to_expr $t 1 0] + set e4 [tree_to_expr $t 1 1] + + do_exprparse_test fts3expr2-$iTest.1 $e1 $t + do_exprparse_test fts3expr2-$iTest.2 $e2 $t + do_exprparse_test fts3expr2-$iTest.3 $e3 $t + do_exprparse_test fts3expr2-$iTest.4 $e4 $t +} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr3.test new file mode 100644 index 0000000000000000000000000000000000000000..83c153218c85495dc9a1e611e97552c0514aaf7c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr3.test @@ -0,0 +1,238 @@ +# 2009 January 1 +# +# 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. The +# focus of this script is testing the part of the FTS3 expression +# parser that rebalances large expressions. +# +# $Id: fts3expr2.test,v 1.2 2009/06/05 17:09:12 drh Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set ::testprefix fts3expr3 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc strip_phrase_data {L} { + if {[lindex $L 0] eq "PHRASE"} { + return [list P [lrange $L 3 end]] + } + return [list \ + [lindex $L 0] \ + [strip_phrase_data [lindex $L 1]] \ + [strip_phrase_data [lindex $L 2]] \ + ] +} +proc test_fts3expr2 {expr} { + strip_phrase_data [ + db one {SELECT fts3_exprtest_rebalance('simple', $expr, 'a', 'b', 'c')} + ] +} + +proc balanced_exprtree_structure {nEntry} { + set L [list] + for {set i 1} {$i <= $nEntry} {incr i} { + lappend L xxx + } + while {[llength $L] > 1} { + set N [list] + if {[llength $L] % 2} { + foreach {a b} [lrange $L 0 end-1] { lappend N [list AND $a $b] } + lappend N [lindex $L end] + } else { + foreach {a b} $L { lappend N [list AND $a $b] } + } + set L $N + } + return [lindex $L 0] +} + +proc balanced_and_tree {nEntry} { + set query [balanced_exprtree_structure $nEntry] + if {$query == "xxx"} { + return "P 1" + } + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query "{P $i}" query + } + return $query +} + +proc random_tree_structure {nEntry bParen op} { + set query xxx + for {set i 1} {$i < $nEntry} {incr i} { + set x1 [expr int(rand()*4.0)] + set x2 [expr int(rand()*2.0)] + if {$x1==0 && $bParen} { + set query "($query)" + } + if {$x2} { + set query "xxx $op $query" + } else { + set query "$query $op xxx" + } + } + return $query +} + +proc random_and_query {nEntry {bParen 0}} { + set query [random_tree_structure $nEntry $bParen AND] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query $i query + } + return $query +} + +proc random_or_query {nEntry} { + set query [random_tree_structure $nEntry 1 OR] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query $i query + } + return $query +} + +proc random_andor_query {nEntry} { + set query [random_tree_structure $nEntry 1 AND] + for {set i 1} {$i <= $nEntry} {incr i} { + regsub xxx $query "([random_or_query $nEntry])" query + } + return $query +} + +proc balanced_andor_tree {nEntry} { + set tree [balanced_exprtree_structure $nEntry] + set node "{[balanced_and_tree $nEntry]}" + regsub -all AND $node OR node + regsub -all xxx $tree $node tree + return $tree +} + +if 1 { + +# Test that queries like "1 AND 2 AND 3 AND 4..." are transformed to +# balanced trees by FTS. +# +for {set i 1} {$i < 100} {incr i} { + do_test 1.$i { + test_fts3expr2 [random_and_query $i] + } [balanced_and_tree $i] +} + +# Same again, except with parenthesis inserted at arbitrary points. +# +for {set i 1} {$i < 100} {incr i} { + do_test 2.$i { + test_fts3expr2 [random_and_query $i 1] + } [balanced_and_tree $i] +} + +# Now attempt to balance two AND trees joined by an OR. +# +for {set i 1} {$i < 100} {incr i} { + do_test 3.$i { + test_fts3expr2 "[random_and_query $i 1] OR [random_and_query $i 1]" + } [list OR [balanced_and_tree $i] [balanced_and_tree $i]] +} + +# Try trees of AND nodes with leaves that are themselves trees of OR nodes. +# +for {set i 2} {$i < 64} {incr i 4} { + do_test 3.$i { + test_fts3expr2 [random_andor_query $i] + } [balanced_andor_tree $i] +} + +# These exceed the depth limit. +# +for {set i 65} {$i < 70} {incr i} { + do_test 3.$i { + list [catch {test_fts3expr2 [random_andor_query $i]} msg] $msg + } {1 {Error parsing expression}} +} + +# This also exceeds the depth limit. +# + +do_test 4.1.1 { + set q "1" + for {set i 2} {$i < 5000} {incr i} { + append q " AND $i" + } + list [catch {test_fts3expr2 $q} msg] $msg +} {1 {Error parsing expression}} +do_test 4.1.2 { + set q "1" + for {set i 2} {$i < 4000} {incr i} { + append q " AND $i" + } + catch {test_fts3expr2 $q} +} {0} + +proc create_toggle_tree {nDepth} { + if {$nDepth == 0} { return xxx } + set nNew [expr $nDepth-1] + if {$nDepth % 2} { + return "([create_toggle_tree $nNew]) OR ([create_toggle_tree $nNew])" + } + return "([create_toggle_tree $nNew]) AND ([create_toggle_tree $nNew])" +} + +do_test 4.2 { + list [catch {test_fts3expr2 [create_toggle_tree 17]} msg] $msg +} {1 {Error parsing expression}} + +set query [random_andor_query 12] +set result [balanced_andor_tree 12] +do_faultsim_test fts3expr3-fault-1 -faults oom-* -body { + test_fts3expr2 $::query +} -test { + faultsim_test_result [list 0 $::result] +} + +} + +#------------------------------------------------------------------- + +foreach {tn expr res} { + 1 {1 OR 2 OR 3 OR 4} {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} + 2 {1 OR (2 AND 3 AND 4 AND 5)} + {OR {P 1} {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}}} + 3 {(2 AND 3 AND 4 AND 5) OR 1} + {OR {AND {AND {P 2} {P 3}} {AND {P 4} {P 5}}} {P 1}} + + 4 {1 AND (2 OR 3 OR 4 OR 5)} + {AND {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} + 5 {(2 OR 3 OR 4 OR 5) AND 1} + {AND {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} + + 6 {(2 OR 3 OR 4 OR 5) NOT 1} + {NOT {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}} {P 1}} + + 7 {1 NOT (2 OR 3 OR 4 OR 5)} + {NOT {P 1} {OR {OR {P 2} {P 3}} {OR {P 4} {P 5}}}} + + 8 {(1 OR 2 OR 3 OR 4) NOT (5 AND 6 AND 7 AND 8)} + {NOT {OR {OR {P 1} {P 2}} {OR {P 3} {P 4}}} {AND {AND {P 5} {P 6}} {AND {P 7} {P 8}}}} +} { + do_test 5.1.$tn { + test_fts3expr2 $expr + } $res +} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr4.test new file mode 100644 index 0000000000000000000000000000000000000000..b9227aef55da93f681c8af5c58c7863c07cdd278 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr4.test @@ -0,0 +1,91 @@ +# 2014 May 7 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr4 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3||!icu { + finish_test + return +} + +set sqlite_fts3_enable_parentheses 1 + +proc test_fts3expr {tokenizer expr} { + db one {SELECT fts3_exprtest($tokenizer, $expr, 'a', 'b', 'c')} +} + +proc do_icu_expr_test {tn expr res} { + set res2 [list {*}$res] + uplevel [list do_test $tn [list test_fts3expr "icu en_US" $expr] $res2] +} + +proc do_simple_expr_test {tn expr res} { + uplevel [list do_test $tn [list test_fts3expr simple $expr] [list {*}$res]] +} + +#------------------------------------------------------------------------- +# +do_icu_expr_test 1.1 "abcd" {PHRASE 3 0 abcd} +do_icu_expr_test 1.2 " tag " {PHRASE 3 0 tag} +do_icu_expr_test 1.3 {"x y z"} {PHRASE 3 0 x y z} +do_icu_expr_test 1.4 {x OR y} {OR {PHRASE 3 0 x} {PHRASE 3 0 y}} +do_icu_expr_test 1.5 {(x OR y)} {OR {PHRASE 3 0 x} {PHRASE 3 0 y}} +do_icu_expr_test 1.6 { "(x OR y)" } {PHRASE 3 0 ( x or y )} + +# In "col:word", if "col" is not the name of a column, the entire thing +# is passed to the tokenizer. +# +do_icu_expr_test 1.7 {a:word} {PHRASE 0 0 word} +# do_icu_expr_test 1.8 {d:word} {PHRASE 3 0 d:word} +do_test 1.8 { + set res [ + db one {SELECT fts3_exprtest('icu en_US', 'd:word', 'a', 'b', 'c')} + ] + expr { + $res=="PHRASE 3 0 d:word" || + $res=="AND {AND {PHRASE 3 0 d} {PHRASE 3 0 :}} {PHRASE 3 0 word}" + } +} 1 + +set sqlite_fts3_enable_parentheses 0 + +do_icu_expr_test 2.1 { + f (e NEAR/2 a) +} {AND {AND {AND {PHRASE 3 0 f} {PHRASE 3 0 (}} {NEAR/2 {PHRASE 3 0 e} {PHRASE 3 0 a}}} {PHRASE 3 0 )}} + +#------------------------------------------------------------------------- +# +do_simple_expr_test 3.1 {*lOl* *h4h*} { + AND {PHRASE 3 0 lol+} {PHRASE 3 0 h4h+} +} + +do_icu_expr_test 3.2 {*lOl* *h4h*} { + AND {AND {AND {PHRASE 3 0 *} {PHRASE 3 0 lol+}} {PHRASE 3 0 *}} {PHRASE 3 0 h4h+} +} + +do_simple_expr_test 3.3 { * } {} +do_simple_expr_test 3.4 { *a } { PHRASE 3 0 a } +do_simple_expr_test 3.5 { a*b } { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} } +do_simple_expr_test 3.6 { *a*b } { AND {PHRASE 3 0 a+} {PHRASE 3 0 b} } +do_simple_expr_test 3.7 { *"abc" } { PHRASE 3 0 abc } +do_simple_expr_test 3.8 { "abc"* } { PHRASE 3 0 abc } +do_simple_expr_test 3.8 { "ab*c" } { PHRASE 3 0 ab+ c } + +do_icu_expr_test 3.9 { "ab*c" } { PHRASE 3 0 ab+ * c } +do_icu_expr_test 3.10 { ab*c } { AND {PHRASE 3 0 ab+} {PHRASE 3 0 c}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr5.test new file mode 100644 index 0000000000000000000000000000000000000000..1317befb1c941f2390944749d814eab4ec7a70d2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3expr5.test @@ -0,0 +1,66 @@ +# 2006 September 9 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3expr5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +proc test_fts3expr {expr} { + db one {SELECT fts3_exprtest('simple', $expr, 'a', 'b', 'c')} +} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t0 USING fts3(x); + SELECT rowid FROM t0 WHERE x MATCH ''; +} {} +do_execsql_test 1.1 { + SELECT rowid FROM t0 WHERE x MATCH '""'; +} {} +do_execsql_test 1.2 { + SELECT rowid FROM t0 WHERE x MATCH '"" ""'; +} {} +do_execsql_test 1.3 { + SELECT rowid FROM t0 WHERE x MATCH '"" OR ""'; +} {} +do_execsql_test 1.4 { + SELECT rowid FROM t0 WHERE x MATCH '"" NOT ""'; +} {} +do_execsql_test 1.5 { + SELECT rowid FROM t0 WHERE x MATCH '""""'; +} {} + +#------------------------------------------------------------------------- +# Various forms of empty phrase expressions. +# +set sqlite_fts3_enable_parentheses 1 +do_test 2.0 { + test_fts3expr {(a:123)(b:234)()(c:456)} +} {AND {AND {PHRASE 0 0 123} {PHRASE 1 0 234}} {PHRASE 2 0 456}} +do_test 2.1 { + test_fts3expr {(a:123)(b:234)(c:456)} +} {AND {AND {PHRASE 0 0 123} {PHRASE 1 0 234}} {PHRASE 2 0 456}} +do_test 2.2 { + list [catch { test_fts3expr {"123" AND ( )} } msg] $msg +} {1 {Error parsing expression}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3f.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3f.test new file mode 100644 index 0000000000000000000000000000000000000000..d9a57cbc30ab455fef9d0c68e8914b805b89f97d --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3f.test @@ -0,0 +1,57 @@ +# 2006 September 9 +# +# 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. The +# focus of this script is testing the FTS3 module. +# +# $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3f + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft USING fts3(x); + BEGIN; + INSERT INTO ft VALUES('a one'), ('b one'), ('c one'); +} + +do_test 1.1 { + set ret [list] + db eval { SELECT docid FROM ft WHERE ft MATCH 'one' } { + if { $docid==2 } { + db eval COMMIT + } + lappend ret $docid + } + set ret +} {1 2 3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO ft VALUES('a one'), ('b one'), ('c one'); +} + +do_execsql_test 1.3 { + SELECT docid, optimize(ft) FROM ft WHERE ft MATCH 'one' +} { + 1 {Index optimized} 2 {Index already optimal} 3 {Index already optimal} + 4 {Index already optimal} + 5 {Index already optimal} 6 {Index already optimal} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault.test new file mode 100644 index 0000000000000000000000000000000000000000..21defd282fd406c5fc7d1e4616da3982d08599df --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault.test @@ -0,0 +1,263 @@ +# 2010 June 15 +# +# 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 fts3fault + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + +# Test error handling in the sqlite3Fts3Init() function. This is the +# function that registers the FTS3 module and various support functions +# with SQLite. +# +do_faultsim_test 1 -body { + sqlite3 db test.db + expr 0 +} -test { + catch { db close } +} + +# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an +# FTS3 table. Specifically, test renaming the table within a transaction +# after it has been written to. +# +faultsim_delete_and_reopen +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE t1 USING fts3; + INSERT INTO t1 VALUES('test renaming the table'); + INSERT INTO t1 VALUES(' after it has been written'); +} +do_faultsim_test 2 -prep { + sqlite3 db test.db + execsql { + BEGIN; + INSERT INTO t1 VALUES('registers the FTS3 module'); + INSERT INTO t1 VALUES('various support functions'); + } +} -body { + execsql { ALTER TABLE t1 RENAME TO t2 } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +# Test error handling in the special case where a single prefix query +# matches terms that reside on a large range of leaf nodes. +# +do_test fts3fault-3.0 { + sqlite3 db test.db + execsql { CREATE VIRTUAL TABLE t3 USING fts4; } + execsql { INSERT INTO t3(t3) VALUES('nodesize=50') } + execsql { BEGIN } + for {set i 0} {$i < 1000} {incr i} { + execsql { INSERT INTO t3 VALUES('aaa' || $i) } + } + execsql { COMMIT } +} {} + +do_faultsim_test 3 -faults oom-transient -prep { + sqlite3 db test.db + execsql { SELECT * FROM t3 WHERE t3 MATCH 'x' } +} -body { + execsql { SELECT count(rowid) FROM t3 WHERE t3 MATCH 'aa*' } +} -test { + faultsim_test_result {0 1000} +} + +do_test fts3fault-4.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t4 USING fts4; + INSERT INTO t4 VALUES('The British Government called on'); + INSERT INTO t4 VALUES('as pesetas then became much'); + } +} {} +faultsim_save_and_close +do_faultsim_test 4 -prep { + faultsim_restore_and_reopen + execsql { SELECT content FROM t4 } +} -body { + execsql { SELECT optimize(t4) FROM t4 LIMIT 1 } +} -test { + faultsim_test_result {0 {{Index optimized}}} +} + +do_test fts3fault-5.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('The British Government called on'); + INSERT INTO t5 VALUES('as pesetas then became much'); + } +} {} +faultsim_save_and_close +do_faultsim_test 5 -prep { + faultsim_restore_and_reopen + execsql { + BEGIN; + INSERT INTO t5 VALUES('influential in shaping his future outlook'); + INSERT INTO t5 VALUES('might be acceptable to the British electorate'); + } +} -body { + execsql { SELECT rowid FROM t5 WHERE t5 MATCH 'british' } +} -test { + faultsim_test_result {0 {1 4}} +} + +do_test fts3fault-6.0 { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t6 USING fts4 } +} {} +faultsim_save_and_close +do_faultsim_test 6 -prep { + faultsim_restore_and_reopen + execsql { SELECT rowid FROM t6 } +} -body { + execsql { DROP TABLE t6 } +} -test { + faultsim_test_result {0 {}} +} + +# Test various malloc failures while processing FTS4 parameters. +# +do_faultsim_test 7.1 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fts3) } +} -test { + faultsim_test_result {0 {}} +} +do_faultsim_test 7.2 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchinfo=fs3) } +} -test { + faultsim_test_result {1 {unrecognized matchinfo: fs3}} \ + {1 {vtable constructor failed: t1}} \ + {1 {SQL logic error}} +} +do_faultsim_test 7.3 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, matchnfo=fts3) } +} -test { + faultsim_test_result {1 {unrecognized parameter: matchnfo=fts3}} \ + {1 {vtable constructor failed: t1}} \ + {1 {SQL logic error}} +} + + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} + +do_test 8.0 { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t8 USING fts4 } + execsql "INSERT INTO t8 VALUES('a b c')" + execsql "INSERT INTO t8 VALUES('b b b')" + execsql "INSERT INTO t8 VALUES('[string repeat {c } 50000]')" + execsql "INSERT INTO t8 VALUES('d d d')" + execsql "INSERT INTO t8 VALUES('e e e')" + execsql "INSERT INTO t8(t8) VALUES('optimize')" + faultsim_save_and_close +} {} + +ifcapable fts4_deferred { + do_faultsim_test 8.1 -faults oom-t* -prep { + faultsim_restore_and_reopen + db func mit mit + } -body { + execsql { SELECT mit(matchinfo(t8, 'x')) FROM t8 WHERE t8 MATCH 'a b c' } + } -test { + faultsim_test_result {0 {{1 1 1 1 4 2 1 5 5}}} + } +} + +do_faultsim_test 8.2 -faults oom-t* -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 's')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 3} $::TMPDBERROR +} +do_faultsim_test 8.3 -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 'a')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 10002} +} +do_faultsim_test 8.4 -prep { + faultsim_restore_and_reopen + db func mit mit +} -body { + execsql { SELECT mit(matchinfo(t8, 'l')) FROM t8 WHERE t8 MATCH 'a b c' } +} -test { + faultsim_test_result {0 3} +} + +do_test 9.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE t9 USING fts4(tokenize=porter); + INSERT INTO t9 VALUES( + 'this record is used toooooooooooooooooooooooooooooooooooooo try to' + ); + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*'; + } + faultsim_save_and_close +} {} +do_faultsim_test 9.1 -prep { + faultsim_restore_and_reopen +} -body { + execsql { SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to*' } +} -test { + faultsim_test_result {0 {{0 0 20 39 0 0 64 2}}} +} + +do_faultsim_test 10.1 -prep { + faultsim_delete_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=d) } +} -test { + faultsim_test_result {0 {}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); +} +faultsim_save_and_close + +do_faultsim_test 11 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { DROP TABLE t1 } +} -test { + faultsim_test_result {0 {}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault2.test new file mode 100644 index 0000000000000000000000000000000000000000..913f9baa0583a9fb4b54336ccbd2f534ff58f677 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault2.test @@ -0,0 +1,250 @@ +# 2011 February 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3fault2 + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +do_test 1.0 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4(x); + INSERT INTO t1 VALUES('a b c'); + INSERT INTO t1 VALUES('c d e'); + CREATE VIRTUAL TABLE terms USING fts4aux(t1); + } + faultsim_save_and_close +} {} + +do_faultsim_test 1.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "CREATE VIRTUAL TABLE terms2 USING fts4aux(t1)" +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 1.2 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms" +} -test { + faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 2 2 c 0 2 2 d * 1 1 d 0 1 1 e * 1 1 e 0 1 1}} +} + +do_faultsim_test 1.3 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms WHERE term>'a' AND TERM < 'd'" +} -test { + faultsim_test_result {0 {b * 1 1 b 0 1 1 c * 2 2 c 0 2 2}} +} + +do_faultsim_test 1.4 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms WHERE term='c'" +} -test { + faultsim_test_result {0 {c * 2 2 c 0 2 2}} +} + +do_test 2.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE tx USING fts4(a, b); + INSERT INTO tx VALUES('a b c', 'x y z'); + CREATE VIRTUAL TABLE terms2 USING fts4aux(tx); + } + faultsim_save_and_close +} {} + +do_faultsim_test 2.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql "SELECT * FROM terms2" +} -test { + faultsim_test_result {0 {a * 1 1 a 0 1 1 b * 1 1 b 0 1 1 c * 1 1 c 0 1 1 x * 1 1 x 1 1 1 y * 1 1 y 1 1 1 z * 1 1 z 1 1 1}} +} + +do_faultsim_test 3.0 -faults oom* -prep { + faultsim_delete_and_reopen + db eval { CREATE TABLE 'xx yy'(a, b); } +} -body { + execsql { + CREATE VIRTUAL TABLE tt USING fts4(content="xx yy"); + } +} -test { + faultsim_test_result {0 {}} +} + +do_faultsim_test 3.1 -faults oom* -prep { + faultsim_delete_and_reopen + db func zip zip + db func unzip unzip +} -body { + execsql { + CREATE VIRTUAL TABLE tt USING fts4(compress=zip, uncompress=unzip); + } +} -test { + faultsim_test_result {0 {}} +} + +do_test 4.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE ft USING fts4(a, b); + INSERT INTO ft VALUES('U U T C O', 'F N D E S'); + INSERT INTO ft VALUES('P H X G B', 'I D M R U'); + INSERT INTO ft VALUES('P P X D M', 'Y V N T C'); + INSERT INTO ft VALUES('Z L Q O W', 'D F U N Q'); + INSERT INTO ft VALUES('A J D U P', 'C H M Q E'); + INSERT INTO ft VALUES('P S A O H', 'S Z C W D'); + INSERT INTO ft VALUES('T B N L W', 'C A K T I'); + INSERT INTO ft VALUES('K E Z L O', 'L L Y C E'); + INSERT INTO ft VALUES('C R E S V', 'Q V F W P'); + INSERT INTO ft VALUES('S K H G W', 'R W Q F G'); + } + faultsim_save_and_close +} {} +do_faultsim_test 4.1 -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql { INSERT INTO ft(ft) VALUES('rebuild') } +} -test { + faultsim_test_result {0 {}} +} + +ifcapable fts3_unicode { + do_test 5.0 { + faultsim_delete_and_reopen + execsql { + CREATE VIRTUAL TABLE ft USING fts4(a, tokenize=unicode61); + } + faultsim_save_and_close + } {} + + do_faultsim_test 5.1 -faults oom* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} + } -body { + execsql { INSERT INTO ft VALUES('the quick brown fox'); } + execsql { INSERT INTO ft VALUES( + 'theunusuallylongtokenthatjustdragsonandonandonandthendragsonsomemoreeof' + ); + } + execsql { SELECT docid FROM ft WHERE ft MATCH 'th*' } + } -test { + faultsim_test_result {0 {1 2}} + } +} + +reset_db +do_test 6.0 { + execsql { + CREATE VIRTUAL TABLE t6 USING fts4(x,order=DESC); + INSERT INTO t6(docid, x) VALUES(-1,'a b'); + INSERT INTO t6(docid, x) VALUES(1, 'b'); + } + faultsim_save_and_close +} {} + +do_faultsim_test 6.1 -faults oom* -prep { + faultsim_restore_and_reopen + db eval {SELECT * FROM sqlite_master} +} -body { + execsql { SELECT docid FROM t6 WHERE t6 MATCH '"a* b"' } +} -test { + faultsim_test_result {0 -1} +} + +#------------------------------------------------------------------------- +# Inject faults into a query for an N-byte prefix that uses a prefix=N+1 +# index. +reset_db +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE t7 USING fts4(x,prefix=2); + INSERT INTO t7 VALUES('the quick brown fox'); + INSERT INTO t7 VALUES('jumped over the'); + INSERT INTO t7 VALUES('lazy dog'); +} +do_faultsim_test 7.1 -faults oom* -body { + execsql { SELECT docid FROM t7 WHERE t7 MATCH 't*' } +} -test { + faultsim_test_result {0 {1 2}} +} + +#------------------------------------------------------------------------- +# Inject faults into a opening an existing fts3 table that has been +# upgraded to add an %_stat table. +# +reset_db +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t8 USING fts3; + INSERT INTO t8 VALUES('the quick brown fox'); + INSERT INTO t8 VALUES('jumped over the'); + INSERT INTO t8 VALUES('lazy dog'); + INSERT INTO t8(t8) VALUES('automerge=8'); + SELECT name FROM sqlite_master WHERE name LIKE 't8%'; +} { + t8 t8_content t8_segments t8_segdir t8_stat +} +faultsim_save_and_close + +do_faultsim_test 8.1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { INSERT INTO t8 VALUES('one two three') } +} -test { + faultsim_test_result {0 {}} +} + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] +do_faultsim_test 8.2 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { ALTER TABLE t8 RENAME TO t8ii } +} -test { + faultsim_test_result {0 {}} $::TMPDBERROR +} + +#------------------------------------------------------------------------- +reset_db +set chunkconfig [fts3_configure_incr_load 1 1] +do_execsql_test 9.0 { + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t9 USING fts3; + WITH s(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50 + ) + INSERT INTO t9 SELECT 'one two three' FROM s; +} + +do_faultsim_test 8.2 -faults io* -body { + execsql { SELECT count(*) FROM t9 WHERE t9 MATCH '"one two three"' } +} -test { + faultsim_test_result {0 50} +} + +eval fts3_configure_incr_load $chunkconfig + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault3.test new file mode 100644 index 0000000000000000000000000000000000000000..ae204718b438feaec94d0064f73f458d603a5ea6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3fault3.test @@ -0,0 +1,82 @@ +# 2023 October 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. +# +#*********************************************************************** +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set ::testprefix fts3fault + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set ::TMPDBERROR [list 1 \ + {unable to open a temporary database file for storing temporary tables} +] + + +# Test error handling in an "ALTER TABLE ... RENAME TO" statement on an +# FTS3 table. Specifically, test renaming the table within a transaction +# after it has been written to. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a); + INSERT INTO t1 VALUES('test renaming the table'); + INSERT INTO t1 VALUES(' after it has been written'); + INSERT INTO t1 VALUES(' actually other stuff instead'); +} +faultsim_save_and_close +do_faultsim_test 1 -faults oom* -prep { + faultsim_restore_and_reopen + execsql { + BEGIN; + DELETE FROM t1 WHERE rowid=2; + } +} -body { + execsql { + DELETE FROM t1; + } +} -test { + catchsql { COMMIT } + faultsim_integrity_check + 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/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3integrity.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3integrity.test new file mode 100644 index 0000000000000000000000000000000000000000..bcbc49dc3370179a7da8b9849d41e6ff1c0dc07a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3integrity.test @@ -0,0 +1,42 @@ +# 2023 December 16 +# +# 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 runs all tests. +# +# $Id: fts3.test,v 1.2 2008/07/23 18:17:32 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3integrity + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + INSERT INTO t1 VALUES('first row'); + INSERT INTO t1 VALUES('second row'); + + CREATE TABLE t2(x PRIMARY KEY); + INSERT INTO t2 VALUES('first row'); + INSERT INTO t2 VALUES('second row'); +} + +sqlite3 db2 test.db + +do_execsql_test -db db2 1.1 { + CREATE TABLE t3(x, y); +} + +do_execsql_test 1.2 { + PRAGMA integrity_check; +} {ok} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3join.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3join.test new file mode 100644 index 0000000000000000000000000000000000000000..cbd08b63f293392500b79caee29ff181e1ffe35c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3join.test @@ -0,0 +1,107 @@ +# 2014 January 4 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set ::testprefix fts3join + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft1 USING fts4(x); + INSERT INTO ft1 VALUES('aaa aaa'); + INSERT INTO ft1 VALUES('aaa bbb'); + INSERT INTO ft1 VALUES('bbb aaa'); + INSERT INTO ft1 VALUES('bbb bbb'); + + CREATE TABLE t1(id, y); + INSERT INTO t1 VALUES(1, 'aaa'); + INSERT INTO t1 VALUES(2, 'bbb'); +} + +do_execsql_test 1.1 { + SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1; +} {1 2 3} + +do_execsql_test 1.2 { + SELECT docid FROM ft1, t1 WHERE ft1 MATCH y AND id=1 ORDER BY docid; +} {1 2 3} + +do_execsql_test 2.0 { + CREATE VIRTUAL TABLE ft2 USING fts4(x); + CREATE VIRTUAL TABLE ft3 USING fts4(y); + + INSERT INTO ft2 VALUES('abc'); + INSERT INTO ft2 VALUES('def'); + INSERT INTO ft3 VALUES('ghi'); + INSERT INTO ft3 VALUES('abc'); +} + +do_execsql_test 2.1 { SELECT * FROM ft2, ft3 WHERE x MATCH y; } {abc abc} +do_execsql_test 2.2 { SELECT * FROM ft2, ft3 WHERE y MATCH x; } {abc abc} +do_execsql_test 2.3 { SELECT * FROM ft3, ft2 WHERE x MATCH y; } {abc abc} +do_execsql_test 2.4 { SELECT * FROM ft3, ft2 WHERE y MATCH x; } {abc abc} + +do_catchsql_test 2.5 { + SELECT * FROM ft3, ft2 WHERE y MATCH x AND x MATCH y; +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE vt USING fts3(x); + INSERT INTO vt VALUES('abc'); + INSERT INTO vt VALUES('xyz'); + + CREATE TABLE tt(a INTEGER PRIMARY KEY); + INSERT INTO tt VALUES(1), (2); +} + +do_execsql_test 3.1 { + SELECT * FROM tt LEFT JOIN ( + SELECT rowid AS rrr, * FROM vt WHERE vt MATCH 'abc' + ) ON tt.a = rrr +} {1 1 abc 2 {} {}} + +do_execsql_test 3.2 { + SELECT * FROM tt LEFT JOIN vt ON (vt MATCH 'abc') +} {1 abc 2 abc} + +#------------------------------------------------------------------------- +# Test that queries of the form found in test case 4.2 use an automatic +# index to avoid running multiple fts queries. +# +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE ft4 USING fts3(x); + CREATE TABLE t4(y, z); + CREATE INDEX t4y ON t1(y); +} + +do_eqp_test 4.2 { + SELECT * FROM t4 LEFT JOIN ( + SELECT docid, * FROM ft4 WHERE ft4 MATCH ? + ) AS rr ON t4.rowid=rr.docid + WHERE t4.y = ?; +} { + QUERY PLAN + |--MATERIALIZE rr + | `--SCAN ft4 VIRTUAL TABLE INDEX 3: + |--SCAN t4 + |--BLOOM FILTER ON rr (docid=?) + `--SEARCH rr USING AUTOMATIC COVERING INDEX (docid=?) LEFT-JOIN +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3malloc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3malloc.test new file mode 100644 index 0000000000000000000000000000000000000000..ed30fe24c8ab0928bae84471e7b8c9e2ad302d2b --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3malloc.test @@ -0,0 +1,307 @@ +# 2009 October 22 +# +# 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 to verify that malloc() errors that occur +# within the FTS3 module code are handled correctly. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +source $testdir/malloc_common.tcl +source $testdir/fts3_common.tcl + +# Ensure the lookaside buffer is disabled for these tests. +# +sqlite3 db test.db +sqlite3_db_config_lookaside db 0 0 0 + +set sqlite_fts3_enable_parentheses 1 +set DO_MALLOC_TEST 1 + +# Test organization: +# +# fts3_malloc-1.*: Test OOM during CREATE and DROP table statements. +# fts3_malloc-2.*: Test OOM during SELECT operations. +# fts3_malloc-3.*: Test OOM during SELECT operations with a larger database. +# fts3_malloc-4.*: Test OOM during database write operations. +# fts3_malloc-5.*: Test that a couple of memory leaks that could follow +# OOM in tokenizer code have been fixed. +# + + +proc normal_list {l} { + set ret [list] + foreach elem $l {lappend ret $elem} + set ret +} + +do_write_test fts3_malloc-1.1 sqlite_master { + CREATE VIRTUAL TABLE ft1 USING fts3(a, b) +} +do_write_test fts3_malloc-1.2 sqlite_master { + CREATE VIRTUAL TABLE ft2 USING fts3([a], [b]); +} +do_write_test fts3_malloc-1.3 sqlite_master { + CREATE VIRTUAL TABLE ft3 USING fts3('a', "b"); +} +do_write_test fts3_malloc-1.4 sqlite_master { + CREATE VIRTUAL TABLE ft4 USING fts3(`a`, 'fred''s column'); +} +do_error_test fts3_malloc-1.5 { + CREATE VIRTUAL TABLE ft5 USING fts3(a, b, tokenize unknown) +} {unknown tokenizer: unknown} +do_write_test fts3_malloc-1.6 sqlite_master { + CREATE VIRTUAL TABLE ft6 USING fts3(a, b, tokenize porter) +} +do_write_test fts3_malloc-1.7 sqlite_master { + CREATE VIRTUAL TABLE ft7 USING fts4(a, b, notindexed=b) +} + +# Test the xConnect/xDisconnect methods: +#db eval { ATTACH 'test2.db' AS aux } +#do_write_test fts3_malloc-1.6 aux.sqlite_master { +# CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +#} +#do_write_test fts3_malloc-1.6 aux.sqlite_master { +# CREATE VIRTUAL TABLE aux.ft7 USING fts3(a, b, c); +#} + + + +do_test fts3_malloc-2.0 { + execsql { + DROP TABLE ft1; + DROP TABLE ft2; + DROP TABLE ft3; + DROP TABLE ft4; + DROP TABLE ft6; + DROP TABLE ft7; + } + execsql { CREATE VIRTUAL TABLE ft USING fts3(a, b) } + for {set ii 1} {$ii < 32} {incr ii} { + set a [list] + set b [list] + if {$ii & 0x01} {lappend a one ; lappend b neung} + if {$ii & 0x02} {lappend a two ; lappend b song } + if {$ii & 0x04} {lappend a three ; lappend b sahm } + if {$ii & 0x08} {lappend a four ; lappend b see } + if {$ii & 0x10} {lappend a five ; lappend b hah } + execsql { INSERT INTO ft VALUES($a, $b) } + } +} {} + +foreach {tn sql result} { + 1 "SELECT count(*) FROM sqlite_master" {5} + 2 "SELECT * FROM ft WHERE docid = 1" {one neung} + 3 "SELECT * FROM ft WHERE docid = 2" {two song} + 4 "SELECT * FROM ft WHERE docid = 3" {{one two} {neung song}} + + 5 "SELECT a FROM ft" { + {one} {two} {one two} + {three} {one three} {two three} + {one two three} {four} {one four} + {two four} {one two four} {three four} + {one three four} {two three four} {one two three four} + {five} {one five} {two five} + {one two five} {three five} {one three five} + {two three five} {one two three five} {four five} + {one four five} {two four five} {one two four five} + {three four five} {one three four five} {two three four five} + {one two three four five} + } + + 6 "SELECT a FROM ft WHERE a MATCH 'one'" { + {one} {one two} {one three} {one two three} + {one four} {one two four} {one three four} {one two three four} + {one five} {one two five} {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 7 "SELECT a FROM ft WHERE a MATCH 'o*'" { + {one} {one two} {one three} {one two three} + {one four} {one two four} {one three four} {one two three four} + {one five} {one two five} {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 8 "SELECT a FROM ft WHERE a MATCH 'o* t*'" { + {one two} {one three} {one two three} + {one two four} {one three four} {one two three four} + {one two five} {one three five} {one two three five} + {one two four five} {one three four five} {one two three four five} + } + + 9 "SELECT a FROM ft WHERE a MATCH '\"o* t*\"'" { + {one two} {one three} {one two three} + {one two four} {one three four} {one two three four} + {one two five} {one three five} {one two three five} + {one two four five} {one three four five} {one two three four five} + } + + 10 {SELECT a FROM ft WHERE a MATCH '"o* f*"'} { + {one four} {one five} {one four five} + } + + 11 {SELECT a FROM ft WHERE a MATCH '"one two three"'} { + {one two three} + {one two three four} + {one two three five} + {one two three four five} + } + + 12 {SELECT a FROM ft WHERE a MATCH '"two three four"'} { + {two three four} + {one two three four} + {two three four five} + {one two three four five} + } + + 12 {SELECT a FROM ft WHERE a MATCH '"two three" five'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 13 {SELECT a FROM ft WHERE ft MATCH '"song sahm" hah'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 14 {SELECT a FROM ft WHERE b MATCH 'neung'} { + {one} {one two} + {one three} {one two three} + {one four} {one two four} + {one three four} {one two three four} + {one five} {one two five} + {one three five} {one two three five} + {one four five} {one two four five} + {one three four five} {one two three four five} + } + + 15 {SELECT a FROM ft WHERE b MATCH '"neung song sahm"'} { + {one two three} {one two three four} + {one two three five} {one two three four five} + } + + 16 {SELECT a FROM ft WHERE b MATCH 'hah "song sahm"'} { + {two three five} {one two three five} + {two three four five} {one two three four five} + } + + 17 {SELECT a FROM ft WHERE b MATCH 'song OR sahm'} { + {two} {one two} {three} + {one three} {two three} {one two three} + {two four} {one two four} {three four} + {one three four} {two three four} {one two three four} + {two five} {one two five} {three five} + {one three five} {two three five} {one two three five} + {two four five} {one two four five} {three four five} + {one three four five} {two three four five} {one two three four five} + } + + 18 {SELECT a FROM ft WHERE a MATCH 'three NOT two'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 19 {SELECT a FROM ft WHERE b MATCH 'sahm NOT song'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 20 {SELECT a FROM ft WHERE ft MATCH 'sahm NOT song'} { + {three} {one three} {three four} + {one three four} {three five} {one three five} + {three four five} {one three four five} + } + + 21 {SELECT a FROM ft WHERE b MATCH 'neung NEAR song NEAR sahm'} { + {one two three} {one two three four} + {one two three five} {one two three four five} + } + +} { + set result [normal_list $result] + do_select_test fts3_malloc-2.$tn $sql $result +} + +do_test fts3_malloc-3.0 { + execsql BEGIN + for {set ii 32} {$ii < 1024} {incr ii} { + set a [list] + set b [list] + if {$ii & 0x0001} {lappend a one ; lappend b neung } + if {$ii & 0x0002} {lappend a two ; lappend b song } + if {$ii & 0x0004} {lappend a three ; lappend b sahm } + if {$ii & 0x0008} {lappend a four ; lappend b see } + if {$ii & 0x0010} {lappend a five ; lappend b hah } + if {$ii & 0x0020} {lappend a six ; lappend b hok } + if {$ii & 0x0040} {lappend a seven ; lappend b jet } + if {$ii & 0x0080} {lappend a eight ; lappend b bairt } + if {$ii & 0x0100} {lappend a nine ; lappend b gow } + if {$ii & 0x0200} {lappend a ten ; lappend b sip } + execsql { INSERT INTO ft VALUES($a, $b) } + } + execsql COMMIT +} {} +foreach {tn sql result} { + 1 "SELECT count(*) FROM ft" {1023} + + 2 "SELECT a FROM ft WHERE a MATCH 'one two three four five six seven eight'" { + {one two three four five six seven eight} + {one two three four five six seven eight nine} + {one two three four five six seven eight ten} + {one two three four five six seven eight nine ten} + } + + 3 {SELECT count(*), sum(docid) FROM ft WHERE a MATCH 'o*'} { + 512 262144 + } + + 4 {SELECT count(*), sum(docid) FROM ft WHERE a MATCH '"two three four"'} { + 128 66368 + } +} { + set result [normal_list $result] + do_select_test fts3_malloc-3.$tn $sql $result +} + +do_test fts3_malloc-4.0 { + execsql { DELETE FROM ft WHERE docid>=32 } +} {} +foreach {tn sql} { + 1 "DELETE FROM ft WHERE ft MATCH 'one'" + 2 "DELETE FROM ft WHERE ft MATCH 'three'" + 3 "DELETE FROM ft WHERE ft MATCH 'five'" +} { + do_write_test fts3_malloc-4.1.$tn ft_content $sql +} +do_test fts3_malloc-4.2 { + execsql { SELECT a FROM ft } +} {two four {two four}} + +do_write_test fts3_malloc-5.1 ft_content { + INSERT INTO ft VALUES('short alongertoken reallyquitealotlongerimeanit andthistokenisjustsolongthatonemightbeforgivenforimaginingthatitwasmerelyacontrivedexampleandnotarealtoken', 'cynics!') +} +do_test fts3_malloc-5.2 { + execsql { CREATE VIRTUAL TABLE ft8 USING fts3(x, tokenize porter) } +} {} + +do_write_test fts3_malloc-5.3 ft_content { + INSERT INTO ft8 VALUES('short alongertoken reallyquitealotlongerimeanit andthistokenisjustsolongthatonemightbeforgivenforimaginingthatitwasmerelyacontrivedexampleandnotarealtoken') +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo.test new file mode 100644 index 0000000000000000000000000000000000000000..af0b1cdc0db3f2d84556d505ecfda3fbcce0ed56 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo.test @@ -0,0 +1,556 @@ +# 2010 November 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. +# +#*********************************************************************** +# This file implements regression tests for the FTS3 module. The focus +# of this file is tables created with the "matchinfo=fts3" option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set testprefix fts3matchinfo +set sqlite_fts3_enable_parentheses 0 + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(matchinfo=fts3); + SELECT name FROM sqlite_master WHERE type = 'table'; +} {t1 t1_content t1_segments t1_segdir t1_stat} + +do_execsql_test 1.1 { + INSERT INTO t1(content) VALUES('I wandered lonely as a cloud'); + INSERT INTO t1(content) VALUES('That floats on high o''er vales and hills,'); + INSERT INTO t1(content) VALUES('When all at once I saw a crowd,'); + INSERT INTO t1(content) VALUES('A host, of golden daffodils,'); + SELECT mit(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'I'; +} {{1 1 1 2 2} {1 1 1 2 2}} + +# Now create an FTS4 table that does not specify matchinfo=fts3. +# +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 SELECT * FROM t1; + SELECT mit(matchinfo(t2)) FROM t2 WHERE t2 MATCH 'I'; +} {{1 1 1 2 2} {1 1 1 2 2}} + +# Test some syntax-error handling. +# +do_catchsql_test 2.0 { + CREATE VIRTUAL TABLE x1 USING fts4(matchinfo=fs3); +} {1 {unrecognized matchinfo: fs3}} +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE x2 USING fts4(mtchinfo=fts3); +} {1 {unrecognized parameter: mtchinfo=fts3}} +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE x2 USING fts4(matchinfo=fts5); +} {1 {unrecognized matchinfo: fts5}} + +# Check that with fts3, the "=" character is permitted in column definitions. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t3 USING fts3(mtchinfo=fts3); + INSERT INTO t3(mtchinfo) VALUES('Beside the lake, beneath the trees'); + SELECT mtchinfo FROM t3; +} {{Beside the lake, beneath the trees}} + +do_execsql_test 3.2 { + CREATE VIRTUAL TABLE xx USING FTS4; +} +do_execsql_test 3.3 { + SELECT * FROM xx WHERE xx MATCH 'abc'; +} +do_execsql_test 3.4 { + SELECT * FROM xx WHERE xx MATCH 'a b c'; +} + + +#-------------------------------------------------------------------------- +# Proc [do_matchinfo_test] is used to test the FTSX matchinfo() function. +# +# The first argument - $tn - is a test identifier. This may be either a +# full identifier (i.e. "fts3matchinfo-1.1") or, if global var $testprefix +# is set, just the numeric component (i.e. "1.1"). +# +# The second argument is the name of an FTSX table. The third is the +# full text of a WHERE/MATCH expression to query the table for +# (i.e. "t1 MATCH 'abc'"). The final argument - $results - should be a +# key-value list (serialized array) with matchinfo() format specifiers +# as keys, and the results of executing the statement: +# +# SELECT matchinfo($tbl, '$key') FROM $tbl WHERE $expr +# +# For example: +# +# CREATE VIRTUAL TABLE t1 USING fts4; +# INSERT INTO t1 VALUES('abc'); +# INSERT INTO t1 VALUES('def'); +# INSERT INTO t1 VALUES('abc abc'); +# +# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" { +# n {3 3} +# p {1 1} +# c {1 1} +# x {{1 3 2} {2 3 2}} +# } +# +# If the $results list contains keys mapped to "-" instead of a matchinfo() +# result, then this command computes the expected results based on other +# mappings to test the matchinfo() function. For example, the command above +# could be changed to: +# +# do_matchinfo_test 1.1 t1 "t1 MATCH 'abc'" { +# n {3 3} p {1 1} c {1 1} x {{1 3 2} {2 3 2}} +# pcx - +# } +# +# And this command would compute the expected results for matchinfo(t1, 'pcx') +# based on the results of matchinfo(t1, 'p'), matchinfo(t1, 'c') and +# matchinfo(t1, 'x') in order to test 'pcx'. +# +proc do_matchinfo_test {tn tbl expr results} { + + foreach {fmt res} $results { + if {$res == "-"} continue + set resarray($fmt) $res + } + + set nRow 0 + foreach {fmt res} [array get resarray] { + if {[llength $res]>$nRow} { set nRow [llength $res] } + } + + # Construct expected results for any formats for which the caller + # supplied result is "-". + # + foreach {fmt res} $results { + if {$res == "-"} { + set res [list] + for {set iRow 0} {$iRow<$nRow} {incr iRow} { + set rowres [list] + foreach c [split $fmt ""] { + set rowres [concat $rowres [lindex $resarray($c) $iRow]] + } + lappend res $rowres + } + set resarray($fmt) $res + } + } + + # Test each matchinfo() request individually. + # + foreach {fmt res} [array get resarray] { + set sql "SELECT mit(matchinfo($tbl, '$fmt')) FROM $tbl WHERE $expr" + do_execsql_test $tn.$fmt $sql [normalize2 $res] + } + + # Test them all executed together (multiple invocations of matchinfo()). + # + set exprlist [list] + foreach {format res} [array get resarray] { + lappend exprlist "mit(matchinfo($tbl, '$format'))" + } + set allres [list] + for {set iRow 0} {$iRow<$nRow} {incr iRow} { + foreach {format res} [array get resarray] { + lappend allres [lindex $res $iRow] + } + } + set sql "SELECT [join $exprlist ,] FROM $tbl WHERE $expr" + do_execsql_test $tn.multi $sql [normalize2 $allres] +} +proc normalize2 {list_of_lists} { + set res [list] + foreach elem $list_of_lists { + lappend res [list {*}$elem] + } + return $res +} + + +do_execsql_test 4.1.0 { + CREATE VIRTUAL TABLE t4 USING fts4(x, y); + INSERT INTO t4 VALUES('a b c d e', 'f g h i j'); + INSERT INTO t4 VALUES('f g h i j', 'a b c d e'); +} + +do_matchinfo_test 4.1.1 t4 {t4 MATCH 'a b c'} { + p {3 3} + c {2 2} + x { + {1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1} + {0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1} + } + n {2 2} + l {{5 5} {5 5}} + a {{5 5} {5 5}} + + s {{3 0} {0 3}} + + xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc - + xpxsscplax - +} + +do_matchinfo_test 4.1.2 t4 {t4 MATCH '"g h i"'} { + p {1 1} + c {2 2} + x { + {0 1 1 1 1 1} + {1 1 1 0 1 1} + } + n {2 2} + l {{5 5} {5 5}} + a {{5 5} {5 5}} + + s {{0 1} {1 0}} + + xxxxxxxxxxxxxxxxxx - pcx - xpc - ccc - pppxpcpcx - laxnpc - + sxsxs - +} + +do_matchinfo_test 4.1.3 t4 {t4 MATCH 'a b'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.4 t4 {t4 MATCH '"a b" c'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.5 t4 {t4 MATCH 'a "b c"'} { s {{2 0} {0 2}} } +do_matchinfo_test 4.1.6 t4 {t4 MATCH 'd d'} { s {{1 0} {0 1}} } +do_matchinfo_test 4.1.7 t4 {t4 MATCH 'f OR abcd'} { + x { + {0 1 1 1 1 1 0 0 0 0 0 0} + {1 1 1 0 1 1 0 0 0 0 0 0} + } +} +do_matchinfo_test 4.1.8 t4 {t4 MATCH 'f -abcd'} { + x { + {0 1 1 1 1 1} + {1 1 1 0 1 1} + } +} + +do_execsql_test 4.2.0 { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('a a a a a'); + INSERT INTO t5 VALUES('a b a b a'); + INSERT INTO t5 VALUES('c b c b c'); + INSERT INTO t5 VALUES('x x x x x'); +} +do_matchinfo_test 4.2.1 t5 {t5 MATCH 'a a'} { + x {{5 8 2 5 8 2} {3 8 2 3 8 2}} + s {2 1} +} +do_matchinfo_test 4.2.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.2.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.2.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.2.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } +do_matchinfo_test 4.2.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1} } + +do_execsql_test 4.3.0 "INSERT INTO t5 VALUES('x y [string repeat {b } 50000]')"; + +# It used to be that the second 'a' token would be deferred. That doesn't +# work any longer. +if 0 { + do_matchinfo_test 4.3.1 t5 {t5 MATCH 'a a'} { + x {{5 8 2 5 5 5} {3 8 2 3 5 5}} + s {2 1} + } +} + +do_matchinfo_test 4.3.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.3.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.3.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.3.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } +do_matchinfo_test 4.3.6 t5 {t5 MATCH 'a OR b'} { s {1 2 1 1} } + +do_execsql_test 4.4.0.1 { INSERT INTO t5(t5) VALUES('optimize') } + +ifcapable fts4_deferred { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.4.0.2 { + UPDATE t5_segments + SET block = zeroblob(length(block)) + WHERE length(block)>10000; + } +} + +do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.4.1 t5 {t5 MATCH 'a a'} { s {2 1} } +do_matchinfo_test 4.4.2 t5 {t5 MATCH 'a b'} { s {2} } +do_matchinfo_test 4.4.3 t5 {t5 MATCH 'a b a'} { s {3} } +do_matchinfo_test 4.4.4 t5 {t5 MATCH 'a a a'} { s {3 1} } +do_matchinfo_test 4.4.5 t5 {t5 MATCH '"a b" "a b"'} { s {2} } + +do_execsql_test 4.5.0 { + CREATE VIRTUAL TABLE t6 USING fts4(a, b, c); + INSERT INTO t6 VALUES('a', 'b', 'c'); +} +do_matchinfo_test 4.5.1 t6 {t6 MATCH 'a b c'} { s {{1 1 1}} } + + +#------------------------------------------------------------------------- +# Check the following restrictions: +# +# + Matchinfo flags 'a', 'l' and 'n' can only be used with fts4, not fts3. +# + Matchinfo flag 'l' cannot be used with matchinfo=fts3. +# +do_execsql_test 5.1 { + CREATE VIRTUAL TABLE t7 USING fts3(a, b); + INSERT INTO t7 VALUES('u v w', 'x y z'); + + CREATE VIRTUAL TABLE t8 USING fts4(a, b, matchinfo=fts3); + INSERT INTO t8 VALUES('u v w', 'x y z'); +} + +do_catchsql_test 5.2.1 { + SELECT matchinfo(t7, 'a') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: a}} +do_catchsql_test 5.2.2 { + SELECT matchinfo(t7, 'l') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: l}} +do_catchsql_test 5.2.3 { + SELECT matchinfo(t7, 'n') FROM t7 WHERE t7 MATCH 'x y' +} {1 {unrecognized matchinfo request: n}} + +do_catchsql_test 5.3.1 { + SELECT matchinfo(t8, 'l') FROM t8 WHERE t8 MATCH 'x y' +} {1 {unrecognized matchinfo request: l}} + +#------------------------------------------------------------------------- +# Test that the offsets() function handles corruption in the %_content +# table correctly. +# +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE t9 USING fts4; + INSERT INTO t9 VALUES( + 'this record is used to try to dectect corruption' + ); + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; +} {{0 0 20 2 0 0 27 2}} + +sqlite3_db_config db DEFENSIVE 0 +do_catchsql_test 6.2 { + UPDATE t9_content SET c0content = 'this record is used to'; + SELECT offsets(t9) FROM t9 WHERE t9 MATCH 'to'; +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +# Test the outcome of matchinfo() when used within a query that does not +# use the full-text index (i.e. lookup by rowid or full-table scan). +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE t10 USING fts4; + INSERT INTO t10 VALUES('first record'); + INSERT INTO t10 VALUES('second record'); +} +do_execsql_test 7.2 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10; +} {blob 0 blob 0} +do_execsql_test 7.3 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) FROM t10 WHERE docid=1; +} {blob 0} +do_execsql_test 7.4 { + SELECT typeof(matchinfo(t10)), length(matchinfo(t10)) + FROM t10 WHERE t10 MATCH 'record' +} {blob 20 blob 20} + +#------------------------------------------------------------------------- +# Test a special case - matchinfo('nxa') with many zero length documents. +# Special because "x" internally uses a statement used by both "n" and "a". +# This was causing a problem at one point in the obscure case where the +# total number of bytes of data stored in an fts3 table was greater than +# the number of rows. i.e. when the following query returns true: +# +# SELECT sum(length(content)) < count(*) FROM fts4table; +# +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE t11 USING fts4; + INSERT INTO t11(t11) VALUES('nodesize=24'); + INSERT INTO t11 VALUES('quitealongstringoftext'); + INSERT INTO t11 VALUES('anotherquitealongstringoftext'); + INSERT INTO t11 VALUES('athirdlongstringoftext'); + INSERT INTO t11 VALUES('andonemoreforgoodluck'); +} +do_test 8.2 { + for {set i 0} {$i < 200} {incr i} { + execsql { INSERT INTO t11 VALUES('') } + } + execsql { INSERT INTO t11(t11) VALUES('optimize') } +} {} +do_execsql_test 8.3 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {{204 1 3 3 0} {204 1 3 3 0} {204 1 3 3 0}} + +# Corruption related tests. +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 8.4.1.1 { UPDATE t11_stat SET value = X'0000'; } +do_catchsql_test 8.5.1.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +do_execsql_test 8.4.2.1 { UPDATE t11_stat SET value = X'00'; } +do_catchsql_test 8.5.2.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +do_execsql_test 8.4.3.1 { UPDATE t11_stat SET value = NULL; } +do_catchsql_test 8.5.3.2 { + SELECT mit(matchinfo(t11, 'nxa')) FROM t11 WHERE t11 MATCH 'a*' +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE t12 USING fts4; + INSERT INTO t12 VALUES('a b c d'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} {{0 0 0 0 0 0 1 1 1}} +do_execsql_test 8.2 { + INSERT INTO t12 VALUES('a d c d'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} { + {0 1 1 0 1 1 1 2 2} {1 1 1 1 1 1 1 2 2} +} +do_execsql_test 8.3 { + INSERT INTO t12 VALUES('a d d a'); + SELECT mit(matchinfo(t12, 'x')) FROM t12 WHERE t12 MATCH 'a NEAR/1 d OR a'; +} { + {0 3 2 0 3 2 1 4 3} {1 3 2 1 3 2 1 4 3} {2 3 2 2 3 2 2 4 3} +} + +do_execsql_test 9.1 { + CREATE VIRTUAL TABLE ft2 USING fts4; + INSERT INTO ft2 VALUES('a b c d e'); + INSERT INTO ft2 VALUES('f a b c d'); + SELECT snippet(ft2, '[', ']', '', -1, 1) FROM ft2 WHERE ft2 MATCH 'c'; +} {{[c]} {[c]}} + +#--------------------------------------------------------------------------- +# Test for a memory leak +# +do_execsql_test 10.1 { + DROP TABLE t10; + CREATE VIRTUAL TABLE t10 USING fts4(idx, value); + INSERT INTO t10 values (1, 'one'),(2, 'two'),(3, 'three'); + SELECT docId, t10.* + FROM t10 + JOIN (SELECT 1 AS idx UNION SELECT 2 UNION SELECT 3) AS x + WHERE t10 MATCH x.idx + AND matchinfo(t10) not null + GROUP BY docId + ORDER BY 1; +} {1 1 one 2 2 two 3 3 three} + +#--------------------------------------------------------------------------- +# Test the 'y' matchinfo flag +# +set sqlite_fts3_enable_parentheses 1 +reset_db +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE tt USING fts3(x, y); + INSERT INTO tt VALUES('c d a c d d', 'e a g b d a'); -- 1 + INSERT INTO tt VALUES('c c g a e b', 'c g d g e c'); -- 2 + INSERT INTO tt VALUES('b e f d e g', 'b a c b c g'); -- 3 + INSERT INTO tt VALUES('a c f f g d', 'd b f d e g'); -- 4 + INSERT INTO tt VALUES('g a c f c f', 'd g g b c c'); -- 5 + INSERT INTO tt VALUES('g a c e b b', 'd b f b g g'); -- 6 + INSERT INTO tt VALUES('f d a a f c', 'e e a d c f'); -- 7 + INSERT INTO tt VALUES('a c b b g f', 'a b a e d f'); -- 8 + INSERT INTO tt VALUES('b a f e c c', 'f d b b a b'); -- 9 + INSERT INTO tt VALUES('f d c e a c', 'f a f a a f'); -- 10 +} + +db func mit mit +foreach {tn expr res} { + 1 "a" { + 1 {1 2} 2 {1 0} 3 {0 1} 4 {1 0} 5 {1 0} + 6 {1 0} 7 {2 1} 8 {1 2} 9 {1 1} 10 {1 3} + } + + 2 "b" { + 1 {0 1} 2 {1 0} 3 {1 2} 4 {0 1} 5 {0 1} + 6 {2 2} 8 {2 1} 9 {1 3} + } + + 3 "y:a" { + 1 {0 2} 3 {0 1} + 7 {0 1} 8 {0 2} 9 {0 1} 10 {0 3} + } + + 4 "x:a" { + 1 {1 0} 2 {1 0} 4 {1 0} 5 {1 0} + 6 {1 0} 7 {2 0} 8 {1 0} 9 {1 0} 10 {1 0} + } + + 5 "a OR b" { + 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} + 6 {1 0 2 2} 7 {2 1 0 0} 8 {1 2 2 1} 9 {1 1 1 3} 10 {1 3 0 0} + } + + 6 "a AND b" { + 1 {1 2 0 1} 2 {1 0 1 0} 3 {0 1 1 2} 4 {1 0 0 1} 5 {1 0 0 1} + 6 {1 0 2 2} 8 {1 2 2 1} 9 {1 1 1 3} + } + + 7 "a OR (a AND b)" { + 1 {1 2 1 2 0 1} 2 {1 0 1 0 1 0} 3 {0 1 0 1 1 2} 4 {1 0 1 0 0 1} + 5 {1 0 1 0 0 1} 6 {1 0 1 0 2 2} 7 {2 1 0 0 0 0} 8 {1 2 1 2 2 1} + 9 {1 1 1 1 1 3} 10 {1 3 0 0 0 0} + } + +} { + do_execsql_test 11.1.$tn.1 { + SELECT rowid, mit(matchinfo(tt, 'y')) FROM tt WHERE tt MATCH $expr + } $res + + set r2 [list] + foreach {rowid L} $res { + lappend r2 $rowid + set M [list] + foreach {a b} $L { + lappend M [expr ($a ? 1 : 0) + ($b ? 2 : 0)] + } + lappend r2 $M + } + + do_execsql_test 11.1.$tn.2 { + SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr + } $r2 + + do_execsql_test 11.1.$tn.2 { + SELECT rowid, mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH $expr + } $r2 +} +set sqlite_fts3_enable_parentheses 0 + +#--------------------------------------------------------------------------- +# Test the 'b' matchinfo flag +# +set sqlite_fts3_enable_parentheses 1 +reset_db +db func mit mit + +do_test 12.0 { + set cols [list] + for {set i 0} {$i < 50} {incr i} { lappend cols "c$i" } + execsql "CREATE VIRTUAL TABLE tt USING fts3([join $cols ,])" +} {} + +do_execsql_test 12.1 { + INSERT INTO tt (rowid, c4, c45) VALUES(1, 'abc', 'abc'); + SELECT mit(matchinfo(tt, 'b')) FROM tt WHERE tt MATCH 'abc'; +} [list [list [expr 1<<4] [expr 1<<(45-32)]]] + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo2.test new file mode 100644 index 0000000000000000000000000000000000000000..670e1079f114feb97d6895402fc2ccee5891d76c --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3matchinfo2.test @@ -0,0 +1,35 @@ +# 2020-05-14 +# +# 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 the FTS3 module. The focus +# of this file is tables created with the "matchinfo=fts3" option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } + +set sqlite_fts3_enable_parentheses 1 + +# Crash case found by cyg0810 at gmail.com 2020-05-14. Reported to +# chromium (which is not vulnerable) who kindly referred it to us. +# +do_execsql_test 1.0 { + CREATE TABLE t_content(col0 INTEGER); + CREATE VIRTUAL TABLE t0 USING fts3(col0 INTEGER PRIMARY KEY,col1 VARCHAR(8),col2 BINARY,col3 BINARY); + INSERT INTO t0 VALUES (1, '1234','aaaa','bbbb'); + SELECT hex(matchinfo(t0,'yxy')) FROM t0 WHERE t0 MATCH x'2b0a312b0a312a312a2a0b5d0a0b0b0a312a0a0b0b0a312a0b310a392a0b0a27312a2a0b5d0a312a0b310a31315d0b310a312a316d2a0b313b15bceaa50a312a0b0a27312a2a0b5d0a312a0b310a312b0b2a310a312a0b2a0b2a0b2e5d0a0bff313336e34a2a312a0b0a3c310b0a0b4b4b0b4b2a4bec40322b2a0b310a0a312a0a0a0a0a0a0a0a0a0b310a312a2a2a0b5d0a0b0b0a312a0b310a312a0b0a4e4541530b310a5df5ced70a0a0a0a0a4f520a0a0a0a0a0a0a312a0b0a4e4541520b310a5d616161610a0a0a0a4f520a0a0a0a0a0a312b0a312a312a0a0a0a0a0a0a004a0b0a310b220a0b0a310a4a22310a0b0a7e6fe0e0e030e0e0e0e0e01176e02000e0e0e0e0e01131320226310a0b0a310a4a22310a0b0a310a766f8b8b4ee0e0300ae0090909090909090909090909090909090909090909090909090909090909090947aaaa540b09090909090909090909090909090909090909090909090909090909090909fae0e0f2f22164e0e0f273e07fefefef7d6dfafafafa6d6d6d6d'; +} {/000000.*0000000/} + + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3misc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3misc.test new file mode 100644 index 0000000000000000000000000000000000000000..a1bec424329519c8f98bf4550225f65a317057c2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3misc.test @@ -0,0 +1,326 @@ +# 2017 March 22 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3misc + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------------- +# A self-join. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + INSERT INTO t1 VALUES('one', 'i'); + INSERT INTO t1 VALUES('one', 'ii'); + INSERT INTO t1 VALUES('two', 'i'); + INSERT INTO t1 VALUES('two', 'ii'); +} + +do_execsql_test 1.1 { + SELECT a.a, b.b FROM t1 a, t1 b WHERE a.t1 MATCH 'two' AND b.t1 MATCH 'i' +} {two i two i two i two i} + +#------------------------------------------------------------------------- +# FTS tables with 128 or more columns. +# +proc v1 {v} { + set vector [list a b c d e f g h] + set res [list] + for {set i 0} {$i<8} {incr i} { + if {$v & (1 << $i)} { lappend res [lindex $vector $i] } + } + set res +} +proc v2 {v} { + set vector [list d e f g h i j k] + set res [list] + for {set i 0} {$i<8} {incr i} { + if {$v & (1 << $i)} { lappend res [lindex $vector $i] } + } + set res +} +db func v1 v1 +db func v2 v2 + +do_test 2.0 { + set cols [list] + for {set i 0} {$i<200} {incr i} { + lappend cols "c$i" + } + execsql "CREATE VIRTUAL TABLE t2 USING fts3([join $cols ,])" + execsql { + WITH data(i) AS ( + SELECT 1 UNION ALL SELECT i+1 FROM data WHERE i<200 + ) + INSERT INTO t2(c198, c199) SELECT v1(i), v2(i) FROM data; + } +} {} +do_execsql_test 2.1 { + SELECT rowid FROM t2 WHERE t2 MATCH '"a b c"' +} { + 7 15 23 31 39 47 55 63 71 79 87 95 103 111 + 119 127 135 143 151 159 167 175 183 191 199 +} +do_execsql_test 2.2 { + SELECT rowid FROM t2 WHERE t2 MATCH '"g h i"' +} { + 56 57 58 59 60 61 62 63 120 121 122 123 124 + 125 126 127 184 185 186 187 188 189 190 191 +} +do_execsql_test 2.3 { + SELECT rowid FROM t2 WHERE t2 MATCH '"i h"' +} { +} +do_execsql_test 2.4 { + SELECT rowid FROM t2 WHERE t2 MATCH '"f e"' +} { +} +do_execsql_test 2.5 { + SELECT rowid FROM t2 WHERE t2 MATCH '"e f"' +} { + 6 7 14 15 22 23 30 31 38 39 46 47 48 49 50 51 52 53 54 55 56 + 57 58 59 60 61 62 63 70 71 78 79 86 87 94 95 102 103 110 + 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 + 134 135 142 143 150 151 158 159 166 167 174 175 176 177 178 179 180 + 181 182 183 184 185 186 187 188 189 190 191 198 199 +} + +#------------------------------------------------------------------------- +# Range constraints on the docid using non-integer values. +# +do_execsql_test 2.6 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN NULL AND 45; +} {} +do_execsql_test 2.7 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN 11.5 AND 48.2; +} { + 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + 29 30 31 34 35 38 39 42 43 46 47 48 +} +do_execsql_test 2.8 { + SELECT rowid FROM t2 WHERE t2 MATCH 'e' AND rowid BETWEEN '11.5' AND '48.2'; +} { + 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 + 29 30 31 34 35 38 39 42 43 46 47 48 +} + +#------------------------------------------------------------------------- +# Phrase query tests. +# +do_execsql_test 3.1.1 { + CREATE VIRTUAL TABLE t3 USING fts3; + INSERT INTO t3 VALUES('a b c'); + INSERT INTO t3 VALUES('d e f'); + INSERT INTO t3 VALUES('a b d'); + INSERT INTO t3 VALUES('1 2 3 4 5 6 7 8 9 10 11'); +} +do_execsql_test 3.1.2 { + SELECT * FROM t3 WHERE t3 MATCH '"a b x y"' ORDER BY docid DESC +} +do_execsql_test 3.1.3 { + SELECT * FROM t3 WHERE t3 MATCH '"a b c" OR "a b x y"' ORDER BY docid DESC +} {{a b c}} +do_execsql_test 3.1.4 { + SELECT * FROM t3 WHERE t3 MATCH '"a* b* x* a*"' +} +do_execsql_test 3.1.5 { + SELECT rowid FROM t3 WHERE t3 MATCH '"2 3 4 5 6 7 8 9"' +} {4} + +#------------------------------------------------------------------------- +# +reset_db +ifcapable fts4_deferred { + do_execsql_test 4.0 { + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t4 USING fts4; + WITH s(i) AS ( SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<8000 ) + INSERT INTO t4 SELECT 'a b c a b c a b c' FROM s; + } + do_execsql_test 4.1 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {8000} + do_execsql_test 4.2 { + SELECT quote(value) from t4_stat where id=0 + } {X'C03EC0B204C0A608'} + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.3 { + UPDATE t4_stat SET value = X'C03EC0B204C0A60800' WHERE id=0; + } + do_catchsql_test 4.4 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {1 {database disk image is malformed}} + do_execsql_test 4.5 { + UPDATE t4_stat SET value = X'00C03EC0B204C0A608' WHERE id=0; + } + do_catchsql_test 4.6 { + SELECT count(*) FROM t4 WHERE t4 MATCH '"a b c" OR "c a b"' + } {1 {database disk image is malformed}} +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.0 { + CREATE VIRTUAL TABLE t5 USING fts4; + INSERT INTO t5 VALUES('a x x x x b x x x x c'); + INSERT INTO t5 VALUES('a x x x x b x x x x c'); + INSERT INTO t5 VALUES('a x x x x b x x x x c'); +} +do_execsql_test 5.1 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/4 c' +} {1 2 3} +do_execsql_test 5.2 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/3 b NEAR/4 c' +} {} +do_execsql_test 5.3 { + SELECT rowid FROM t5 WHERE t5 MATCH 'a NEAR/4 b NEAR/3 c' +} {} +do_execsql_test 5.4 { + SELECT rowid FROM t5 WHERE t5 MATCH 'y NEAR/4 b NEAR/4 c' +} {} +do_execsql_test 5.5 { + SELECT rowid FROM t5 WHERE t5 MATCH 'x OR a NEAR/3 b NEAR/3 c' +} {1 2 3} +do_execsql_test 5.5 { + SELECT rowid FROM t5 WHERE t5 MATCH 'x OR y NEAR/3 b NEAR/3 c' +} {1 2 3} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE t6 USING fts4; + + BEGIN; + WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000) + INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s; + + INSERT INTO t6 VALUES('x x x x x x x x x x x A'); + INSERT INTO t6 VALUES('x x x x x x x x x x x B'); + INSERT INTO t6 VALUES('x x x x x x x x x x x A'); + INSERT INTO t6 VALUES('x x x x x x x x x x x B'); + + WITH s(i) AS (SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<50000) + INSERT INTO t6 SELECT 'x x x x x x x x x x x' FROM s; + COMMIT; +} +do_execsql_test 6.1 { + SELECT rowid FROM t6 WHERE t6 MATCH 'b OR "x a"' +} {50001 50002 50003 50004} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 7.0 { + CREATE VIRTUAL TABLE vt0 USING fts3(c0); + INSERT INTO vt0 VALUES (x'00'); +} +do_execsql_test 7.1 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# Ticket [8a6fa2bb]. +# +reset_db +do_execsql_test 7.0.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=DESC); + INSERT INTO vt0(c0) VALUES (0), (0); +} +do_execsql_test 7.0.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +reset_db +do_execsql_test 7.1.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, order=ASC); + INSERT INTO vt0(c0) VALUES (0), (0); +} +do_execsql_test 7.1.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +do_execsql_test 7.2.1 { + CREATE VIRTUAL TABLE ft USING fts4(c0, c1, order=DESC, prefix=1); + INSERT INTO ft VALUES('a b c d', 'hello world'); + INSERT INTO ft VALUES('negative', 'positive'); + INSERT INTO ft VALUES('hello world', 'a b c d'); +} +do_execsql_test 7.2.2 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# Ticket [745f1abc]. +# +reset_db +do_execsql_test 8.1 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, prefix=1); +} +do_execsql_test 8.2 { + BEGIN; + INSERT INTO vt0 VALUES (0); + INSERT INTO vt0(vt0) VALUES('optimize'); + COMMIT; +} +do_execsql_test 8.3 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 9.0 { + CREATE VIRTUAL TABLE t1 using fts4(mailcontent); + insert into t1(rowid, mailcontent) values + (-4764623217061966105, 'we are going to upgrade'), + (8324454597464624651, 'we are going to upgrade'); +} + +do_execsql_test 9.1 { + INSERT INTO t1(t1) VALUES('integrity-check'); +} + +do_execsql_test 9.2 { + SELECT rowid FROM t1 WHERE t1 MATCH 'upgrade'; +} { + -4764623217061966105 8324454597464624651 +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 10.0 { + CREATE VIRTUAL TABLE f USING fts3(a,b); + CREATE TABLE 'f_stat'(id INTEGER PRIMARY KEY, value BLOB); + INSERT INTO f_stat VALUES (1,x'3b3b3b3b3b3b3b28ffffffffffffffffff1807f9073481f1d43bc93b3b3b3b3b3b3b3b3b3b18073b3b3b3b3b3b3b9b003b'); +} {} + +do_catchsql_test 10.1 { + INSERT INTO f(f) VALUES ('merge=69,59'); +} {1 {database disk image is malformed}} + +#------------------------------------------------------------------------- +do_execsql_test 11.0 { + CREATE VIRTUAL TABLE xyz USING fts3(); +} +do_execsql_test 11.1 { + SELECT * FROM xyz WHERE xyz MATCH 'a NEAR/4294836224 a'; +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3near.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3near.test new file mode 100644 index 0000000000000000000000000000000000000000..2d9981e5355197acfb28382c391005cfeadb6bb6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3near.test @@ -0,0 +1,597 @@ + +# 2007 October 15 +# +# 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. +# +#************************************************************************* +# +# $Id: fts3near.test,v 1.3 2009/01/02 17:33:46 danielk1977 Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +db eval { + CREATE VIRTUAL TABLE t1 USING fts3(content); + INSERT INTO t1(content) VALUES('one three four five'); + INSERT INTO t1(content) VALUES('two three four five'); + INSERT INTO t1(content) VALUES('one two three four five'); +} + +do_test fts3near-1.1 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/0 three'} +} {1} +do_test fts3near-1.2 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/1 two'} +} {3} +do_test fts3near-1.3 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR/1 three'} +} {1 3} +do_test fts3near-1.4 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'three NEAR/1 one'} +} {1 3} +do_test fts3near-1.5 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"one two" NEAR/1 five'} +} {} +do_test fts3near-1.6 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"one two" NEAR/2 five'} +} {3} +do_test fts3near-1.7 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR four'} +} {1 3} +do_test fts3near-1.8 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'four NEAR three'} +} {1 2 3} +do_test fts3near-1.9 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/0 three'} +} {1 2 3} +do_test fts3near-1.10 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/2 one'} +} {1 3} +do_test fts3near-1.11 { + execsql {SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/1 one'} +} {1} +do_test fts3near-1.12 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'five NEAR/1 "two three"'} +} {2 3} +do_test fts3near-1.13 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR five'} +} {1 3} + +do_test fts3near-1.14 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'four NEAR four'} +} {} +do_test fts3near-1.15 { + execsql {SELECT docid FROM t1 WHERE content MATCH 'one NEAR two NEAR one'} +} {3} + +do_test fts3near-1.16 { + execsql { + SELECT docid FROM t1 WHERE content MATCH '"one three" NEAR/0 "four five"' + } +} {1} +do_test fts3near-1.17 { + execsql { + SELECT docid FROM t1 WHERE content MATCH '"four five" NEAR/0 "one three"' + } +} {1} + + +# Output format of the offsets() function: +# +# +# +db eval { + INSERT INTO t1(content) VALUES('A X B C D A B'); +} +do_test fts3near-2.1 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/0 B' + } +} {{0 0 10 1 0 1 12 1}} +do_test fts3near-2.2 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'B NEAR/0 A' + } +} {{0 1 10 1 0 0 12 1}} +do_test fts3near-2.3 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH '"C D" NEAR/0 A' + } +} {{0 0 6 1 0 1 8 1 0 2 10 1}} +do_test fts3near-2.4 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/0 "C D"' + } +} {{0 1 6 1 0 2 8 1 0 0 10 1}} +do_test fts3near-2.5 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR A' + } +} {{0 0 0 1 0 1 0 1 0 0 10 1 0 1 10 1}} +do_test fts3near-2.6 { + execsql { + INSERT INTO t1 VALUES('A A A'); + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR/2 A'; + } +} [list [list 0 0 0 1 0 1 0 1 0 0 2 1 0 1 2 1 0 0 4 1 0 1 4 1]] +do_test fts3near-2.7 { + execsql { + DELETE FROM t1; + INSERT INTO t1 VALUES('A A A A'); + SELECT offsets(t1) FROM t1 WHERE content MATCH 'A NEAR A NEAR A'; + } +} [list [list \ + 0 0 0 1 0 1 0 1 0 2 0 1 0 0 2 1 \ + 0 1 2 1 0 2 2 1 0 0 4 1 0 1 4 1 \ + 0 2 4 1 0 0 6 1 0 1 6 1 0 2 6 1 \ +]] + +db eval { + DELETE FROM t1; + INSERT INTO t1(content) VALUES( + 'one two three two four six three six nine four eight twelve' + ); +} + +do_test fts3near-3.1 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/1 one'} +} {{0 1 0 3 0 0 8 5}} +do_test fts3near-3.2 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'one NEAR/1 three'} +} {{0 0 0 3 0 1 8 5}} +do_test fts3near-3.3 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/1 two'} +} {{0 1 4 3 0 0 8 5 0 1 14 3}} +do_test fts3near-3.4 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/2 two'} +} {{0 1 4 3 0 0 8 5 0 1 14 3 0 0 27 5}} +do_test fts3near-3.5 { + execsql {SELECT offsets(t1) FROM t1 WHERE content MATCH 'two NEAR/2 three'} +} {{0 0 4 3 0 1 8 5 0 0 14 3 0 1 27 5}} +do_test fts3near-3.6 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH 'three NEAR/0 "two four"' + } +} {{0 0 8 5 0 1 14 3 0 2 18 4}} +do_test fts3near-3.7 { + execsql { + SELECT offsets(t1) FROM t1 WHERE content MATCH '"two four" NEAR/0 three'} +} {{0 2 8 5 0 0 14 3 0 1 18 4}} + +db eval { + INSERT INTO t1(content) VALUES(' + This specification defines Cascading Style Sheets, level 2 (CSS2). CSS2 is a style sheet language that allows authors and users to attach style (e.g., fonts, spacing, and aural cues) to structured documents (e.g., HTML documents and XML applications). By separating the presentation style of documents from the content of documents, CSS2 simplifies Web authoring and site maintenance. + + CSS2 builds on CSS1 (see [CSS1]) and, with very few exceptions, all valid CSS1 style sheets are valid CSS2 style sheets. CSS2 supports media-specific style sheets so that authors may tailor the presentation of their documents to visual browsers, aural devices, printers, braille devices, handheld devices, etc. This specification also supports content positioning, downloadable fonts, table layout, features for internationalization, automatic counters and numbering, and some properties related to user interface. + ') +} +do_test fts3near-4.1 { + execsql { + SELECT snippet(t1) FROM t1 WHERE content MATCH 'specification NEAR supports' + } +} {{...braille devices, handheld devices, etc. This specification also supports content positioning, downloadable fonts, table layout...}} + +do_test fts3near-5.1 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification attach' + } +} {2} +do_test fts3near-5.2 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR attach' + } +} {} +do_test fts3near-5.3 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/18 attach' + } +} {} +do_test fts3near-5.4 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/19 attach' + } +} {2} +do_test fts3near-5.5 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/000018 attach' + } +} {} +do_test fts3near-5.6 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'specification NEAR/000019 attach' + } +} {2} + +db eval { + INSERT INTO t1 VALUES(' + abbrev aberrations abjurations aboding abr abscesses absolutistic + abstention abuses acanthuses acceptance acclaimers accomplish + accoutring accusation acetonic acid acolytes acquitting acrylonitrile + actives acyclic addicted adenoid adjacently adjusting admissible + adoption adulated advantaging advertisers aedes aerogramme aetiology + affiliative afforest afterclap agamogenesis aggrade agings agonize + agron ailurophile airfreight airspeed alarmists alchemizing + alexandrines alien aliped all allergenic allocator allowances almost + alphabetizes altho alvine amaurosis ambles ameliorate amicability amnio + amour ampicillin amusement anadromous analogues anarchy anchormen + anecdota aneurin angst animating anlage announcements anodized + answerable antemeridian anthracene antiabortionist anticlimaxes + antifriction antimitotic antiphon antiques antithetic anviled + apatosaurus aphrodisia apodal aposiopesis apparatus appendectomies + applications appraisingly appropriate apteryx arabinose + arboricultural archdeaconates archipelago ardently arguers armadillo + arnicas arrayed arrowy arthroscope artisans ascensive ashier + aspersorium assail assentor assignees assonants astereognosis + astringency astutest atheistical atomize attachment attenuates + attrahent audibility augite auricle auteurists autobus autolysis + autosome avenge avidest aw awl ayes babirusa backbeats backgrounder + backseat backswings baddie bagnios baked balefuller ballista balmily + bandbox bandylegged bankruptcy baptism barbering bargain barneys + barracuda barterer bashes bassists bathers batterer bavardage + beachfront beanstalk beauteous become bedim bedtimes beermats begat + begun belabors bellarmine belongings bending benthos bereavements + besieger bestialized betide bevels biases bicarbonates bidentate bigger + bile billow bine biodynamics biomedicine biotites birding bisection + bitingly bkg blackheads blaeberry blanking blatherer bleeper blindage + blithefulness blockish bloodstreams bloused blubbing bluestocking + blurted boatbill bobtailed boffo bold boltrope bondservant bonks + bookbinding bookworm booting borating boscages botchers bougainvillea + bounty bowlegged boyhood bracketed brainstorm brandishes + braunschweigers brazilin breakneck breathlessness brewage bridesmaids + brighter brisker broader brokerages bronziest browband brunets bryology + bucking budlike bugleweed bulkily bulling bummer bunglers bureau burgs + burrito bushfire buss butlery buttressing bylines cabdriver cached + cadaverousnesses cafeterias cakewalk calcifies calendula callboy calms + calyptra camisoles camps candelabrum caned cannolis canoodling cantors + cape caponize capsuling caracoled carbolics carcase carditis caretakers + carnallite carousel carrageenan cartels carves cashbook castanets + casuistry catalyzer catchers categorizations cathexis caucuses + causeway cavetto cede cella cementite centenary centrals ceramics ceria + cervixes chafferer chalcopyrites chamfers change chaotically + characteristically charivari chases chatterer cheats cheeks chef + chemurgy chetah chickaree chigoes chillies chinning chirp chive + chloroforms chokebore choplogic chorioids chromatic chronically + chubbiest chunder chutzpah cimetidine cinque circulated circumscribe + cirrose citrin claddagh clamorousness clapperboards classicalism + clauses cleanse clemency clicker clinchers cliquiest clods closeting + cloudscape clucking cnidarian coalfish coatrack coca cockfights coddled + coeducation coexistence cognitively coiffed colatitude collage + collections collinear colonelcy colorimetric columelliform combos + comforters commence commercialist commit commorancy communized compar + compendiously complainers compliance composition comprised comradery + concelebrants concerted conciliation concourses condensate + condonations confab confessionals confirmed conforming congeal + congregant conjectured conjurers connoisseurs conscripting + conservator consolable conspired constricting consuls contagious + contemporaneity contesters continuities contractors contrarian + contrive convalescents convents convexly convulsed cooncan coparcenary + coprolite copyreader cordially corklike cornflour coroner corralling + corrigible corsages cosies cosmonauts costumer cottontails counselings + counterclaim counterpane countertenors courageously couth coveting + coworker cozier cracklings crampon crappies craved cream credenzas + crematoriums cresol cricoid crinkle criterion crocodile crore crossover + crowded cruelest crunch cruzeiros cryptomeria cubism cuesta culprit + cumquat cupped curdle curly cursoring curvy customized cutting cyclamens + cylindrical cytaster dachshund daikon damages damselfly dangling + darkest databanks dauphine dazzling deadpanned deathday debauchers + debunking decameter decedents decibel decisions declinations + decomposition decoratively decretive deduct deescalated defecating + deferentially definiendum defluxion defrocks degrade deice dekaliters + deli delinquencies deludedly demarcates demineralizers demodulating + demonstrabilities demurred deniabilities denouncement denudation + departure deplorable deposing depredatory deputizes derivational + desalinization descriptors desexes desisted despising destitute + detectability determiner detoxifying devalued devilries devotions + dextrous diagenesis dialling diaphoresis diazonium dickeys diddums + differencing dig dignified dildo dimetric dineric dinosaurs diplodocus + directer dirty disagrees disassembler disburses disclosures + disconcerts discountability discrete disembarrass disenthrone + disgruntled dishpans disintegrators dislodged disobedient + dispassionate dispiritednesses dispraised disqualifying + dissatisfying dissidence dissolvers distich distracting distrusts + ditto diverse divineness dizzily dockyard dodgers doggish doited dom + dominium doohickey doozie dorsum doubleheaders dourer downbeats + downshifted doyennes draftsman dramatic drawling dredge drifter + drivelines droopier drowsed drunkards dubiosities duding dulcifying + dumpcart duodecillion durable duteous dyed dysgenic eagles earplugs + earwitness ebonite echoers economical ectothermous edibility educates + effected effigies eggbeaters egresses ejaculates elasticize elector + electrodynamometer electrophorus elem eligibly eloped emaciating + embarcaderos embezzlers embosses embryectomy emfs emotionalizing + empiricist emu enamels enchained encoded encrusts endeavored endogamous + endothelioma energizes engager engrosses enl enologist enrolls ensphere + enters entirety entrap entryways envies eosinophil epicentral + epigrammatized episodic epochs equestrian equitably erect ernes + errorless escalated eschatology espaliers essonite estop eternity + ethnologically eudemonics euphonious euthenist evangelizations + eventuality evilest evulsion examinee exceptionably exciter + excremental execrably exemplars exhalant exhorter exocrine exothermic + expected expends explainable exploratory expostulatory expunges + extends externals extorts extrapolative extrorse eyebolt eyra + facetiously factor faeries fairings fallacies falsities fancifulness + fantasticalness farmhouse fascinate fatalistically fattener fave + fearlessly featly federates feints fellowman fencers ferny + fertilenesses feta feudality fibers fictionalize fiefs fightback + filefish filmier finaglers fingerboards finochio firefly firmament + fishmeal fitted fjords flagitiousnesses flamen flaps flatfooting + flauntier fleapit fleshes flickertail flints floaty floorboards + floristic flow fluffily fluorescein flutes flyspecks foetal folderols + followable foolhardier footlockers foppish forceless foredo foreknows + foreseeing foretaste forgather forlorn formidableness fortalice + forwarding founding foxhunting fragmentarily frangipani fray freeform + freezable freshening fridges frilliest frizzed frontbench frottages + fruitcake fryable fugleman fulminated functionalists fungoid furfuran + furtive fussy fwd gadolinium galabias gallinaceous galvanism gamers + gangland gaoling garganey garrisoning gasp gate gauger gayety geed + geminately generalissimos genii gentled geochronology geomorphic + geriatricians gesellschaft ghat gibbeting giggles gimps girdlers + glabella glaive glassfuls gleefully glistered globetrotted glorifier + gloving glutathione glyptodont goaled gobsmacked goggliest golliwog + goobers gooseberries gormandizer gouramis grabbier gradually grampuses + grandmothers granulated graptolite gratuitously gravitates greaten + greenmailer greys grills grippers groan gropingly grounding groveling + grueled grunter guardroom guggle guineas gummed gunnysacks gushingly + gutturals gynecoid gyrostabilizer habitudes haemophilia hailer hairs + halest hallow halters hamsters handhelds handsaw hangup haranguer + hardheartedness harlotry harps hashing hated hauntingly hayrack + headcases headphone headword heartbreakers heaters hebephrenia + hedonist heightening heliozoan helots hemelytron hemorrhagic hent + herbicides hereunto heroines heteroclitics heterotrophs hexers + hidebound hies hightails hindmost hippopotomonstrosesquipedalian + histologist hittable hobbledehoys hogans holdings holocrine homegirls + homesteader homogeneousness homopolar honeys hoodwinks hoovered + horizontally horridness horseshoers hospitalization hotdogging houri + housemate howitzers huffier humanist humid humors huntress husbandmen + hyaenas hydride hydrokinetics hydroponically hygrothermograph + hyperbolically hypersensitiveness hypnogogic hypodermically + hypothermia iatrochemistry ichthyological idealist ideograms idling + igniting illegal illuminatingly ilmenite imbibing immateriality + immigrating immortalizes immures imparts impeder imperfection + impersonated implant implying imposition imprecating imprimis + improvising impv inanenesses inaugurate incapably incentivize + incineration incloses incomparableness inconsequential incorporate + incrementing incumbered indecorous indentation indicative indignities + indistinguishably indoors indulges ineducation inerrable + inexperienced infants infestations infirmnesses inflicting + infracostal ingathered ingressions inheritances iniquity + injuriousnesses innervated inoculates inquisitionist insectile + insiders insolate inspirers instatement instr insulates intactness + intellects intensifies intercalations intercontinental interferon + interlarded intermarrying internalizing interpersonally + interrelatednesses intersperse interviewees intolerance + intransigents introducing intubates invades inventing inveterate + invocate iodides irenicism ironsmith irreducibly irresistibility + irriguous isobarisms isometrically issuable itineracies jackdaws + jaggery jangling javelins jeeringly jeremiad jeweler jigsawing jitter + jocosity jokester jot jowls judicative juicy jungly jurists juxtaposed + kalpa karstify keddah kendo kermesses keynote kibbutznik kidnaper + kilogram kindred kingpins kissers klatch kneads knobbed knowingest + kookaburras kruller labefaction labyrinths lacquer laddered lagoons + lambency laminates lancinate landscapist lankiness lapse larked lasso + laterite laudableness laundrywomen lawgiver laypersons leafhoppers + leapfrogs leaven leeches legated legislature leitmotifs lenients + leprous letterheads levelling lexicographically liberalists + librettist licorice lifesaving lightheadedly likelier limekiln limped + lines linkers lipoma liquidator listeners litharge litmus + liverishnesses loamier lobeline locative locutionary loggier loiterer + longevity loomed loping lotion louts lowboys luaus lucrativeness lulus + lumpier lungi lush luthern lymphangial lythraceous machinists maculate + maggot magnetochemistry maharani maimers majored malaprops malignants + maloti mammary manchineel manfully manicotti manipulativenesses + mansards manufactories maraschino margin markdown marooning marshland + mascaraing massaging masticate matchmark matings mattes mausoleum + mayflies mealworm meataxe medevaced medievalist meetings megavitamin + melded melodramatic memorableness mendaciousnesses mensurable + mercenaries mere meronymous mesmerizes mestee metallurgical + metastasize meterages meticulosity mewed microbe microcrystalline + micromanager microsporophyll midiron miffed milder militiamen + millesimal milometer mincing mingily minims minstrelsy mires + misanthropic miscalculate miscomprehended misdefines misery mishears + misled mispickel misrepresent misspending mistranslate miswriting + mixologists mobilizers moderators modulate mojo mollies momentum monde + monied monocles monographs monophyletic monotonousness moocher + moorages morality morion mortally moseyed motherly motorboat mouldering + mousers moveables mucky mudslides mulatto multicellularity + multipartite multivalences mundanities murkiest mushed muskiness + mutability mutisms mycelia myosotis mythicist nacred namable napkin + narghile nastiness nattering nauseations nearliest necessitate + necrophobia neg negotiators neologizes nephrotomy netiquette + neurophysiology newbie newspaper niccolite nielsbohriums nightlong + nincompoops nitpicked nix noddling nomadize nonadhesive noncandidates + nonconducting nondigestible nones nongreasy nonjoinder nonoccurrence + nonporousness nonrestrictive nonstaining nonuniform nooses northwards + nostalgic notepaper nourishment noyades nuclides numberless numskulls + nutmegged nymphaea oatmeal obis objurgators oblivious obsequiousness + obsoletism obtruding occlusions ocher octettes odeums offcuts + officiation ogival oilstone olestras omikron oncogenesis onsetting + oomphs openly ophthalmoscope opposites optimum orangutans + orchestrations ordn organophosphates origin ornithosis orthognathous + oscillatory ossuaries ostracized ounce outbreaks outearning outgrows + outlived outpoints outrunning outspends outwearing overabound + overbalance overcautious overcrowds overdubbing overexpanding + overgraze overindustrialize overlearning overoptimism overproducing + overripe overshadowing overspreading overstuff overtones overwind ow + oxidizing pacer packs paganish painstakingly palate palette pally + palsying pandemic panhandled pantheism papaws papped parading + parallelize paranoia parasitically pardners parietal parodied pars + participator partridgeberry passerines password pastors + paterfamiliases patination patrolman paunch pawnshops peacekeeper + peatbog peculator pedestrianism peduncles pegboard pellucidnesses + pendency penitentiary penstock pentylenetetrazol peptidase perched + perennial performing perigynous peripheralize perjurer permissively + perpetuals persistency perspicuously perturbingly pesky petcock + petrologists pfennige pharmacies phenformin philanderers + philosophically phonecards phosgenes photocomposer photogenic photons + phototype phylloid physiotherapeutics picadores pickup pieces pigging + pilaster pillion pimples pinioned pinpricks pipers pirogi pit + pitifullest pizza placental plainly planing plasmin platforming + playacts playwrights plectra pleurisy plopped plug plumule plussed + poaches poetasters pointless polarize policyholder polkaed + polyadelphous polygraphing polyphonous pomace ponderers pooch poplar + porcelains portableness portly positioning postage posthumously + postponed potages potholed poulard powdering practised pranksters + preadapt preassigning precentors precipitous preconditions predefined + predictors preengage prefers prehumans premedical prenotification + preplanning prepuberty presbytery presentation presidia prestissimo + preterites prevailer prewarmed priding primitively principalships + prisage privileged probed prochurch proctoscope products proficients + prognathism prohibiting proletarianisms prominence promulgates + proofreading property proportions prorate proselytize prosthesis + proteins prototypic provenances provitamin prudish pseudonymities + psychoanalysts psychoneuroses psychrometer publishable pufferies + pullet pulses punchy punkins purchased purities pursers pushover + putridity pylons pyrogenous pzazz quadricepses quaff qualmish quarriers + quasilinear queerness questionnaires quieten quintals quislings quoits + rabidness racketeers radiative radioisotope radiotherapists ragingly + rainband rakishness rampagers rands raped rare raspy ratiocinator + rattlebrain ravening razz reactivation readoption realm reapportioning + reasoning reattempts rebidding rebuts recapitulatory receptiveness + recipes reckonings recognizee recommendatory reconciled reconnoiters + recontaminated recoupments recruits recumbently redact redefine + redheaded redistributable redraw redwing reeled reenlistment reexports + refiles reflate reflowing refortified refried refuses regelate + registrant regretting rehabilitative reigning reinduced reinstalled + reinvesting rejoining relations relegates religiosities reluctivity + remastered reminisce remodifying remounted rends renovate reordered + repartee repel rephrase replicate repossessing reprint reprogramed + repugnantly requiter rescheduling resegregate resettled residually + resold resourcefulness respondent restating restrainedly resubmission + resurveyed retaliating retiarius retorsion retreated retrofitting + returning revanchism reverberated reverted revitalization + revolutionize rewind rhapsodizing rhizogenic rhythms ricketinesses + ridicule righteous rilles rinks rippliest ritualize riyals roast rockery + roguish romanizations rookiest roquelaure rotation rotundity rounder + routinizing rubberize rubricated ruefully ruining rummaged runic + russets ruttish sackers sacrosanctly safeguarding said salaciousness + salinity salsas salutatorians sampan sandbag saned santonin + saprophagous sarnies satem saturant savaged sawbucks scablike scalp + scant scared scatter schedulers schizophrenics schnauzers schoolmarms + scintillae scleroses scoped scotched scram scratchiness screwball + scripting scrubwomen scrutinizing scumbled scuttled seals seasickness + seccos secretions secularizing seditiousnesses seeking segregators + seize selfish semeiology seminarian semitropical sensate sensors + sentimo septicemic sequentially serener serine serums + sesquicentennials seventeen sexiest sforzandos shadowing shallot + shampooing sharking shearer sheered shelters shifter shiner shipper + shitted shoaled shofroth shorebirds shortsightedly showboated shrank + shrines shucking shuttlecocks sickeningly sideling sidewise sigil + signifiers siliceous silty simony simulative singled sinkings sirrah + situps skateboarder sketchpad skim skirmished skulkers skywalk slander + slating sleaziest sleepyheads slicking slink slitting slot slub + slumlords smallest smattered smilier smokers smriti snailfish snatch + snides snitching snooze snowblowers snub soapboxing socialite sockeyes + softest sold solicitings solleret sombreros somnolencies sons sopor + sorites soubrette soupspoon southpaw spaces spandex sparkers spatially + speccing specking spectroscopists speedsters spermatics sphincter + spiffied spindlings spirals spitball splayfeet splitter spokeswomen + spooled sportily spousals sprightliness sprogs spurner squalene + squattered squelches squirms stablish staggerings stalactitic stamp + stands starflower starwort stations stayed steamroll steeplebush + stemmatics stepfathers stereos steroid sticks stillage stinker + stirringly stockpiling stomaching stopcock stormers strabismuses + strainer strappado strawberries streetwise striae strikeouts strives + stroppiest stubbed study stunting style suavity subchloride subdeb + subfields subjoin sublittoral subnotebooks subprograms subside + substantial subtenants subtreasuries succeeding sucked sufferers + sugarier sulfaguanidine sulphating summerhouse sunbonnets sunned + superagency supercontinent superheroes supernatural superscribing + superthin supplest suppositive surcease surfs surprise survey + suspiration svelte swamplands swashes sweatshop swellhead swindling + switching sworn syllabuses sympathetics synchrocyclotron syndic + synonymously syringed tablatures tabulation tackling taiga takas talker + tamarisks tangential tans taproom tarpapers taskmaster tattiest + tautologically taxied teacup tearjerkers technocracies teepee + telegenic telephony telexed temperaments temptress tenderizing tensed + tenuring tergal terned terror testatrices tetherball textile thatched + their theorem thereof thermometers thewy thimerosal thirsty + thoroughwort threateningly thrived through thumbnails thwacks + ticketing tie til timekeepers timorousness tinkers tippers tisane + titrating toastmaster toff toking tomb tongs toolmakings topes topple + torose tortilla totalizing touchlines tousling townsmen trachea + tradeable tragedienne traitorous trances transcendentalists + transferrable tranship translating transmogrifying transportable + transvestism traumatize treachery treed trenail tressing tribeswoman + trichromatism triennials trikes trims triplicate tristich trivializes + trombonist trots trouts trued trunnion tryster tubes tulle tundras turban + turgescence turnround tutelar tweedinesses twill twit tympanum typists + tzarists ulcered ultramodern umbles unaccountability unamended + unassertivenesses unbanned unblocked unbundled uncertified unclaimed + uncoated unconcerns unconvinced uncrossing undefined underbodice + underemphasize undergrowth underpayment undershirts understudy + underwritten undissolved unearthed unentered unexpended unfeeling + unforeseen unfussy unhair unhinges unifilar unimproved uninvitingly + universalization unknowns unlimbering unman unmet unnaturalness + unornament unperturbed unprecedentedly unproportionate unread + unreflecting unreproducible unripe unsatisfying unseaworthiness + unsharable unsociable unstacking unsubtly untactfully untied untruest + unveils unwilled unyokes upheave upraised upstart upwind urethrae + urtexts usurers uvula vacillators vailed validation valvule vanities + varia variously vassaled vav veggies velours venerator ventrals + verbalizes verification vernacularized verticality vestigially via + vicariously victoriousness viewpoint villainies vines violoncellist + virtual viscus vital vitrify viviparous vocalizers voidable volleys + volutes vouches vulcanology wackos waggery wainwrights waling wallowing + wanking wardroom warmup wartiest washwoman watchman watermarks waverer + wayzgoose weariest weatherstripped weediness weevil welcomed + wentletrap whackers wheatworm whelp whf whinged whirl whistles whithers + wholesomeness whosoever widows wikiup willowier windburned windsail + wingspread winterkilled wisecracking witchgrass witling wobbliest + womanliness woodcut woodworking woozy working worldwide worthiest + wrappings wretched writhe wynd xylophone yardarm yea yelped yippee yoni + yuks zealotry zigzagger zitherists zoologists zygosis'); +} + +do_test fts3near-6.1 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev zygosis' + } +} {3} +do_test fts3near-6.2 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR zygosis' + } +} {} +do_test fts3near-6.3 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/100 zygosis' + } +} {} +do_test fts3near-6.4 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/1000 zygosis' + } +} {} +do_test fts3near-6.5 { + execsql { + SELECT docid FROM t1 WHERE content MATCH 'abbrev NEAR/10000 zygosis' + } +} {3} + +# Ticket 38b1ae018f. +# +do_execsql_test fts3near-7.1 { + CREATE VIRTUAL TABLE x USING fts4(y,z); + INSERT INTO x VALUES('aaa bbb ccc ddd', 'bbb ddd aaa ccc'); + SELECT * FROM x where y MATCH 'bbb NEAR/6 aaa'; +} {{aaa bbb ccc ddd} {bbb ddd aaa ccc}} + +do_execsql_test fts3near-7.2 { + CREATE VIRTUAL TABLE t2 USING fts4(a, b); + INSERT INTO t2 VALUES('A B C', 'A D E'); + SELECT * FROM t2 where t2 MATCH 'a:A NEAR E' +} {} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3prefix2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3prefix2.test new file mode 100644 index 0000000000000000000000000000000000000000..e033fb6bcb82e2158c7ed1eb0af77786bd695813 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3prefix2.test @@ -0,0 +1,61 @@ +# 2012 January 25 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3prefix2 + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { PRAGMA page_size = 512 } +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(x, prefix="2,3"); + + BEGIN; + INSERT INTO t1 VALUES('T TX T TX T TX T TX T TX'); + INSERT INTO t1 SELECT * FROM t1; -- 2 + INSERT INTO t1 SELECT * FROM t1; -- 4 + INSERT INTO t1 SELECT * FROM t1; -- 8 + INSERT INTO t1 SELECT * FROM t1; -- 16 + INSERT INTO t1 SELECT * FROM t1; -- 32 + INSERT INTO t1 SELECT * FROM t1; -- 64 + INSERT INTO t1 SELECT * FROM t1; -- 128 + INSERT INTO t1 SELECT * FROM t1; -- 256 + INSERT INTO t1 SELECT * FROM t1; -- 512 + INSERT INTO t1 SELECT * FROM t1; -- 1024 + INSERT INTO t1 SELECT * FROM t1; -- 2048 + COMMIT; +} + +do_execsql_test 1.2 { + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + INSERT INTO t1 SELECT * FROM t1 LIMIT 10; + DELETE FROM t1 WHERE docid > 5; +} + +do_execsql_test 1.3 { + SELECT * FROM t1 WHERE t1 MATCH 'T*'; +} { + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} + {T TX T TX T TX T TX T TX} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3rank.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3rank.test new file mode 100644 index 0000000000000000000000000000000000000000..fd1a1c89d769c0e31efbb4924d2f1d45215ff856 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3rank.test @@ -0,0 +1,69 @@ +# 2017 October 7 +# +# 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. The +# focus of this script is testing the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3rank + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +install_fts3_rank_function db +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3(a, b); + INSERT INTO t1 VALUES('one two', 'one'); + INSERT INTO t1 VALUES('one two', 'three'); + INSERT INTO t1 VALUES('one two', 'two'); +} + +do_execsql_test 1.1 { + SELECT * FROM t1 WHERE t1 MATCH 'one' + ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} { + {one two} one + {one two} three + {one two} two +} + +do_execsql_test 1.2 { + SELECT * FROM t1 WHERE t1 MATCH 'two' + ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} { + {one two} two + {one two} one + {one two} three +} + +do_catchsql_test 1.3 { + SELECT * FROM t1 ORDER BY rank(matchinfo(t1), 1.0, 1.0) DESC, rowid +} {1 {invalid matchinfo blob passed to function rank()}} + +do_catchsql_test 1.4 { + SELECT * FROM t1 ORDER BY rank(x'0000000000000000') DESC, rowid +} {0 {{one two} one {one two} three {one two} two}} + +if {$tcl_platform(byteOrder)=="littleEndian"} { + do_catchsql_test 1.5le { + SELECT * FROM t1 ORDER BY rank(x'0100000001000000') DESC, rowid + } {1 {invalid matchinfo blob passed to function rank()}} +} else { + do_catchsql_test 1.5be { + SELECT * FROM t1 ORDER BY rank(x'0000000100000001') DESC, rowid + } {1 {invalid matchinfo blob passed to function rank()}} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3shared.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3shared.test new file mode 100644 index 0000000000000000000000000000000000000000..0943c0510fcb6300b2be9bcbfd56c64c8c40c143 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3shared.test @@ -0,0 +1,176 @@ +# +# 2010 September 17 +# +# 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. The +# focus of this file is the interactions between the FTS3/4 module +# and shared-cache mode. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !fts3||!shared_cache { + finish_test + return +} +set ::testprefix fts3shared + +db close +set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + +# Open two connections to the database in shared-cache mode. +# +sqlite3 db test.db +sqlite3 db2 test.db + +# Create a virtual FTS3 table. Populate it with some initial data. +# +do_execsql_test fts3shared-1.1 { + CREATE VIRTUAL TABLE t1 USING fts3(x); + BEGIN; + INSERT INTO t1 VALUES('We listened and looked sideways up!'); + INSERT INTO t1 VALUES('Fear at my heart, as at a cup,'); + INSERT INTO t1 VALUES('My life-blood seemed to sip!'); + INSERT INTO t1 VALUES('The stars were dim, and thick the night'); + COMMIT; +} {} + +# Open a write transaction and insert rows into the FTS3 table. This takes +# a write-lock on the underlying t1_content table. +# +do_execsql_test fts3shared-1.2 { + BEGIN; + INSERT INTO t1 VALUES('The steersman''s face by his lamp gleamed white;'); +} {} + +# Now try a SELECT on the full-text table. This particular SELECT does not +# read data from the %_content table. But it still attempts to obtain a lock +# on that table and so the SELECT fails. +# +do_test fts3shared-1.3 { + catchsql { + BEGIN; + SELECT rowid FROM t1 WHERE t1 MATCH 'stars' + } db2 +} {1 {database table is locked}} + +# Verify that the first connection can commit its transaction. +# +do_test fts3shared-1.4 { sqlite3_get_autocommit db } 0 +do_execsql_test fts3shared-1.5 { COMMIT } {} +do_test fts3shared-1.6 { sqlite3_get_autocommit db } 1 + +# Verify that the second connection still has an open transaction. +# +do_test fts3shared-1.6 { sqlite3_get_autocommit db2 } 0 + +db close +db2 close + +#------------------------------------------------------------------------- +# The following tests - fts3shared-2.* - test that unless FTS is bypassed +# and the underlying tables accessed directly, it is not possible for an +# SQLITE_LOCKED error to be enountered when committing an FTS transaction. +# +# Any SQLITE_LOCKED error should be returned when the fts4 (or fts4aux) +# table is first read/written within a transaction, not later on. +# +set LOCKED {1 {database table is locked}} +forcedelete test.db +sqlite3 dbR test.db +sqlite3 dbW test.db +do_test 2.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts4; + CREATE TABLE t2ext(a, b); + CREATE VIRTUAL TABLE t2 USING fts4(content=t2ext); + CREATE VIRTUAL TABLE t1aux USING fts4aux(t1); + CREATE VIRTUAL TABLE t2aux USING fts4aux(t2); + + INSERT INTO t1 VALUES('a b c'); + INSERT INTO t2(rowid, a, b) VALUES(1, 'd e f', 'g h i'); + } dbW +} {} + +# Test that once [dbW] has written to the FTS table, no client may read +# from the FTS or fts4aux table. +do_test 2.2.1 { + execsql { + BEGIN; + INSERT INTO t1 VALUES('j k l'); + } dbW + execsql BEGIN dbR +} {} +do_test 2.2.2 { catchsql "SELECT * FROM t1 WHERE rowid=1" dbR } $LOCKED +do_test 2.2.3 { catchsql "SELECT * FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED +do_test 2.2.4 { catchsql "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" dbR } $LOCKED +do_test 2.2.5 { catchsql "SELECT * FROM t1" dbR } $LOCKED +do_test 2.2.6 { catchsql "SELECT * FROM t1aux" dbR } $LOCKED +do_test 2.2.7 { execsql COMMIT dbW } {} +do_test 2.2.8 { execsql COMMIT dbR } {} + +# Same test as 2.2.*, except with a content= table. +# +do_test 2.3.1 { + execsql { + BEGIN; + INSERT INTO t2(rowid, a, b) VALUES(2, 'j k l', 'm n o'); + } dbW + execsql BEGIN dbR +} {} +do_test 2.3.3 { catchsql "SELECT * FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED +do_test 2.3.4 { catchsql "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" dbR } $LOCKED +do_test 2.3.6 { catchsql "SELECT * FROM t2aux" dbR } $LOCKED +do_test 2.3.7 { execsql COMMIT dbW } {} +do_test 2.3.8 { execsql COMMIT dbR } {} + +# Test that once a connection has read from the FTS or fts4aux table, +# another connection may not write to the FTS table. +# +foreach {tn sql} { + 1 "SELECT * FROM t1 WHERE rowid=1" + 2 "SELECT * FROM t1 WHERE t1 MATCH 'a'" + 3 "SELECT rowid FROM t1 WHERE t1 MATCH 'a'" + 4 "SELECT * FROM t1" + 5 "SELECT * FROM t1aux" +} { + + do_test 2.4.$tn { + execsql BEGIN dbR + execsql $::sql dbR + execsql BEGIN dbW + catchsql "INSERT INTO t1 VALUES('p q r')" dbW + } $LOCKED + + execsql ROLLBACK dbR + execsql ROLLBACK dbW +} + +# Same test as 2.4.*, except with a content= table. +# +foreach {tn sql} { + 2 "SELECT * FROM t2 WHERE t2 MATCH 'a'" + 3 "SELECT rowid FROM t2 WHERE t2 MATCH 'a'" + 5 "SELECT * FROM t2aux" +} { + + do_test 2.5.$tn { + execsql BEGIN dbR + execsql $::sql dbR + execsql BEGIN dbW + catchsql "INSERT INTO t2(rowid, a, b) VALUES(3, 's t u', 'v w x')" dbW + } $LOCKED + + execsql ROLLBACK dbR + execsql ROLLBACK dbW +} + +dbW close +dbR close +sqlite3_enable_shared_cache $::enable_shared_cache +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3snippet.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3snippet.test new file mode 100644 index 0000000000000000000000000000000000000000..ad1fbb3bef73f16a29347bd55f14145de125ccb6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3snippet.test @@ -0,0 +1,595 @@ +# 2010 January 07 +# +# 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. +# +#************************************************************************* +# +# The tests in this file test the FTS3 auxillary functions offsets(), +# snippet() and matchinfo() work. At time of writing, running this file +# provides full coverage of fts3_snippet.c. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3snippet + +# If SQLITE_ENABLE_FTS3 is not defined, omit this file. +ifcapable !fts3 { finish_test ; return } +source $testdir/fts3_common.tcl + +set sqlite_fts3_enable_parentheses 1 +set DO_MALLOC_TEST 0 + +# Transform the list $L to its "normal" form. So that it can be compared to +# another list with the same set of elements using [string compare]. +# +proc normalize {L} { + set ret [list] + foreach l $L {lappend ret $l} + return $ret +} + +proc do_offsets_test {name expr args} { + set result [list] + foreach a $args { + lappend result [normalize $a] + } + do_select_test $name { + SELECT offsets(ft) FROM ft WHERE ft MATCH $expr + } $result +} + +# Document text used by a few tests. Contains the English names of all +# integers between 1 and 300. +# +set numbers [normalize { + one two three four five six seven eight nine ten eleven twelve thirteen + fourteen fifteen sixteen seventeen eighteen nineteen twenty twentyone + twentytwo twentythree twentyfour twentyfive twentysix twentyseven + twentyeight twentynine thirty thirtyone thirtytwo thirtythree thirtyfour + thirtyfive thirtysix thirtyseven thirtyeight thirtynine forty fortyone + fortytwo fortythree fortyfour fortyfive fortysix fortyseven fortyeight + fortynine fifty fiftyone fiftytwo fiftythree fiftyfour fiftyfive fiftysix + fiftyseven fiftyeight fiftynine sixty sixtyone sixtytwo sixtythree sixtyfour + sixtyfive sixtysix sixtyseven sixtyeight sixtynine seventy seventyone + seventytwo seventythree seventyfour seventyfive seventysix seventyseven + seventyeight seventynine eighty eightyone eightytwo eightythree eightyfour + eightyfive eightysix eightyseven eightyeight eightynine ninety ninetyone + ninetytwo ninetythree ninetyfour ninetyfive ninetysix ninetyseven + ninetyeight ninetynine onehundred onehundredone onehundredtwo + onehundredthree onehundredfour onehundredfive onehundredsix onehundredseven + onehundredeight onehundrednine onehundredten onehundredeleven + onehundredtwelve onehundredthirteen onehundredfourteen onehundredfifteen + onehundredsixteen onehundredseventeen onehundredeighteen onehundrednineteen + onehundredtwenty onehundredtwentyone onehundredtwentytwo + onehundredtwentythree onehundredtwentyfour onehundredtwentyfive + onehundredtwentysix onehundredtwentyseven onehundredtwentyeight + onehundredtwentynine onehundredthirty onehundredthirtyone + onehundredthirtytwo onehundredthirtythree onehundredthirtyfour + onehundredthirtyfive onehundredthirtysix onehundredthirtyseven + onehundredthirtyeight onehundredthirtynine onehundredforty + onehundredfortyone onehundredfortytwo onehundredfortythree + onehundredfortyfour onehundredfortyfive onehundredfortysix + onehundredfortyseven onehundredfortyeight onehundredfortynine + onehundredfifty onehundredfiftyone onehundredfiftytwo onehundredfiftythree + onehundredfiftyfour onehundredfiftyfive onehundredfiftysix + onehundredfiftyseven onehundredfiftyeight onehundredfiftynine + onehundredsixty onehundredsixtyone onehundredsixtytwo onehundredsixtythree + onehundredsixtyfour onehundredsixtyfive onehundredsixtysix + onehundredsixtyseven onehundredsixtyeight onehundredsixtynine + onehundredseventy onehundredseventyone onehundredseventytwo + onehundredseventythree onehundredseventyfour onehundredseventyfive + onehundredseventysix onehundredseventyseven onehundredseventyeight + onehundredseventynine onehundredeighty onehundredeightyone + onehundredeightytwo onehundredeightythree onehundredeightyfour + onehundredeightyfive onehundredeightysix onehundredeightyseven + onehundredeightyeight onehundredeightynine onehundredninety + onehundredninetyone onehundredninetytwo onehundredninetythree + onehundredninetyfour onehundredninetyfive onehundredninetysix + onehundredninetyseven onehundredninetyeight onehundredninetynine twohundred + twohundredone twohundredtwo twohundredthree twohundredfour twohundredfive + twohundredsix twohundredseven twohundredeight twohundrednine twohundredten + twohundredeleven twohundredtwelve twohundredthirteen twohundredfourteen + twohundredfifteen twohundredsixteen twohundredseventeen twohundredeighteen + twohundrednineteen twohundredtwenty twohundredtwentyone twohundredtwentytwo + twohundredtwentythree twohundredtwentyfour twohundredtwentyfive + twohundredtwentysix twohundredtwentyseven twohundredtwentyeight + twohundredtwentynine twohundredthirty twohundredthirtyone + twohundredthirtytwo twohundredthirtythree twohundredthirtyfour + twohundredthirtyfive twohundredthirtysix twohundredthirtyseven + twohundredthirtyeight twohundredthirtynine twohundredforty + twohundredfortyone twohundredfortytwo twohundredfortythree + twohundredfortyfour twohundredfortyfive twohundredfortysix + twohundredfortyseven twohundredfortyeight twohundredfortynine + twohundredfifty twohundredfiftyone twohundredfiftytwo twohundredfiftythree + twohundredfiftyfour twohundredfiftyfive twohundredfiftysix + twohundredfiftyseven twohundredfiftyeight twohundredfiftynine + twohundredsixty twohundredsixtyone twohundredsixtytwo twohundredsixtythree + twohundredsixtyfour twohundredsixtyfive twohundredsixtysix + twohundredsixtyseven twohundredsixtyeight twohundredsixtynine + twohundredseventy twohundredseventyone twohundredseventytwo + twohundredseventythree twohundredseventyfour twohundredseventyfive + twohundredseventysix twohundredseventyseven twohundredseventyeight + twohundredseventynine twohundredeighty twohundredeightyone + twohundredeightytwo twohundredeightythree twohundredeightyfour + twohundredeightyfive twohundredeightysix twohundredeightyseven + twohundredeightyeight twohundredeightynine twohundredninety + twohundredninetyone twohundredninetytwo twohundredninetythree + twohundredninetyfour twohundredninetyfive twohundredninetysix + twohundredninetyseven twohundredninetyeight twohundredninetynine + threehundred +}] + +foreach {DO_MALLOC_TEST enc} { + 0 utf8 + 1 utf8 + 1 utf16 +} { + + db close + forcedelete test.db + sqlite3 db test.db + sqlite3_db_config_lookaside db 0 0 0 + db eval "PRAGMA encoding = \"$enc\"" + + # Set variable $T to the test name prefix for this iteration of the loop. + # + set T "fts3snippet-1.$enc" + + ########################################################################## + # Test the offset function. + # + do_test $T.1.1 { + execsql { + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('xxx xxx xxx xxx'); + } + } {} + do_offsets_test $T.1.2 {xxx} {0 0 0 3 0 0 4 3 0 0 8 3 0 0 12 3} + do_offsets_test $T.1.3 {"xxx xxx"} { + 0 0 0 3 0 0 4 3 0 1 4 3 0 0 8 3 + 0 1 8 3 0 1 12 3 + } + do_offsets_test $T.1.4 {"xxx xxx" xxx} { + 0 0 0 3 0 2 0 3 0 0 4 3 0 1 4 3 + 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3 + 0 1 12 3 0 2 12 3 + } + do_offsets_test $T.1.5 {xxx "xxx xxx"} { + 0 0 0 3 0 1 0 3 0 0 4 3 0 1 4 3 + 0 2 4 3 0 0 8 3 0 1 8 3 0 2 8 3 + 0 0 12 3 0 2 12 3 + } + + do_test $T.2.1 { + set v1 [lrange $numbers 0 99] + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(a, b); + INSERT INTO ft VALUES($v1, $numbers); + INSERT INTO ft VALUES($v1, NULL); + } + } {} + + set off [string first "twohundred " $numbers] + do_offsets_test $T.2.1 {twohundred} [list 1 0 $off 10] + + set off [string first "onehundred " $numbers] + do_offsets_test $T.2.2 {onehundred} \ + [list 0 0 $off 10 1 0 $off 10] [list 0 0 $off 10] + + # Test a corruption case: + sqlite3_db_config db DEFENSIVE 0 + execsql { UPDATE ft_content SET c1b = 'hello world' WHERE c1b = $numbers } + do_error_test $T.2.3 { + SELECT offsets(ft) FROM ft WHERE ft MATCH 'onehundred' + } {database disk image is malformed} + + ########################################################################## + # Test the snippet function. + # + proc do_snippet_test {name expr iCol nTok args} { + set res [list] + foreach a $args { lappend res [string trim $a] } + do_select_test $name { + SELECT snippet(ft,'{','}','...',$iCol,$nTok) FROM ft WHERE ft MATCH $expr + } $res + } + do_test $T.3.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES('one two three four five six seven eight nine ten'); + } + } {} + do_snippet_test $T.3.2 one 0 5 "{one} two three four five..." + do_snippet_test $T.3.3 two 0 5 "one {two} three four five..." + do_snippet_test $T.3.4 three 0 5 "one two {three} four five..." + do_snippet_test $T.3.5 four 0 5 "...two three {four} five six..." + do_snippet_test $T.3.6 five 0 5 "...three four {five} six seven..." + do_snippet_test $T.3.7 six 0 5 "...four five {six} seven eight..." + do_snippet_test $T.3.8 seven 0 5 "...five six {seven} eight nine..." + do_snippet_test $T.3.9 eight 0 5 "...six seven {eight} nine ten" + do_snippet_test $T.3.10 nine 0 5 "...six seven eight {nine} ten" + do_snippet_test $T.3.11 ten 0 5 "...six seven eight nine {ten}" + + do_test $T.4.1 { + execsql { + INSERT INTO ft VALUES( + 'one two three four five ' + || 'six seven eight nine ten ' + || 'eleven twelve thirteen fourteen fifteen ' + || 'sixteen seventeen eighteen nineteen twenty ' + || 'one two three four five ' + || 'six seven eight nine ten ' + || 'eleven twelve thirteen fourteen fifteen ' + || 'sixteen seventeen eighteen nineteen twenty' + ); + } + } {} + + do_snippet_test $T.4.2 {one nine} 0 5 { + {one} two three...eight {nine} ten + } { + {one} two three...eight {nine} ten... + } + + do_snippet_test $T.4.3 {one nine} 0 -5 { + {one} two three four five...six seven eight {nine} ten + } { + {one} two three four five...seven eight {nine} ten eleven... + } + do_snippet_test $T.4.3 {one nineteen} 0 -5 { + ...eighteen {nineteen} twenty {one} two... + } + do_snippet_test $T.4.4 {two nineteen} 0 -5 { + ...eighteen {nineteen} twenty one {two}... + } + do_snippet_test $T.4.5 {three nineteen} 0 -5 { + ...{nineteen} twenty one two {three}... + } + + do_snippet_test $T.4.6 {four nineteen} 0 -5 { + ...two three {four} five six...seventeen eighteen {nineteen} twenty one... + } + do_snippet_test $T.4.7 {four NEAR nineteen} 0 -5 { + ...seventeen eighteen {nineteen} twenty one...two three {four} five six... + } + + do_snippet_test $T.4.8 {four nineteen} 0 5 { + ...three {four} five...eighteen {nineteen} twenty... + } + do_snippet_test $T.4.9 {four NEAR nineteen} 0 5 { + ...eighteen {nineteen} twenty...three {four} five... + } + do_snippet_test $T.4.10 {four NEAR nineteen} 0 -5 { + ...seventeen eighteen {nineteen} twenty one...two three {four} five six... + } + do_snippet_test $T.4.11 {four NOT (nineteen twentyone)} 0 5 { + ...two three {four} five six... + } { + ...two three {four} five six... + } + do_snippet_test $T.4.12 {four OR nineteen NEAR twentyone} 0 5 { + ...two three {four} five six... + } { + ...two three {four} five six... + } + + do_test $T.5.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(a, b, c); + INSERT INTO ft VALUES( + 'one two three four five', + 'four five six seven eight', + 'seven eight nine ten eleven' + ); + } + } {} + + do_snippet_test $T.5.2 {five} -1 3 {...three four {five}} + do_snippet_test $T.5.3 {five} 0 3 {...three four {five}} + do_snippet_test $T.5.4 {five} 1 3 {four {five} six...} + do_snippet_test $T.5.5 {five} 2 3 {seven eight nine...} + + do_test $T.5.6 { + execsql { UPDATE ft SET b = NULL } + } {} + + do_snippet_test $T.5.7 {five} -1 3 {...three four {five}} + do_snippet_test $T.5.8 {five} 0 3 {...three four {five}} + do_snippet_test $T.5.9 {five} 1 3 {} + do_snippet_test $T.5.10 {five} 2 3 {seven eight nine...} + + do_snippet_test $T.5.11 {one "seven eight nine"} -1 -3 { + {one} two three...{seven} {eight} {nine}... + } + + do_test $T.6.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x); + INSERT INTO ft VALUES($numbers); + } + } {} + do_snippet_test $T.6.2 { + one fifty onehundred onehundredfifty twohundredfifty threehundred + } -1 4 { + {one}...{fifty}...{onehundred}...{onehundredfifty}... + } + do_snippet_test $T.6.3 { + one fifty onehundred onehundredfifty twohundredfifty threehundred + } -1 -4 { + {one} two three four...fortyeight fortynine {fifty} fiftyone...ninetyeight ninetynine {onehundred} onehundredone...onehundredfortyeight onehundredfortynine {onehundredfifty} onehundredfiftyone... + } + + do_test $T.7.1 { + execsql { + BEGIN; + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x); + } + set testresults [list] + for {set i 1} {$i < 150} {incr i} { + set commas [string repeat , $i] + execsql {INSERT INTO ft VALUES('one' || $commas || 'two')} + lappend testresults "{one}$commas{two}" + } + execsql COMMIT + } {} + eval [list do_snippet_test $T.7.2 {one two} -1 3] $testresults + + ########################################################################## + # Test the matchinfo function. + # + proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r + } + db func mit mit + proc do_matchinfo_test {name expr args} { + set res [list] + foreach a $args { lappend res [normalize $a] } + do_select_test $name { + SELECT mit(matchinfo(ft)) FROM ft WHERE ft MATCH $expr + } $res + } + do_test $T.8.1 { + set ten {one two three four five six seven eight nine ten} + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3; + INSERT INTO ft VALUES($ten); + INSERT INTO ft VALUES($ten || ' ' || $ten); + } + } {} + + do_matchinfo_test $T.8.2 "one" {1 1 1 3 2} {1 1 2 3 2} + do_matchinfo_test $T.8.3 "one NEAR/3 ten" {2 1 1 1 1 1 1 1} + do_matchinfo_test $T.8.4 "five NEAR/4 ten" \ + {2 1 1 3 2 1 3 2} {2 1 2 3 2 2 3 2} + do_matchinfo_test $T.8.5 "six NEAR/3 ten NEAR/3 two" \ + {3 1 1 1 1 1 1 1 1 1 1} + do_matchinfo_test $T.8.6 "five NEAR/4 ten NEAR/3 two" \ + {3 1 2 2 1 1 1 1 1 1 1} + + do_test $T.9.1 { + execsql { + DROP TABLE IF EXISTS ft; + CREATE VIRTUAL TABLE ft USING fts3(x, y); + } + foreach n {1 2 3} { + set v1 [lrange $numbers 0 [expr $n*100]] + set v2 [string trim [string repeat "$numbers " $n]] + set docid [expr $n * 1000000] + execsql { INSERT INTO ft(docid, x, y) VALUES($docid, $v1, $v2) } + } + } {} + do_matchinfo_test $T.9.2 {two*} \ + { 1 2 1 105 3 101 606 3} \ + { 1 2 3 105 3 202 606 3} \ + { 1 2 101 105 3 303 606 3} + + do_matchinfo_test $T.9.4 {"one* two*"} \ + { 1 2 1 5 3 2 12 3} \ + { 1 2 2 5 3 4 12 3} \ + { 1 2 2 5 3 6 12 3} + + do_matchinfo_test $T.9.5 {twohundredfifty} \ + { 1 2 0 1 1 1 6 3} \ + { 1 2 0 1 1 2 6 3} \ + { 1 2 1 1 1 3 6 3} + + do_matchinfo_test $T.9.6 {"threehundred one"} \ + { 1 2 0 0 0 1 3 2} \ + { 1 2 0 0 0 2 3 2} + + do_matchinfo_test $T.9.7 {one OR fivehundred} \ + { 2 2 1 3 3 1 6 3 0 0 0 0 0 0 } \ + { 2 2 1 3 3 2 6 3 0 0 0 0 0 0 } \ + { 2 2 1 3 3 3 6 3 0 0 0 0 0 0 } + + do_matchinfo_test $T.9.8 {two OR "threehundred one"} \ + { 2 2 1 3 3 1 6 3 0 0 0 0 3 2 } \ + { 2 2 1 3 3 2 6 3 0 0 0 1 3 2 } \ + { 2 2 1 3 3 3 6 3 0 0 0 2 3 2 } + + do_select_test $T.9.9 { + SELECT mit(matchinfo(ft)), mit(matchinfo(ft)) + FROM ft WHERE ft MATCH 'two OR "threehundred one"' + } [normalize { + {2 2 1 3 3 1 6 3 0 0 0 0 3 2} + {2 2 1 3 3 1 6 3 0 0 0 0 3 2} + {2 2 1 3 3 2 6 3 0 0 0 1 3 2} + {2 2 1 3 3 2 6 3 0 0 0 1 3 2} + {2 2 1 3 3 3 6 3 0 0 0 2 3 2} + {2 2 1 3 3 3 6 3 0 0 0 2 3 2} + }] + + # EVIDENCE-OF: R-40630-02268 If used within a SELECT that uses the + # "query by rowid" or "linear scan" strategies, then the snippet and + # offsets both return an empty string, and the matchinfo function + # returns a blob value zero bytes in size. + # + set r 1000000 ;# A rowid that exists in table ft + do_select_test $T.10.0 { SELECT rowid FROM ft WHERE rowid = $r } $r + do_select_test $T.10.1 { + SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft; + } {0 text 0 text 0 text} + do_select_test $T.10.2 { + SELECT length(offsets(ft)), typeof(offsets(ft)) FROM ft WHERE rowid = $r + } {0 text} + do_select_test $T.10.3 { + SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft; + } {0 text 0 text 0 text} + do_select_test $T.10.4 { + SELECT length(snippet(ft)), typeof(snippet(ft)) FROM ft WHERE rowid = $r; + } {0 text} + do_select_test $T.10.5 { + SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft; + } {0 blob 0 blob 0 blob} + do_select_test $T.10.6 { + SELECT length(matchinfo(ft)), typeof(matchinfo(ft)) FROM ft WHERE rowid = $r + } {0 blob} +} + +#------------------------------------------------------------------------- +# Test an interaction between the snippet() function and OR clauses. +# +do_execsql_test 2.1 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 VALUES('one two three four five'); + INSERT INTO t2 VALUES('two three four five one'); + INSERT INTO t2 VALUES('three four five one two'); + INSERT INTO t2 VALUES('four five one two three'); + INSERT INTO t2 VALUES('five one two three four'); +} + +do_execsql_test 2.2 { + SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' +} { + {[one] two three [four] five} + {two three [four] five [one]} + {three [four] five [one] two} + {[four] five [one] two three} + {five [one] two three [four]} +} + +do_execsql_test 2.3 { + SELECT snippet(t2, '[', ']') FROM t2 + WHERE t2 MATCH 'one OR (four AND six)' + ORDER BY docid DESC +} { + {five [one] two three [four]} + {[four] five [one] two three} + {three [four] five [one] two} + {two three [four] five [one]} + {[one] two three [four] five} +} + +do_execsql_test 2.4 { + INSERT INTO t2 VALUES('six'); +} + +do_execsql_test 2.5 { + SELECT snippet(t2, '[', ']') FROM t2 WHERE t2 MATCH 'one OR (four AND six)' +} { + {[one] two three [four] five} + {two three [four] five [one]} + {three [four] five [one] two} + {[four] five [one] two three} + {five [one] two three [four]} +} + +do_execsql_test 2.6 { + SELECT snippet(t2, '[', ']') FROM t2 + WHERE t2 MATCH 'one OR (four AND six)' + ORDER BY docid DESC +} { + {five [one] two three [four]} + {[four] five [one] two three} + {three [four] five [one] two} + {two three [four] five [one]} + {[one] two three [four] five} +} + +#------------------------------------------------------------------------- +do_execsql_test 3 { + CREATE VIRTUAL TABLE t3 USING fts4; + INSERT INTO t3 VALUES('[one two three]'); +} +do_execsql_test 3.1 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one'; +} {{[one two three]}} +do_execsql_test 3.2 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'two'; +} {{[one two three]}} +do_execsql_test 3.3 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'three'; +} {{[one two three]}} +do_execsql_test 3.4 { + SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'one OR two OR three'; +} {{[one two three]}} + +#------------------------------------------------------------------------- +# Request a snippet 0 tokens in size. This is always an empty string. +do_execsql_test 4.1 { + CREATE VIRTUAL TABLE t4 USING fts4; + INSERT INTO t4 VALUES('a b c d'); + SELECT snippet(t4, '[', ']', '...', 0, 0) FROM t4 WHERE t4 MATCH 'b'; +} {{}} + +do_test 4.2 { + set x35 [string trim [string repeat "x " 35]] + execsql "INSERT INTO t4 VALUES('$x35 E $x35 F $x35 G $x35');" + llength [db one { + SELECT snippet(t4, '', '', '', 0, 64) FROM t4 WHERE t4 MATCH 'E' + }] +} {64} + +do_test 4.3 { + llength [db one { + SELECT snippet(t4, '', '', '', 0, 150) FROM t4 WHERE t4 MATCH 'E' + }] +} {64} + +#------------------------------------------------------------------------- +# Request a snippet from a query with more than 64 phrases. +# +do_execsql_test 5.0 { + CREATE VIRTUAL TABLE t5 USING fts3(x); + INSERT INTO t5 VALUES('a1 a2 a3'); + INSERT INTO t5 VALUES('a4 a5 a6'); + INSERT INTO t5 VALUES('a70 a71 a72'); +} + +do_execsql_test 5.1 { + SELECT snippet(t5, '[', ']') FROM t5 WHERE t5 MATCH + 'a1 OR a2 OR a3 OR a4 OR a5 OR a6 OR a7 OR a8 OR a9 OR a10 OR ' || + 'a11 OR a12 OR a13 OR a14 OR a15 OR a16 OR a17 OR a18 OR a19 OR a10 OR ' || + 'a21 OR a22 OR a23 OR a24 OR a25 OR a26 OR a27 OR a28 OR a29 OR a20 OR ' || + 'a31 OR a32 OR a33 OR a34 OR a35 OR a36 OR a37 OR a38 OR a39 OR a30 OR ' || + 'a41 OR a42 OR a43 OR a44 OR a45 OR a46 OR a47 OR a48 OR a49 OR a40 OR ' || + 'a51 OR a52 OR a53 OR a54 OR a55 OR a56 OR a57 OR a58 OR a59 OR a50 OR ' || + 'a61 OR a62 OR a63 OR a64 OR a65 OR a66 OR a67 OR a68 OR a69 OR a60 OR ' || + 'a71 OR a72 OR a73 OR a74 OR a75 OR a76 OR a77 OR a78 OR a79 OR a70' +} { + {[a1] [a2] [a3]} + {[a4] [a5] [a6]} + {[a70] [a71] [a72]} +} + +do_execsql_test 5.2 { + SELECT snippet(t5, '[', ']', -1, 0) FROM t5 WHERE t5 MATCH 'a5' +} {{a4 [a5] a6}} + +set sqlite_fts3_enable_parentheses 0 +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok1.test new file mode 100644 index 0000000000000000000000000000000000000000..139fae89d905acd20a9a5660d6aa6d31c57a89ad --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok1.test @@ -0,0 +1,124 @@ +# 2013 April 22 +# +# 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. The +# focus of this script is testing the "fts3tokenize" virtual table +# that is part of the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3tok1 + +#------------------------------------------------------------------------- +# Simple test cases. Using the default (simple) tokenizer. +# +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts3tokenize(simple); + CREATE VIRTUAL TABLE t2 USING fts3tokenize(); + CREATE VIRTUAL TABLE t3 USING fts3tokenize(simple, '', 'xyz '); +} + +foreach {tn tbl} {1 t1 2 t2 3 t3} { + do_execsql_test 1.$tn.1 "SELECT * FROM $tbl WHERE input = 'one two three'" { + {one two three} one 0 3 0 + {one two three} two 4 7 1 + {one two three} three 8 13 2 + } + + do_execsql_test 1.$tn.2 " + SELECT token FROM $tbl WHERE input = 'OnE tWo tHrEe' + " { + one two three + } +} + +do_execsql_test 1.4 { + SELECT token FROM t3 WHERE input = '1x2x3x' +} {1 2 3} + +do_execsql_test 1.5 { + SELECT token FROM t1 WHERE input = '1x2x3x' +} {1x2x3x} + +do_execsql_test 1.6 { + SELECT token FROM t3 WHERE input = '1''2x3x' +} {1'2 3} + +do_execsql_test 1.7 { + SELECT token FROM t3 WHERE input = '' +} {} + +do_execsql_test 1.8 { + SELECT token FROM t3 WHERE input = NULL +} {} + +do_execsql_test 1.9 { + SELECT * FROM t3 WHERE input = 123 +} {123 123 0 3 0} + +do_execsql_test 1.10 { + SELECT * FROM t1 WHERE input = 'a b c' AND token = 'b'; +} { + {a b c} b 2 3 1 +} + +do_execsql_test 1.11 { + SELECT * FROM t1 WHERE token = 'b' AND input = 'a b c'; +} { + {a b c} b 2 3 1 +} + +do_execsql_test 1.12 { + SELECT * FROM t1 WHERE input < 'b' AND input = 'a b c'; +} { + {a b c} a 0 1 0 + {a b c} b 2 3 1 + {a b c} c 4 5 2 +} + +do_execsql_test 1.13.1 { + CREATE TABLE c1(x); + INSERT INTO c1(x) VALUES('a b c'); + INSERT INTO c1(x) VALUES('d e f'); +} +do_execsql_test 1.13.2 { + SELECT * FROM c1, t1 WHERE input = x AND c1.rowid=t1.rowid; +} { + {a b c} {a b c} a 0 1 0 + {d e f} {d e f} e 2 3 1 +} + + +#------------------------------------------------------------------------- +# Error cases. +# +do_catchsql_test 2.0 { + CREATE VIRTUAL TABLE tX USING fts3tokenize(nosuchtokenizer); +} {1 {unknown tokenizer: nosuchtokenizer}} + +do_catchsql_test 2.1 { + CREATE VIRTUAL TABLE t4 USING fts3tokenize; + SELECT * FROM t4; +} {1 {SQL logic error}} + +do_catchsql_test 2.2 { + CREATE VIRTUAL TABLE t USING fts4(tokenize=simple""); +} {0 {}} + +ifcapable fts3_unicode { + do_catchsql_test 2.3 { + CREATE VIRTUAL TABLE u USING fts4(tokenize=unicode61""); + } {1 {unknown tokenizer}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok_err.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok_err.test new file mode 100644 index 0000000000000000000000000000000000000000..df0d4beebd266c7adec3398c6e2c38592107c1ed --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3tok_err.test @@ -0,0 +1,47 @@ +# 2013 April 22 +# +# 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. The +# focus of this script is testing the "fts3tokenize" virtual table +# that is part of the FTS3 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +ifcapable !fts3 { finish_test ; return } +set ::testprefix fts3tok_err + + +faultsim_save_and_close +do_faultsim_test fts3tok_err-1 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { CREATE VIRTUAL TABLE t1 USING fts3tokenize("simple"); } +} -test { + faultsim_test_result {0 {}} +} + +do_test fts3tok_err-2.prep { + faultsim_delete_and_reopen + execsql { CREATE VIRTUAL TABLE t1 USING fts3tokenize("simple"); } + faultsim_save_and_close +} {} + +do_faultsim_test fts3tok_err-2 -faults oom* -prep { + faultsim_restore_and_reopen +} -body { + execsql { SELECT token FROM t1 WHERE input = 'A galaxy far, far away' } +} -test { + faultsim_test_result {0 {a galaxy far far away}} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3varint.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3varint.test new file mode 100644 index 0000000000000000000000000000000000000000..9f797ed954ad6acb7c4948b58d03b15856803d34 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts3varint.test @@ -0,0 +1,121 @@ +# 2007 November 23 +# +# 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 runs all tests. +# +# $Id: fts3.test,v 1.2 2008/07/23 18:17:32 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts3varint + +ifcapable !fts3 { + finish_test + return +} + +proc test_list {list} { + foreach n $list { fts3_test_varint $n } +} + +proc do_fts3_varint_test {tn list} { + uplevel [list do_test $tn [list test_list $list] {}] +} + +do_fts3_varint_test 1.0 { + 1 10 100 1000 10000 100000 1000000 + 10000000 100000000 1000000000 10000000000 + 100000000000 1000000000000 10000000000000 +} + +do_fts3_varint_test 1.1 { + -1 -10 -100 -1000 -10000 -100000 -1000000 + -10000000 -100000000 -1000000000 -10000000000 + -100000000000 -1000000000000 -10000000000000 +} + +do_fts3_varint_test 2.0 { 0 1 2 } +do_fts3_varint_test 2.1 { 1 2 3 } +do_fts3_varint_test 2.2 { 3 4 5 } +do_fts3_varint_test 2.3 { 7 8 9 } +do_fts3_varint_test 2.4 { 15 16 17 } +do_fts3_varint_test 2.5 { 31 32 33 } +do_fts3_varint_test 2.6 { 63 64 65 } +do_fts3_varint_test 2.7 { 127 128 129 } +do_fts3_varint_test 2.8 { 255 256 257 } +do_fts3_varint_test 2.9 { 511 512 513 } +do_fts3_varint_test 2.10 { 1023 1024 1025 } +do_fts3_varint_test 2.11 { 2047 2048 2049 } +do_fts3_varint_test 2.12 { 4095 4096 4097 } +do_fts3_varint_test 2.13 { 8191 8192 8193 } +do_fts3_varint_test 2.14 { 16383 16384 16385 } +do_fts3_varint_test 2.15 { 32767 32768 32769 } +do_fts3_varint_test 2.16 { 65535 65536 65537 } +do_fts3_varint_test 2.17 { 131071 131072 131073 } +do_fts3_varint_test 2.18 { 262143 262144 262145 } +do_fts3_varint_test 2.19 { 524287 524288 524289 } +do_fts3_varint_test 2.20 { 1048575 1048576 1048577 } +do_fts3_varint_test 2.21 { 2097151 2097152 2097153 } +do_fts3_varint_test 2.22 { 4194303 4194304 4194305 } +do_fts3_varint_test 2.23 { 8388607 8388608 8388609 } +do_fts3_varint_test 2.24 { 16777215 16777216 16777217 } +do_fts3_varint_test 2.25 { 33554431 33554432 33554433 } +do_fts3_varint_test 2.26 { 67108863 67108864 67108865 } +do_fts3_varint_test 2.27 { 134217727 134217728 134217729 } +do_fts3_varint_test 2.28 { 268435455 268435456 268435457 } +do_fts3_varint_test 2.29 { 536870911 536870912 536870913 } +do_fts3_varint_test 2.30 { 1073741823 1073741824 1073741825 } +do_fts3_varint_test 2.31 { 2147483647 2147483648 2147483649 } +do_fts3_varint_test 2.32 { 4294967295 4294967296 4294967297 } +do_fts3_varint_test 2.33 { 8589934591 8589934592 8589934593 } +do_fts3_varint_test 2.34 { 17179869183 17179869184 17179869185 } +do_fts3_varint_test 2.35 { 34359738367 34359738368 34359738369 } +do_fts3_varint_test 2.36 { 68719476735 68719476736 68719476737 } +do_fts3_varint_test 2.37 { 137438953471 137438953472 137438953473 } +do_fts3_varint_test 2.38 { 274877906943 274877906944 274877906945 } +do_fts3_varint_test 2.39 { 549755813887 549755813888 549755813889 } +do_fts3_varint_test 2.40 { 1099511627775 1099511627776 1099511627777 } +do_fts3_varint_test 2.41 { 2199023255551 2199023255552 2199023255553 } +do_fts3_varint_test 2.42 { 4398046511103 4398046511104 4398046511105 } +do_fts3_varint_test 2.43 { 8796093022207 8796093022208 8796093022209 } +do_fts3_varint_test 2.44 { 17592186044415 17592186044416 17592186044417 } +do_fts3_varint_test 2.45 { 35184372088831 35184372088832 35184372088833 } +do_fts3_varint_test 2.46 { 70368744177663 70368744177664 70368744177665 } +do_fts3_varint_test 2.47 { 140737488355327 140737488355328 140737488355329 } +do_fts3_varint_test 2.48 { 281474976710655 281474976710656 281474976710657 } +do_fts3_varint_test 2.49 { 562949953421311 562949953421312 562949953421313 } +do_fts3_varint_test 2.50 { 1125899906842623 1125899906842624 1125899906842625 } +do_fts3_varint_test 2.51 { 2251799813685247 2251799813685248 2251799813685249 } +do_fts3_varint_test 2.52 { 4503599627370495 4503599627370496 4503599627370497 } +do_fts3_varint_test 2.53 { 9007199254740991 9007199254740992 9007199254740993 } +do_fts3_varint_test 2.54 { + 18014398509481983 18014398509481984 18014398509481985 } +do_fts3_varint_test 2.55 { + 36028797018963967 36028797018963968 36028797018963969 } +do_fts3_varint_test 2.56 { + 72057594037927935 72057594037927936 72057594037927937 } +do_fts3_varint_test 2.57 { + 144115188075855871 144115188075855872 144115188075855873 } +do_fts3_varint_test 2.58 { + 288230376151711743 288230376151711744 288230376151711745 } +do_fts3_varint_test 2.59 { + 576460752303423487 576460752303423488 576460752303423489 } +do_fts3_varint_test 2.60 { + 1152921504606846975 1152921504606846976 1152921504606846977 } +do_fts3_varint_test 2.61 { + 2305843009213693951 2305843009213693952 2305843009213693953 } +do_fts3_varint_test 2.62 { + 4611686018427387903 4611686018427387904 4611686018427387905 } + +if {![catch {fts3_test_varint 18446744073709551615}]} { + do_fts3_varint_test 2.63 { + 9223372036854775807 9223372036854775808 9223372036854775809 } + + do_fts3_varint_test 3.0 { 18446744073709551615 -18446744073709551615 } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4aa.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4aa.test new file mode 100644 index 0000000000000000000000000000000000000000..0c6c0b972f1afbdb512265c090d3b8f67f8318fe --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4aa.test @@ -0,0 +1,256 @@ +# 2010 February 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table with +# the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +# The following is a list of queries to perform against the above +# FTS3/FTS4 database. We will be trying these queries in various +# configurations to ensure that they always return the same answers. +# +set fts4aa_queries { + {abraham} + {the king} + {"the king"} + {abraham OR joseph} + {ab* OR jos*} + {lived t*} + {spake hebrew} + {melchizedek} + {t* melchizedek} + {melchizedek t*} +} +unset -nocomplain fts4aa_res + +# Set up the baseline results +# +do_test fts4aa-1.0 { + db eval { + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis + foreach q $::fts4aa_queries { + set r [db eval {SELECT docid FROM t1 WHERE words MATCH $q ORDER BY docid}] + set ::fts4aa_res($q) $r + } +} {} + +# Legacy test cases +# +do_test fts4aa-1.1 { + db eval { + SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize + } +} {} +do_test fts4aa-1.2 { + db eval { + SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 + } +} {} + +proc mit {blob} { + set scan(littleEndian) i* + set scan(bigEndian) I* + binary scan $blob $scan($::tcl_platform(byteOrder)) r + return $r +} +db func mit mit + +do_test fts4aa-1.3 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 WHERE t1 MATCH 'melchizedek'; + } +} {1014018 {1 1 1 1 1 1533 25 20}} +do_test fts4aa-1.4 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'spake hebrew' + ORDER BY docid; + } +} {1039014 {2 1 1 40 40 1 6 6 1533 25 42} 1039017 {2 1 1 40 40 1 6 6 1533 25 26}} +do_test fts4aa-1.5 { + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'laban overtook jacob' + ORDER BY docid; + } +} {1031025 {3 1 2 54 46 1 3 3 2 181 160 1533 25 24}} + +do_test fts4aa-1.6 { + db eval { + DELETE FROM t1 WHERE docid!=1050026; + SELECT hex(size) FROM t1_docsize; + SELECT hex(value) FROM t1_stat; + } +} {17 01176F} + +do_test fts4aa-1.7 { + db eval { + SELECT docid FROM t1 EXCEPT SELECT docid FROM t1_docsize + } +} {} +do_test fts4aa-1.8 { + db eval { + SELECT docid FROM t1_docsize EXCEPT SELECT docid FROM t1 + } +} {} +ifcapable fts4_deferred { + do_test fts4aa-1.9 { + # Note: Token 'in' is being deferred in the following query. + db eval { + SELECT docid, mit(matchinfo(t1, 'pcxnal')) FROM t1 + WHERE t1 MATCH 'joseph died in egypt' + ORDER BY docid; + } + } {1050026 {4 1 1 1 1 1 1 1 2 1 1 1 1 1 1 23 23}} +} + +# Should get the same search results from FTS3 +# +do_test fts4aa-2.0 { + db eval { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts3(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-2.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# Should get the same search results when the page size is very large +# +do_test fts4aa-3.0 { + db close + forcedelete test.db + sqlite3 db test.db + db eval { + PRAGMA page_size=65536; + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-3.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# Should get the same search results when an authorizer prevents +# all PRAGMA statements. +# +proc no_pragma_auth {code arg1 arg2 arg3 arg4 args} { + if {$code=="SQLITE_PRAGMA"} {return SQLITE_DENY} + return SQLITE_OK; +} +do_test fts4aa-4.0 { + db auth ::no_pragma_auth + db eval { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(words, tokenize porter); + } + fts_kjv_genesis +} {} +unset -nocomplain ii +set ii 0 +foreach {q r} [array get fts4aa_res] { + incr ii + do_test fts4aa-4.$ii { + db eval {SELECT docid FROM t1 WHERE words MATCH $::q ORDER BY docid} + } $r +} + +# 2019-11-16 https://bugs.chromium.org/p/chromium/issues/detail?id=1025472 +# +db close +sqlite3 db :memory: +do_execsql_test fts4aa-5.10 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, c, d, e,f,g,h,i,j,k,l,m,n,o,p,q,r); + INSERT INTO t1 VALUES('X Y', '2', '3', '4', '5', '6', '7', '8', '9', '0', + 'a','b','c','d','e','f','g','h'); + UPDATE t1_docsize SET size=x'88' WHERE docid=1; +} {} +do_catchsql_test fts4aa-5.20 { + SELECT quote(matchinfo(t1, 'l')) FROM t1 WHERE t1 MATCH 'X Y'; +} {1 {database disk image is malformed}} +do_execsql_test fts4aa-5.30 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(a,b,c,d); + INSERT INTO t1 VALUES('one two','three four','five six','seven eight'); +} {} +do_catchsql_test fts4aa-5.40 { + UPDATE t1_stat SET value=x'01010101' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.50 { + UPDATE t1_stat SET value=x'010101' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.60 { + UPDATE t1_stat SET value=x'01' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} +do_catchsql_test fts4aa-5.70 { + UPDATE t1_stat SET value=x'' WHERE id=0; + SELECT quote(matchinfo(t1,'a')) FROM t1 WHERE t1 MATCH 'one two'; +} {1 {database disk image is malformed}} + +# 2019-11-18 https://bugs.chromium.org/p/chromium/issues/detail?id=1025467 +db close +sqlite3 db :memory: +if {$tcl_platform(byteOrder)=="littleEndian"} { + set res {X'0200000000000000000000000E0000000E00000001000000010000000100000001000000'} +} else { + set res {X'0000000200000000000000000000000E0000000E00000001000000010000000100000001'} +} +do_catchsql_test fts4aa-6.10 { + CREATE VIRTUAL TABLE f USING fts4(); + INSERT INTO f_segdir VALUES (77,91,0,0,'255 77',x'0001308000004d5c4ddddddd4d4d7b4d4d4d614d8019ff4d05000001204d4d2e4d6e4d4d4d4b4d6c4d004d4d4d4d4d4d3d000000004d5d4d4d645d4d004d4d4d4d4d4d4d4d4d454d6910004d05ffff054d646c4d004d5d4d4d4d4d3d000000004d4d4d4d4d4d4d4d4d4d4d69624d4d4d04004d4d4d4d4d604d4ce1404d554d45'); + INSERT INTO f_segdir VALUES (77,108,0,0,'255 77',x'0001310000fa64004d4d4d3c5d4d654d4d4d614d8000ff4d05000001204d4d2e4d6e4d4d4dff4d4d4d4d4d4d00104d4d4d4d000000004d4d4d0400311d4d4d4d4d4d4d4d4d4d684d6910004d05ffff054d4d6c4d004d4d4d4d4d4d3d000000004d4d4d4d644d4d4d4d4d4d69624d4d4d03ed4d4d4d4d4d604d4ce1404d550080'); + INSERT INTO f_stat VALUES (0,x'80808080100000000064004d4d4d3c4d4d654d4d4d614d8000ff4df6ff1a00204d4d2e4d6e4d4d4d104d4d4d4d4d4d00104d4d4d4d4d4d69574d4d4d000031044d4d4d3e4d4d4c4d05004d6910'); + SELECT quote(matchinfo(f,'pnax')) from f where f match '0 1'; +} {1 {database disk image is malformed}} + +# 2019-11-18 Detect infinite loop in fts3SelectLeaf() +db close +sqlite3 db :memory: +do_catchsql_test fts4aa-7.10 { + CREATE VIRTUAL TABLE f USING fts4(); + INSERT INTO f_segdir VALUES (63,60,60,60,'60 60',x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c483c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c283c3c3c3c3c3c3c3c3c3c3c223c3c3c3c3c3c3c3c3c'); + INSERT INTO f_segments VALUES (60,x'3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2a3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c803c3c3c3c3c3c233c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1a3c3c3c3c3c3c000200003c3c3c3c3c3c3c3c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d898d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3cba3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c00023c3c3c3c3c3c383c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbc3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c16161616161616163c3c3c3c3c3c3c3c3c3c3c3c3c583c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c013c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c20003c3c3c3c3c3c3c3c3c3c3c800000003c3c3c3c3c3c3c2c3c3c3c3c3c3c353c08080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808f4080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808080808083c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c323c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cfcfcfcfcfcfcfcfcfcfcfc10fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfd02fcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfcfc03e8fcfcfcfc3c3c3c3c3c3c8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c553c3c3c3c3c3c3c3c3c3c3c3c3c573c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000000803c3c4dd5d5a6d52cf3d5d5d5d5d5d5d5d5d5d5d5d5d5d53c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c013c3c3c3c00643c3c3c3ce93c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c263c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c363c3c3c3c3c3c3c3c3c3c3c3c3c3c543c3c3c3c3c3c3c3c3c3c273c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c330000003c3c3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c000010003c3c3c3c3c3c413c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c403c3c3c3c3c3c3c3c3c3c3c3cec0000fa3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c5e3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c1b3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c243c3c373c3c3c3c3cff3c3c3c3c3c3c3c3c3c3c3c3c3c000080003c3c3c3c3c3c3c3c3c3c353c3c3c3c3c3d3c3c3c3c3c3c3c3c3c3c3c3c4d3c3c3c3c3c3c3c3c3c3c3c3c3c40003c3c3c3c3c293c3c3c3c3c3c3c3c3c3d3c3c3c3c3c3c3c3c353c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c4f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cff7f3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c2d3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3ca43c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3cbf3c3c3c3c3c3c3c3c3c008000003c3c3c3c3c3c3c3c343c3c373c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c593c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c3c'); + SELECT * from f where f match '0'; +} {1 {database disk image is malformed}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4check.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4check.test new file mode 100644 index 0000000000000000000000000000000000000000..7f1004d8b30fce46c6808ce30d413b80dc55965a --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4check.test @@ -0,0 +1,223 @@ +# 2012 March 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS 'integrity-check' function, +# used to check if the current FTS index accurately reflects the content +# of the table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4check + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Run the integrity-check on FTS table $tbl using database handle $db. If +# the integrity-check passes, return "ok". Otherwise, throw an exception. +# +proc fts_integrity {db tbl} { + $db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')" + return "ok" +} + +#------------------------------------------------------------------------- +# Test cases 1.* +# +# 1.0: Build a reasonably sized FTS table (5000 rows). +# +# 1.1: Run the integrity check code to check it passes. +# +# 1.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# + +# Build an FTS table and check the integrity-check passes. +# +do_test 1.0 { fts3_build_db_1 5000 } {} +do_test 1.1 { fts_integrity db t1 } {ok} + +# Mess around with the underlying tables. Check that this causes the +# integrity-check test to fail. +# +foreach {tn disruption} { + 1 { + INSERT INTO t1_content(docid, c0x, c1y) VALUES(NULL, 'a', 'b'); + } + 2 { + DELETE FROM t1_content WHERE docid = (SELECT max(docid) FROM t1_content); + } + 3 { + DELETE FROM t1_segdir WHERE level=0 AND idx=( + SELECT max(idx) FROM t1_segdir WHERE level=0 + ); + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 1.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 1.2.2.$tn { + INSERT INTO t1 (t1) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_execsql_test 1.2.3.$tn { + PRAGMA integrity_check; + } {{malformed inverted index for FTS4 table main.t1}} + do_execsql_test 1.2.4.$tn "ROLLBACK" +} + +do_test 1.3 { fts_integrity db t1 } {ok} + +#------------------------------------------------------------------------- +# Test cases 2.* +# +# 2.0: Build a reasonably sized FTS table (20000 rows) that includes +# prefix indexes. +# +# 2.1: Run the integrity check code to check it passes. +# +# 2.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# + +do_test 2.0 { fts3_build_db_2 -extra {prefix="3,1"} 20000 } {} +do_test 2.1 { fts_integrity db t2 } {ok} +foreach {tn disruption} { + 1 { + INSERT INTO t2_content VALUES(NULL, 'xyz') + } + 3 { + DELETE FROM t2_segdir WHERE level=0 AND idx=( + SELECT max(idx) FROM t2_segdir WHERE level=1024 + ); + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 2.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 2.2.2.$tn { + INSERT INTO t2 (t2) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_test 2.2.3.$tn { + db eval {PRAGMA integrity_check(t2);} + } {{malformed inverted index for FTS4 table main.t2}} + do_execsql_test 2.2.4.$tn "ROLLBACK" +} + + +#------------------------------------------------------------------------- +# Test cases 3.* +# +# 3.0: Build a reasonably sized FTS table (5000 rows) that includes +# prefix indexes and uses the languageid= feature. +# +# 3.1: Run the integrity check code to check it passes. +# +# 3.2: Make a series of minor changes to the underlying FTS data structures +# (e.g. delete or insert a row from the %_content table). Check that +# this causes the integrity-check code to fail. +# +do_test 3.0 { + reset_db + fts3_build_db_1 5000 + execsql { + CREATE VIRTUAL TABLE t3 USING fts4(x, y, prefix="2,3", languageid=langid); + } + foreach docid [execsql {SELECT docid FROM t1 ORDER BY 1 ASC}] { + execsql { + INSERT INTO t3(x, y, langid) + SELECT x, y, (docid%9)*4 FROM t1 WHERE docid=$docid; + } + } +} {} +do_test 3.1 { fts_integrity db t3 } {ok} + +foreach {tn disruption} { + 1 { + INSERT INTO t3_content(c0x, c1y, langid) VALUES(NULL, 'a', 0); + } + 2 { + UPDATE t3_content SET langid=langid+1 WHERE rowid = ( + SELECT max(rowid) FROM t3_content + ) + } +} { + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 3.2.1.$tn "BEGIN; $disruption" + do_catchsql_test 3.2.2.$tn { + INSERT INTO t3 (t3) VALUES('integrity-check') + } {1 {database disk image is malformed}} + do_execsql_test 3.2.3.$tn "ROLLBACK" +} + +#-------------------------------------------------------------------------- +# Test case 4.* +# +# Test that the integrity-check works if there are "notindexed" columns. +# +do_execsql_test 4.0 { + CREATE VIRTUAL TABLE t4 USING fts4(a, b, c, notindexed=b); + INSERT INTO t4 VALUES('text one', 'text two', 'text three'); + INSERT INTO t4(t4) VALUES('integrity-check'); +} + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 4.1 { + PRAGMA writable_schema = 1; + UPDATE sqlite_master + SET sql = 'CREATE VIRTUAL TABLE t4 USING fts4(a, b, c)' + WHERE name = 't4'; +} + +do_test 4.2 { + db close + sqlite3 db test.db + catchsql { + INSERT INTO t4(t4) VALUES('integrity-check'); + } +} {1 {database disk image is malformed}} +reset_db + +#-------------------------------------------------------------------------- +# Test case 5.* +# +# Test that the integrity-check works if there is uncommitted data. +# +do_execsql_test 5.0 { + BEGIN; + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5 VALUES('And down by Kosiosko, where the reed-banks sweep'); + INSERT INTO t5 VALUES('and sway, and the rolling plains are wide, the'); + INSERT INTO t5 VALUES('man from snowy river is a household name today,'); + INSERT INTO t5 VALUES('and the stockmen tell the story of his ride'); +} + +do_execsql_test 5.1 { + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + +sqlite3_db_config db DEFENSIVE 0 +do_catchsql_test 5.2 { + INSERT INTO t5_content VALUES(5, 'his hardy mountain pony'); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {1 {database disk image is malformed}} + +do_execsql_test 5.3 ROLLBACK + +do_execsql_test 5.4 { + CREATE VIRTUAL TABLE t5 USING fts4(a, prefix="1,2,3"); + INSERT INTO t5(t5) VALUES('integrity-check'); +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4docid.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4docid.test new file mode 100644 index 0000000000000000000000000000000000000000..2328b6ec1d3cf6ea2537b13a94d29ed758077ee1 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4docid.test @@ -0,0 +1,116 @@ +# 2012 March 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 +source $testdir/fts3_common.tcl +set ::testprefix fts4docid + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Initialize a table with pseudo-randomly generated data. +# +do_execsql_test 1.0 { CREATE VIRTUAL TABLE t1 USING fts4; } +do_test 1.1 { + foreach {docid content} { + 0 {F N K B T I K V B A} 1 {D M J E S P H E L O} + 2 {W U T Q T Q T L H G} 3 {D W H M B R S Z B K} + 4 {F Q I N P Q J L Z D} 5 {J O Q E Y A O E L B} + 6 {O V R A C R K C Y H} 7 {Z J H T Q Q O R A G} + 8 {L K J W G D Y W B M} 9 {K E Y I A Q R Q T S} + 10 {N P H Y Z M R T I C} 11 {E X H O I S E S Z F} + 12 {B Y Q T J X C L L J} 13 {Q D C U U A Q E Z U} + 14 {S I T C J R X S J M} 15 {M X M K E X L H Q Y} + 16 {O W E I C H U Y S Y} 17 {P V V E M T H C C S} + 18 {L Y A M I E N M X O} 19 {S Y R U L S Q Y F P} + 20 {U J S T T J J S V X} 21 {T E I W P O V A A P} + 22 {W D K H D H F G O J} 23 {T X Y P G M J U I L} + 24 {F V X E B C N B K W} 25 {E B A Y N N T Z I C} + 26 {G E E B C P U D H G} 27 {J D J K N S B Q T M} + 28 {Q T G M D O D Y V G} 29 {P X W I W V P W Z G} + } { + execsql { INSERT INTO t1(docid, content) VALUES($docid, $content) } + } +} {} + +# Quick test regarding affinites and the docid/rowid column. +do_execsql_test 2.1.1 { SELECT docid FROM t1 WHERE docid = 5 } {5} +do_execsql_test 2.1.2 { SELECT docid FROM t1 WHERE docid = '5' } {5} +do_execsql_test 2.1.3 { SELECT docid FROM t1 WHERE docid = +5 } {5} +do_execsql_test 2.1.4 { SELECT docid FROM t1 WHERE docid = +'5' } {5} +do_execsql_test 2.1.5 { SELECT docid FROM t1 WHERE docid < 5 } {0 1 2 3 4} +do_execsql_test 2.1.6 { SELECT docid FROM t1 WHERE docid < '5' } {0 1 2 3 4} + +do_execsql_test 2.2.1 { SELECT rowid FROM t1 WHERE rowid = 5 } {5} +do_execsql_test 2.2.2 { SELECT rowid FROM t1 WHERE rowid = '5' } {5} +do_execsql_test 2.2.3 { SELECT rowid FROM t1 WHERE rowid = +5 } {5} +do_execsql_test 2.2.4 { SELECT rowid FROM t1 WHERE rowid = +'5' } {5} +do_execsql_test 2.2.5 { SELECT rowid FROM t1 WHERE rowid < 5 } {0 1 2 3 4} +do_execsql_test 2.2.6 { SELECT rowid FROM t1 WHERE rowid < '5' } {0 1 2 3 4} + +#------------------------------------------------------------------------- +# Now test a bunch of full-text queries featuring range constraints on +# the docid field. Each query is run so that the range constraint: +# +# * is on the docid field, +# * is on the docid field with a unary +, +# * is on the rowid field, +# * is on the rowid field with a unary +. +# +# Queries are run with both "ORDER BY docid DESC" and "ORDER BY docid ASC" +# clauses. +# +foreach {tn where result} { + 1 {WHERE t1 MATCH 'O' AND xxx < 17} {1 5 6 7 11 16} + 2 {WHERE t1 MATCH 'O' AND xxx < 4123456789123456} {1 5 6 7 11 16 18 21 22 28} + 3 {WHERE t1 MATCH 'O' AND xxx < 1} {} + 4 {WHERE t1 MATCH 'O' AND xxx < -4123456789123456} {} + + 5 {WHERE t1 MATCH 'O' AND xxx > 17} {18 21 22 28} + 6 {WHERE t1 MATCH 'O' AND xxx > 4123456789123456} {} + 7 {WHERE t1 MATCH 'O' AND xxx > 1} {5 6 7 11 16 18 21 22 28} + 8 {WHERE t1 MATCH 'O' AND xxx > -4123456789123456} {1 5 6 7 11 16 18 21 22 28} + + 9 {WHERE t1 MATCH '"Q T"' AND xxx < 27} {2 9 12} + 10 {WHERE t1 MATCH '"Q T"' AND xxx <= 27} {2 9 12 27} + 11 {WHERE t1 MATCH '"Q T"' AND xxx > 27} {28} + 12 {WHERE t1 MATCH '"Q T"' AND xxx >= 27} {27 28} +} { + foreach {tn2 ref order} { + 1 docid "ORDER BY docid ASC" + 2 +docid "ORDER BY docid ASC" + 3 rowid "ORDER BY docid ASC" + 4 +rowid "ORDER BY docid ASC" + + 5 docid "ORDER BY docid DESC" + 6 +docid "ORDER BY docid DESC" + 7 rowid "ORDER BY docid DESC" + 8 +rowid "ORDER BY docid DESC" + } { + set w [string map "xxx $ref" $where] + set q "SELECT docid FROM t1 $w $order" + + if {$tn2<5} { + set r [lsort -integer -increasing $result] + } else { + set r [lsort -integer -decreasing $result] + } + + do_execsql_test 3.$tn.$tn2 $q $r + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth.test new file mode 100644 index 0000000000000000000000000000000000000000..5cf877747b845ec80519e2cdb80cad7bcab346d9 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth.test @@ -0,0 +1,441 @@ +# 2014 May 12 +# +# 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. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4growth + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +sqlite3_db_config db DEFENSIVE 0 +do_execsql_test 1.1 { CREATE VIRTUAL TABLE x1 USING fts3; } + +do_test 1.2 { + foreach L { + {"See here, young man," said Mulga Bill, "from Walgett to the sea,} + {From Conroy's Gap to Castlereagh, there's none can ride like me.} + {I'm good all round at everything as everybody knows,} + {Although I'm not the one to talk -- I hate a man that blows.} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { SELECT end_block, length(root) FROM x1_segdir } +} {{0 114} 114 {0 118} 118 {0 95} 95 {0 115} 115} + +do_execsql_test 1.3 { + INSERT INTO x1(x1) VALUES('optimize'); + SELECT level, end_block, length(root) FROM x1_segdir; +} {0 {0 394} 394} + +do_test 1.4 { + foreach L { + {But riding is my special gift, my chiefest, sole delight;} + {Just ask a wild duck can it swim, a wildcat can it fight.} + {There's nothing clothed in hair or hide, or built of flesh or steel,} + {There's nothing walks or jumps, or runs, on axle, hoof, or wheel,} + {But what I'll sit, while hide will hold and girths and straps are tight:} + {I'll ride this here two-wheeled concern right straight away at sight."} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { + INSERT INTO x1(x1) VALUES('merge=4,4'); + SELECT level, end_block, length(root) FROM x1_segdir; + } +} {1 {224 921} 2} + +do_execsql_test 1.5 { + SELECT length(block) FROM x1_segments; +} {921 {}} + +do_test 1.6 { + foreach L { + {'Twas Mulga Bill, from Eaglehawk, that sought his own abode,} + {That perched above Dead Man's Creek, beside the mountain road.} + {He turned the cycle down the hill and mounted for the fray,} + {But 'ere he'd gone a dozen yards it bolted clean away.} + + {It left the track, and through the trees, just like a silver steak,} + {It whistled down the awful slope towards the Dead Man's Creek.} + {It shaved a stump by half an inch, it dodged a big white-box:} + {The very wallaroos in fright went scrambling up the rocks,} + + {The wombats hiding in their caves dug deeper underground,} + {As Mulga Bill, as white as chalk, sat tight to every bound.} + {It struck a stone and gave a spring that cleared a fallen tree,} + {It raced beside a precipice as close as close could be;} + + {And then as Mulga Bill let out one last despairing shriek} + {It made a leap of twenty feet into the Dead Man's Creek.} + {It shaved a stump by half an inch, it dodged a big white-box:} + {The very wallaroos in fright went scrambling up the rocks,} + {The wombats hiding in their caves dug deeper underground,} + } { + execsql { INSERT INTO x1 VALUES($L) } + } + execsql { + SELECT level, end_block, length(root) FROM x1_segdir; + } +} {1 {224 921} 2 1 {226 1230} 7 0 {0 98} 98} + +do_execsql_test 1.7 { + SELECT sum(length(block)) FROM x1_segments WHERE blockid IN (224,225,226) +} {1230} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.1 { + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x2 USING fts4; +} +fts_kjv_genesis +do_test 2.2 { + foreach id [db eval {SELECT docid FROM t1}] { + execsql { + INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id + } + } + foreach id [db eval {SELECT docid FROM t1}] { + execsql { + INSERT INTO x2(docid, content) SELECT NULL, words FROM t1 WHERE docid=$id + } + if {[db one {SELECT count(*) FROM x2_segdir WHERE level<2}]==2} break + } +} {} + +do_execsql_test 2.3 { + SELECT count(*) FROM x2_segdir WHERE level=2; + SELECT count(*) FROM x2_segdir WHERE level=3; +} {6 0} + +do_execsql_test 2.4 { + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT count(*) FROM x2_segdir WHERE level=2; + SELECT count(*) FROM x2_segdir WHERE level=3; +} {6 1} + +do_execsql_test 2.5 { + SELECT end_block FROM x2_segdir WHERE level=3; + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT end_block FROM x2_segdir WHERE level=3; + INSERT INTO x2(x2) VALUES('merge=4,4'); + SELECT end_block FROM x2_segdir WHERE level=3; +} {{5588 -3950} {5588 -11766} {5588 -15541}} + +do_execsql_test 2.6 { + SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE + blockid BETWEEN start_block AND leaves_end_block + AND level=3 +} {15541} + +do_execsql_test 2.7 { + INSERT INTO x2(x2) VALUES('merge=1000,4'); + SELECT end_block FROM x2_segdir WHERE level=3; +} {{5588 127563}} + +do_execsql_test 2.8 { + SELECT sum(length(block)) FROM x2_segdir, x2_segments WHERE + blockid BETWEEN start_block AND leaves_end_block + AND level=3 +} {127563} + +#-------------------------------------------------------------------------- +# Test that delete markers are removed from FTS segments when possible. +# It is only possible to remove delete markers when the output of the +# merge operation will become the oldest segment in the index. +# +# 3.1 - when the oldest segment is created by an 'optimize'. +# 3.2 - when the oldest segment is created by an incremental merge. +# 3.3 - by a crisis merge. +# + +proc insert_doc {args} { + foreach iDoc $args { + set L [lindex { + {In your eagerness to engage the Trojans,} + {don’t any of you charge ahead of others,} + {trusting in your strength and horsemanship.} + {And don’t lag behind. That will hurt our charge.} + {Any man whose chariot confronts an enemy’s} + {should thrust with his spear at him from there.} + {That’s the most effective tactic, the way} + {men wiped out city strongholds long ago —} + {their chests full of that style and spirit.} + } [expr $iDoc%9]] + execsql { REPLACE INTO x3(docid, content) VALUES($iDoc, $L) } + } +} + +proc delete_doc {args} { + foreach iDoc $args { + execsql { DELETE FROM x3 WHERE docid = $iDoc } + } +} + +proc second {x} { lindex $x 1 } +db func second second + +do_execsql_test 3.0 { CREATE VIRTUAL TABLE x3 USING fts4 } + +do_test 3.1.1 { + db transaction { insert_doc 1 2 3 4 5 6 } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 412} +do_test 3.1.2 { + delete_doc 1 2 3 4 5 6 + execsql { SELECT count(*) FROM x3_segdir } +} {0} +do_test 3.1.3 { + db transaction { + insert_doc 1 2 3 4 5 6 7 8 9 + delete_doc 9 8 7 + } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 591 0 1 65 0 2 72 0 3 76} +do_test 3.1.4 { + execsql { INSERT INTO x3(x3) VALUES('optimize') } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {0 0 412} + +do_test 3.2.1 { + execsql { DELETE FROM x3 } + insert_doc 8 7 6 5 4 3 2 1 + delete_doc 7 8 + execsql { SELECT count(*) FROM x3_segdir } +} {10} +do_test 3.2.2 { + execsql { INSERT INTO x3(x3) VALUES('merge=500,10') } + execsql { SELECT level, idx, second(end_block) FROM x3_segdir } +} {1 0 412} + +# This assumes the crisis merge happens when there are already 16 +# segments and one more is added. +# +do_test 3.3.1 { + execsql { DELETE FROM x3 } + insert_doc 1 2 3 4 5 6 7 8 9 10 11 + delete_doc 11 10 9 8 7 + execsql { SELECT count(*) FROM x3_segdir } +} {16} + +do_test 3.3.2 { + insert_doc 12 + execsql { SELECT level, idx, second(end_block) FROM x3_segdir WHERE level=1 } +} {1 0 412} + +#-------------------------------------------------------------------------- +# Check a theory on a bug in fts4 - that segments with idx==0 were not +# being incrementally merged correctly. Theory turned out to be false. +# +do_execsql_test 4.1 { + DROP TABLE IF EXISTS x4; + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x4 USING fts4(words); +} +do_test 4.2 { + fts_kjv_genesis + execsql { INSERT INTO x4 SELECT words FROM t1 } + execsql { INSERT INTO x4 SELECT words FROM t1 } +} {} + +do_execsql_test 4.3 { + SELECT level, idx, second(end_block) FROM x4_segdir +} {0 0 117483 0 1 118006} + +do_execsql_test 4.4 { + INSERT INTO x4(x4) VALUES('merge=10,2'); + SELECT count(*) FROM x4_segdir; +} {3} + +do_execsql_test 4.5 { + INSERT INTO x4(x4) VALUES('merge=10,2'); + SELECT count(*) FROM x4_segdir; +} {3} + +do_execsql_test 4.6 { + INSERT INTO x4(x4) VALUES('merge=1000,2'); + SELECT count(*) FROM x4_segdir; +} {1} + + + +#-------------------------------------------------------------------------- +# Check that segments are not promoted if the "end_block" field does not +# contain a size. +# +do_execsql_test 5.1 { + DROP TABLE IF EXISTS x2; + DROP TABLE IF EXISTS t1; + CREATE TABLE t1(docid, words); + CREATE VIRTUAL TABLE x2 USING fts4; +} +fts_kjv_genesis + +proc first {L} {lindex $L 0} +db func first first + +do_test 5.2 { + foreach r [db eval { SELECT rowid FROM t1 }] { + execsql { + INSERT INTO x2(docid, content) SELECT docid, words FROM t1 WHERE rowid=$r + } + } + foreach d [db eval { SELECT docid FROM t1 LIMIT -1 OFFSET 20 }] { + execsql { DELETE FROM x2 WHERE docid = $d } + } + + execsql { + INSERT INTO x2(x2) VALUES('optimize'); + SELECT level, idx, end_block FROM x2_segdir + } +} {2 0 {752 1926}} + +do_execsql_test 5.3 { + UPDATE x2_segdir SET end_block = CAST( first(end_block) AS INTEGER ); + SELECT end_block, typeof(end_block) FROM x2_segdir; +} {752 integer} + +do_execsql_test 5.4 { + INSERT INTO x2 SELECT words FROM t1 LIMIT 50; + SELECT level, idx, end_block FROM x2_segdir +} {2 0 752 0 0 {758 5174}} + +do_execsql_test 5.5 { + UPDATE x2_segdir SET end_block = end_block || ' 1926' WHERE level=2; + INSERT INTO x2 SELECT words FROM t1 LIMIT 40; + SELECT level, idx, end_block FROM x2_segdir +} {0 0 {752 1926} 0 1 {758 5174} 0 2 {763 4170}} + +proc t1_to_x2 {} { + foreach id [db eval {SELECT docid FROM t1 LIMIT 2}] { + execsql { + DELETE FROM x2 WHERE docid=$id; + INSERT INTO x2(docid, content) SELECT $id, words FROM t1 WHERE docid=$id; + } + } +} + +#-------------------------------------------------------------------------- +# Check that segments created by auto-merge are not promoted until they +# are completed. +# + +do_execsql_test 6.1 { + CREATE VIRTUAL TABLE x5 USING fts4; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 0; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 25; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 50; + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 75; + SELECT count(*) FROM x5_segdir +} {4} + +do_execsql_test 6.2 { + INSERT INTO x5(x5) VALUES('merge=2,4'); + SELECT level, idx, end_block FROM x5_segdir; +} {0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850} 0 3 {40 8689} 1 0 {1320 -3117}} + +do_execsql_test 6.3 { + INSERT INTO x5 SELECT words FROM t1 LIMIT 100 OFFSET 100; + SELECT level, idx, end_block FROM x5_segdir; +} { + 0 0 {10 9216} 0 1 {21 9330} 0 2 {31 8850} + 0 3 {40 8689} 1 0 {1320 -3117} 0 4 {1329 8297} +} + +do_execsql_test 6.4 { + INSERT INTO x5(x5) VALUES('merge=200,4'); + SELECT level, idx, end_block FROM x5_segdir; +} {0 0 {1329 8297} 1 0 {1320 28009}} + +do_execsql_test 6.5 { + INSERT INTO x5 SELECT words FROM t1; + SELECT level, idx, end_block FROM x5_segdir; +} { + 0 1 {1329 8297} 0 0 {1320 28009} 0 2 {1449 118006} +} + +#-------------------------------------------------------------------------- +# Ensure that if part of an incremental merge is performed by an old +# version that does not support storing segment sizes in the end_block +# field, no size is stored in the final segment (as it would be incorrect). +# +do_execsql_test 7.1 { + CREATE VIRTUAL TABLE x6 USING fts4; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + INSERT INTO x6 SELECT words FROM t1; + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} +} + +do_execsql_test 7.2 { + INSERT INTO x6(x6) VALUES('merge=25,4'); + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 {23694 -69477} +} + +do_execsql_test 7.3 { + UPDATE x6_segdir SET end_block = first(end_block) WHERE level=1; + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 23694 +} + +do_execsql_test 7.4 { + INSERT INTO x6(x6) VALUES('merge=25,4'); + SELECT level, idx, end_block FROM x6_segdir; +} { + 0 0 {118 117483} 0 1 {238 118006} 0 2 {358 118006} + 0 3 {478 118006} 0 4 {598 118006} 0 5 {718 118006} + 1 0 23694 +} + +do_execsql_test 7.5 { + INSERT INTO x6(x6) VALUES('merge=2500,4'); + SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; +} { + 1 0 719 1171 23694 +} + +do_execsql_test 7.6 { + INSERT INTO x6(x6) VALUES('merge=2500,2'); + SELECT level, idx, start_block, leaves_end_block, end_block FROM x6_segdir; +} { + 1 0 719 1171 23694 +} + +do_execsql_test 7.7 { + SELECT sum(length(block)) FROM x6_segments +} {635247} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth2.test new file mode 100644 index 0000000000000000000000000000000000000000..bcccf89c87a53f63431450659bbfa0727eedf272 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4growth2.test @@ -0,0 +1,92 @@ +# 2014 May 12 +# +# 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. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4growth2 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +do_execsql_test 1.0 { CREATE TABLE t1(docid, words); } +fts_kjv_genesis + +proc structure {} { + puts [ db eval {SELECT level, count(*) FROM x1_segdir GROUP BY level} ] +} + +proc tt {val} { + execsql { + DELETE FROM x1 + WHERE docid IN (SELECT docid FROM t1 WHERE (rowid-1)%4==$val+0); + } + execsql { + INSERT INTO x1(docid, content) + SELECT docid, words FROM t1 WHERE (rowid%4)==$val+0; + } +} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE x1 USING fts4; + INSERT INTO x1(x1) VALUES('automerge=2'); +} + +do_test 1.2 { + for {set i 0} {$i < 40} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { + SELECT max(level) FROM x1_segdir; + SELECT count(*) FROM x1_segdir WHERE level=2; + } +} {2 1} + +do_test 1.3 { + for {set i 0} {$i < 40} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { + SELECT max(level) FROM x1_segdir; + SELECT count(*) FROM x1_segdir WHERE level=2; + } +} {2 1} + +#------------------------------------------------------------------------- +# +do_execsql_test 2.1 { + DELETE FROM t1 WHERE rowid>16; + DROP TABLE IF EXISTS x1; + CREATE VIRTUAL TABLE x1 USING fts4; +} + +db func second second +proc second {L} {lindex $L 1} + +for {set tn 0} {$tn < 40} {incr tn} { + do_test 2.2.$tn { + for {set i 0} {$i < 100} {incr i} { + tt 0 ; tt 1 ; tt 2 ; tt 3 + } + execsql { SELECT max(level) FROM x1_segdir } + } {1} +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4incr.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4incr.test new file mode 100644 index 0000000000000000000000000000000000000000..92104888b427a1869d851fd383ba236109c56dde --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4incr.test @@ -0,0 +1,77 @@ +# 2012 March 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 +source $testdir/fts3_common.tcl +set ::testprefix fts4incr + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table +# with the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +do_test 1.0 { + execsql { CREATE VIRTUAL TABLE t1 USING fts4(words) } + fts_kjv_genesis +} {} + +do_execsql_test 1.1 { + SELECT min(docid), max(docid) FROM t1; +} {1001001 1050026} + +foreach {tn q res} { + 1 { SELECT count(*) FROM t1 WHERE t1 MATCH 'and' AND docid < 1010000} 224 + 2 { SELECT count(*) FROM t1 WHERE t1 MATCH '"in the"' AND docid < 1010000} 47 + 3 { SELECT count(*) FROM t1 WHERE t1 MATCH '"And God"' AND docid < 1010000} 33 + 4 { SELECT count(*) FROM t1 WHERE t1 + MATCH '"land of canaan"' AND docid < 1030000 } 7 +} { + foreach s {0 1} { + execsql "INSERT INTO t1(t1) VALUES('test-no-incr-doclist=$s')" + do_execsql_test 2.$tn.$s $q $res + set t($s) [lindex [time [list execsql $q] 100] 0] + } + if {0} { + puts "with optimization: $t(0) without: $t(1)" + } +} + +do_test 2.1 { + execsql { + CREATE VIRTUAL TABLE t2 USING fts4(order=DESC); + } + set num [list one two three four five six seven eight nine ten] + execsql BEGIN + for {set i 0} {$i < 10000} {incr i} { + set x "[lindex $num [expr $i%10]] zero" + execsql { INSERT INTO t2(docid, content) VALUES($i, $x) } + } + execsql COMMIT + execsql { INSERT INTO t2(t2) VALUES('optimize') } +} {} + +do_execsql_test 2.2 { + SELECT count(*) FROM t2 WHERE t2 MATCH '"never zero"' +} {0} + +do_execsql_test 2.3 { + SELECT count(*) FROM t2 WHERE t2 MATCH '"two zero"' +} {1000} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4intck1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4intck1.test new file mode 100644 index 0000000000000000000000000000000000000000..6596b2f99726fcf5aa887447d4dc81080221e2aa --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4intck1.test @@ -0,0 +1,75 @@ +# 2023-10-23 +# +# 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. +# +#*********************************************************************** +# +# Test PRAGMA integrity_check against and FTS3/FTS4 table. +# + + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !fts3 { finish_test ; return } + +set ::testprefix fts4intck1 + +proc slang {in} { + return [string map {th d e eh} $in] +} + +db function slang -deterministic -innocuous slang +do_execsql_test 1.0 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c TEXT AS (slang(b))); + INSERT INTO t1(b) VALUES('the quick fox jumps over the lazy brown dog'); + SELECT c FROM t1; +} {{deh quick fox jumps ovehr deh lazy brown dog}} + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t2 USING fts4(content="t1", c); + INSERT INTO t2(t2) VALUES('rebuild'); + SELECT docid FROM t2 WHERE t2 MATCH 'deh'; +} {1} + +do_execsql_test 1.2 { + PRAGMA integrity_check(t2); +} {ok} + +db close +sqlite3 db test.db +do_execsql_test 2.1 { + PRAGMA integrity_check(t2); +} {{unable to validate the inverted index for FTS4 table main.t2: SQL logic error}} + +db function slang -deterministic -innocuous slang +do_execsql_test 2.2 { + PRAGMA integrity_check(t2); +} {ok} + +proc slang {in} {return $in} +do_execsql_test 2.3 { + PRAGMA integrity_check(t2); +} {{malformed inverted index for FTS4 table main.t2}} + +#------------------------------------------------------------------------- +# Test that integrity-check works on a read-only database. +# +reset_db +do_execsql_test 3.0 { + CREATE VIRTUAL TABLE x1 USING fts4(a, b); + INSERT INTO x1 VALUES('one', 'two'); + INSERT INTO x1 VALUES('three', 'four'); +} +db close +sqlite3 db test.db -readonly 1 + +do_execsql_test 3.1 { + PRAGMA integrity_check; +} {ok} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4langid.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4langid.test new file mode 100644 index 0000000000000000000000000000000000000000..7be594bd5f374733a99cb050bacb8cb08c2028fb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4langid.test @@ -0,0 +1,508 @@ +# 2012 March 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the languageid=xxx FTS4 option. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +set ::testprefix fts4langid + +#--------------------------------------------------------------------------- +# Test plan: +# +# 1.* - Warm-body tests created for specific purposes during development. +# Passing these doesn't really prove much. +# +# 2.1.* - Test that FTS queries only ever return rows associated with +# the requested language. +# +# 2.2.* - Same as 2.1.*, after an 'optimize' command. +# +# 2.3.* - Same as 2.1.*, after a 'rebuild' command. +# +# 3.* - Tests with content= tables. Both where there is a real +# underlying content table and where there is not. +# +# 4.* - Test that if one is provided, the tokenizer xLanguage method +# is called to configure the tokenizer before tokenizing query +# or document text. +# +# 5.* - Test the fts4aux table when the associated FTS4 table contains +# multiple languages. +# + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts4(a, b, languageid=lang_id); +} + +do_execsql_test 1.2 { + SELECT sql FROM sqlite_master WHERE name = 't1_content'; +} {{CREATE TABLE 't1_content'(docid INTEGER PRIMARY KEY, 'c0a', 'c1b', langid)}} + +do_execsql_test 1.3 {SELECT docid FROM t1} {} +do_execsql_test 1.4 {SELECT lang_id FROM t1} {} + +do_execsql_test 1.5 {INSERT INTO t1(a, b) VALUES('aaa', 'bbb')} +do_execsql_test 1.6 {SELECT lang_id FROM t1 } {0} + +do_execsql_test 1.7 {INSERT INTO t1(a, b, lang_id) VALUES('aaa', 'bbb', 4)} +do_execsql_test 1.8 {SELECT lang_id FROM t1 } {0 4} + +do_execsql_test 1.9 {INSERT INTO t1(a, b, lang_id) VALUES('aaa', 'bbb', 'xyz')} +do_execsql_test 1.10 {SELECT lang_id FROM t1} {0 4 0} + +do_execsql_test 1.11 { + CREATE VIRTUAL TABLE t2 USING fts4; + INSERT INTO t2 VALUES('abc'); +} +do_execsql_test 1.12 { SELECT rowid FROM t2 WHERE content MATCH 'abc' } 1 + +do_execsql_test 1.13 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(languageid=lang_id); + INSERT INTO t1(content) VALUES('a b c'); + INSERT INTO t1(content, lang_id) VALUES('a b c', 1); +} + +do_execsql_test 1.14 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b'; +} {1} +do_execsql_test 1.15 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b' AND lang_id = 0; +} {1} + +do_execsql_test 1.16 { + SELECT rowid FROM t1 WHERE t1 MATCH 'b' AND lang_id = 1; +} {2} + +do_catchsql_test 1.17 { + INSERT INTO t1(content, lang_id) VALUES('123', -1); +} {1 {constraint failed}} + +do_execsql_test 1.18 { + DROP TABLE t1; + CREATE VIRTUAL TABLE t1 USING fts4(languageid=lang_id); + INSERT INTO t1(content, lang_id) VALUES('A', 13); + INSERT INTO t1(content, lang_id) VALUES('B', 13); + INSERT INTO t1(content, lang_id) VALUES('C', 13); + INSERT INTO t1(content, lang_id) VALUES('D', 13); + INSERT INTO t1(content, lang_id) VALUES('E', 13); + INSERT INTO t1(content, lang_id) VALUES('F', 13); + INSERT INTO t1(content, lang_id) VALUES('G', 13); + INSERT INTO t1(content, lang_id) VALUES('H', 13); + INSERT INTO t1(content, lang_id) VALUES('I', 13); + INSERT INTO t1(content, lang_id) VALUES('J', 13); + INSERT INTO t1(content, lang_id) VALUES('K', 13); + INSERT INTO t1(content, lang_id) VALUES('L', 13); + INSERT INTO t1(content, lang_id) VALUES('M', 13); + INSERT INTO t1(content, lang_id) VALUES('N', 13); + INSERT INTO t1(content, lang_id) VALUES('O', 13); + INSERT INTO t1(content, lang_id) VALUES('P', 13); + INSERT INTO t1(content, lang_id) VALUES('Q', 13); + INSERT INTO t1(content, lang_id) VALUES('R', 13); + INSERT INTO t1(content, lang_id) VALUES('S', 13); + SELECT rowid FROM t1 WHERE t1 MATCH 'A'; +} {} + + +#------------------------------------------------------------------------- +# Test cases 2.* +# +proc build_multilingual_db_1 {db} { + $db eval { CREATE VIRTUAL TABLE t2 USING fts4(x, y, languageid=l) } + + set xwords [list zero one two three four five six seven eight nine ten] + set ywords [list alpha beta gamma delta epsilon zeta eta theta iota kappa] + + for {set i 0} {$i < 1000} {incr i} { + set iLangid [expr $i%9] + set x "" + set y "" + + set x [list] + lappend x [lindex $xwords [expr ($i / 1000) % 10]] + lappend x [lindex $xwords [expr ($i / 100) % 10]] + lappend x [lindex $xwords [expr ($i / 10) % 10]] + lappend x [lindex $xwords [expr ($i / 1) % 10]] + + set y [list] + lappend y [lindex $ywords [expr ($i / 1000) % 10]] + lappend y [lindex $ywords [expr ($i / 100) % 10]] + lappend y [lindex $ywords [expr ($i / 10) % 10]] + lappend y [lindex $ywords [expr ($i / 1) % 10]] + + $db eval { INSERT INTO t2(docid, x, y, l) VALUES($i, $x, $y, $iLangid) } + } + + $db eval { + CREATE TABLE data(x, y, l); + INSERT INTO data(rowid, x, y, l) SELECT docid, x, y, l FROM t2; + } +} + +proc rowid_list_set_langid {langid} { + set ::rowid_list_langid $langid +} +proc rowid_list {pattern} { + set langid $::rowid_list_langid + set res [list] + db eval {SELECT rowid, x, y FROM data WHERE l = $langid ORDER BY rowid ASC} { + if {[string match "*$pattern*" $x] || [string match "*$pattern*" $y]} { + lappend res $rowid + } + } + return $res +} + +proc or_merge_list {list1 list2} { + set res [list] + + set i1 0 + set i2 0 + + set n1 [llength $list1] + set n2 [llength $list2] + + while {$i1 < $n1 && $i2 < $n2} { + set e1 [lindex $list1 $i1] + set e2 [lindex $list2 $i2] + + if {$e1==$e2} { + lappend res $e1 + incr i1 + incr i2 + } elseif {$e1 < $e2} { + lappend res $e1 + incr i1 + } else { + lappend res $e2 + incr i2 + } + } + + concat $res [lrange $list1 $i1 end] [lrange $list2 $i2 end] +} + +proc or_merge_lists {args} { + set res [lindex $args 0] + for {set i 1} {$i < [llength $args]} {incr i} { + set res [or_merge_list $res [lindex $args $i]] + } + set res +} + +proc and_merge_list {list1 list2} { + foreach i $list2 { set a($i) 1 } + set res [list] + foreach i $list1 { + if {[info exists a($i)]} {lappend res $i} + } + set res +} + + +proc and_merge_lists {args} { + set res [lindex $args 0] + for {set i 1} {$i < [llength $args]} {incr i} { + set res [and_merge_list $res [lindex $args $i]] + } + set res +} + +proc filter_list {list langid} { + set res [list] + foreach i $list { + if {($i % 9) == $langid} {lappend res $i} + } + set res +} + +do_test 2.0 { + reset_db + build_multilingual_db_1 db +} {} + +proc do_test_query1 {tn query res_script} { + for {set langid 0} {$langid < 10} {incr langid} { + rowid_list_set_langid $langid + set res [eval $res_script] + + set actual [ + execsql {SELECT docid FROM t2 WHERE t2 MATCH $query AND l = $langid} + ] + do_test $tn.$langid [list set {} $actual] $res + } +} + +# Run some queries. +do_test_query1 2.1.1 {delta} { rowid_list delta } +do_test_query1 2.1.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.1.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.1.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +# Now try the same tests as above, but after running the 'optimize' +# command on the FTS table. +# +do_execsql_test 2.2 { + INSERT INTO t2(t2) VALUES('optimize'); + SELECT count(*) FROM t2_segdir; +} {9} +do_test_query1 2.2.1 {delta} { rowid_list delta } +do_test_query1 2.2.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.2.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.2.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +# And rebuild. +# +do_test 2.3 { + reset_db + build_multilingual_db_1 db + execsql { INSERT INTO t2(t2) VALUES('rebuild') } +} {} +do_test_query1 2.3.1 {delta} { rowid_list delta } +do_test_query1 2.3.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 2.3.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 2.3.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +#------------------------------------------------------------------------- +# Test cases 3.* +# +do_test 3.0 { + reset_db + build_multilingual_db_1 db + execsql { + CREATE TABLE t3_data(l, x, y); + INSERT INTO t3_data(rowid, l, x, y) SELECT docid, l, x, y FROM t2; + DROP TABLE t2; + } +} {} +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE t2 USING fts4(content=t3_data, languageid=l); + INSERT INTO t2(t2) VALUES('rebuild'); +} + +do_test_query1 3.1.1 {delta} { rowid_list delta } +do_test_query1 3.1.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 3.1.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 3.1.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +do_execsql_test 3.2.1 { + DROP TABLE t2; + CREATE VIRTUAL TABLE t2 USING fts4(x, y, languageid=l, content=nosuchtable); +} + +do_execsql_test 3.2.2 { + INSERT INTO t2(docid, x, y, l) SELECT rowid, x, y, l FROM t3_data; +} + +do_execsql_test 3.2.3 { + DROP TABLE t3_data; +} + +do_test_query1 3.3.1 {delta} { rowid_list delta } +do_test_query1 3.3.2 {"zero one two"} { rowid_list "zero one two" } +do_test_query1 3.3.3 {zero one two} { + and_merge_lists [rowid_list zero] [rowid_list one] [rowid_list two] +} +do_test_query1 3.3.4 {"zero one" OR "one two"} { + or_merge_lists [rowid_list "zero one"] [rowid_list "one two"] +} + +do_execsql_test 3.4 { + CREATE TABLE t8c(a, b); + CREATE VIRTUAL TABLE t8 USING fts4(content=t8c, languageid=langid); + INSERT INTO t8(docid, a, b) VALUES(-1, 'one two three', 'x y z'); + SELECT docid FROM t8 WHERE t8 MATCH 'one x' AND langid=0 +} {-1} + +#------------------------------------------------------------------------- +# Test cases 4.* +# +proc build_multilingual_db_2 {db} { + $db eval { + CREATE VIRTUAL TABLE t4 USING fts4( + tokenize=testtokenizer, + languageid=lid + ); + } + for {set i 0} {$i < 50} {incr i} { + execsql { + INSERT INTO t4(docid, content, lid) VALUES($i, 'The Quick Brown Fox', $i) + } + } +} + +do_test 4.1.0 { + reset_db + set ptr [fts3_test_tokenizer] + sqlite3_db_config db SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1 + execsql { SELECT fts3_tokenizer('testtokenizer', $ptr) } + build_multilingual_db_2 db +} {} +do_execsql_test 4.1.1 { + SELECT docid FROM t4 WHERE t4 MATCH 'quick'; +} {0} +do_execsql_test 4.1.2 { + SELECT docid FROM t4 WHERE t4 MATCH 'quick' AND lid=1; +} {} +do_execsql_test 4.1.3 { + SELECT docid FROM t4 WHERE t4 MATCH 'Quick' AND lid=1; +} {1} +for {set i 0} {$i < 50} {incr i} { + do_execsql_test 4.1.4.$i { + SELECT count(*) FROM t4 WHERE t4 MATCH 'fox' AND lid=$i; + } [expr 0==($i%2)] +} +do_catchsql_test 4.1.5 { + INSERT INTO t4(content, lid) VALUES('hello world', 101) +} {1 {SQL logic error}} + +#------------------------------------------------------------------------- +# Test cases 5.* +# +# The following test cases are designed to detect a 32-bit overflow bug +# that existed at one point. +# +proc build_multilingual_db_3 {db} { + $db eval { + CREATE VIRTUAL TABLE t5 USING fts4(languageid=lid); + } + set languages [list 0 1 2 [expr 1<<30]] + + foreach lid $languages { + execsql { + INSERT INTO t5(docid, content, lid) VALUES( + $lid, 'My language is ' || $lid, $lid + ) + } + } +} + +do_test 5.1.0 { + reset_db + build_multilingual_db_3 db +} {} + +do_execsql_test 5.1.1 { + SELECT level FROM t5_segdir; +} [list 0 1024 2048 [expr 1<<40]] + +do_execsql_test 5.1.2 {SELECT docid FROM t5 WHERE t5 MATCH 'language'} 0 +foreach langid [list 0 1 2 [expr 1<<30]] { + do_execsql_test 5.2.$langid { + SELECT docid FROM t5 WHERE t5 MATCH 'language' AND lid = $langid + } $langid +} + +set lid [expr 1<<30] +do_execsql_test 5.3.1 { + CREATE VIRTUAL TABLE t6 USING fts4(languageid=lid); + INSERT INTO t6 VALUES('I belong to language 0!'); +} +do_test 5.3.2 { + for {set i 0} {$i < 20} {incr i} { + execsql { + INSERT INTO t6(content, lid) VALUES( + 'I (row '||$i||') belong to langauge N!', $lid + ); + } + } + execsql { SELECT docid FROM t6 WHERE t6 MATCH 'belong' } +} {1} + +do_test 5.3.3 { + execsql { SELECT docid FROM t6 WHERE t6 MATCH 'belong' AND lid=$lid} +} {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21} + +do_execsql_test 5.3.4 { INSERT INTO t6(t6) VALUES('optimize') } {} +do_execsql_test 5.3.5 { SELECT docid FROM t6 WHERE t6 MATCH 'belong' } {1} +do_execsql_test 5.3.6 { + SELECT docid FROM t6 WHERE t6 MATCH 'belong' AND lid=$lid +} {2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21} + + +set lid [expr 1<<30] +foreach lid [list 4 [expr 1<<30]] { + do_execsql_test 5.4.$lid.1 { + DELETE FROM t6; + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {0 0} + do_execsql_test 5.4.$lid.2 { + INSERT INTO t6(content, lid) VALUES('zero zero zero', $lid); + INSERT INTO t6(content, lid) VALUES('zero zero one', $lid); + INSERT INTO t6(content, lid) VALUES('zero one zero', $lid); + INSERT INTO t6(content, lid) VALUES('zero one one', $lid); + INSERT INTO t6(content, lid) VALUES('one zero zero', $lid); + INSERT INTO t6(content, lid) VALUES('one zero one', $lid); + INSERT INTO t6(content, lid) VALUES('one one zero', $lid); + INSERT INTO t6(content, lid) VALUES('one one one', $lid); + + SELECT docid FROM t6 WHERE t6 MATCH '"zero zero"' AND lid=$lid; + } {1 2 5} + + do_execsql_test 5.4.$lid.3 { + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {8 0} + + do_execsql_test 5.4.$lid.4 { + INSERT INTO t6(t6) VALUES('merge=100,3'); + INSERT INTO t6(t6) VALUES('merge=100,3'); + SELECT docid FROM t6 WHERE t6 MATCH '"zero zero"' AND lid=$lid; + } {1 2 5} + + do_execsql_test 5.4.$lid.5 { + SELECT count(*) FROM t6_segdir; + SELECT count(*) FROM t6_segments; + } {1 2} +} + +reset_db +do_execsql_test 6.0 { + CREATE VIRTUAL TABLE vt0 USING fts4(c0, languageid="lid"); + INSERT INTO vt0 VALUES ('a'), ('b'); + BEGIN; + UPDATE vt0 SET lid = 1 WHERE lid=0; +} +do_execsql_test 6.1 { + INSERT INTO vt0(vt0) VALUES('integrity-check'); + PRAGMA integrity_check; +} {ok} +do_execsql_test 6.2 { + COMMIT; + INSERT INTO vt0(vt0) VALUES('integrity-check'); +} +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4lastrowid.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4lastrowid.test new file mode 100644 index 0000000000000000000000000000000000000000..7b35e3c53bb9a0a6d46b7065e649d12d68ebfb94 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4lastrowid.test @@ -0,0 +1,72 @@ +# 2017 Feb 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. +# +#*********************************************************************** +# +# Tests of the last_insert_rowid functionality with fts4. +# + +set testdir [file dirname $argv0] +source [file join [file dirname [info script]] tester.tcl] +set testprefix fts4lastrowid + +ifcapable !fts3 { + finish_test + return +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(str); +} + +do_execsql_test 1.1 { + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + SELECT last_insert_rowid(); +} {3} + +do_execsql_test 1.2 { + BEGIN; + INSERT INTO t1 VALUES('one string'); + INSERT INTO t1 VALUES('two string'); + INSERT INTO t1 VALUES('three string'); + COMMIT; + SELECT last_insert_rowid(); +} {6} + +do_execsql_test 1.3 { + INSERT INTO t1(rowid, str) VALUES(-22, 'some more text'); + SELECT last_insert_rowid(); +} {-22} + +do_execsql_test 1.4 { + BEGIN; + INSERT INTO t1(rowid, str) VALUES(45, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(46, 'some more text'); + INSERT INTO t1(rowid, str) VALUES(222, 'some more text'); + SELECT last_insert_rowid(); + COMMIT; + SELECT last_insert_rowid(); +} {222 222} + +do_execsql_test 1.5 { + CREATE TABLE x1(x); + INSERT INTO x1 VALUES('john'), ('paul'), ('george'), ('ringo'); + INSERT INTO t1 SELECT x FROM x1; + SELECT last_insert_rowid(); +} {226} + +do_execsql_test 1.6 { + INSERT INTO t1(rowid, str) SELECT rowid+10, x FROM x1; + SELECT last_insert_rowid(); +} {14} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge.test new file mode 100644 index 0000000000000000000000000000000000000000..ffef0e9334c81116c9fc92fe63449f035b293303 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge.test @@ -0,0 +1,347 @@ +# 2012 March 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the incremental merge function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +proc fts3_integrity_check {tbl} { + db eval "INSERT INTO $tbl ($tbl) VALUES('integrity-check')" + return "ok" +} + +foreach mod {fts3 fts4} { + set ::testprefix fts4merge-$mod + reset_db + + #------------------------------------------------------------------------- + # Test cases 1.* + # + do_test 1.0 { fts3_build_db_1 -module $mod 1004 } {} + do_test 1.1 { fts3_integrity_check t1 } {ok} + do_execsql_test 1.1 { + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6 7 8 9 10 11} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + + for {set i 0} {$i<20} {incr i} { + do_execsql_test 1.2.$i.1 { INSERT INTO t1(t1) VALUES('merge=1') } + do_test 1.2.$i.2 { fts3_integrity_check t1 } ok + do_execsql_test 1.2.$i.3 { + SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three' + } {123 132 213 231 312 321} + } + + do_execsql_test 1.3 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level + } { + 2 {0 1 2 3} + } + + for {set i 0} {$i<100} {incr i} { + do_execsql_test 1.4.$i { INSERT INTO t1(t1) VALUES('merge=1,4') } + do_test 1.4.$i.2 { fts3_integrity_check t1 } ok + do_execsql_test 1.4.$i.3 { + SELECT docid FROM t1 WHERE t1 MATCH 'zero one two three' + } {123 132 213 231 312 321} + } + + do_execsql_test 1.5 { + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level + } { + 3 0 + } + + #------------------------------------------------------------------------- + # Test cases 2.* test that errors in the xxx part of the 'merge=xxx' are + # handled correctly. + # + do_execsql_test 2.0 "CREATE VIRTUAL TABLE t2 USING $mod" + + foreach {tn arg} { + 1 {merge=abc} + 2 {merge=%%%} + 3 {merge=,} + 4 {merge=5,} + 5 {merge=6,%} + 6 {merge=6,six} + 7 {merge=6,1} + } { + do_catchsql_test 2.$tn { + INSERT INTO t2(t2) VALUES($arg); + } {1 {SQL logic error}} + } + + #------------------------------------------------------------------------- + # Test cases 3.* + # + do_test 3.0 { + reset_db + execsql { PRAGMA page_size = 512 } + fts3_build_db_2 -module $mod 30040 + } {} + do_test 3.1 { fts3_integrity_check t2 } {ok} + + do_execsql_test 3.2 { + SELECT level, string_agg(idx, ' ') FROM t2_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6} + 1 {0 1 2 3 4} + 2 {0 1 2 3 4} + 3 {0 1 2 3 4 5 6} + } + + do_execsql_test 3.3 { + INSERT INTO t2(t2) VALUES('merge=1000000,2'); + SELECT level, group_concat(idx, ' ') FROM t2_segdir GROUP BY level + } { + 4 0 + } + + #------------------------------------------------------------------------- + # Test cases 4.* + # + reset_db + do_execsql_test 4.1 " + PRAGMA page_size = 512; + CREATE VIRTUAL TABLE t4 USING $mod; + PRAGMA main.page_size; + " {512} + + do_test 4.2 { + foreach x {a c b d e f g h i j k l m n o p} { + execsql "INSERT INTO t4 VALUES('[string repeat $x 600]')" + } + execsql {SELECT level, string_agg(idx, ' ') FROM t4_segdir GROUP BY level} + } {0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15}} + + foreach {tn expect} { + 1 "0 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} 1 0" + 2 "0 {0 1 2 3 4 5 6 7 8 9 10 11 12} 1 0" + 3 "0 {0 1 2 3 4 5 6 7 8 9 10 11} 1 0" + 4 "0 {0 1 2 3 4 5 6 7 8 9 10} 1 0" + 5 "0 {0 1 2 3 4 5 6 7 8 9} 1 0" + 6 "0 {0 1 2 3 4 5 6 7 8} 1 0" + 7 "0 {0 1 2 3 4 5 6 7} 1 0" + 8 "0 {0 1 2 3 4 5 6} 1 0" + 9 "0 {0 1 2 3 4 5} 1 0" + } { + do_execsql_test 4.3.$tn { + INSERT INTO t4(t4) VALUES('merge=1,16'); + SELECT level, group_concat(idx, ' ') FROM t4_segdir GROUP BY level; + } $expect + } + + do_execsql_test 4.4.1 { + SELECT quote(value) FROM t4_stat WHERE rowid=1 + } {X'0006'} + + sqlite3_db_config db DEFENSIVE 0 + do_execsql_test 4.4.2 { + DELETE FROM t4_stat WHERE rowid=1; + INSERT INTO t4(t4) VALUES('merge=1,12'); + SELECT level, string_agg(idx, ' ') FROM t4_segdir GROUP BY level; + } "0 {0 1 2 3 4 5} 1 0" + + + #------------------------------------------------------------------------- + # Test cases 5.* + # + # Test that if a crisis-merge occurs that disrupts an ongoing incremental + # merge, the next call to "merge=A,B" identifies this and starts a new + # incremental merge. There are two scenarios: + # + # * There are less segments on the input level that the disrupted + # incremental merge operated on, or + # + # * Sufficient segments exist on the input level but the segments + # contain keys smaller than the largest key in the potential output + # segment. + # + do_test 5.1 { + reset_db + fts3_build_db_1 -module $mod 1000 + } {} + + do_execsql_test 5.2 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + + do_execsql_test 5.3 { + INSERT INTO t1(t1) VALUES('merge=1,5'); + INSERT INTO t1(t1) VALUES('merge=1,5'); + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level; + } { + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14} + 2 {0 1 2 3} + } + + do_execsql_test 5.4 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} + do_test 5.5 { + foreach docid [execsql {SELECT docid FROM t1}] { + execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid} + } + } {} + + do_execsql_test 5.6 {SELECT quote(value) from t1_stat WHERE rowid=1} {X'010F'} + + do_execsql_test 5.7 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12} + 2 {0 1 2 3 4 5 6 7} + X'010F' + } + + do_execsql_test 5.8 { + INSERT INTO t1(t1) VALUES('merge=1,6'); + INSERT INTO t1(t1) VALUES('merge=1,6'); + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2 3 4 5 6 7 8} X'010E' + } + + do_test 5.8.1 { fts3_integrity_check t1 } ok + + do_test 5.9 { + set L [expr 16*16*7 + 16*3 + 12] + foreach docid [execsql { + SELECT docid FROM t1 UNION ALL SELECT docid FROM t1 LIMIT $L + }] { + execsql {INSERT INTO t1 SELECT * FROM t1 WHERE docid=$docid} + } + } {} + + do_execsql_test 5.10 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 0 {0 1 2 3 4 5 6 7 8 9 10 11} 1 0 2 0 3 0 X'010E' + } + + do_execsql_test 5.11 { + INSERT INTO t1(t1) VALUES('merge=1,6'); + SELECT level, string_agg(idx, ' ') FROM t1_segdir GROUP BY level; + SELECT quote(value) from t1_stat WHERE rowid=1; + } { + 1 {0 1} 2 0 3 0 X'010E' + } + + #------------------------------------------------------------------------- + # Test cases 6.* + # + # At one point the following test caused an assert() to fail (because the + # second 'merge=1,2' operation below actually "merges" a single input + # segment, which was unexpected). + # + do_test 6.1 { + reset_db + set a [string repeat a 900] + set b [string repeat b 900] + set c [string repeat c 900] + set d [string repeat d 900] + + execsql "CREATE VIRTUAL TABLE t1 USING $mod" + execsql { + BEGIN; + INSERT INTO t1 VALUES($a); + INSERT INTO t1 VALUES($b); + COMMIT; + BEGIN; + INSERT INTO t1 VALUES($c); + INSERT INTO t1 VALUES($d); + COMMIT; + } + + execsql { + INSERT INTO t1(t1) VALUES('merge=1,2'); + INSERT INTO t1(t1) VALUES('merge=1,2'); + } + } {} + + #------------------------------------------------------------------------- + # Test cases 7.* + # + # Test that the value returned by sqlite3_total_changes() increases by + # 1 following a no-op "merge=A,B", or by more than 1 if actual work is + # performed. + # + do_test 7.0 { + reset_db + fts3_build_db_1 -module $mod 1000 + } {} + + do_execsql_test 7.1 { + SELECT level, group_concat(idx, ' ') FROM t1_segdir GROUP BY level + } { + 0 {0 1 2 3 4 5 6 7} + 1 {0 1 2 3 4 5 6 7 8 9 10 11 12 13} + 2 {0 1 2} + } + do_test 7.2 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=2,10') } + expr { ([db total_changes] - $x)>1 } + } {1} + do_test 7.3 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {1} + do_test 7.4 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {0} + do_test 7.5 { + set x [db total_changes] + execsql { INSERT INTO t1(t1) VALUES('merge=200,10') } + expr { ([db total_changes] - $x)>1 } + } {0} +} + +#------------------------------------------------------------------------- +# Test cases 8.* - ticket [bf1aab89]. +# +set testprefix fts4merge +reset_db +do_execsql_test 8.0 { + CREATE VIRTUAL TABLE t1 USING fts4(a, order=DESC); + INSERT INTO t1(a) VALUES (0); + INSERT INTO t1(a) VALUES (0); + UPDATE t1 SET a = NULL; +} + +do_execsql_test 8.1 { + INSERT INTO t1(t1) VALUES('merge=1,4'); +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge3.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge3.test new file mode 100644 index 0000000000000000000000000000000000000000..08b68b97d9653669b0e8a9f9edf40fc0f3f1f5c7 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge3.test @@ -0,0 +1,105 @@ +# 2012 March 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the incremental merge function. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +source $testdir/lock_common.tcl +source $testdir/bc_common.tcl + +set ::testprefix fts4merge3 + +ifcapable !fts3 { + finish_test + return +} + +if {"" == [bc_find_binaries backcompat.test]} { + finish_test + return +} + +db close +do_all_bc_test { + + sql2 { PRAGMA page_size = 512 } + if { 0==[catch { sql2 { CREATE VIRTUAL TABLE x USING fts4 } } ] } { + + # Build a large database. + set msg "this takes around 12 seconds" + do_test "1.1 ($msg)" { fts3_build_db_2 20000 } {} + + # Run some queries on it, using the old and new versions. + do_test 1.2 { sql1 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485} + do_test 1.3 { sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" } {1485} + + do_test 1.4 { + set x [sql2 "PRAGMA page_count"] + expr {$x>=1284 && $x<=1286} + } {1} + do_test 1.5 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } [list 0 15 1 1 2 14 3 4] + + # Run some incr-merge operations on the db. + for {set i 0} {$i<10} {incr i} { + do_test 1.6.$i.1 { sql1 { INSERT INTO t2(t2) VALUES('merge=2,2') } } {} + do_test 1.6.$i.2 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485} + } + + do_test 1.7 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } {2 15 3 5} + + # Using the old connection, insert many rows. + do_test 1.8 { + for {set i 0} {$i < 1500} {incr i} { + sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i" + } + } {} + + do_test 1.9 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } [list 0 12 1 13 2 4 3 6] + + # Run a big incr-merge operation on the db. + do_test 1.10 { sql1 { INSERT INTO t2(t2) VALUES('merge=2000,2') } } {} + do_test 1.11 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485} + + do_test 1.12 { + for {set i 0} {$i < 1500} {incr i} { + sql2 "INSERT INTO t2 SELECT content FROM t2 WHERE docid = $i" + } + } {} + do_test 1.13 { + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485 22985} + + do_test 1.14 { + sql2 "INSERT INTO t2(t2) VALUES('optimize')" + sql2 "SELECT docid FROM t2 WHERE t2 MATCH 'abc'" + } {1485 21485 22985} + + do_test 1.15 { sql2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level ORDER BY 1 + } } {4 1} + } +} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge4.test new file mode 100644 index 0000000000000000000000000000000000000000..12328c23df6b1bb96e96c5c15b5b18a5330d1474 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge4.test @@ -0,0 +1,102 @@ +# 2013 May 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4merge4 + +ifcapable !fts3||!shared_cache { + finish_test + return +} + +set ::enable_shared_cache [sqlite3_enable_shared_cache 1] + +do_execsql_test 1.1 { CREATE VIRTUAL TABLE t1 USING fts4 } + +do_test 1.2 { + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } +} {} + +do_test 1.3 { + execsql BEGIN + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } + execsql { + INSERT INTO t1(t1) VALUES('merge=8,50'); + COMMIT + } +} {} + +reset_db +do_execsql_test 2.0 { CREATE VIRTUAL TABLE t1 USING fts4 } +do_test 2.1 { + for {set i 0} {$i < 2000} {incr i} { + execsql {INSERT INTO t1 VALUES('a b c d e f g h i j k l');} + } +} {} +do_execsql_test 2.2 { SELECT count(*) FROM t1_segdir; } 35 +do_execsql_test 2.3 { INSERT INTO t1(t1) VALUES('optimize') } {} +do_execsql_test 2.4 { SELECT count(*) FROM t1_segdir; } 1 + +#------------------------------------------------------------------------- +# Now test that the automerge=? option appears to work. +# +do_execsql_test 2.1 { CREATE VIRTUAL TABLE t2 USING fts4; } + +set doc "" +foreach c1 "a b c d e f g h i j" { + foreach c2 "a b c d e f g h i j" { + foreach c3 "a b c d e f g h i j" { + lappend doc "$c1$c2$c3" + } + } +} +set doc [string repeat $doc 10] + +foreach {tn am expected} { + 1 {automerge=2} {1 1 2 1 4 1 6 1} + 2 {automerge=4} {1 2 2 1 3 1} + 3 {automerge=8} {0 4 1 3 2 1} + 4 {automerge=1} {0 4 1 3 2 1} +} { + foreach {tn2 openclose} {1 {} 2 { db close ; sqlite3 db test.db }} { + do_test 2.2.$tn.$tn2 { + execsql { DELETE FROM t2 } + execsql { INSERT INTO t2(t2) VALUES($am) }; + + eval $openclose + + for {set i 0} {$i < 100} {incr i} { + execsql { + BEGIN; + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + INSERT INTO t2 VALUES($doc); + COMMIT; + } + } + + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } + } [list {*}$expected] + } +} + +sqlite3_enable_shared_cache $::enable_shared_cache +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge5.test new file mode 100644 index 0000000000000000000000000000000000000000..1fad778b95e742c10730cefb9ce577eb23190629 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4merge5.test @@ -0,0 +1,58 @@ +# 2019 October 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The +# focus of this script is testing the FTS4 module. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4merge5 + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +source $testdir/genesis.tcl + +do_execsql_test 1.1 { + CREATE TABLE t1(docid, words); +} +fts_kjv_genesis + +do_execsql_test 1.2 { + CREATE VIRTUAL TABLE x1 USING fts3; + INSERT INTO x1(x1) VALUES('nodesize=64'); + INSERT INTO x1(x1) VALUES('maxpending=64'); +} + +do_execsql_test 1.3 { + INSERT INTO x1(docid, content) SELECT * FROM t1; +} + +for {set tn 1} {1} {incr tn} { + set tc1 [db total_changes] + do_execsql_test 1.4.$tn.1 { + INSERT INTO x1(x1) VALUES('merge=1,2'); + } + set tc2 [db total_changes] + + if {($tc2 - $tc1)<2} break + + do_execsql_test 1.4.$tn.1 { + INSERT INTO x1(x1) VALUES('integrity-check'); + } +} + + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4min.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4min.test new file mode 100644 index 0000000000000000000000000000000000000000..ca63b3961716c7fa97cfda72d819b9af55ebbeeb --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4min.test @@ -0,0 +1,53 @@ +# 2020 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. +# +#************************************************************************* +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set ::testprefix fts4min + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +#------------------------------------------------------------------ +do_execsql_test 0.0 { + CREATE TABLE t1(a NOT NULL, b); + CREATE INDEX i1 ON t1(a); +} + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE ft USING fts3(c); + INSERT INTO ft(docid, c) VALUES(22, 'hello world'); + INSERT INTO ft(docid, c) VALUES(44, 'hello world'); + INSERT INTO ft(docid, c) VALUES(11, 'hello world'); +} + +do_eqp_test 1.1.1 { + SELECT max(rowid) FROM ft +} {VIRTUAL TABLE INDEX 0:DESC} + +do_eqp_test 1.1.2 { + SELECT min(rowid) FROM ft +} {VIRTUAL TABLE INDEX 0:ASC} + +do_execsql_test 1.2.1 { + SELECT max(rowid) FROM ft +} {44} + +do_execsql_test 1.2.2 { + SELECT min(rowid) FROM ft +} {11} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4opt.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4opt.test new file mode 100644 index 0000000000000000000000000000000000000000..4b3d003239971c511fc7bb40dc4ec25c9a644aa5 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4opt.test @@ -0,0 +1,214 @@ +# 2016 March 8 +# +# 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 +source $testdir/fts3_common.tcl +set ::testprefix fts4opt + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +# Create the fts_kjv_genesis procedure which fills and FTS3/4 table +# with the complete text of the Book of Genesis. +# +source $testdir/genesis.tcl + +do_execsql_test 1.0 { CREATE TABLE t1(docid, words) } +fts_kjv_genesis + +#------------------------------------------------------------------------- +# Argument $db is an open database handle. $tbl is the name of an FTS3/4 +# table with the database. This command rearranges the contents of the +# %_segdir table so that all segments within each index are on the same +# level. This means that the 'merge' command can then be used for an +# incremental optimize routine. +# +proc prepare_for_optimize {db tbl} { + sqlite3_db_config $db DEFENSIVE 0 + $db eval [string map [list % $tbl] { + BEGIN; + CREATE TEMP TABLE tmp_segdir( + level, idx, start_block, leaves_end_block, end_block, root + ); + + INSERT INTO temp.tmp_segdir + SELECT + 1024*(o.level / 1024) + 32, -- level + sum(o.leveli.idx)), -- idx + o.start_block, o.leaves_end_block, o.end_block, o.root -- other + FROM %_segdir o, %_segdir i + WHERE (o.level / 1024) = (i.level / 1024) + GROUP BY o.level, o.idx; + + DELETE FROM %_segdir; + INSERT INTO %_segdir SELECT * FROM temp.tmp_segdir; + DROP TABLE temp.tmp_segdir; + + COMMIT; + }] +} + +do_test 1.1 { + execsql { CREATE VIRTUAL TABLE t2 USING fts4(words, prefix="1,2,3") } + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } +} {} + +do_execsql_test 1.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 13 1 15 2 5 + 1024 13 1025 15 1026 5 + 2048 13 2049 15 2050 5 + 3072 13 3073 15 3074 5 +} + +do_execsql_test 1.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 1.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 33 + 1056 33 + 2080 33 + 3104 33 +} + +do_test 1.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 1.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 1.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +#------------------------------------------------------------------------- + +do_execsql_test 2.0 { + DELETE FROM t2; +} +do_test 2.1 { + foreach {docid words} [db eval { SELECT * FROM t1 }] { + execsql { INSERT INTO t2(docid, words) VALUES($docid, $words) } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 2} { execsql { DELETE FROM t2 WHERE docid = $docid } } + } + + set i 0 + foreach {docid words} [db eval { SELECT * FROM t1 }] { + if {[incr i] % 3} { + execsql { INSERT OR REPLACE INTO t2(docid, words) VALUES($docid, $words) } + } + } +} {} + +do_execsql_test 2.2 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 0 10 1 15 2 12 + 1024 10 1025 15 1026 12 + 2048 10 2049 15 2050 12 + 3072 10 3073 15 3074 12 +} + +do_execsql_test 2.3 { INSERT INTO t2(t2) VALUES('integrity-check') } +prepare_for_optimize db t2 +do_execsql_test 2.4 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.5 { + SELECT level, count(*) FROM t2_segdir GROUP BY level +} { + 32 37 + 1056 37 + 2080 37 + 3104 37 +} + +do_test 2.6 { + while 1 { + set tc1 [db total_changes] + execsql { INSERT INTO t2(t2) VALUES('merge=5,2') } + set tc2 [db total_changes] + if {($tc2 - $tc1) < 2} break + } + execsql { SELECT level, count(*) FROM t2_segdir GROUP BY level } +} {33 1 1057 1 2081 1 3105 1} +do_execsql_test 2.7 { INSERT INTO t2(t2) VALUES('integrity-check') } + +do_execsql_test 2.8 { + INSERT INTO t2(words) SELECT words FROM t1; + SELECT level, count(*) FROM t2_segdir GROUP BY level; +} {0 2 1024 2 2048 2 3072 2} + +#------------------------------------------------------------------------- +# Check that 'optimize' works when there is data in the in-memory hash +# table, but no segments at all on disk. +# +do_execsql_test 3.1 { + CREATE VIRTUAL TABLE fts USING fts4 (t); + INSERT INTO fts (fts) VALUES ('optimize'); +} +do_execsql_test 3.2 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT count(*) FROM fts_segdir; +} {0} +do_execsql_test 3.3 { + BEGIN; + INSERT INTO fts (rowid, t) VALUES (2, 'test'); + INSERT INTO fts (fts) VALUES ('optimize'); + COMMIT; + SELECT level, idx FROM fts_segdir; +} {0 0} +do_execsql_test 3.4 { + INSERT INTO fts(fts) VALUES('integrity-check'); + SELECT rowid FROM fts WHERE fts MATCH 'test'; +} {2} +do_execsql_test 3.5 { + INSERT INTO fts (fts) VALUES ('optimize'); + INSERT INTO fts(fts) VALUES('integrity-check'); +} +do_test 3.6 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} +do_test 3.7 { + execsql { INSERT INTO fts (rowid, t) VALUES (3, 'xyz') } + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {([db total_changes] - $c1) > 1} +} {1} +do_test 3.8 { + set c1 [db total_changes] + execsql { INSERT INTO fts (fts) VALUES ('optimize') } + expr {[db total_changes] - $c1} +} {1} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4record.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4record.test new file mode 100644 index 0000000000000000000000000000000000000000..f1a3eafa75db5ede51868922154298a2a2fb90a2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4record.test @@ -0,0 +1,120 @@ +# 2019 September 18 +# +# 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. The +# focus of this script is testing the FTS4 module. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +source $testdir/fts3_common.tcl +set testprefix fts4record + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +sqlite3_fts3_may_be_corrupt 1 + +do_execsql_test 1.0 { + CREATE VIRTUAL TABLE t1 USING fts4(x); + INSERT INTO t1 VALUES('terma terma terma termb'); +} + +do_execsql_test 1.1 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D6105010203030004016203010500' +} + +proc make_record_wrapper {args} { make_fts3record $args } +db func record make_record_wrapper + +do_execsql_test 1.2 { + select quote( + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 3, 1, 5, 0 + ) ); +} { + X'00057465726D6105010203030004016203010500' +} + +do_execsql_test 1.3.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 3, 1, 5, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.3.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 4, 1, 5, + 256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.4.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.3 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + +do_execsql_test 1.5.1 { + UPDATE t1_segdir SET root = + record(0, 5, 'terma', 5, 1, 2, 3, 3, 0, + 4, 1, 'b' , 4, 1, 5, + 256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 + ); +} + +do_catchsql_test 1.4.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_execsql_test 1.4.3 { + SELECT quote(root) FROM t1_segdir +} { + X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + + +do_execsql_test 1.5.1 { + UPDATE t1_segdir SET root = + X'00057465726D61050102030300040162040105FF00010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100' +} + +do_catchsql_test 1.5.2 { + SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*' +} {1 {database disk image is malformed}} + +do_catchsql_test 1.5.3 { + INSERT INTO t1(t1) VALUES('integrity-check'); +} {1 {database disk image is malformed}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4upfrom.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4upfrom.test new file mode 100644 index 0000000000000000000000000000000000000000..889b64ad680c1649ffe6de15a2b5f7402dfadaaa --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fts4upfrom.test @@ -0,0 +1,139 @@ +# 2020 February 24 +# +# 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. The +# focus of this script is testing UPDATE statements with FROM clauses +# against FTS4 tables. +# +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix fts4upfrom + +# If SQLITE_ENABLE_FTS3 is defined, omit this file. +ifcapable !fts3 { + finish_test + return +} + +foreach {tn create_table} { + 0 { CREATE VIRTUAL TABLE ft USING fts5(a, b, c) } + 1 { CREATE VIRTUAL TABLE ft USING fts3(a, b, c) } + 2 { CREATE TABLE ft(a, b, c) } + 3 { + CREATE TABLE real(a, b, c); + CREATE INDEX i1 ON real(a); + CREATE VIEW ft AS SELECT rowid, a, b, c FROM real; + CREATE TRIGGER tr1 INSTEAD OF INSERT ON ft BEGIN + INSERT INTO real(rowid, a, b, c) VALUES(new.rowid, new.a, new.b, new.c); + END; + CREATE TRIGGER tr2 INSTEAD OF UPDATE ON ft BEGIN + UPDATE real SET rowid=new.rowid, a=new.a, b=new.b, c=new.c + WHERE rowid=old.rowid; + END; + } +} { + if {$tn==0} { ifcapable !fts5 { continue } } + catchsql { DROP VIEW IF EXISTS changes } + catchsql { DROP TABLE IF EXISTS ft } + catchsql { DROP VIEW IF EXISTS ft } + execsql $create_table + + do_execsql_test 1.$tn.0 { + INSERT INTO ft(a, b, c) VALUES('a', NULL, 'apple'); + INSERT INTO ft(a, b, c) VALUES('b', NULL, 'banana'); + INSERT INTO ft(a, b, c) VALUES('c', NULL, 'cherry'); + INSERT INTO ft(a, b, c) VALUES('d', NULL, 'damson plum'); + } + + do_execsql_test 1.$tn.1 { + SELECT a, b, c FROM ft ORDER BY rowid; + } { + a {} apple + b {} banana + c {} cherry + d {} {damson plum} + } + + do_execsql_test 1.$tn.2 { + UPDATE ft SET b=o.c FROM ft AS o WHERE (ft.a == char(unicode(o.a)+1)) + } + + do_execsql_test 1.$tn.3 { + SELECT a, b, c FROM ft ORDER BY rowid; + } { + a {} apple + b apple banana + c banana cherry + d cherry {damson plum} + } + + do_catchsql_test 1.$tn.4 { + UPDATE ft SET c=v FROM changes WHERE a=k; + } {1 {no such table: changes}} + + do_execsql_test 1.$tn.5 { + create view changes(k, v) AS + VALUES( 'd', 'dewberry' ) UNION ALL + VALUES( 'c', 'clementine' ) UNION ALL + VALUES( 'b', 'blueberry' ) UNION ALL + VALUES( 'a', 'apricot' ) + ; + } + + do_execsql_test 1.$tn.6 { + UPDATE ft SET c=v FROM changes WHERE a=k; + } + + do_execsql_test 1.$tn.7 { + SELECT rowid, a, b, c FROM ft ORDER BY rowid; + } { + 1 a {} apricot + 2 b apple blueberry + 3 c banana clementine + 4 d cherry dewberry + } + + do_execsql_test 1.$tn.8 " + WITH x1(o, n) AS ( + VALUES(1, 11) UNION ALL + VALUES(2, 12) UNION ALL + VALUES(3, 13) UNION ALL + VALUES(4, 14) + ) + SELECT ft.rowid, a, b, c, o, n FROM ft, x1 WHERE ft.rowid = o; + " { + 1 a {} apricot 1 11 + 2 b apple blueberry 2 12 + 3 c banana clementine 3 13 + 4 d cherry dewberry 4 14 + } + + set ROWID rowid + if {$tn==1} { set ROWID docid } + do_execsql_test 1.$tn.9 " + WITH x1(o, n) AS ( + VALUES(1, 11) UNION ALL + VALUES(2, 12) UNION ALL + VALUES(3, 13) UNION ALL + VALUES(4, 14) + ) + UPDATE ft SET $ROWID = n FROM x1 WHERE ft.rowid = o; + SELECT rowid, a, b, c FROM ft ORDER BY rowid; + " { + 11 a {} apricot + 12 b apple blueberry + 13 c banana clementine + 14 d cherry dewberry + } +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/func4.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/func4.test new file mode 100644 index 0000000000000000000000000000000000000000..fb74b7d8d56d0c5ed226fcaf9572fb1ee5d3fea6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/func4.test @@ -0,0 +1,781 @@ +# 2023-03-10 +# +# 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. The focus of +# 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 +# expression arguments as double precision floating point values. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set saved_tcl_precision $tcl_precision +set tcl_precision 0 +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:\ + highPrecision: $highPrecision(1) $highPrecision(2) $highPrecision(3)" +} + +do_execsql_test func4-1.1 { + SELECT tointeger(NULL); +} {{}} +do_execsql_test func4-1.2 { + SELECT tointeger(''); +} {{}} +do_execsql_test func4-1.3 { + SELECT tointeger(' '); +} {{}} +do_execsql_test func4-1.4 { + SELECT tointeger('1234'); +} {1234} +do_execsql_test func4-1.5 { + SELECT tointeger(' 1234'); +} {{}} +do_execsql_test func4-1.6 { + SELECT tointeger('bad'); +} {{}} +do_execsql_test func4-1.7 { + SELECT tointeger('0xBAD'); +} {{}} +do_execsql_test func4-1.8 { + SELECT tointeger('123BAD'); +} {{}} +do_execsql_test func4-1.9 { + SELECT tointeger('0x123BAD'); +} {{}} +do_execsql_test func4-1.10 { + SELECT tointeger('123NO'); +} {{}} +do_execsql_test func4-1.11 { + SELECT tointeger('0x123NO'); +} {{}} +do_execsql_test func4-1.12 { + SELECT tointeger('-0x1'); +} {{}} +do_execsql_test func4-1.13 { + SELECT tointeger('-0x0'); +} {{}} +do_execsql_test func4-1.14 { + SELECT tointeger('0x0'); +} {{}} +do_execsql_test func4-1.15 { + SELECT tointeger('0x1'); +} {{}} +do_execsql_test func4-1.16 { + SELECT tointeger(-1); +} {-1} +do_execsql_test func4-1.17 { + SELECT tointeger(-0); +} {0} +do_execsql_test func4-1.18 { + SELECT tointeger(0); +} {0} +do_execsql_test func4-1.19 { + SELECT tointeger(1); +} {1} +do_execsql_test func4-1.20 { + SELECT tointeger(-1.79769313486232e308 - 1); +} {{}} +do_execsql_test func4-1.21 { + SELECT tointeger(-1.79769313486232e308); +} {{}} +do_execsql_test func4-1.22 { + SELECT tointeger(-1.79769313486232e308 + 1); +} {{}} +do_execsql_test func4-1.23 { + SELECT tointeger(-9223372036854775808 - 1); +} {{}} +do_execsql_test func4-1.24 { + SELECT tointeger(-9223372036854775808); +} {-9223372036854775808} +do_execsql_test func4-1.25 { + SELECT tointeger(-9223372036854775808 + 1); +} {-9223372036854775807} +do_execsql_test func4-1.26 { + SELECT tointeger(-9223372036854775807 - 1); +} {-9223372036854775808} +do_execsql_test func4-1.27 { + SELECT tointeger(-9223372036854775807); +} {-9223372036854775807} +do_execsql_test func4-1.28 { + SELECT tointeger(-9223372036854775807 + 1); +} {-9223372036854775806} +do_execsql_test func4-1.29 { + SELECT tointeger(-2147483648 - 1); +} {-2147483649} +do_execsql_test func4-1.30 { + SELECT tointeger(-2147483648); +} {-2147483648} +do_execsql_test func4-1.31 { + SELECT tointeger(-2147483648 + 1); +} {-2147483647} +do_execsql_test func4-1.32 { + SELECT tointeger(2147483647 - 1); +} {2147483646} +do_execsql_test func4-1.33 { + SELECT tointeger(2147483647); +} {2147483647} +do_execsql_test func4-1.34 { + SELECT tointeger(2147483647 + 1); +} {2147483648} +do_execsql_test func4-1.35 { + SELECT tointeger(9223372036854775807 - 1); +} {9223372036854775806} +do_execsql_test func4-1.36 { + SELECT tointeger(9223372036854775807); +} {9223372036854775807} +if {$highPrecision(1)} { + do_execsql_test func4-1.37 { + SELECT tointeger(9223372036854775807 + 1); + } {{}} +} +do_execsql_test func4-1.38 { + SELECT tointeger(1.79769313486232e308 - 1); +} {{}} +do_execsql_test func4-1.39 { + SELECT tointeger(1.79769313486232e308); +} {{}} +do_execsql_test func4-1.40 { + SELECT tointeger(1.79769313486232e308 + 1); +} {{}} +do_execsql_test func4-1.41 { + SELECT tointeger(4503599627370496 - 1); +} {4503599627370495} +do_execsql_test func4-1.42 { + SELECT tointeger(4503599627370496); +} {4503599627370496} +do_execsql_test func4-1.43 { + SELECT tointeger(4503599627370496 + 1); +} {4503599627370497} +do_execsql_test func4-1.44 { + SELECT tointeger(9007199254740992 - 1); +} {9007199254740991} +do_execsql_test func4-1.45 { + SELECT tointeger(9007199254740992); +} {9007199254740992} +do_execsql_test func4-1.46 { + SELECT tointeger(9007199254740992 + 1); +} {9007199254740993} +do_execsql_test func4-1.47 { + SELECT tointeger(9223372036854775807 - 1); +} {9223372036854775806} +do_execsql_test func4-1.48 { + SELECT tointeger(9223372036854775807); +} {9223372036854775807} +if {$highPrecision(1)} { + do_execsql_test func4-1.49 { + SELECT tointeger(9223372036854775807 + 1); + } {{}} + do_execsql_test func4-1.50 { + SELECT tointeger(9223372036854775808 - 1); + } {{}} + do_execsql_test func4-1.51 { + SELECT tointeger(9223372036854775808); + } {{}} + do_execsql_test func4-1.52 { + SELECT tointeger(9223372036854775808 + 1); + } {{}} +} +do_execsql_test func4-1.53 { + SELECT tointeger(18446744073709551616 - 1); +} {{}} +do_execsql_test func4-1.54 { + SELECT tointeger(18446744073709551616); +} {{}} +do_execsql_test func4-1.55 { + SELECT tointeger(18446744073709551616 + 1); +} {{}} + +ifcapable floatingpoint { + + do_execsql_test func4-2.1 { + SELECT toreal(NULL); + } {{}} + do_execsql_test func4-2.2 { + SELECT toreal(''); + } {{}} + do_execsql_test func4-2.3 { + SELECT toreal(' '); + } {{}} + do_execsql_test func4-2.4 { + SELECT toreal('1234'); + } {1234.0} + do_execsql_test func4-2.5 { + SELECT toreal(' 1234'); + } {{}} + do_execsql_test func4-2.6 { + SELECT toreal('bad'); + } {{}} + do_execsql_test func4-2.7 { + SELECT toreal('0xBAD'); + } {{}} + do_execsql_test func4-2.8 { + SELECT toreal('123BAD'); + } {{}} + do_execsql_test func4-2.9 { + SELECT toreal('0x123BAD'); + } {{}} + do_execsql_test func4-2.10 { + SELECT toreal('123NO'); + } {{}} + do_execsql_test func4-2.11 { + SELECT toreal('0x123NO'); + } {{}} + do_execsql_test func4-2.12 { + SELECT toreal('-0x1'); + } {{}} + do_execsql_test func4-2.13 { + SELECT toreal('-0x0'); + } {{}} + do_execsql_test func4-2.14 { + SELECT toreal('0x0'); + } {{}} + do_execsql_test func4-2.15 { + SELECT toreal('0x1'); + } {{}} + do_execsql_test func4-2.16 { + SELECT toreal(-1); + } {-1.0} + do_execsql_test func4-2.17 { + SELECT toreal(-0); + } {0.0} + do_execsql_test func4-2.18 { + SELECT toreal(0); + } {0.0} + do_execsql_test func4-2.19 { + SELECT toreal(1); + } {1.0} + do_execsql_test func4-2.20 { + SELECT toreal(-1.79769313486232e308 - 1); + } {-Inf} + do_execsql_test func4-2.21 { + SELECT toreal(-1.79769313486232e308); + } {-Inf} + do_execsql_test func4-2.22 { + SELECT toreal(-1.79769313486232e308 + 1); + } {-Inf} + do_execsql_test func4-2.23 { + SELECT toreal(-9223372036854775808 - 1); + } {-9.223372036854776e+18} + do_execsql_test func4-2.24 { + SELECT toreal(-9223372036854775808); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-2.25 { + SELECT toreal(-9223372036854775808 + 1); + } {{}} + } + do_execsql_test func4-2.26 { + SELECT toreal(-9223372036854775807 - 1); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-2.27 { + SELECT toreal(-9223372036854775807); + } {{}} + do_execsql_test func4-2.28 { + SELECT toreal(-9223372036854775807 + 1); + } {{}} + } + do_execsql_test func4-2.29 { + SELECT toreal(-2147483648 - 1); + } {-2147483649.0} + do_execsql_test func4-2.30 { + SELECT toreal(-2147483648); + } {-2147483648.0} + do_execsql_test func4-2.31 { + SELECT toreal(-2147483648 + 1); + } {-2147483647.0} + do_execsql_test func4-2.32 { + SELECT toreal(2147483647 - 1); + } {2147483646.0} + do_execsql_test func4-2.33 { + SELECT toreal(2147483647); + } {2147483647.0} + do_execsql_test func4-2.34 { + SELECT toreal(2147483647 + 1); + } {2147483648.0} + if {$highPrecision(2)} { + do_execsql_test func4-2.35 { + SELECT toreal(9223372036854775807 - 1); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-2.36 { + SELECT toreal(9223372036854775807); + } {{}} + } + } + do_execsql_test func4-2.37 { + SELECT toreal(9223372036854775807 + 1); + } {9.223372036854776e+18} + do_execsql_test func4-2.38 { + SELECT toreal(1.79769313486232e308 - 1); + } {Inf} + do_execsql_test func4-2.39 { + SELECT toreal(1.79769313486232e308); + } {Inf} + do_execsql_test func4-2.40 { + SELECT toreal(1.79769313486232e308 + 1); + } {Inf} + do_execsql_test func4-2.41 { + SELECT toreal(4503599627370496 - 1); + } {4503599627370495.0} + do_execsql_test func4-2.42 { + SELECT toreal(4503599627370496); + } {4503599627370496.0} + do_execsql_test func4-2.43 { + SELECT toreal(4503599627370496 + 1); + } {4503599627370497.0} + do_execsql_test func4-2.44 { + SELECT toreal(9007199254740992 - 1); + } {9007199254740991.0} + do_execsql_test func4-2.45 { + SELECT toreal(9007199254740992); + } {9007199254740992.0} + 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); + } {9007199254740994.0} + do_execsql_test func4-2.48 { + SELECT toreal(tointeger(9223372036854775808) - 1); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-2.49 { + SELECT toreal(tointeger(9223372036854775808)); + } {{}} + do_execsql_test func4-2.50 { + SELECT toreal(tointeger(9223372036854775808) + 1); + } {{}} + } + do_execsql_test func4-2.51 { + SELECT toreal(tointeger(18446744073709551616) - 1); + } {{}} + do_execsql_test func4-2.52 { + SELECT toreal(tointeger(18446744073709551616)); + } {{}} + do_execsql_test func4-2.53 { + SELECT toreal(tointeger(18446744073709551616) + 1); + } {{}} +} + +ifcapable check { + do_execsql_test func4-3.1 { + CREATE TABLE t1( + x INTEGER CHECK(tointeger(x) IS NOT NULL) + ); + } {} + do_test func4-3.2 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.3 { + catchsql { + INSERT INTO t1 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.4 { + catchsql { + INSERT INTO t1 (x) VALUES (''); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.5 { + catchsql { + INSERT INTO t1 (x) VALUES ('bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.6 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.7 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56bad'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.8 { + catchsql { + INSERT INTO t1 (x) VALUES (1234); + } + } {0 {}} + do_test func4-3.9 { + catchsql { + INSERT INTO t1 (x) VALUES (1234.56); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.10 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234'); + } + } {0 {}} + do_test func4-3.11 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.56'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.12 { + catchsql { + INSERT INTO t1 (x) VALUES (ZEROBLOB(4)); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.13 { + catchsql { + INSERT INTO t1 (x) VALUES (X''); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.14 { + catchsql { + INSERT INTO t1 (x) VALUES (X'1234'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.15 { + catchsql { + INSERT INTO t1 (x) VALUES (X'12345678'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + do_test func4-3.16 { + catchsql { + INSERT INTO t1 (x) VALUES ('1234.00'); + } + } {0 {}} + do_test func4-3.17 { + catchsql { + INSERT INTO t1 (x) VALUES (1234.00); + } + } {0 {}} + do_test func4-3.18 { + catchsql { + INSERT INTO t1 (x) VALUES ('-9223372036854775809'); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + if {$highPrecision(1)} { + do_test func4-3.19 { + catchsql { + INSERT INTO t1 (x) VALUES (9223372036854775808); + } + } {1 {CHECK constraint failed: tointeger(x) IS NOT NULL}} + } + do_execsql_test func4-3.20 { + SELECT x FROM t1 WHERE x>0 ORDER BY x; + } {1234 1234 1234 1234} + + ifcapable floatingpoint { + do_execsql_test func4-4.1 { + CREATE TABLE t2( + x REAL CHECK(toreal(x) IS NOT NULL) + ); + } {} + do_test func4-4.2 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.3 { + catchsql { + INSERT INTO t2 (x) VALUES (NULL); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.4 { + catchsql { + INSERT INTO t2 (x) VALUES (''); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.5 { + catchsql { + INSERT INTO t2 (x) VALUES ('bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.6 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.7 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56bad'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.8 { + catchsql { + INSERT INTO t2 (x) VALUES (1234); + } + } {0 {}} + do_test func4-4.9 { + catchsql { + INSERT INTO t2 (x) VALUES (1234.56); + } + } {0 {}} + do_test func4-4.10 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234'); + } + } {0 {}} + do_test func4-4.11 { + catchsql { + INSERT INTO t2 (x) VALUES ('1234.56'); + } + } {0 {}} + do_test func4-4.12 { + catchsql { + INSERT INTO t2 (x) VALUES (ZEROBLOB(4)); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.13 { + catchsql { + INSERT INTO t2 (x) VALUES (X''); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.14 { + catchsql { + INSERT INTO t2 (x) VALUES (X'1234'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_test func4-4.15 { + catchsql { + INSERT INTO t2 (x) VALUES (X'12345678'); + } + } {1 {CHECK constraint failed: toreal(x) IS NOT NULL}} + do_execsql_test func4-4.16 { + SELECT x FROM t2 ORDER BY x; + } {1234.0 1234.0 1234.56 1234.56} + } +} + +ifcapable floatingpoint { + do_execsql_test func4-5.1 { + SELECT tointeger(toreal('1234')); + } {1234} + do_execsql_test func4-5.2 { + SELECT tointeger(toreal(-1)); + } {-1} + do_execsql_test func4-5.3 { + SELECT tointeger(toreal(-0)); + } {0} + do_execsql_test func4-5.4 { + SELECT tointeger(toreal(0)); + } {0} + do_execsql_test func4-5.5 { + SELECT tointeger(toreal(1)); + } {1} + do_execsql_test func4-5.6 { + SELECT tointeger(toreal(-9223372036854775808 - 1)); + } {{}} + do_execsql_test func4-5.7 { + SELECT tointeger(toreal(-9223372036854775808)); + } {{}} + if {$highPrecision(2)} { + do_execsql_test func4-5.8 { + SELECT tointeger(toreal(-9223372036854775808 + 1)); + } {{}} + } + do_execsql_test func4-5.9 { + SELECT tointeger(toreal(-2147483648 - 1)); + } {-2147483649} + do_execsql_test func4-5.10 { + SELECT tointeger(toreal(-2147483648)); + } {-2147483648} + do_execsql_test func4-5.11 { + SELECT tointeger(toreal(-2147483648 + 1)); + } {-2147483647} + do_execsql_test func4-5.12 { + SELECT tointeger(toreal(2147483647 - 1)); + } {2147483646} + do_execsql_test func4-5.13 { + SELECT tointeger(toreal(2147483647)); + } {2147483647} + do_execsql_test func4-5.14 { + SELECT tointeger(toreal(2147483647 + 1)); + } {2147483648} + do_execsql_test func4-5.15 { + SELECT tointeger(toreal(9223372036854775807 - 1)); + } {{}} + if {$highPrecision(1)} { + do_execsql_test func4-5.16 { + SELECT tointeger(toreal(9223372036854775807)); + } {{}} + do_execsql_test func4-5.17 { + SELECT tointeger(toreal(9223372036854775807 + 1)); + } {{}} + } + do_execsql_test func4-5.18 { + SELECT tointeger(toreal(4503599627370496 - 1)); + } {4503599627370495} + do_execsql_test func4-5.19 { + SELECT tointeger(toreal(4503599627370496)); + } {4503599627370496} + do_execsql_test func4-5.20 { + SELECT tointeger(toreal(4503599627370496 + 1)); + } {4503599627370497} + do_execsql_test func4-5.21 { + SELECT tointeger(toreal(9007199254740992 - 1)); + } {9007199254740991} + do_execsql_test func4-5.22 { + SELECT tointeger(toreal(9007199254740992)); + } {9007199254740992} + 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)); + } {9007199254740994} + if {$highPrecision(1)} { + do_execsql_test func4-5.25 { + SELECT tointeger(toreal(9223372036854775808 - 1)); + } {{}} + do_execsql_test func4-5.26 { + SELECT tointeger(toreal(9223372036854775808)); + } {{}} + do_execsql_test func4-5.27 { + SELECT tointeger(toreal(9223372036854775808 + 1)); + } {{}} + } + do_execsql_test func4-5.28 { + SELECT tointeger(toreal(18446744073709551616 - 1)); + } {{}} + do_execsql_test func4-5.29 { + SELECT tointeger(toreal(18446744073709551616)); + } {{}} + do_execsql_test func4-5.30 { + SELECT tointeger(toreal(18446744073709551616 + 1)); + } {{}} +} + +for {set i 0} {$i < 10} {incr i} { + if {$i == 8} continue + do_execsql_test func4-6.1.$i.1 [subst { + SELECT tointeger(x'[string repeat 01 $i]'); + }] {{}} + ifcapable floatingpoint { + do_execsql_test func4-6.1.$i.2 [subst { + SELECT toreal(x'[string repeat 01 $i]'); + }] {{}} + } +} + +do_execsql_test func4-6.2.1 { + SELECT tointeger(x'0102030405060708'); +} {578437695752307201} +do_execsql_test func4-6.2.2 { + SELECT tointeger(x'0807060504030201'); +} {72623859790382856} + +ifcapable floatingpoint { + do_execsql_test func4-6.3.1 { + SELECT toreal(x'ffefffffffffffff'); + } {-1.7976931348623157e+308} + do_execsql_test func4-6.3.2 { + SELECT toreal(x'8010000000000000'); + } {-2.2250738585072014e-308} + do_execsql_test func4-6.3.3 { + SELECT toreal(x'c000000000000000'); + } {-2.0} + do_execsql_test func4-6.3.4 { + SELECT toreal(x'bff0000000000000'); + } {-1.0} + do_execsql_test func4-6.3.5 { + SELECT toreal(x'8000000000000000'); + } {-0.0} + do_execsql_test func4-6.3.6 { + SELECT toreal(x'0000000000000000'); + } {0.0} + do_execsql_test func4-6.3.7 { + SELECT toreal(x'3ff0000000000000'); + } {1.0} + do_execsql_test func4-6.3.8 { + SELECT toreal(x'4000000000000000'); + } {2.0} + do_execsql_test func4-6.3.9 { + SELECT toreal(x'0010000000000000'); + } {2.2250738585072014e-308} + do_execsql_test func4-6.3.10 { + SELECT toreal(x'7fefffffffffffff'); + } {1.7976931348623157e+308} + do_execsql_test func4-6.3.11 { + SELECT toreal(x'8000000000000001'); + } {-5e-324} + do_execsql_test func4-6.3.12 { + SELECT toreal(x'800fffffffffffff'); + } {-2.225073858507201e-308} + do_execsql_test func4-6.3.13 { + SELECT toreal(x'0000000000000001'); + } {5e-324} + do_execsql_test func4-6.3.14 { + SELECT toreal(x'000fffffffffffff'); + } {2.225073858507201e-308} + do_execsql_test func4-6.3.15 { + SELECT toreal(x'fff0000000000000'); + } {-Inf} + do_execsql_test func4-6.3.16 { + SELECT toreal(x'7ff0000000000000'); + } {Inf} + do_execsql_test func4-6.3.17 { + SELECT toreal(x'fff8000000000000'); + } {{}} + do_execsql_test func4-6.3.18 { + SELECT toreal(x'fff0000000000001'); + } {{}} + do_execsql_test func4-6.3.19 { + SELECT toreal(x'fff7ffffffffffff'); + } {{}} + do_execsql_test func4-6.3.20 { + SELECT toreal(x'7ff0000000000001'); + } {{}} + do_execsql_test func4-6.3.21 { + SELECT toreal(x'7ff7ffffffffffff'); + } {{}} + do_execsql_test func4-6.3.22 { + SELECT toreal(x'fff8000000000001'); + } {{}} + do_execsql_test func4-6.3.23 { + SELECT toreal(x'ffffffffffffffff'); + } {{}} + do_execsql_test func4-6.3.24 { + SELECT toreal(x'7ff8000000000000'); + } {{}} + do_execsql_test func4-6.3.25 { + SELECT toreal(x'7fffffffffffffff'); + } {{}} +} + +set tcl_precision $saved_tcl_precision +unset saved_tcl_precision +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/func5.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/func5.test new file mode 100644 index 0000000000000000000000000000000000000000..8c3dd05c609bef067b99a8193a98ff6d5136aa24 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/func5.test @@ -0,0 +1,64 @@ +# 2013-11-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. +# +#************************************************************************* +# +# Testing of function factoring and the SQLITE_DETERMINISTIC flag. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Verify that constant string expressions that get factored into initializing +# code are not reused between function parameters and other values in the +# VDBE program, as the function might have changed the encoding. +# +do_execsql_test func5-1.1 { + PRAGMA encoding=UTF16le; + CREATE TABLE t1(x,a,b,c); + INSERT INTO t1 VALUES(1,'ab','cd',1); + INSERT INTO t1 VALUES(2,'gh','ef',5); + INSERT INTO t1 VALUES(3,'pqr','fuzzy',99); + INSERT INTO t1 VALUES(4,'abcdefg','xy',22); + INSERT INTO t1 VALUES(5,'shoe','mayer',2953); + SELECT x FROM t1 WHERE c=instr('abcdefg',b) OR a='abcdefg' ORDER BY +x; +} {2 4} +do_execsql_test func5-1.2 { + SELECT x FROM t1 WHERE a='abcdefg' OR c=instr('abcdefg',b) ORDER BY +x; +} {2 4} + +# Verify that SQLITE_DETERMINISTIC functions get factored out of the +# evaluation loop whereas non-deterministic functions do not. counter1() +# is marked as non-deterministic and so is not factored out of the loop, +# and it really is non-deterministic, returning a different result each +# time. But counter2() is marked as deterministic, so it does get factored +# out of the loop. counter2() has the same implementation as counter1(), +# returning a different result on each invocation, but because it is +# only invoked once outside of the loop, it appears to return the same +# result multiple times. +# +do_execsql_test func5-2.1 { + CREATE TABLE t2(x,y); + INSERT INTO t2 VALUES(1,2),(3,4),(5,6),(7,8); + SELECT x, y FROM t2 WHERE x+5=5+x ORDER BY +x; +} {1 2 3 4 5 6 7 8} +sqlite3_create_function db +do_execsql_test func5-2.2 { + SELECT x, y FROM t2 + WHERE x+counter1('hello')=counter1('hello')+x + ORDER BY +x; +} {} +set cvalue [db one {SELECT counter2('hello')+1}] +do_execsql_test func5-2.3 { + SELECT x, y FROM t2 + WHERE x+counter2('hello')=$cvalue+x + ORDER BY +x; +} {1 2 3 4 5 6 7 8} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/func6.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/func6.test new file mode 100644 index 0000000000000000000000000000000000000000..acca490f334d71f6a1a302a2e741cc39a7f635a6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/func6.test @@ -0,0 +1,183 @@ +# 2017-12-16 +# +# 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. +# +#************************************************************************* +# +# Test cases for the sqlite_offset() function. +# +# Some of the tests in this file depend on the exact placement of content +# within b-tree pages. Such placement is at the implementations discretion, +# and so it is possible for results to change from one release to the next. +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !offset_sql_func { + finish_test + return +} + +set bNullTrim 0 +ifcapable null_trim { + set bNullTrim 1 +} + +do_execsql_test func6-100 { + PRAGMA page_size=4096; + PRAGMA auto_vacuum=NONE; + CREATE TABLE t1(a,b,c,d); + WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) + INSERT INTO t1(a,b,c,d) SELECT printf('abc%03x',x), x, 1000-x, NULL FROM c; + CREATE INDEX t1a ON t1(a); + CREATE INDEX t1bc ON t1(b,c); + CREATE TABLE t2(x TEXT PRIMARY KEY, y) WITHOUT ROWID; + INSERT INTO t2(x,y) SELECT a, b FROM t1; +} + +# Load the contents of $file from disk and return it encoded as a hex +# string. +proc loadhex {file} { + set fd [open $file] + fconfigure $fd -translation binary + set data [read $fd] + close $fd + binary encode hex $data +} + +# Each argument is either an integer between 0 and 65535, a text value, or +# an empty string representing an SQL NULL. This command builds an SQLite +# record containing the values passed as arguments and returns it encoded +# as a hex string. +proc hexrecord {args} { + set hdr "" + set body "" + + if {$::bNullTrim} { + while {[llength $args] && [lindex $args end]=={}} { + set args [lrange $args 0 end-1] + } + } + + foreach x $args { + if {$x==""} { + append hdr 00 + } elseif {[string is integer $x]==0} { + set n [string length $x] + append hdr [format %02x [expr $n*2 + 13]] + append body [binary encode hex $x] + } elseif {$x == 0} { + append hdr 08 + } elseif {$x == 1} { + append hdr 09 + } elseif {$x <= 127} { + append hdr 01 + append body [format %02x $x] + } else { + append hdr 02 + append body [format %04x $x] + } + } + set res [format %02x [expr 1 + [string length $hdr]/2]] + append res $hdr + append res $body +} + +# Argument $off is an offset into the database image encoded as a hex string +# in argument $hexdb. This command returns 0 if the offset contains the hex +# $hexrec, or throws an exception otherwise. +# +proc offset_contains_record {off hexdb hexrec} { + set n [string length $hexrec] + set off [expr $off*2] + if { [string compare $hexrec [string range $hexdb $off [expr $off+$n-1]]] } { + error "record not found!" + } + return 0 +} + +# This command is the implementation of SQL function "offrec()". The first +# argument to this is an offset value. The remaining values are used to +# formulate an SQLite record. If database file test.db does not contain +# an equivalent record at the specified offset, an exception is thrown. +# Otherwise, 0 is returned. +# +proc offrec {args} { + set offset [lindex $args 0] + set rec [hexrecord {*}[lrange $args 1 end]] + offset_contains_record $offset $::F $rec +} +set F [loadhex test.db] +db func offrec offrec + +# Test the sanity of the tests. +if {$bNullTrim} { + set offset 8180 +} else { + set offset 8179 +} +do_execsql_test func6-105 { + SELECT sqlite_offset(d) FROM t1 ORDER BY rowid LIMIT 1; +} $offset +do_test func6-106 { + set r [hexrecord abc001 1 999 {}] + offset_contains_record $offset $F $r +} 0 + +set z100 [string trim [string repeat "0 " 100]] + +# Test offsets within table b-tree t1. +do_execsql_test func6-110 { + SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY rowid +} $z100 + +do_execsql_test func6-120 { + SELECT a, typeof(sqlite_offset(+a)) FROM t1 + ORDER BY rowid LIMIT 2; +} {abc001 null abc002 null} + +# Test offsets within index b-tree t1a. +do_execsql_test func6-130 { + SELECT offrec(sqlite_offset(a), a, rowid) FROM t1 ORDER BY a +} $z100 + +# Test offsets within table b-tree t1 with a temp b-tree ORDER BY. +do_execsql_test func6-140 { + SELECT offrec(sqlite_offset(d), a, b, c, d) FROM t1 ORDER BY a +} $z100 + +# Test offsets from both index t1a and table t1 in the same query. +do_execsql_test func6-150 { + SELECT offrec(sqlite_offset(a), a, rowid), + offrec(sqlite_offset(d), a, b, c, d) + FROM t1 ORDER BY a +} [concat $z100 $z100] + +# Test offsets from both index t1bc and table t1 in the same query. +do_execsql_test func6-160 { + SELECT offrec(sqlite_offset(b), b, c, rowid), + offrec(sqlite_offset(c), b, c, rowid), + offrec(sqlite_offset(d), a, b, c, d) + FROM t1 + ORDER BY b +} [concat $z100 $z100 $z100] + +# Test offsets in WITHOUT ROWID table t2. +do_execsql_test func6-200 { + SELECT offrec( sqlite_offset(y), x, y ) FROM t2 ORDER BY x +} $z100 + +# 2022-03-14 dbsqlfuzz 474499f3977d95fdf2dbcd99c50be1d0082e4c92 +reset_db +do_execsql_test func6-300 { + CREATE TABLE t2(a INT, b INT PRIMARY KEY) WITHOUT ROWID; + CREATE INDEX x3 ON t2(b); + CREATE TABLE t1(a INT PRIMARY KEY, b TEXT); + SELECT * FROM t1 WHERE a IN (SELECT sqlite_offset(b) FROM t2); +} {} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/func7.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/func7.test new file mode 100644 index 0000000000000000000000000000000000000000..6026b557f5b64381d0fb9755d762fa308b6449a0 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/func7.test @@ -0,0 +1,251 @@ +# 2020-12-07 +# +# 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. +# +#************************************************************************* +# +# Test cases for SQL functions based off the standard math library +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !mathlib { + finish_test + return +} + +do_execsql_test func7-100 { + SELECT ceil(99.9), ceiling(-99.01), floor(17), floor(-17.99); +} {100.0 -99.0 17 -18.0} +do_execsql_test func7-110 { + SELECT quote(ceil(NULL)), ceil('-99.99'); +} {NULL -99.0} +do_execsql_test func7-200 { + SELECT round(ln(5),2), log(100.0), log(100), log(2,'256'); +} {1.61 2.0 2.0 8.0} +do_execsql_test func7-210 { + SELECT ln(-5), log(-5,100.0); +} {{} {}} + +# Test cases derived from PostgreSQL documentation +# +do_execsql_test func7-pg-100 { + SELECT abs(-17.4) +} {17.4} +do_execsql_test func7-pg-110 { + SELECT ceil(42.2) +} {43.0} +do_execsql_test func7-pg-120 { + SELECT ceil(-42.2) +} {-42.0} +do_execsql_test func7-pg-130 { + SELECT round(exp(1.0),7) +} {2.7182818} +do_execsql_test func7-pg-140 { + SELECT floor(42.8) +} {42.0} +do_execsql_test func7-pg-150 { + SELECT floor(-42.8) +} {-43.0} +do_execsql_test func7-pg-160 { + SELECT round(ln(2.0),7) +} {0.6931472} +do_execsql_test func7-pg-170 { + SELECT log(100.0) +} {2.0} +do_execsql_test func7-pg-180 { + SELECT log10(1000.0) +} {3.0} +do_execsql_test func7-pg-181 { + SELECT format('%.30f', log10(100.0) ); +} {2.000000000000000000000000000000} +do_execsql_test func7-pg-182 { + SELECT format('%.30f', ln(exp(2.0)) ); +} {2.000000000000000000000000000000} +do_execsql_test func7-pg-190 { + SELECT log(2.0, 64.0) +} {6.0} +do_execsql_test func7-pg-200 { + SELECT mod(9,4); +} {1.0} +do_execsql_test func7-pg-210 { + SELECT round(pi(),7); +} {3.1415927} +do_execsql_test func7-pg-220 { + SELECT power(9,3); +} {729.0} +do_execsql_test func7-pg-230 { + SELECT round(radians(45.0),7); +} {0.7853982} +do_execsql_test func7-pg-240 { + SELECT round(42.4); +} {42.0} +do_execsql_test func7-pg-250 { + SELECT round(42.4382,2); +} {42.44} +do_execsql_test func7-pg-260 { + SELECT sign(-8.4); +} {-1} +do_execsql_test func7-pg-270 { + SELECT round( sqrt(2), 7); +} {1.4142136} +do_execsql_test func7-pg-280 { + SELECT trunc(42.8), trunc(-42.8); +} {42.0 -42.0} +do_execsql_test func7-pg-300 { + SELECT acos(1); +} {0.0} +do_execsql_test func7-pg-301 { + SELECT format('%f',degrees(acos(0.5))); +} {60.0} +do_execsql_test func7-pg-310 { + SELECT round( asin(1), 7); +} {1.5707963} +do_execsql_test func7-pg-311 { + SELECT format('%f',degrees( asin(0.5) )); +} {30.0} +do_execsql_test func7-pg-320 { + SELECT round( atan(1), 7); +} {0.7853982} +do_execsql_test func7-pg-321 { + SELECT degrees( atan(1) ); +} {45.0} +do_execsql_test func7-pg-330 { + SELECT round( atan2(1,0), 7); +} {1.5707963} +do_execsql_test func7-pg-331 { + SELECT degrees( atan2(1,0) ); +} {90.0} +do_execsql_test func7-pg-400 { + SELECT cos(0); +} {1.0} +do_execsql_test func7-pg-401 { + SELECT cos( radians(60.0) ); +} {0.5} +do_execsql_test func7-pg-400 { + SELECT cos(0); +} {1.0} +do_execsql_test func7-pg-410 { + SELECT round( sin(1), 7); +} {0.841471} +do_execsql_test func7-pg-411 { + SELECT sin( radians(30) ); +} {0.5} +do_execsql_test func7-pg-420 { + SELECT round( tan(1), 7); +} {1.5574077} +do_execsql_test func7-pg-421 { + SELECT round(tan( radians(45) ),10); +} {1.0} +do_execsql_test func7-pg-500 { + SELECT round( sinh(1), 7); +} {1.1752012} +do_execsql_test func7-pg-510 { + SELECT round( cosh(0), 7); +} {1.0} +do_execsql_test func7-pg-520 { + SELECT round( tanh(1), 7); +} {0.7615942} +do_execsql_test func7-pg-530 { + SELECT round( asinh(1), 7); +} {0.8813736} +do_execsql_test func7-pg-540 { + SELECT round( acosh(1), 7); +} {0.0} +do_execsql_test func7-pg-550 { + SELECT round( atanh(0.5), 7); +} {0.5493061} + +# Test cases derived from MySQL documentation +# +do_execsql_test func7-mysql-100 { + SELECT acos(1); +} {0.0} +do_execsql_test func7-mysql-110 { + SELECT acos(1.0001); +} {{}} +do_execsql_test func7-mysql-120 { + SELECT round( acos(0.0), 7); +} {1.5707963} +do_execsql_test func7-mysql-130 { + SELECT round( asin(0.2), 7); +} {0.2013579} +do_execsql_test func7-mysql-140 { + SELECT asin('foo'); +} {{}} ;# Note: MySQL returns 0 here, not NULL. + # SQLite deliberately returns NULL. + # SQLServer and Oracle throw an error. +do_execsql_test func7-mysql-150 { + SELECT round( atan(2), 7), round( atan(-2), 7); +} {1.1071487 -1.1071487} +do_execsql_test func7-mysql-160 { + SELECT round( atan2(-2,2), 7), round( atan2(pi(),0), 7); +} {-0.7853982 1.5707963} +do_execsql_test func7-mysql-170 { + SELECT ceiling(1.23), ceiling(-1.23); +} {2.0 -1.0} +do_execsql_test func7-mysql-180 { + SELECT cos(pi()); +} {-1.0} +do_execsql_test func7-mysql-190 { + SELECT degrees(pi()), degrees(pi()/2); +} {180.0 90.0} +do_execsql_test func7-mysql-190 { + SELECT round( exp(2), 7), round( exp(-2), 7), exp(0); +} {7.3890561 0.1353353 1.0} +do_execsql_test func7-mysql-200 { + SELECT floor(1.23), floor(-1.23); +} {1.0 -2.0} +do_execsql_test func7-mysql-210 { + SELECT round(ln(2),7), quote(ln(-2)); +} {0.6931472 NULL} +#do_execsql_test func7-mysql-220 { +# SELECT round(log(2),7), log(-2); +#} {0.6931472 NULL} +# log() means natural logarithm in MySQL +do_execsql_test func7-mysql-230 { + SELECT log(2,65536), log(10,100), quote(log(1,100)), quote(log(0,100)); +} {16.0 2.0 NULL NULL} +do_execsql_test func7-mysql-240 { + SELECT log2(65536), quote(log2(-100)), quote(log2(0)); +} {16.0 NULL NULL} +do_execsql_test func7-mysql-250 { + SELECT round(log10(2),7), log10(100), quote(log10(-100)); +} {0.30103 2.0 NULL} +do_execsql_test func7-mysql-260 { + SELECT mod(234,10), 253%7, mod(29,9), 29%9; +} {4.0 1 2.0 2} +do_execsql_test func7-mysql-270 { + SELECT mod(34.5,3); +} {1.5} +do_execsql_test func7-mysql-280 { + SELECT pow(2,2), pow(2,-2); +} {4.0 0.25} +do_execsql_test func7-mysql-281 { + SELECT power(2,2), power(2,-2); +} {4.0 0.25} +do_execsql_test func7-mysql-290 { + SELECT round(radians(90),7); +} {1.5707963} +do_execsql_test func7-mysql-300 { + SELECT sign(-32), sign(0), sign(234); +} {-1 0 1} +do_execsql_test func7-mysql-310 { + SELECT sin(pi()) BETWEEN -1.0e-15 AND 1.0e-15; +} {1} +do_execsql_test func7-mysql-320 { + SELECT sqrt(4), round(sqrt(20),7), quote(sqrt(-16)); +} {2.0 4.472136 NULL} +do_execsql_test func7-mysql-330 { + SELECT tan(pi()) BETWEEN -1.0e-15 AND 1.0e-15; +} {1} +do_execsql_test func7-mysql-331 { + SELECT round(tan(pi()+1),7); +} {1.5574077} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/func9.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/func9.test new file mode 100644 index 0000000000000000000000000000000000000000..6cf9fc31ecdc7afffd3d1fd95e9e87851f3bc7cf --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/func9.test @@ -0,0 +1,40 @@ +# 2023-08-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. +# +#************************************************************************* +# +# Test cases for SQL newer functions +# +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test func9-100 { + SELECT concat('abc',123,null,'xyz'); +} {abc123xyz} +do_execsql_test func9-110 { + SELECT typeof(concat(null)); +} {text} +do_catchsql_test func9-120 { + SELECT concat(); +} {1 {wrong number of arguments to function concat()}} +do_execsql_test func9-130 { + SELECT concat_ws(',',1,2,3,4,5,6,7,8,NULL,9,10,11,12); +} {1,2,3,4,5,6,7,8,9,10,11,12} +do_execsql_test func9-140 { + SELECT concat_ws(NULL,1,2,3,4,5,6,7,8,NULL,9,10,11,12); +} {{}} +do_catchsql_test func9-150 { + SELECT concat_ws(); +} {1 {wrong number of arguments to function concat_ws()}} +do_catchsql_test func9-160 { + SELECT concat_ws(','); +} {1 {wrong number of arguments to function concat_ws()}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz-oss1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz-oss1.test new file mode 100644 index 0000000000000000000000000000000000000000..46feeb62ebc0ae7b2fdca424e4e44e4c37df5369 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz-oss1.test @@ -0,0 +1,2007 @@ +# 2012 May 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. +# +# NB: Portions of this file are extracted from open-source projects +# covered by permissive licenses. Use of this file for testing is clearly +# allowed. However, do not incorporate the text of this one file into +# end-products without checking the licenses on the open-source projects +# from which this code was extracted. This warning applies to this one +# file only - not the bulk of the SQLite source code and tests. +# +#*********************************************************************** +# +# This file contains large and complex schemas obtained from open-source +# software projects. The schemas are parsed just to make sure that nothing +# breaks in the parser logic. +# +# These tests merely verify that the parse occurs without error. +# No attempt is made to verify correct operation of the resulting schema +# and statements. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# Schema and query extracted from Skrooge.org. +# +do_test fuzz-oss1-skrooge { + db eval { +CREATE TABLE parameters (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_uuid_parent TEXT NOT NULL DEFAULT '',t_name TEXT NOT NULL,t_value TEXT NOT NULL DEFAULT '',b_blob BLOB,d_lastmodifdate DATE NOT NULL DEFAULT CURRENT_TIMESTAMP,i_tmp INTEGER NOT NULL DEFAULT 0); +CREATE TABLE doctransaction (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_mode VARCHAR(1) DEFAULT 'U' CHECK (t_mode IN ('U', 'R')),d_date DATE NOT NULL,t_savestep VARCHAR(1) DEFAULT 'N' CHECK (t_savestep IN ('Y', 'N')),i_parent INTEGER, t_refreshviews VARCHAR(1) DEFAULT 'Y' CHECK (t_refreshviews IN ('Y', 'N'))); +CREATE TABLE doctransactionitem (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, rd_doctransaction_id INTEGER NOT NULL,i_object_id INTEGER NOT NULL,t_object_table TEXT NOT NULL,t_action VARCHAR(1) DEFAULT 'I' CHECK (t_action IN ('I', 'U', 'D')),t_sqlorder TEXT NOT NULL DEFAULT ''); +CREATE TABLE doctransactionmsg (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, rd_doctransaction_id INTEGER NOT NULL,t_message TEXT NOT NULL DEFAULT '',t_popup VARCHAR(1) DEFAULT 'Y' CHECK (t_popup IN ('Y', 'N'))); +CREATE TABLE unit(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_symbol TEXT NOT NULL DEFAULT '',t_country TEXT NOT NULL DEFAULT '',t_type VARCHAR(1) NOT NULL DEFAULT 'C' CHECK (t_type IN ('1', '2', 'C', 'S', 'I', 'O')),t_internet_code TEXT NOT NULL DEFAULT '',i_nbdecimal INT NOT NULL DEFAULT 2,rd_unit_id INTEGER NOT NULL DEFAULT 0, t_source TEXT NOT NULL DEFAULT ''); +CREATE TABLE unitvalue(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rd_unit_id INTEGER NOT NULL,d_date DATE NOT NULL,f_quantity FLOAT NOT NULL CHECK (f_quantity>=0)); +CREATE TABLE bank (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_bank_number TEXT NOT NULL DEFAULT '',t_icon TEXT NOT NULL DEFAULT ''); +CREATE TABLE interest(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rd_account_id INTEGER NOT NULL,d_date DATE NOT NULL,f_rate FLOAT NOT NULL CHECK (f_rate>=0),t_income_value_date_mode VARCHAR(1) NOT NULL DEFAULT 'F' CHECK (t_income_value_date_mode IN ('F', '0', '1', '2', '3', '4', '5')),t_expenditure_value_date_mode VARCHAR(1) NOT NULL DEFAULT 'F' CHECK (t_expenditure_value_date_mode IN ('F', '0', '1', '2', '3', '4', '5')),t_base VARCHAR(3) NOT NULL DEFAULT '24' CHECK (t_base IN ('24', '360', '365'))); +CREATE TABLE operation(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,i_group_id INTEGER NOT NULL DEFAULT 0,i_number INTEGER DEFAULT 0 CHECK (i_number>=0),d_date DATE NOT NULL DEFAULT '0000-00-00',rd_account_id INTEGER NOT NULL,t_mode TEXT NOT NULL DEFAULT '',r_payee_id INTEGER NOT NULL DEFAULT 0,t_comment TEXT NOT NULL DEFAULT '',rc_unit_id INTEGER NOT NULL,t_status VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_status IN ('N', 'P', 'Y')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),t_imported VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_imported IN ('Y', 'N', 'P', 'T')),t_template VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_template IN ('Y', 'N')),t_import_id TEXT NOT NULL DEFAULT '',i_tmp INTEGER NOT NULL DEFAULT 0,r_recurrentoperation_id INTEGER NOT NULL DEFAULT 0); +CREATE TABLE operationbalance(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,f_balance FLOAT NOT NULL DEFAULT 0,r_operation_id INTEGER NOT NULL); +CREATE TABLE refund (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_comment TEXT NOT NULL DEFAULT '',t_close VARCHAR(1) DEFAULT 'N' CHECK (t_close IN ('Y', 'N'))); +CREATE TABLE payee (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '',t_address TEXT NOT NULL DEFAULT '', t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N'))); +CREATE TABLE suboperation(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_comment TEXT NOT NULL DEFAULT '',rd_operation_id INTEGER NOT NULL,r_category_id INTEGER NOT NULL DEFAULT 0,f_value FLOAT NOT NULL DEFAULT 0.0,i_tmp INTEGER NOT NULL DEFAULT 0,r_refund_id INTEGER NOT NULL DEFAULT 0, t_formula TEXT NOT NULL DEFAULT ''); +CREATE TABLE rule (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_description TEXT NOT NULL DEFAULT '',t_definition TEXT NOT NULL DEFAULT '',t_action_description TEXT NOT NULL DEFAULT '',t_action_definition TEXT NOT NULL DEFAULT '',t_action_type VARCHAR(1) DEFAULT 'S' CHECK (t_action_type IN ('S', 'U', 'A')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),f_sortorder FLOAT); +CREATE TABLE budget (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rc_category_id INTEGER NOT NULL DEFAULT 0,t_including_subcategories TEXT NOT NULL DEFAULT 'N' CHECK (t_including_subcategories IN ('Y', 'N')),f_budgeted FLOAT NOT NULL DEFAULT 0.0,f_budgeted_modified FLOAT NOT NULL DEFAULT 0.0,f_transferred FLOAT NOT NULL DEFAULT 0.0,i_year INTEGER NOT NULL DEFAULT 2010,i_month INTEGER NOT NULL DEFAULT 0 CHECK (i_month>=0 AND i_month<=12)); +CREATE TABLE budgetcategory(id INTEGER NOT NULL DEFAULT 0,id_category INTEGER NOT NULL DEFAULT 0); +CREATE TABLE budgetrule (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,rc_category_id INTEGER NOT NULL DEFAULT 0,t_category_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_category_condition IN ('Y', 'N')),t_year_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_year_condition IN ('Y', 'N')),i_year INTEGER NOT NULL DEFAULT 2010,i_month INTEGER NOT NULL DEFAULT 0 CHECK (i_month>=0 AND i_month<=12),t_month_condition TEXT NOT NULL DEFAULT 'Y' CHECK (t_month_condition IN ('Y', 'N')),i_condition INTEGER NOT NULL DEFAULT 0 CHECK (i_condition IN (-1,0,1)),f_quantity FLOAT NOT NULL DEFAULT 0.0,t_absolute TEXT NOT NULL DEFAULT 'Y' CHECK (t_absolute IN ('Y', 'N')),rc_category_id_target INTEGER NOT NULL DEFAULT 0,t_category_target TEXT NOT NULL DEFAULT 'Y' CHECK (t_category_target IN ('Y', 'N')),t_rule TEXT NOT NULL DEFAULT 'N' CHECK (t_rule IN ('N', 'C', 'Y'))); +CREATE TABLE "recurrentoperation" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,d_date DATE NOT NULL DEFAULT '0000-00-00',rd_operation_id INTEGER NOT NULL,i_period_increment INTEGER NOT NULL DEFAULT 1 CHECK (i_period_increment>=0),t_period_unit TEXT NOT NULL DEFAULT 'M' CHECK (t_period_unit IN ('D', 'W', 'M', 'Y')),t_auto_write VARCHAR(1) DEFAULT 'Y' CHECK (t_auto_write IN ('Y', 'N')),i_auto_write_days INTEGER NOT NULL DEFAULT 5 CHECK (i_auto_write_days>=0),t_warn VARCHAR(1) DEFAULT 'Y' CHECK (t_warn IN ('Y', 'N')),i_warn_days INTEGER NOT NULL DEFAULT 5 CHECK (i_warn_days>=0),t_times VARCHAR(1) DEFAULT 'N' CHECK (t_times IN ('Y', 'N')),i_nb_times INTEGER NOT NULL DEFAULT 1 CHECK (i_nb_times>=0)); +CREATE TABLE "category" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '' CHECK (t_name NOT LIKE '% > %'),t_fullname TEXT,rd_category_id INT,t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N'))); +CREATE TABLE "account"(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL,t_number TEXT NOT NULL DEFAULT '',t_agency_number TEXT NOT NULL DEFAULT '',t_agency_address TEXT NOT NULL DEFAULT '',t_comment TEXT NOT NULL DEFAULT '',t_close VARCHAR(1) DEFAULT 'N' CHECK (t_close IN ('Y', 'N')),t_type VARCHAR(1) NOT NULL DEFAULT 'C' CHECK (t_type IN ('C', 'D', 'A', 'I', 'L', 'W', 'O')),t_bookmarked VARCHAR(1) NOT NULL DEFAULT 'N' CHECK (t_bookmarked IN ('Y', 'N')),rd_bank_id INTEGER NOT NULL); +CREATE TABLE "node" (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,t_name TEXT NOT NULL DEFAULT '' CHECK (t_name NOT LIKE '% > %'),t_fullname TEXT,t_icon TEXT DEFAULT '',f_sortorder FLOAT,t_autostart VARCHAR(1) DEFAULT 'N' CHECK (t_autostart IN ('Y', 'N')),t_data TEXT,rd_node_id INT CONSTRAINT fk_id REFERENCES node(id) ON DELETE CASCADE); +CREATE TABLE vm_category_display_tmp( + id INT, + t_name TEXT, + t_fullname TEXT, + rd_category_id INT, + t_bookmarked TEXT, + i_NBOPERATIONS, + f_REALCURRENTAMOUNT +); +CREATE TABLE vm_budget_tmp( + id INT, + rc_category_id INT, + t_including_subcategories TEXT, + f_budgeted REAL, + f_budgeted_modified REAL, + f_transferred REAL, + i_year INT, + i_month INT, + t_CATEGORY, + t_PERIOD, + f_CURRENTAMOUNT, + t_RULES +); +CREATE INDEX idx_doctransaction_parent ON doctransaction (i_parent); +CREATE INDEX idx_doctransactionitem_i_object_id ON doctransactionitem (i_object_id); +CREATE INDEX idx_doctransactionitem_t_object_table ON doctransactionitem (t_object_table); +CREATE INDEX idx_doctransactionitem_t_action ON doctransactionitem (t_action); +CREATE INDEX idx_doctransactionitem_rd_doctransaction_id ON doctransactionitem (rd_doctransaction_id); +CREATE INDEX idx_doctransactionitem_optimization ON doctransactionitem (rd_doctransaction_id, i_object_id, t_object_table, t_action, id); +CREATE INDEX idx_unit_unit_id ON unitvalue(rd_unit_id); +CREATE INDEX idx_account_bank_id ON account(rd_bank_id); +CREATE INDEX idx_account_type ON account(t_type); +CREATE INDEX idx_category_category_id ON category(rd_category_id); +CREATE INDEX idx_category_t_fullname ON category(t_fullname); +CREATE INDEX idx_operation_account_id ON operation (rd_account_id); +CREATE INDEX idx_operation_tmp1_found_transfert ON operation (rc_unit_id, d_date); +CREATE INDEX idx_operation_grouped_operation_id ON operation (i_group_id); +CREATE INDEX idx_operation_i_number ON operation (i_number); +CREATE INDEX idx_operation_i_tmp ON operation (i_tmp); +CREATE INDEX idx_operation_rd_account_id ON operation (rd_account_id); +CREATE INDEX idx_operation_rc_unit_id ON operation (rc_unit_id); +CREATE INDEX idx_operation_t_status ON operation (t_status); +CREATE INDEX idx_operation_t_import_id ON operation (t_import_id); +CREATE INDEX idx_operation_t_template ON operation (t_template); +CREATE INDEX idx_operation_d_date ON operation (d_date); +CREATE INDEX idx_operationbalance_operation_id ON operationbalance (r_operation_id); +CREATE INDEX idx_suboperation_operation_id ON suboperation (rd_operation_id); +CREATE INDEX idx_suboperation_i_tmp ON suboperation (i_tmp); +CREATE INDEX idx_suboperation_category_id ON suboperation (r_category_id); +CREATE INDEX idx_suboperation_refund_id_id ON suboperation (r_refund_id); +CREATE INDEX idx_recurrentoperation_rd_operation_id ON recurrentoperation (rd_operation_id); +CREATE INDEX idx_refund_close ON refund(t_close); +CREATE INDEX idx_interest_account_id ON interest (rd_account_id); +CREATE INDEX idx_rule_action_type ON rule(t_action_type); +CREATE INDEX idx_budget_category_id ON budget(rc_category_id); +CREATE INDEX idx_budgetcategory_id ON budgetcategory (id); +CREATE INDEX idx_budgetcategory_id_category ON budgetcategory (id_category); +CREATE UNIQUE INDEX uidx_parameters_uuid_parent_name ON parameters (t_uuid_parent, t_name); +CREATE UNIQUE INDEX uidx_node_parent_id_name ON node(t_name,rd_node_id); +CREATE UNIQUE INDEX uidx_node_fullname ON node(t_fullname); +CREATE UNIQUE INDEX uidx_unit_name ON unit(t_name); +CREATE UNIQUE INDEX uidx_unit_symbol ON unit(t_symbol); +CREATE UNIQUE INDEX uidx_unitvalue ON unitvalue(d_date,rd_unit_id); +CREATE UNIQUE INDEX uidx_bank_name ON bank(t_name); +CREATE UNIQUE INDEX uidx_account_name ON account(t_name); +CREATE UNIQUE INDEX uidx_category_parent_id_name ON category(t_name,rd_category_id); +CREATE UNIQUE INDEX uidx_category_fullname ON category(t_fullname); +CREATE UNIQUE INDEX uidx_refund_name ON refund(t_name); +CREATE UNIQUE INDEX uidx_payee_name ON payee(t_name); +CREATE UNIQUE INDEX uidx_interest ON interest(d_date,rd_account_id); +CREATE UNIQUE INDEX uidx_budget ON budget(i_year,i_month, rc_category_id); +CREATE VIEW v_node AS SELECT * from node; +CREATE VIEW v_node_displayname AS SELECT *, t_fullname AS t_displayname from node; +CREATE VIEW v_parameters_displayname AS SELECT *, t_name AS t_displayname from parameters; +CREATE TRIGGER fkdc_parameters_parameters_uuid BEFORE DELETE ON parameters FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'parameters'; END; +CREATE TRIGGER fkdc_node_parameters_uuid BEFORE DELETE ON node FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'node'; END; +CREATE TRIGGER cpt_node_fullname1 AFTER INSERT ON node BEGIN UPDATE node SET t_fullname=CASE WHEN new.rd_node_id IS NULL OR new.rd_node_id='' OR new.rd_node_id=0 THEN new.t_name ELSE (SELECT c.t_fullname from node c where c.id=new.rd_node_id)||' > '||new.t_name END WHERE id=new.id;END; +CREATE TRIGGER cpt_node_fullname2 AFTER UPDATE OF t_name, rd_node_id ON node BEGIN UPDATE node SET t_fullname=CASE WHEN new.rd_node_id IS NULL OR new.rd_node_id='' OR new.rd_node_id=0 THEN new.t_name ELSE (SELECT c.t_fullname from node c where c.id=new.rd_node_id)||' > '||new.t_name END WHERE id=new.id;UPDATE node SET t_name=t_name WHERE rd_node_id=new.id;END; +CREATE TRIGGER fki_account_bank_rd_bank_id_id BEFORE INSERT ON account FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (bank est utilisé par account) +Nom de la contrainte : fki_account_bank_rd_bank_id_id') WHERE NEW.rd_bank_id!=0 AND NEW.rd_bank_id!='' AND (SELECT id FROM bank WHERE id = NEW.rd_bank_id) IS NULL; END; +CREATE TRIGGER fku_account_bank_rd_bank_id_id BEFORE UPDATE ON account FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (bank est utilisé par account) +Nom de la contrainte : fku_account_bank_rd_bank_id_id') WHERE NEW.rd_bank_id!=0 AND NEW.rd_bank_id!='' AND (SELECT id FROM bank WHERE id = NEW.rd_bank_id) IS NULL; END; +CREATE TRIGGER fkdc_bank_account_id_rd_bank_id BEFORE DELETE ON bank FOR EACH ROW BEGIN DELETE FROM account WHERE account.rd_bank_id = OLD.id; END; +CREATE TRIGGER fki_budget_category_rc_category_id_id BEFORE INSERT ON budget FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budget) +Nom de la contrainte : fki_budget_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fku_budget_category_rc_category_id_id BEFORE UPDATE ON budget FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budget) +Nom de la contrainte : fku_budget_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fkd_budget_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budget) +Nom de la contrainte : fkd_budget_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM budget WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_budgetrule_category_rc_category_id_id BEFORE INSERT ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budgetrule) +Nom de la contrainte : fki_budgetrule_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fku_budgetrule_category_rc_category_id_id BEFORE UPDATE ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budgetrule) +Nom de la contrainte : fku_budgetrule_category_rc_category_id_id') WHERE NEW.rc_category_id!=0 AND NEW.rc_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id) IS NULL; END; +CREATE TRIGGER fkd_budgetrule_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budgetrule) +Nom de la contrainte : fkd_budgetrule_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM budgetrule WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_budgetrule_category_rc_category_id_target_id BEFORE INSERT ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par budgetrule) +Nom de la contrainte : fki_budgetrule_category_rc_category_id_target_id') WHERE NEW.rc_category_id_target!=0 AND NEW.rc_category_id_target!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id_target) IS NULL; END; +CREATE TRIGGER fku_budgetrule_category_rc_category_id_target_id BEFORE UPDATE ON budgetrule FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par budgetrule) +Nom de la contrainte : fku_budgetrule_category_rc_category_id_target_id') WHERE NEW.rc_category_id_target!=0 AND NEW.rc_category_id_target!='' AND (SELECT id FROM category WHERE id = NEW.rc_category_id_target) IS NULL; END; +CREATE TRIGGER fkd_budgetrule_category_rc_category_id_target_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par budgetrule) +Nom de la contrainte : fkd_budgetrule_category_rc_category_id_target_id') WHERE (SELECT rc_category_id_target FROM budgetrule WHERE rc_category_id_target = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_category_category_rd_category_id_id BEFORE INSERT ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par category) +Nom de la contrainte : fki_category_category_rd_category_id_id') WHERE NEW.rd_category_id!=0 AND NEW.rd_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rd_category_id) IS NULL; END; +CREATE TRIGGER fku_category_category_rd_category_id_id BEFORE UPDATE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par category) +Nom de la contrainte : fku_category_category_rd_category_id_id') WHERE NEW.rd_category_id!=0 AND NEW.rd_category_id!='' AND (SELECT id FROM category WHERE id = NEW.rd_category_id) IS NULL; END; +CREATE TRIGGER fkdc_category_category_id_rd_category_id BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM category WHERE category.rd_category_id = OLD.id; END; +CREATE TRIGGER fki_doctransactionitem_doctransaction_rd_doctransaction_id_id BEFORE INSERT ON doctransactionitem FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (doctransaction est utilisé par doctransactionitem) +Nom de la contrainte : fki_doctransactionitem_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fku_doctransactionitem_doctransaction_rd_doctransaction_id_id BEFORE UPDATE ON doctransactionitem FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (doctransaction est utilisé par doctransactionitem) +Nom de la contrainte : fku_doctransactionitem_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fkdc_doctransaction_doctransactionitem_id_rd_doctransaction_id BEFORE DELETE ON doctransaction FOR EACH ROW BEGIN DELETE FROM doctransactionitem WHERE doctransactionitem.rd_doctransaction_id = OLD.id; END; +CREATE TRIGGER fki_doctransactionmsg_doctransaction_rd_doctransaction_id_id BEFORE INSERT ON doctransactionmsg FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (doctransaction est utilisé par doctransactionmsg) +Nom de la contrainte : fki_doctransactionmsg_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fku_doctransactionmsg_doctransaction_rd_doctransaction_id_id BEFORE UPDATE ON doctransactionmsg FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (doctransaction est utilisé par doctransactionmsg) +Nom de la contrainte : fku_doctransactionmsg_doctransaction_rd_doctransaction_id_id') WHERE NEW.rd_doctransaction_id!=0 AND NEW.rd_doctransaction_id!='' AND (SELECT id FROM doctransaction WHERE id = NEW.rd_doctransaction_id) IS NULL; END; +CREATE TRIGGER fkdc_doctransaction_doctransactionmsg_id_rd_doctransaction_id BEFORE DELETE ON doctransaction FOR EACH ROW BEGIN DELETE FROM doctransactionmsg WHERE doctransactionmsg.rd_doctransaction_id = OLD.id; END; +CREATE TRIGGER fki_interest_account_rd_account_id_id BEFORE INSERT ON interest FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (account est utilisé par interest) +Nom de la contrainte : fki_interest_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fku_interest_account_rd_account_id_id BEFORE UPDATE ON interest FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (account est utilisé par interest) +Nom de la contrainte : fku_interest_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fkdc_account_interest_id_rd_account_id BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM interest WHERE interest.rd_account_id = OLD.id; END; +CREATE TRIGGER fki_node_node_rd_node_id_id BEFORE INSERT ON node FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (node est utilisé par node) +Nom de la contrainte : fki_node_node_rd_node_id_id') WHERE NEW.rd_node_id!=0 AND NEW.rd_node_id!='' AND (SELECT id FROM node WHERE id = NEW.rd_node_id) IS NULL; END; +CREATE TRIGGER fku_node_node_rd_node_id_id BEFORE UPDATE ON node FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (node est utilisé par node) +Nom de la contrainte : fku_node_node_rd_node_id_id') WHERE NEW.rd_node_id!=0 AND NEW.rd_node_id!='' AND (SELECT id FROM node WHERE id = NEW.rd_node_id) IS NULL; END; +CREATE TRIGGER fkdc_node_node_id_rd_node_id BEFORE DELETE ON node FOR EACH ROW BEGIN DELETE FROM node WHERE node.rd_node_id = OLD.id; END; +CREATE TRIGGER fki_operation_account_rd_account_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (account est utilisé par operation) +Nom de la contrainte : fki_operation_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fku_operation_account_rd_account_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (account est utilisé par operation) +Nom de la contrainte : fku_operation_account_rd_account_id_id') WHERE NEW.rd_account_id!=0 AND NEW.rd_account_id!='' AND (SELECT id FROM account WHERE id = NEW.rd_account_id) IS NULL; END; +CREATE TRIGGER fkdc_account_operation_id_rd_account_id BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM operation WHERE operation.rd_account_id = OLD.id; END; +CREATE TRIGGER fki_operation_payee_r_payee_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (payee est utilisé par operation) +Nom de la contrainte : fki_operation_payee_r_payee_id_id') WHERE NEW.r_payee_id!=0 AND NEW.r_payee_id!='' AND (SELECT id FROM payee WHERE id = NEW.r_payee_id) IS NULL; END; +CREATE TRIGGER fku_operation_payee_r_payee_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (payee est utilisé par operation) +Nom de la contrainte : fku_operation_payee_r_payee_id_id') WHERE NEW.r_payee_id!=0 AND NEW.r_payee_id!='' AND (SELECT id FROM payee WHERE id = NEW.r_payee_id) IS NULL; END; +CREATE TRIGGER fkd_operation_payee_r_payee_id_id BEFORE DELETE ON payee FOR EACH ROW BEGIN UPDATE operation SET r_payee_id=0 WHERE r_payee_id=OLD.id; END; +CREATE TRIGGER fki_operation_unit_rc_unit_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par operation) +Nom de la contrainte : fki_operation_unit_rc_unit_id_id') WHERE NEW.rc_unit_id!=0 AND NEW.rc_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rc_unit_id) IS NULL; END; +CREATE TRIGGER fku_operation_unit_rc_unit_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par operation) +Nom de la contrainte : fku_operation_unit_rc_unit_id_id') WHERE NEW.rc_unit_id!=0 AND NEW.rc_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rc_unit_id) IS NULL; END; +CREATE TRIGGER fkd_operation_unit_rc_unit_id_id BEFORE DELETE ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (unit est utilisé par operation) +Nom de la contrainte : fkd_operation_unit_rc_unit_id_id') WHERE (SELECT rc_unit_id FROM operation WHERE rc_unit_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fki_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE INSERT ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (recurrentoperation est utilisé par operation) +Nom de la contrainte : fki_operation_recurrentoperation_r_recurrentoperation_id_id') WHERE NEW.r_recurrentoperation_id!=0 AND NEW.r_recurrentoperation_id!='' AND (SELECT id FROM recurrentoperation WHERE id = NEW.r_recurrentoperation_id) IS NULL; END; +CREATE TRIGGER fku_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE UPDATE ON operation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (recurrentoperation est utilisé par operation) +Nom de la contrainte : fku_operation_recurrentoperation_r_recurrentoperation_id_id') WHERE NEW.r_recurrentoperation_id!=0 AND NEW.r_recurrentoperation_id!='' AND (SELECT id FROM recurrentoperation WHERE id = NEW.r_recurrentoperation_id) IS NULL; END; +CREATE TRIGGER fkd_operation_recurrentoperation_r_recurrentoperation_id_id BEFORE DELETE ON recurrentoperation FOR EACH ROW BEGIN UPDATE operation SET r_recurrentoperation_id=0 WHERE r_recurrentoperation_id=OLD.id; END; +CREATE TRIGGER fki_operationbalance_operation_r_operation_id_id BEFORE INSERT ON operationbalance FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par operationbalance) +Nom de la contrainte : fki_operationbalance_operation_r_operation_id_id') WHERE NEW.r_operation_id!=0 AND NEW.r_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.r_operation_id) IS NULL; END; +CREATE TRIGGER fku_operationbalance_operation_r_operation_id_id BEFORE UPDATE ON operationbalance FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par operationbalance) +Nom de la contrainte : fku_operationbalance_operation_r_operation_id_id') WHERE NEW.r_operation_id!=0 AND NEW.r_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.r_operation_id) IS NULL; END; +CREATE TRIGGER fkd_operationbalance_operation_r_operation_id_id BEFORE DELETE ON operation FOR EACH ROW BEGIN UPDATE operationbalance SET r_operation_id=0 WHERE r_operation_id=OLD.id; END; +CREATE TRIGGER fki_recurrentoperation_operation_rd_operation_id_id BEFORE INSERT ON recurrentoperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par recurrentoperation) +Nom de la contrainte : fki_recurrentoperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fku_recurrentoperation_operation_rd_operation_id_id BEFORE UPDATE ON recurrentoperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par recurrentoperation) +Nom de la contrainte : fku_recurrentoperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fkdc_operation_recurrentoperation_id_rd_operation_id BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM recurrentoperation WHERE recurrentoperation.rd_operation_id = OLD.id; END; +CREATE TRIGGER fki_suboperation_operation_rd_operation_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (operation est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_operation_rd_operation_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (operation est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_operation_rd_operation_id_id') WHERE NEW.rd_operation_id!=0 AND NEW.rd_operation_id!='' AND (SELECT id FROM operation WHERE id = NEW.rd_operation_id) IS NULL; END; +CREATE TRIGGER fkdc_operation_suboperation_id_rd_operation_id BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM suboperation WHERE suboperation.rd_operation_id = OLD.id; END; +CREATE TRIGGER fki_suboperation_category_r_category_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (category est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_category_r_category_id_id') WHERE NEW.r_category_id!=0 AND NEW.r_category_id!='' AND (SELECT id FROM category WHERE id = NEW.r_category_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_category_r_category_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (category est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_category_r_category_id_id') WHERE NEW.r_category_id!=0 AND NEW.r_category_id!='' AND (SELECT id FROM category WHERE id = NEW.r_category_id) IS NULL; END; +CREATE TRIGGER fkd_suboperation_category_r_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN UPDATE suboperation SET r_category_id=0 WHERE r_category_id=OLD.id; END; +CREATE TRIGGER fki_suboperation_refund_r_refund_id_id BEFORE INSERT ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (refund est utilisé par suboperation) +Nom de la contrainte : fki_suboperation_refund_r_refund_id_id') WHERE NEW.r_refund_id!=0 AND NEW.r_refund_id!='' AND (SELECT id FROM refund WHERE id = NEW.r_refund_id) IS NULL; END; +CREATE TRIGGER fku_suboperation_refund_r_refund_id_id BEFORE UPDATE ON suboperation FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (refund est utilisé par suboperation) +Nom de la contrainte : fku_suboperation_refund_r_refund_id_id') WHERE NEW.r_refund_id!=0 AND NEW.r_refund_id!='' AND (SELECT id FROM refund WHERE id = NEW.r_refund_id) IS NULL; END; +CREATE TRIGGER fkd_suboperation_refund_r_refund_id_id BEFORE DELETE ON refund FOR EACH ROW BEGIN UPDATE suboperation SET r_refund_id=0 WHERE r_refund_id=OLD.id; END; +CREATE TRIGGER fki_unit_unit_rd_unit_id_id BEFORE INSERT ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par unit) +Nom de la contrainte : fki_unit_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fku_unit_unit_rd_unit_id_id BEFORE UPDATE ON unit FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par unit) +Nom de la contrainte : fku_unit_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fkdc_unit_unit_id_rd_unit_id BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM unit WHERE unit.rd_unit_id = OLD.id; END; +CREATE TRIGGER fki_unitvalue_unit_rd_unit_id_id BEFORE INSERT ON unitvalue FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible d''ajouter un objet (unit est utilisé par unitvalue) +Nom de la contrainte : fki_unitvalue_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fku_unitvalue_unit_rd_unit_id_id BEFORE UPDATE ON unitvalue FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de modifier un objet (unit est utilisé par unitvalue) +Nom de la contrainte : fku_unitvalue_unit_rd_unit_id_id') WHERE NEW.rd_unit_id!=0 AND NEW.rd_unit_id!='' AND (SELECT id FROM unit WHERE id = NEW.rd_unit_id) IS NULL; END; +CREATE TRIGGER fkdc_unit_unitvalue_id_rd_unit_id BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM unitvalue WHERE unitvalue.rd_unit_id = OLD.id; END; +CREATE TRIGGER fkd_vm_budget_tmp_category_rc_category_id_id BEFORE DELETE ON category FOR EACH ROW BEGIN SELECT RAISE(ABORT, 'Impossible de détruire un objet (category est utilisé par vm_budget_tmp) +Nom de la contrainte : fkd_vm_budget_tmp_category_rc_category_id_id') WHERE (SELECT rc_category_id FROM vm_budget_tmp WHERE rc_category_id = OLD.id) IS NOT NULL; END; +CREATE TRIGGER fkdc_category_vm_category_display_tmp_id_rd_category_id BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM vm_category_display_tmp WHERE vm_category_display_tmp.rd_category_id = OLD.id; END; +CREATE VIEW v_unit_displayname AS SELECT *, t_name||' ('||t_symbol||')' AS t_displayname FROM unit; +CREATE VIEW v_unit_tmp1 AS SELECT *,(SELECT count(*) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS i_NBVALUES, (CASE WHEN unit.rd_unit_id=0 THEN '' ELSE (SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=unit.rd_unit_id) END) AS t_UNIT,(CASE unit.t_type WHEN '1' THEN 'Monnaie principale' WHEN '2' THEN 'Monnaie secondaire' WHEN 'C' THEN 'Monnaie' WHEN 'S' THEN 'Action' WHEN 'I' THEN 'Indice' ELSE 'Objet' END) AS t_TYPENLS, (SELECT MIN(s.d_date) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS d_MINDATE, (SELECT MAX(s.d_date) FROM unitvalue s WHERE s.rd_unit_id=unit.id) AS d_MAXDATE from unit; +CREATE VIEW v_unit_tmp2 AS SELECT *,CASE WHEN v_unit_tmp1.t_type='1' THEN 1 ELSE IFNULL((SELECT s.f_quantity FROM unitvalue s WHERE s.rd_unit_id=v_unit_tmp1.id AND s.d_date=v_unit_tmp1.d_MAXDATE),1) END AS f_LASTVALUE from v_unit_tmp1; +CREATE VIEW v_unit AS SELECT *,v_unit_tmp2.f_LASTVALUE*IFNULL((SELECT s2.f_LASTVALUE FROM v_unit_tmp2 s2 WHERE s2.id=v_unit_tmp2.rd_unit_id) , 1) AS f_CURRENTAMOUNT from v_unit_tmp2; +CREATE VIEW v_unitvalue_displayname AS SELECT *, (SELECT t_displayname FROM v_unit_displayname WHERE unitvalue.rd_unit_id=v_unit_displayname.id)||' '||STRFTIME('%d/%m/%Y',d_date) AS t_displayname FROM unitvalue; +CREATE VIEW v_unitvalue AS SELECT * FROM unitvalue; +CREATE VIEW v_suboperation AS SELECT * FROM suboperation; +CREATE VIEW v_operation_numbers AS SELECT DISTINCT i_number, rd_account_id FROM operation; +CREATE VIEW v_operation_next_numbers AS SELECT T1.i_number+1 AS i_number FROM v_operation_numbers AS T1 LEFT OUTER JOIN v_operation_numbers T2 ON T2.rd_account_id=T1.rd_account_id AND T2.i_number=T1.i_number+1 WHERE T1.i_number!=0 AND (T2.i_number IS NULL) ORDER BY T1.i_number; +CREATE VIEW v_operation_tmp1 AS SELECT *,(SELECT t_name FROM payee s WHERE s.id=operation.r_payee_id) AS t_PAYEE,(SELECT TOTAL(s.f_value) FROM suboperation s WHERE s.rd_operation_id=operation.ID) AS f_QUANTITY,(SELECT count(*) FROM suboperation s WHERE s.rd_operation_id=operation.ID) AS i_NBSUBCATEGORY FROM operation; +CREATE VIEW v_operation AS SELECT *,(SELECT s.id FROM suboperation s WHERE s.rd_operation_id=v_operation_tmp1.id AND ABS(s.f_value)=(SELECT MAX(ABS(s2.f_value)) FROM suboperation s2 WHERE s2.rd_operation_id=v_operation_tmp1.id)) AS i_MOSTIMPSUBOP,((SELECT s.f_CURRENTAMOUNT FROM v_unit s WHERE s.id=v_operation_tmp1.rc_unit_id)*v_operation_tmp1.f_QUANTITY) AS f_CURRENTAMOUNT, (CASE WHEN v_operation_tmp1.i_group_id<>0 AND EXISTS (SELECT 1 FROM account a WHERE v_operation_tmp1.rd_account_id=a.id AND a.t_type<>'L') AND EXISTS (SELECT 1 FROM v_operation_tmp1 op2, account a WHERE op2.i_group_id=v_operation_tmp1.i_group_id AND op2.rd_account_id=a.id AND a.t_type<>'L' AND op2.rc_unit_id=v_operation_tmp1.rc_unit_id AND op2.f_QUANTITY=-v_operation_tmp1.f_QUANTITY) THEN 'Y' ELSE 'N' END) AS t_TRANSFER FROM v_operation_tmp1; +CREATE VIEW v_operation_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||IFNULL(t_PAYEE,'')||' '||v_operation.f_CURRENTAMOUNT||' '||(SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=v_operation.rc_unit_id) AS t_displayname FROM v_operation; +CREATE VIEW v_operation_delete AS SELECT *, (CASE WHEN t_status='Y' THEN 'Vous n''êtes pas autorisé à détruire cette opération car en état « rapproché »' END) t_delete_message FROM operation; +CREATE VIEW v_account AS SELECT *,(SELECT MAX(s.d_date) FROM interest s WHERE s.rd_account_id=account.id) AS d_MAXDATE, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=account.id AND s.t_template='N') AS f_CURRENTAMOUNT FROM account; +CREATE VIEW v_account_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM operation WHERE rd_account_id=account.id AND d_date<>'0000-00-00' AND t_template='N' AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce compte car il contient des opérations rapprochées' END) t_delete_message FROM account; +CREATE VIEW v_bank_displayname AS SELECT *, t_name AS t_displayname FROM bank; +CREATE VIEW v_account_displayname AS SELECT *, (SELECT t_displayname FROM v_bank_displayname WHERE account.rd_bank_id=v_bank_displayname.id)||'-'||t_name AS t_displayname FROM account; +CREATE VIEW v_bank AS SELECT *,(SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_account s WHERE s.rd_bank_id=bank.id) AS f_CURRENTAMOUNT FROM bank; +CREATE VIEW v_category_displayname AS SELECT *, t_fullname AS t_displayname FROM category; +CREATE VIEW v_category AS SELECT * FROM category; +CREATE VIEW v_recurrentoperation AS SELECT *,i_period_increment||' '||(CASE t_period_unit WHEN 'Y' THEN 'année(s)' WHEN 'M' THEN 'mois' WHEN 'W' THEN 'semaine(s)' ELSE 'jour(s)' END) AS t_PERIODNLS FROM recurrentoperation; +CREATE VIEW v_recurrentoperation_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||SUBSTR((SELECT t_displayname FROM v_operation_displayname WHERE v_operation_displayname.id=v_recurrentoperation.rd_operation_id), 11) AS t_displayname FROM v_recurrentoperation; +CREATE VIEW v_unitvalue_display AS SELECT *,IFNULL((SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=(SELECT s2.rd_unit_id FROM unit s2 WHERE s2.id=unitvalue.rd_unit_id)),'') AS t_UNIT,STRFTIME('%Y-%m',unitvalue.d_date) AS d_DATEMONTH,STRFTIME('%Y',unitvalue.d_date) AS d_DATEYEAR FROM unitvalue; +CREATE VIEW v_suboperation_display AS SELECT *,IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=v_suboperation.r_category_id),'') AS t_CATEGORY, IFNULL((SELECT s.t_name FROM refund s WHERE s.id=v_suboperation.r_refund_id),'') AS t_REFUND, (CASE WHEN v_suboperation.f_value>=0 THEN v_suboperation.f_value ELSE 0 END) AS f_VALUE_INCOME, (CASE WHEN v_suboperation.f_value<=0 THEN v_suboperation.f_value ELSE 0 END) AS f_VALUE_EXPENSE FROM v_suboperation; +CREATE VIEW v_suboperation_displayname AS SELECT *, t_CATEGORY||' : '||f_value AS t_displayname FROM v_suboperation_display; +CREATE VIEW v_operation_display_all AS SELECT *,(SELECT s.t_name FROM account s WHERE s.id=v_operation.rd_account_id) AS t_ACCOUNT,(SELECT (CASE WHEN s.t_symbol!='' THEN s.t_symbol ELSE s.t_name END) FROM unit s WHERE s.id=v_operation.rc_unit_id) AS t_UNIT,(SELECT s.t_CATEGORY FROM v_suboperation_display s WHERE s.id=v_operation.i_MOSTIMPSUBOP) AS t_CATEGORY,(SELECT s.t_REFUND FROM v_suboperation_display s WHERE s.id=v_operation.i_MOSTIMPSUBOP) AS t_REFUND,(CASE WHEN v_operation.f_QUANTITY<0 THEN '-' WHEN v_operation.f_QUANTITY=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE, (CASE WHEN v_operation.f_QUANTITY<=0 THEN 'Dépense' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS, STRFTIME('%Y-W%W',v_operation.d_date) AS d_DATEWEEK,STRFTIME('%Y-%m',v_operation.d_date) AS d_DATEMONTH,STRFTIME('%Y',v_operation.d_date)||'-Q'||(CASE WHEN STRFTIME('%m',v_operation.d_date)<='03' THEN '1' WHEN STRFTIME('%m',v_operation.d_date)<='06' THEN '2' WHEN STRFTIME('%m',v_operation.d_date)<='09' THEN '3' ELSE '4' END) AS d_DATEQUARTER, STRFTIME('%Y',v_operation.d_date)||'-S'||(CASE WHEN STRFTIME('%m',v_operation.d_date)<='06' THEN '1' ELSE '2' END) AS d_DATESEMESTER, STRFTIME('%Y',v_operation.d_date) AS d_DATEYEAR, (SELECT count(*) FROM v_recurrentoperation s WHERE s.rd_operation_id=v_operation.id) AS i_NBRECURRENT, (CASE WHEN v_operation.f_QUANTITY>=0 THEN v_operation.f_QUANTITY ELSE 0 END) AS f_QUANTITY_INCOME, (CASE WHEN v_operation.f_QUANTITY<=0 THEN v_operation.f_QUANTITY ELSE 0 END) AS f_QUANTITY_EXPENSE, (SELECT o2.f_balance FROM operationbalance o2 WHERE o2.r_operation_id=v_operation.id ) AS f_BALANCE, (CASE WHEN v_operation.f_QUANTITY>=0 THEN v_operation.f_CURRENTAMOUNT ELSE 0 END) AS f_CURRENTAMOUNT_INCOME, (CASE WHEN v_operation.f_QUANTITY<=0 THEN v_operation.f_CURRENTAMOUNT ELSE 0 END) AS f_CURRENTAMOUNT_EXPENSE FROM v_operation; +CREATE VIEW v_operation_template_display AS SELECT * FROM v_operation_display_all WHERE t_template='Y'; +CREATE VIEW v_operation_display AS SELECT * FROM v_operation_display_all WHERE d_date!='0000-00-00' AND t_template='N'; +CREATE VIEW v_unit_display AS SELECT *,(SELECT TOTAL(o.f_QUANTITY) FROM v_operation_display o WHERE o.rc_unit_id=v_unit.id) AS f_QUANTITYOWNED FROM v_unit; +CREATE VIEW v_account_display AS SELECT (CASE t_type WHEN 'C' THEN 'Courant' WHEN 'D' THEN 'Carte de crédit' WHEN 'A' THEN 'Actif' WHEN 'I' THEN 'Investissement' WHEN 'W' THEN 'Portefeuille' WHEN 'L' THEN 'Prêt' WHEN 'O' THEN 'Autre' END) AS t_TYPENLS,bank.t_name AS t_BANK,bank.t_bank_number AS t_BANK_NUMBER,bank.t_icon AS t_ICON,v_account.*,(v_account.f_CURRENTAMOUNT/(SELECT u.f_CURRENTAMOUNT FROM v_unit u, operation s WHERE u.id=s.rc_unit_id AND s.rd_account_id=v_account.id AND s.d_date='0000-00-00')) AS f_QUANTITY, (SELECT (CASE WHEN u.t_symbol!='' THEN u.t_symbol ELSE u.t_name END) FROM unit u, operation s WHERE u.id=s.rc_unit_id AND s.rd_account_id=v_account.id AND s.d_date='0000-00-00') AS t_UNIT, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.t_status!='N' AND s.t_template='N') AS f_CHECKED, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.t_status='N' AND s.t_template='N') AS f_COMING_SOON, (SELECT TOTAL(s.f_CURRENTAMOUNT) FROM v_operation s WHERE s.rd_account_id=v_account.id AND s.d_date<=date('now') AND s.t_template='N') AS f_TODAYAMOUNT, (SELECT count(*) FROM v_operation_display s WHERE s.rd_account_id=v_account.id) AS i_NBOPERATIONS, IFNULL((SELECT s.f_rate FROM interest s WHERE s.rd_account_id=v_account.id AND s.d_date=v_account.d_MAXDATE),0) AS f_RATE FROM v_account, bank WHERE bank.id=v_account.rd_bank_id; +CREATE VIEW v_operation_consolidated AS SELECT (SELECT s.t_TYPENLS FROM v_account_display s WHERE s.id=op.rd_account_id) AS t_ACCOUNTTYPE,(SELECT u.t_TYPENLS FROM v_unit u WHERE u.id=op.rc_unit_id) AS t_UNITTYPE,sop.id AS i_SUBOPID, sop.r_refund_id AS r_refund_id, (CASE WHEN sop.t_comment='' THEN op.t_comment ELSE sop.t_comment END) AS t_REALCOMMENT, sop.t_CATEGORY AS t_REALCATEGORY, sop.t_REFUND AS t_REALREFUND, sop.r_category_id AS i_IDCATEGORY, (CASE WHEN sop.f_value<0 THEN '-' WHEN sop.f_value=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE, (CASE WHEN sop.f_value<0 THEN 'Dépense' WHEN sop.f_value=0 THEN '' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS, sop.f_value AS f_REALQUANTITY, sop.f_VALUE_INCOME AS f_REALQUANTITY_INCOME, sop.f_VALUE_EXPENSE AS f_REALQUANTITY_EXPENSE, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_value) AS f_REALCURRENTAMOUNT, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_VALUE_INCOME) AS f_REALCURRENTAMOUNT_INCOME, ((SELECT u.f_CURRENTAMOUNT FROM v_unit u WHERE u.id=op.rc_unit_id)*sop.f_VALUE_EXPENSE) AS f_REALCURRENTAMOUNT_EXPENSE, op.* FROM v_operation_display_all AS op, v_suboperation_display AS sop WHERE op.t_template='N' AND sop.rd_operation_id=op.ID; +CREATE VIEW v_operation_prop AS SELECT p.id AS i_PROPPID, p.t_name AS i_PROPPNAME, p.t_value AS i_PROPVALUE, op.* FROM v_operation_consolidated AS op LEFT OUTER JOIN parameters AS p ON p.t_uuid_parent=op.id||'-operation'; +CREATE VIEW v_refund_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM v_operation_consolidated WHERE r_refund_id=refund.id AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce suiveur car utilisé par des opérations rapprochées' END) t_delete_message FROM refund; +CREATE VIEW v_refund AS SELECT *, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE o.r_refund_id=refund.id) AS f_CURRENTAMOUNT FROM refund; +CREATE VIEW v_refund_display AS SELECT *,(SELECT MIN(o.d_date) FROM v_operation_consolidated o WHERE o.r_refund_id=v_refund.id) AS d_FIRSTDATE, (SELECT MAX(o.d_date) FROM v_operation_consolidated o WHERE o.r_refund_id=v_refund.id) AS d_LASTDATE FROM v_refund; +CREATE VIEW v_refund_displayname AS SELECT *, t_name AS t_displayname FROM refund; +CREATE VIEW v_payee_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM operation WHERE r_payee_id=payee.id AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire ce tiers car utilisé par des opérations rapprochées' END) t_delete_message FROM payee; +CREATE VIEW v_payee AS SELECT *, (SELECT TOTAL(o.f_CURRENTAMOUNT) FROM v_operation o WHERE o.r_payee_id=payee.id AND o.t_template='N') AS f_CURRENTAMOUNT FROM payee; +CREATE VIEW v_payee_display AS SELECT * FROM v_payee; +CREATE VIEW v_payee_displayname AS SELECT *, t_name AS t_displayname FROM payee; +CREATE VIEW v_category_delete AS SELECT *, (CASE WHEN EXISTS(SELECT 1 FROM v_operation_consolidated WHERE (t_REALCATEGORY=category.t_fullname OR t_REALCATEGORY like category.t_fullname||'%') AND t_status='Y') THEN 'Vous n''êtes pas autorisé à détruire cette catégorie car utilisée par des opérations rapprochées' END) t_delete_message FROM category; +CREATE VIEW v_category_display_tmp AS SELECT *,(SELECT count(distinct(so.rd_operation_id)) FROM operation o, suboperation so WHERE so.rd_operation_id=o.id AND so.r_category_id=v_category.ID AND o.t_template='N') AS i_NBOPERATIONS, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE o.i_IDCATEGORY=v_category.ID) AS f_REALCURRENTAMOUNT FROM v_category; +CREATE VIEW v_category_display AS SELECT *,f_REALCURRENTAMOUNT+(SELECT TOTAL(c.f_REALCURRENTAMOUNT) FROM vm_category_display_tmp c WHERE c.t_fullname LIKE vm_category_display_tmp.t_fullname||' > %') AS f_SUMCURRENTAMOUNT, i_NBOPERATIONS+(SELECT CAST(TOTAL(c.i_NBOPERATIONS) AS INTEGER) FROM vm_category_display_tmp c WHERE c.t_fullname like vm_category_display_tmp.t_fullname||' > %') AS i_SUMNBOPERATIONS, (CASE WHEN t_bookmarked='Y' THEN 'Y' WHEN EXISTS(SELECT 1 FROM category c WHERE c.t_bookmarked='Y' AND c.t_fullname like vm_category_display_tmp.t_fullname||' > %') THEN 'C' ELSE 'N' END) AS t_HASBOOKMARKEDCHILD, (CASE WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT<0 THEN '-' WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT=0 THEN '' ELSE '+' END) AS t_TYPEEXPENSE,(CASE WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT<0 THEN 'Dépense' WHEN vm_category_display_tmp.f_REALCURRENTAMOUNT=0 THEN '' ELSE 'Revenu' END) AS t_TYPEEXPENSENLS FROM vm_category_display_tmp; +CREATE VIEW v_recurrentoperation_display AS SELECT rop.*, op.t_ACCOUNT, op.i_number, op.t_mode, op.i_group_id, op.t_TRANSFER, op.t_PAYEE, op.t_comment, op.t_CATEGORY, op.t_status, op.f_CURRENTAMOUNT FROM v_recurrentoperation rop, v_operation_display_all AS op WHERE rop.rd_operation_id=op.ID; +CREATE VIEW v_rule AS SELECT *,(SELECT COUNT(1) FROM rule r WHERE r.f_sortorder<=rule.f_sortorder) AS i_ORDER FROM rule; +CREATE VIEW v_rule_displayname AS SELECT *, t_definition AS t_displayname FROM rule; +CREATE VIEW v_interest AS SELECT *,(SELECT s.t_name FROM account s WHERE s.id=interest.rd_account_id) AS t_ACCOUNT FROM interest; +CREATE VIEW v_interest_displayname AS SELECT *, STRFTIME('%d/%m/%Y',d_date)||' '||f_rate||'%' AS t_displayname FROM interest; +CREATE VIEW v_budgetrule AS SELECT *, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budgetrule.rc_category_id),'') AS t_CATEGORYCONDITION, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budgetrule.rc_category_id_target),'') AS t_CATEGORY, (CASE WHEN budgetrule.i_condition=-1 THEN 'Négatif' WHEN budgetrule.i_condition=1 THEN 'Positif' WHEN budgetrule.i_condition=0 THEN 'Tous' END) AS t_WHENNLS, f_quantity||(CASE WHEN budgetrule.t_absolute='N' THEN '%' ELSE (SELECT t_symbol FROM unit WHERE t_type='1') END) AS t_WHATNLS,(CASE WHEN budgetrule.t_rule='N' THEN 'Suivant' WHEN budgetrule.t_rule='C' THEN 'Courant' WHEN budgetrule.t_rule='Y' THEN 'Année' END) AS t_RULENLS FROM budgetrule; +CREATE VIEW v_budgetrule_display AS SELECT * FROM v_budgetrule; +CREATE VIEW v_budgetrule_displayname AS SELECT *, t_WHENNLS||' '||t_WHATNLS||' '||t_RULENLS||' '||t_CATEGORY AS t_displayname FROM v_budgetrule; +CREATE VIEW v_budget_tmp AS SELECT *, IFNULL((SELECT s.t_fullname FROM category s WHERE s.id=budget.rc_category_id),'') AS t_CATEGORY, (i_year||(CASE WHEN i_month=0 THEN '' WHEN i_month<10 THEN '-0'||i_month ELSE '-'||i_month END)) AS t_PERIOD, (SELECT TOTAL(o.f_REALCURRENTAMOUNT) FROM v_operation_consolidated o WHERE STRFTIME('%Y', o.d_date)=i_year AND (i_month=0 OR STRFTIME('%m', o.d_date)=i_month) AND o.i_IDCATEGORY IN (SELECT b2.id_category FROM budgetcategory b2 WHERE b2.id=budget.id)) AS f_CURRENTAMOUNT, (SELECT GROUP_CONCAT(v_budgetrule_displayname.t_displayname,',') FROM v_budgetrule_displayname WHERE (v_budgetrule_displayname.t_year_condition='N' OR budget.i_year=v_budgetrule_displayname.i_year) AND (v_budgetrule_displayname.t_month_condition='N' OR budget.i_month=v_budgetrule_displayname.i_month) AND (v_budgetrule_displayname.t_category_condition='N' OR budget.rc_category_id=v_budgetrule_displayname.rc_category_id) ORDER BY v_budgetrule_displayname.t_absolute DESC, v_budgetrule_displayname.id) AS t_RULES FROM budget; +CREATE VIEW v_budget AS SELECT *, (f_CURRENTAMOUNT-f_budgeted_modified) AS f_DELTABEFORETRANSFER, (f_CURRENTAMOUNT-f_budgeted_modified-f_transferred) AS f_DELTA FROM v_budget_tmp; +CREATE VIEW v_budget_display AS SELECT *, (f_CURRENTAMOUNT-f_budgeted_modified) AS f_DELTABEFORETRANSFER, (f_CURRENTAMOUNT-f_budgeted_modified-f_transferred) AS f_DELTA FROM vm_budget_tmp; +CREATE VIEW v_budget_displayname AS SELECT *, t_CATEGORY||' '||t_PERIOD||' '||f_budgeted_modified AS t_displayname FROM v_budget; +CREATE TRIGGER fkdc_bank_parameters_uuid BEFORE DELETE ON bank FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'bank'; END; +CREATE TRIGGER fkdc_account_parameters_uuid BEFORE DELETE ON account FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'account'; END; +CREATE TRIGGER fkdc_unit_parameters_uuid BEFORE DELETE ON unit FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'unit'; END; +CREATE TRIGGER fkdc_unitvalue_parameters_uuid BEFORE DELETE ON unitvalue FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'unitvalue'; END; +CREATE TRIGGER fkdc_category_parameters_uuid BEFORE DELETE ON category FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'category'; END; +CREATE TRIGGER fkdc_operation_parameters_uuid BEFORE DELETE ON operation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'operation'; END; +CREATE TRIGGER fkdc_interest_parameters_uuid BEFORE DELETE ON interest FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'interest'; END; +CREATE TRIGGER fkdc_suboperation_parameters_uuid BEFORE DELETE ON suboperation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'suboperation'; END; +CREATE TRIGGER fkdc_refund_parameters_uuid BEFORE DELETE ON refund FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'refund'; END; +CREATE TRIGGER fkdc_payee_parameters_uuid BEFORE DELETE ON payee FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'payee'; END; +CREATE TRIGGER fkdc_recurrentoperation_parameters_uuid BEFORE DELETE ON recurrentoperation FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'recurrentoperation'; END; +CREATE TRIGGER fkdc_rule_parameters_uuid BEFORE DELETE ON rule FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'rule'; END; +CREATE TRIGGER fkdc_budget_parameters_uuid BEFORE DELETE ON budget FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'budget'; END; +CREATE TRIGGER fkdc_budgetrule_parameters_uuid BEFORE DELETE ON budgetrule FOR EACH ROW BEGIN DELETE FROM parameters WHERE parameters.t_uuid_parent=OLD.id||'-'||'budgetrule'; END; +CREATE TRIGGER cpt_category_fullname1 AFTER INSERT ON category BEGIN UPDATE category SET t_fullname=CASE WHEN rd_category_id IS NULL OR rd_category_id='' OR rd_category_id=0 THEN new.t_name ELSE (SELECT c.t_fullname FROM category c WHERE c.id=new.rd_category_id)||' > '||new.t_name END WHERE id=new.id;END; +CREATE TRIGGER cpt_category_fullname2 AFTER UPDATE OF t_name, rd_category_id ON category BEGIN UPDATE category SET t_fullname=CASE WHEN rd_category_id IS NULL OR rd_category_id='' OR rd_category_id=0 THEN new.t_name ELSE (SELECT c.t_fullname FROM category c WHERE c.id=new.rd_category_id)||' > '||new.t_name END WHERE id=new.id;UPDATE category SET t_name=t_name WHERE rd_category_id=new.id;END; +CREATE TRIGGER fkdc_category_delete BEFORE DELETE ON category FOR EACH ROW BEGIN UPDATE suboperation SET r_category_id=OLD.rd_category_id WHERE r_category_id=OLD.id; END; +explain + SELECT TOTAL(f_CURRENTAMOUNT), d_DATEMONTH + from v_operation_display + WHERE d_DATEMONTH IN ('2012-05', '2012-04') + group by d_DATEMONTH, t_TYPEEXPENSE; + } +} {/.* Goto .*/} + +# The next test requires FTS4 +ifcapable !fts3 { + finish_test + return +} + +# Taken from the gnome-shell project +# +db close +forcedelete test.db +sqlite3 db test.db +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DDL 1 +sqlite3_db_config db SQLITE_DBCONFIG_DQS_DML 1 +do_test fuzz-oss1-gnomeshell { + db eval { +CREATE TABLE Resource (ID INTEGER NOT NULL PRIMARY KEY, Uri TEXT NOT +NULL, UNIQUE (Uri)); +CREATE VIRTUAL TABLE fts USING fts4; +CREATE TABLE "mfo:Action" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mfo:Enclosure" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:remoteLink" INTEGER, "mfo:remoteLink:graph" INTEGER, +"mfo:groupDefault" INTEGER, "mfo:groupDefault:graph" INTEGER, +"mfo:localLink" INTEGER, "mfo:localLink:graph" INTEGER, "mfo:optional" +INTEGER, "mfo:optional:graph" INTEGER); +CREATE TABLE "mfo:FeedChannel" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:updatedTime" INTEGER, "mfo:updatedTime:graph" INTEGER, +"mfo:updatedTime:localDate" INTEGER, "mfo:updatedTime:localTime" +INTEGER, "mfo:unreadCount" INTEGER, "mfo:unreadCount:graph" INTEGER, +"mfo:totalCount" INTEGER, "mfo:totalCount:graph" INTEGER, "mfo:action" +INTEGER, "mfo:action:graph" INTEGER, "mfo:type" INTEGER, +"mfo:type:graph" INTEGER); +CREATE TABLE "mfo:FeedElement" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:image" TEXT COLLATE NOCASE, "mfo:image:graph" INTEGER, +"mfo:feedSettings" INTEGER, "mfo:feedSettings:graph" INTEGER); +CREATE TABLE "mfo:FeedMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:downloadedTime" INTEGER, "mfo:downloadedTime:graph" INTEGER, +"mfo:downloadedTime:localDate" INTEGER, "mfo:downloadedTime:localTime" +INTEGER); +CREATE TABLE "mfo:FeedMessage_mfo:enclosureList" (ID INTEGER NOT NULL, +"mfo:enclosureList" INTEGER NOT NULL, "mfo:enclosureList:graph" +INTEGER); +CREATE TABLE "mfo:FeedSettings" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:updateInterval" INTEGER, "mfo:updateInterval:graph" INTEGER, +"mfo:expiryInterval" INTEGER, "mfo:expiryInterval:graph" INTEGER, +"mfo:downloadPath" TEXT COLLATE NOCASE, "mfo:downloadPath:graph" +INTEGER, "mfo:downloadFlag" INTEGER, "mfo:downloadFlag:graph" INTEGER, +"mfo:maxSize" INTEGER, "mfo:maxSize:graph" INTEGER); +CREATE TABLE "mfo:FeedType" (ID INTEGER NOT NULL PRIMARY KEY, +"mfo:name" TEXT COLLATE NOCASE, "mfo:name:graph" INTEGER); +CREATE TABLE "mlo:GeoBoundingBox" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoBoundingBox_mlo:bbNorthWest" (ID INTEGER NOT +NULL, "mlo:bbNorthWest" INTEGER NOT NULL, "mlo:bbNorthWest:graph" +INTEGER); +CREATE TABLE "mlo:GeoBoundingBox_mlo:bbSouthEast" (ID INTEGER NOT +NULL, "mlo:bbSouthEast" INTEGER NOT NULL, "mlo:bbSouthEast:graph" +INTEGER); +CREATE TABLE "mlo:GeoLocation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoLocation_mlo:asBoundingBox" (ID INTEGER NOT NULL, +"mlo:asBoundingBox" INTEGER NOT NULL, "mlo:asBoundingBox:graph" +INTEGER); +CREATE TABLE "mlo:GeoLocation_mlo:asGeoPoint" (ID INTEGER NOT NULL, +"mlo:asGeoPoint" INTEGER NOT NULL, "mlo:asGeoPoint:graph" INTEGER); +CREATE TABLE "mlo:GeoLocation_mlo:asPostalAddress" (ID INTEGER NOT +NULL, "mlo:asPostalAddress" INTEGER NOT NULL, +"mlo:asPostalAddress:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoPoint_mlo:address" (ID INTEGER NOT NULL, +"mlo:address" TEXT NOT NULL, "mlo:address:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:altitude" (ID INTEGER NOT NULL, +"mlo:altitude" REAL NOT NULL, "mlo:altitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:city" (ID INTEGER NOT NULL, "mlo:city" +TEXT NOT NULL, "mlo:city:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:country" (ID INTEGER NOT NULL, +"mlo:country" TEXT NOT NULL, "mlo:country:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:latitude" (ID INTEGER NOT NULL, +"mlo:latitude" REAL NOT NULL, "mlo:latitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:longitude" (ID INTEGER NOT NULL, +"mlo:longitude" REAL NOT NULL, "mlo:longitude:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:state" (ID INTEGER NOT NULL, +"mlo:state" TEXT NOT NULL, "mlo:state:graph" INTEGER); +CREATE TABLE "mlo:GeoPoint_mlo:timestamp" (ID INTEGER NOT NULL, +"mlo:timestamp" INTEGER NOT NULL, "mlo:timestamp:graph" INTEGER, +"mlo:timestamp:localDate" INTEGER NOT NULL, "mlo:timestamp:localTime" +INTEGER NOT NULL); +CREATE TABLE "mlo:GeoSphere" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:GeoSphere_mlo:radius" (ID INTEGER NOT NULL, +"mlo:radius" REAL NOT NULL, "mlo:radius:graph" INTEGER); +CREATE TABLE "mlo:Landmark" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LandmarkCategory" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LandmarkCategory_mlo:isRemovable" (ID INTEGER NOT +NULL, "mlo:isRemovable" INTEGER NOT NULL, "mlo:isRemovable:graph" +INTEGER); +CREATE TABLE "mlo:Landmark_mlo:belongsToCategory" (ID INTEGER NOT +NULL, "mlo:belongsToCategory" INTEGER NOT NULL, +"mlo:belongsToCategory:graph" INTEGER); +CREATE TABLE "mlo:Landmark_mlo:poiLocation" (ID INTEGER NOT NULL, +"mlo:poiLocation" INTEGER NOT NULL, "mlo:poiLocation:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxEastLimit" (ID INTEGER +NOT NULL, "mlo:boxEastLimit" INTEGER NOT NULL, +"mlo:boxEastLimit:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxNorthLimit" (ID INTEGER +NOT NULL, "mlo:boxNorthLimit" INTEGER NOT NULL, +"mlo:boxNorthLimit:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxSouthWestCorner" (ID +INTEGER NOT NULL, "mlo:boxSouthWestCorner" INTEGER NOT NULL, +"mlo:boxSouthWestCorner:graph" INTEGER); +CREATE TABLE "mlo:LocationBoundingBox_mlo:boxVerticalLimit" (ID +INTEGER NOT NULL, "mlo:boxVerticalLimit" INTEGER NOT NULL, +"mlo:boxVerticalLimit:graph" INTEGER); +CREATE TABLE "mlo:PointOfInterest" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:Route" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mlo:Route_mlo:endTime" (ID INTEGER NOT NULL, +"mlo:endTime" INTEGER NOT NULL, "mlo:endTime:graph" INTEGER, +"mlo:endTime:localDate" INTEGER NOT NULL, "mlo:endTime:localTime" +INTEGER NOT NULL); +CREATE TABLE "mlo:Route_mlo:routeDetails" (ID INTEGER NOT NULL, +"mlo:routeDetails" TEXT NOT NULL, "mlo:routeDetails:graph" INTEGER); +CREATE TABLE "mlo:Route_mlo:startTime" (ID INTEGER NOT NULL, +"mlo:startTime" INTEGER NOT NULL, "mlo:startTime:graph" INTEGER, +"mlo:startTime:localDate" INTEGER NOT NULL, "mlo:startTime:localTime" +INTEGER NOT NULL); +CREATE TABLE "mto:DownloadTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:State" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:SyncTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:Transfer" (ID INTEGER NOT NULL PRIMARY KEY, +"mto:transferState" INTEGER, "mto:transferState:graph" INTEGER, +"mto:method" INTEGER, "mto:method:graph" INTEGER, "mto:created" +INTEGER, "mto:created:graph" INTEGER, "mto:created:localDate" INTEGER, +"mto:created:localTime" INTEGER, "mto:account" TEXT COLLATE NOCASE, +"mto:account:graph" INTEGER, "mto:starter" INTEGER, +"mto:starter:graph" INTEGER, "mto:agent" INTEGER, "mto:agent:graph" +INTEGER); +CREATE TABLE "mto:TransferElement" (ID INTEGER NOT NULL PRIMARY KEY, +"mto:source" INTEGER, "mto:source:graph" INTEGER, "mto:destination" +INTEGER, "mto:destination:graph" INTEGER, "mto:startedTime" INTEGER, +"mto:startedTime:graph" INTEGER, "mto:startedTime:localDate" INTEGER, +"mto:startedTime:localTime" INTEGER, "mto:completedTime" INTEGER, +"mto:completedTime:graph" INTEGER, "mto:completedTime:localDate" +INTEGER, "mto:completedTime:localTime" INTEGER, "mto:state" INTEGER, +"mto:state:graph" INTEGER); +CREATE TABLE "mto:TransferMethod" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:Transfer_mto:transferList" (ID INTEGER NOT NULL, +"mto:transferList" INTEGER NOT NULL, "mto:transferList:graph" +INTEGER); +CREATE TABLE "mto:Transfer_mto:transferPrivacyLevel" (ID INTEGER NOT +NULL, "mto:transferPrivacyLevel" TEXT NOT NULL, +"mto:transferPrivacyLevel:graph" INTEGER); +CREATE TABLE "mto:UploadTransfer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "mto:UploadTransfer_mto:transferCategory" (ID INTEGER NOT +NULL, "mto:transferCategory" TEXT NOT NULL, +"mto:transferCategory:graph" INTEGER); +CREATE TABLE "mtp:ScanType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nao:Property" (ID INTEGER NOT NULL PRIMARY KEY, +"nao:propertyName" TEXT COLLATE NOCASE, "nao:propertyName:graph" +INTEGER, "nao:propertyValue" TEXT COLLATE NOCASE, +"nao:propertyValue:graph" INTEGER); +CREATE TABLE "nao:Tag" (ID INTEGER NOT NULL PRIMARY KEY, +"nao:prefLabel" TEXT COLLATE NOCASE, "nao:prefLabel:graph" INTEGER, +"nao:description" TEXT COLLATE NOCASE, "nao:description:graph" +INTEGER); +CREATE TABLE "nao:Tag_tracker:isDefaultTag" (ID INTEGER NOT NULL, +"tracker:isDefaultTag" INTEGER NOT NULL, "tracker:isDefaultTag:graph" +INTEGER); +CREATE TABLE "nao:Tag_tracker:tagRelatedTo" (ID INTEGER NOT NULL, +"tracker:tagRelatedTo" INTEGER NOT NULL, "tracker:tagRelatedTo:graph" +INTEGER); +CREATE TABLE "ncal:AccessClassification" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Alarm" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:repeat" INTEGER, "ncal:repeat:graph" INTEGER); +CREATE TABLE "ncal:AlarmAction" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Alarm_ncal:action" (ID INTEGER NOT NULL, +"ncal:action" INTEGER NOT NULL, "ncal:action:graph" INTEGER); +CREATE TABLE "ncal:Attachment" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:attachmentUri" INTEGER, "ncal:attachmentUri:graph" INTEGER, +"ncal:fmttype" TEXT COLLATE NOCASE, "ncal:fmttype:graph" INTEGER, +"ncal:encoding" INTEGER, "ncal:encoding:graph" INTEGER, +"ncal:attachmentContent" TEXT COLLATE NOCASE, +"ncal:attachmentContent:graph" INTEGER); +CREATE TABLE "ncal:AttachmentEncoding" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Attendee" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:delegatedTo" INTEGER, "ncal:delegatedTo:graph" INTEGER, +"ncal:delegatedFrom" INTEGER, "ncal:delegatedFrom:graph" INTEGER, +"ncal:cutype" INTEGER, "ncal:cutype:graph" INTEGER, "ncal:member" +INTEGER, "ncal:member:graph" INTEGER, "ncal:role" INTEGER, +"ncal:role:graph" INTEGER, "ncal:rsvp" INTEGER, "ncal:rsvp:graph" +INTEGER, "ncal:partstat" INTEGER, "ncal:partstat:graph" INTEGER); +CREATE TABLE "ncal:AttendeeOrOrganizer" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:dir" INTEGER, "ncal:dir:graph" INTEGER, +"ncal:involvedContact" INTEGER, "ncal:involvedContact:graph" INTEGER, +"ncal:sentBy" INTEGER, "ncal:sentBy:graph" INTEGER); +CREATE TABLE "ncal:AttendeeRole" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:BydayRulePart" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:BydayRulePart_ncal:bydayModifier" (ID INTEGER NOT +NULL, "ncal:bydayModifier" INTEGER NOT NULL, +"ncal:bydayModifier:graph" INTEGER); +CREATE TABLE "ncal:BydayRulePart_ncal:bydayWeekday" (ID INTEGER NOT +NULL, "ncal:bydayWeekday" INTEGER NOT NULL, "ncal:bydayWeekday:graph" +INTEGER); +CREATE TABLE "ncal:Calendar" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:method" TEXT COLLATE NOCASE, "ncal:method:graph" INTEGER, +"ncal:calscale" INTEGER, "ncal:calscale:graph" INTEGER, "ncal:prodid" +TEXT COLLATE NOCASE, "ncal:prodid:graph" INTEGER, "ncal:version" TEXT +COLLATE NOCASE, "ncal:version:graph" INTEGER); +CREATE TABLE "ncal:CalendarDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:CalendarScale" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:CalendarUserType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Calendar_ncal:component" (ID INTEGER NOT NULL, +"ncal:component" INTEGER NOT NULL, "ncal:component:graph" INTEGER); +CREATE TABLE "ncal:Event" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:eventStatus" INTEGER, "ncal:eventStatus:graph" INTEGER, +"ncal:transp" INTEGER, "ncal:transp:graph" INTEGER); +CREATE TABLE "ncal:EventStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Freebusy" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:FreebusyPeriod" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:fbtype" INTEGER, "ncal:fbtype:graph" INTEGER); +CREATE TABLE "ncal:FreebusyType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Freebusy_ncal:freebusy" (ID INTEGER NOT NULL, +"ncal:freebusy" INTEGER NOT NULL, "ncal:freebusy:graph" INTEGER); +CREATE TABLE "ncal:Journal" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:journalStatus" INTEGER, "ncal:journalStatus:graph" INTEGER); +CREATE TABLE "ncal:JournalStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:NcalDateTime" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:ncalTimezone" INTEGER, "ncal:ncalTimezone:graph" INTEGER, +"ncal:date" INTEGER, "ncal:date:graph" INTEGER, "ncal:date:localDate" +INTEGER, "ncal:date:localTime" INTEGER, "ncal:dateTime" INTEGER, +"ncal:dateTime:graph" INTEGER, "ncal:dateTime:localDate" INTEGER, +"ncal:dateTime:localTime" INTEGER); +CREATE TABLE "ncal:NcalPeriod" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:periodBegin" INTEGER, "ncal:periodBegin:graph" INTEGER, +"ncal:periodBegin:localDate" INTEGER, "ncal:periodBegin:localTime" +INTEGER, "ncal:periodDuration" INTEGER, "ncal:periodDuration:graph" +INTEGER, "ncal:periodEnd" INTEGER, "ncal:periodEnd:graph" INTEGER, +"ncal:periodEnd:localDate" INTEGER, "ncal:periodEnd:localTime" +INTEGER); +CREATE TABLE "ncal:NcalTimeEntity" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Organizer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:ParticipationStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceFrequency" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceIdentifier" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:range" INTEGER, "ncal:range:graph" INTEGER, +"ncal:recurrenceIdDateTime" INTEGER, "ncal:recurrenceIdDateTime:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceIdentifierRange" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:RecurrenceRule" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:until" INTEGER, "ncal:until:graph" INTEGER, +"ncal:until:localDate" INTEGER, "ncal:until:localTime" INTEGER, +"ncal:wkst" INTEGER, "ncal:wkst:graph" INTEGER, "ncal:interval" +INTEGER, "ncal:interval:graph" INTEGER, "ncal:count" INTEGER, +"ncal:count:graph" INTEGER, "ncal:freq" INTEGER, "ncal:freq:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byday" (ID INTEGER NOT NULL, +"ncal:byday" INTEGER NOT NULL, "ncal:byday:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byhour" (ID INTEGER NOT NULL, +"ncal:byhour" INTEGER NOT NULL, "ncal:byhour:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byminute" (ID INTEGER NOT NULL, +"ncal:byminute" INTEGER NOT NULL, "ncal:byminute:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bymonth" (ID INTEGER NOT NULL, +"ncal:bymonth" INTEGER NOT NULL, "ncal:bymonth:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bymonthday" (ID INTEGER NOT +NULL, "ncal:bymonthday" INTEGER NOT NULL, "ncal:bymonthday:graph" +INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bysecond" (ID INTEGER NOT NULL, +"ncal:bysecond" INTEGER NOT NULL, "ncal:bysecond:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:bysetpos" (ID INTEGER NOT NULL, +"ncal:bysetpos" INTEGER NOT NULL, "ncal:bysetpos:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byweekno" (ID INTEGER NOT NULL, +"ncal:byweekno" INTEGER NOT NULL, "ncal:byweekno:graph" INTEGER); +CREATE TABLE "ncal:RecurrenceRule_ncal:byyearday" (ID INTEGER NOT +NULL, "ncal:byyearday" INTEGER NOT NULL, "ncal:byyearday:graph" +INTEGER); +CREATE TABLE "ncal:RequestStatus" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:statusDescription" TEXT COLLATE NOCASE, +"ncal:statusDescription:graph" INTEGER, "ncal:returnStatus" TEXT +COLLATE NOCASE, "ncal:returnStatus:graph" INTEGER, +"ncal:requestStatusData" TEXT COLLATE NOCASE, +"ncal:requestStatusData:graph" INTEGER); +CREATE TABLE "ncal:TimeTransparency" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Timezone" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:tzurl" INTEGER, "ncal:tzurl:graph" INTEGER, "ncal:standard" +INTEGER, "ncal:standard:graph" INTEGER, "ncal:daylight" INTEGER, +"ncal:daylight:graph" INTEGER, "ncal:tzid" TEXT COLLATE NOCASE, +"ncal:tzid:graph" INTEGER); +CREATE TABLE "ncal:TimezoneObservance" (ID INTEGER NOT NULL PRIMARY +KEY, "ncal:tzoffsetfrom" TEXT COLLATE NOCASE, +"ncal:tzoffsetfrom:graph" INTEGER, "ncal:tzoffsetto" TEXT COLLATE +NOCASE, "ncal:tzoffsetto:graph" INTEGER, "ncal:tzname" TEXT COLLATE +NOCASE, "ncal:tzname:graph" INTEGER); +CREATE TABLE "ncal:Todo" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:percentComplete" INTEGER, "ncal:percentComplete:graph" INTEGER, +"ncal:completed" INTEGER, "ncal:completed:graph" INTEGER, +"ncal:completed:localDate" INTEGER, "ncal:completed:localTime" +INTEGER, "ncal:todoStatus" INTEGER, "ncal:todoStatus:graph" INTEGER, +"ncal:due" INTEGER, "ncal:due:graph" INTEGER); +CREATE TABLE "ncal:TodoStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:Trigger" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:related" INTEGER, "ncal:related:graph" INTEGER, +"ncal:triggerDateTime" INTEGER, "ncal:triggerDateTime:graph" INTEGER, +"ncal:triggerDateTime:localDate" INTEGER, +"ncal:triggerDateTime:localTime" INTEGER, "ncal:triggerDuration" +INTEGER, "ncal:triggerDuration:graph" INTEGER); +CREATE TABLE "ncal:TriggerRelation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "ncal:UnionParentClass" (ID INTEGER NOT NULL PRIMARY KEY, +"ncal:lastModified" INTEGER, "ncal:lastModified:graph" INTEGER, +"ncal:lastModified:localDate" INTEGER, "ncal:lastModified:localTime" +INTEGER, "ncal:trigger" INTEGER, "ncal:trigger:graph" INTEGER, +"ncal:created" INTEGER, "ncal:created:graph" INTEGER, +"ncal:created:localDate" INTEGER, "ncal:created:localTime" INTEGER, +"ncal:url" INTEGER, "ncal:url:graph" INTEGER, "ncal:comment" TEXT +COLLATE NOCASE, "ncal:comment:graph" INTEGER, "ncal:summaryAltRep" +INTEGER, "ncal:summaryAltRep:graph" INTEGER, "ncal:priority" INTEGER, +"ncal:priority:graph" INTEGER, "ncal:location" TEXT COLLATE NOCASE, +"ncal:location:graph" INTEGER, "ncal:uid" TEXT COLLATE NOCASE, +"ncal:uid:graph" INTEGER, "ncal:requestStatus" INTEGER, +"ncal:requestStatus:graph" INTEGER, "ncal:recurrenceId" INTEGER, +"ncal:recurrenceId:graph" INTEGER, "ncal:dtstamp" INTEGER, +"ncal:dtstamp:graph" INTEGER, "ncal:dtstamp:localDate" INTEGER, +"ncal:dtstamp:localTime" INTEGER, "ncal:class" INTEGER, +"ncal:class:graph" INTEGER, "ncal:organizer" INTEGER, +"ncal:organizer:graph" INTEGER, "ncal:dtend" INTEGER, +"ncal:dtend:graph" INTEGER, "ncal:summary" TEXT COLLATE NOCASE, +"ncal:summary:graph" INTEGER, "ncal:descriptionAltRep" INTEGER, +"ncal:descriptionAltRep:graph" INTEGER, "ncal:commentAltRep" INTEGER, +"ncal:commentAltRep:graph" INTEGER, "ncal:sequence" INTEGER, +"ncal:sequence:graph" INTEGER, "ncal:contact" TEXT COLLATE NOCASE, +"ncal:contact:graph" INTEGER, "ncal:contactAltRep" INTEGER, +"ncal:contactAltRep:graph" INTEGER, "ncal:locationAltRep" INTEGER, +"ncal:locationAltRep:graph" INTEGER, "ncal:geo" INTEGER, +"ncal:geo:graph" INTEGER, "ncal:resourcesAltRep" INTEGER, +"ncal:resourcesAltRep:graph" INTEGER, "ncal:dtstart" INTEGER, +"ncal:dtstart:graph" INTEGER, "ncal:description" TEXT COLLATE NOCASE, +"ncal:description:graph" INTEGER, "ncal:relatedToSibling" TEXT COLLATE +NOCASE, "ncal:relatedToSibling:graph" INTEGER, "ncal:duration" +INTEGER, "ncal:duration:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:attach" (ID INTEGER NOT NULL, +"ncal:attach" INTEGER NOT NULL, "ncal:attach:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:attendee" (ID INTEGER NOT +NULL, "ncal:attendee" INTEGER NOT NULL, "ncal:attendee:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:categories" (ID INTEGER NOT +NULL, "ncal:categories" TEXT NOT NULL, "ncal:categories:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:exdate" (ID INTEGER NOT NULL, +"ncal:exdate" INTEGER NOT NULL, "ncal:exdate:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:exrule" (ID INTEGER NOT NULL, +"ncal:exrule" INTEGER NOT NULL, "ncal:exrule:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:hasAlarm" (ID INTEGER NOT +NULL, "ncal:hasAlarm" INTEGER NOT NULL, "ncal:hasAlarm:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:ncalRelation" (ID INTEGER NOT +NULL, "ncal:ncalRelation" TEXT NOT NULL, "ncal:ncalRelation:graph" +INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:rdate" (ID INTEGER NOT NULL, +"ncal:rdate" INTEGER NOT NULL, "ncal:rdate:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:relatedToChild" (ID INTEGER +NOT NULL, "ncal:relatedToChild" TEXT NOT NULL, +"ncal:relatedToChild:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:relatedToParent" (ID INTEGER +NOT NULL, "ncal:relatedToParent" TEXT NOT NULL, +"ncal:relatedToParent:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:resources" (ID INTEGER NOT +NULL, "ncal:resources" TEXT NOT NULL, "ncal:resources:graph" INTEGER); +CREATE TABLE "ncal:UnionParentClass_ncal:rrule" (ID INTEGER NOT NULL, +"ncal:rrule" INTEGER NOT NULL, "ncal:rrule:graph" INTEGER); +CREATE TABLE "ncal:Weekday" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Affiliation" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:department" TEXT COLLATE NOCASE, "nco:department:graph" INTEGER, +"nco:org" INTEGER, "nco:org:graph" INTEGER, "nco:role" TEXT COLLATE +NOCASE, "nco:role:graph" INTEGER); +CREATE TABLE "nco:Affiliation_nco:title" (ID INTEGER NOT NULL, +"nco:title" TEXT NOT NULL, "nco:title:graph" INTEGER); +CREATE TABLE "nco:AuthorizationStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:BbsNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:CarPhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:CellPhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Contact" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:fullname" TEXT COLLATE NOCASE, "nco:fullname:graph" INTEGER, +"nco:key" INTEGER, "nco:key:graph" INTEGER, "nco:contactUID" TEXT +COLLATE NOCASE, "nco:contactUID:graph" INTEGER, "nco:contactLocalUID" +TEXT COLLATE NOCASE, "nco:contactLocalUID:graph" INTEGER, +"nco:hasLocation" INTEGER, "nco:hasLocation:graph" INTEGER, +"nco:nickname" TEXT COLLATE NOCASE, "nco:nickname:graph" INTEGER, +"nco:representative" INTEGER, "nco:representative:graph" INTEGER, +"nco:photo" INTEGER, "nco:photo:graph" INTEGER, "nco:birthDate" +INTEGER, "nco:birthDate:graph" INTEGER, "nco:birthDate:localDate" +INTEGER, "nco:birthDate:localTime" INTEGER, "nco:sound" INTEGER, +"nco:sound:graph" INTEGER); +CREATE TABLE "nco:ContactGroup" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:contactGroupName" TEXT COLLATE NOCASE, +"nco:contactGroupName:graph" INTEGER); +CREATE TABLE "nco:ContactList" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ContactListDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ContactList_nco:containsContact" (ID INTEGER NOT +NULL, "nco:containsContact" INTEGER NOT NULL, +"nco:containsContact:graph" INTEGER); +CREATE TABLE "nco:ContactMedium" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:contactMediumComment" TEXT COLLATE NOCASE, +"nco:contactMediumComment:graph" INTEGER); +CREATE TABLE "nco:Contact_ncal:anniversary" (ID INTEGER NOT NULL, +"ncal:anniversary" INTEGER NOT NULL, "ncal:anniversary:graph" +INTEGER); +CREATE TABLE "nco:Contact_ncal:birthday" (ID INTEGER NOT NULL, +"ncal:birthday" INTEGER NOT NULL, "ncal:birthday:graph" INTEGER); +CREATE TABLE "nco:Contact_nco:belongsToGroup" (ID INTEGER NOT NULL, +"nco:belongsToGroup" INTEGER NOT NULL, "nco:belongsToGroup:graph" +INTEGER); +CREATE TABLE "nco:Contact_nco:note" (ID INTEGER NOT NULL, "nco:note" +TEXT NOT NULL, "nco:note:graph" INTEGER); +CREATE TABLE "nco:Contact_scal:anniversary" (ID INTEGER NOT NULL, +"scal:anniversary" INTEGER NOT NULL, "scal:anniversary:graph" +INTEGER); +CREATE TABLE "nco:Contact_scal:birthday" (ID INTEGER NOT NULL, +"scal:birthday" INTEGER NOT NULL, "scal:birthday:graph" INTEGER); +CREATE TABLE "nco:DomesticDeliveryAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:EmailAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:emailAddress" TEXT COLLATE NOCASE UNIQUE, +"nco:emailAddress:graph" INTEGER); +CREATE TABLE "nco:FaxNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Gender" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:IMAccount" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:imAccountAddress" INTEGER UNIQUE, "nco:imAccountAddress:graph" +INTEGER, "nco:imAccountType" TEXT COLLATE NOCASE, +"nco:imAccountType:graph" INTEGER, "nco:imDisplayName" TEXT COLLATE +NOCASE, "nco:imDisplayName:graph" INTEGER, "nco:imEnabled" INTEGER, +"nco:imEnabled:graph" INTEGER); +CREATE TABLE "nco:IMAccount_nco:hasIMContact" (ID INTEGER NOT NULL, +"nco:hasIMContact" INTEGER NOT NULL, "nco:hasIMContact:graph" +INTEGER); +CREATE TABLE "nco:IMAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:imID" TEXT COLLATE NOCASE, "nco:imID:graph" INTEGER, +"nco:imNickname" TEXT COLLATE NOCASE, "nco:imNickname:graph" INTEGER, +"nco:imAvatar" INTEGER, "nco:imAvatar:graph" INTEGER, "nco:imProtocol" +TEXT COLLATE NOCASE, "nco:imProtocol:graph" INTEGER, +"nco:imStatusMessage" TEXT COLLATE NOCASE, +"nco:imStatusMessage:graph" INTEGER, "nco:imPresence" INTEGER, +"nco:imPresence:graph" INTEGER, "nco:presenceLastModified" INTEGER, +"nco:presenceLastModified:graph" INTEGER, +"nco:presenceLastModified:localDate" INTEGER, +"nco:presenceLastModified:localTime" INTEGER, +"nco:imAddressAuthStatusFrom" INTEGER, +"nco:imAddressAuthStatusFrom:graph" INTEGER, +"nco:imAddressAuthStatusTo" INTEGER, "nco:imAddressAuthStatusTo:graph" +INTEGER); +CREATE TABLE "nco:IMAddress_nco:imCapability" (ID INTEGER NOT NULL, +"nco:imCapability" INTEGER NOT NULL, "nco:imCapability:graph" +INTEGER); +CREATE TABLE "nco:IMCapability" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:InternationalDeliveryAddress" (ID INTEGER NOT NULL +PRIMARY KEY); +CREATE TABLE "nco:IsdnNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:MessagingNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ModemNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:OrganizationContact" (ID INTEGER NOT NULL PRIMARY +KEY, "nco:logo" INTEGER, "nco:logo:graph" INTEGER); +CREATE TABLE "nco:PagerNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:ParcelDeliveryAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:PcsNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:PersonContact" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:nameFamily" TEXT COLLATE NOCASE, "nco:nameFamily:graph" INTEGER, +"nco:nameGiven" TEXT COLLATE NOCASE, "nco:nameGiven:graph" INTEGER, +"nco:nameAdditional" TEXT COLLATE NOCASE, "nco:nameAdditional:graph" +INTEGER, "nco:nameHonorificSuffix" TEXT COLLATE NOCASE, +"nco:nameHonorificSuffix:graph" INTEGER, "nco:nameHonorificPrefix" +TEXT COLLATE NOCASE, "nco:nameHonorificPrefix:graph" INTEGER, +"nco:hobby" TEXT COLLATE NOCASE, "nco:hobby:graph" INTEGER, +"nco:gender" INTEGER, "nco:gender:graph" INTEGER); +CREATE TABLE "nco:PersonContact_nco:hasAffiliation" (ID INTEGER NOT +NULL, "nco:hasAffiliation" INTEGER NOT NULL, +"nco:hasAffiliation:graph" INTEGER); +CREATE TABLE "nco:PhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:phoneNumber" TEXT COLLATE NOCASE, "nco:phoneNumber:graph" +INTEGER); +CREATE TABLE "nco:PostalAddress" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:region" TEXT COLLATE NOCASE, "nco:region:graph" INTEGER, +"nco:country" TEXT COLLATE NOCASE, "nco:country:graph" INTEGER, +"nco:extendedAddress" TEXT COLLATE NOCASE, +"nco:extendedAddress:graph" INTEGER, "nco:addressLocation" INTEGER, +"nco:addressLocation:graph" INTEGER, "nco:streetAddress" TEXT COLLATE +NOCASE, "nco:streetAddress:graph" INTEGER, "nco:postalcode" TEXT +COLLATE NOCASE, "nco:postalcode:graph" INTEGER, "nco:locality" TEXT +COLLATE NOCASE, "nco:locality:graph" INTEGER, "nco:county" TEXT +COLLATE NOCASE, "nco:county:graph" INTEGER, "nco:district" TEXT +COLLATE NOCASE, "nco:district:graph" INTEGER, "nco:pobox" TEXT +COLLATE NOCASE, "nco:pobox:graph" INTEGER); +CREATE TABLE "nco:PresenceStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:Role" (ID INTEGER NOT NULL PRIMARY KEY, "nco:video" +INTEGER, "nco:video:graph" INTEGER); +CREATE TABLE "nco:Role_nco:blogUrl" (ID INTEGER NOT NULL, +"nco:blogUrl" INTEGER NOT NULL, "nco:blogUrl:graph" INTEGER); +CREATE TABLE "nco:Role_nco:foafUrl" (ID INTEGER NOT NULL, +"nco:foafUrl" INTEGER NOT NULL, "nco:foafUrl:graph" INTEGER); +CREATE TABLE "nco:Role_nco:hasContactMedium" (ID INTEGER NOT NULL, +"nco:hasContactMedium" INTEGER NOT NULL, "nco:hasContactMedium:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasEmailAddress" (ID INTEGER NOT NULL, +"nco:hasEmailAddress" INTEGER NOT NULL, "nco:hasEmailAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasIMAddress" (ID INTEGER NOT NULL, +"nco:hasIMAddress" INTEGER NOT NULL, "nco:hasIMAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasPhoneNumber" (ID INTEGER NOT NULL, +"nco:hasPhoneNumber" INTEGER NOT NULL, "nco:hasPhoneNumber:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:hasPostalAddress" (ID INTEGER NOT NULL, +"nco:hasPostalAddress" INTEGER NOT NULL, "nco:hasPostalAddress:graph" +INTEGER); +CREATE TABLE "nco:Role_nco:url" (ID INTEGER NOT NULL, "nco:url" +INTEGER NOT NULL, "nco:url:graph" INTEGER); +CREATE TABLE "nco:Role_nco:websiteUrl" (ID INTEGER NOT NULL, +"nco:websiteUrl" INTEGER NOT NULL, "nco:websiteUrl:graph" INTEGER); +CREATE TABLE "nco:VideoTelephoneNumber" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nco:VoicePhoneNumber" (ID INTEGER NOT NULL PRIMARY KEY, +"nco:voiceMail" INTEGER, "nco:voiceMail:graph" INTEGER); +CREATE TABLE "nfo:Application" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Archive" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:uncompressedSize" INTEGER, "nfo:uncompressedSize:graph" INTEGER); +CREATE TABLE "nfo:ArchiveItem" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:isPasswordProtected" INTEGER, "nfo:isPasswordProtected:graph" +INTEGER); +CREATE TABLE "nfo:Attachment" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Audio" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:channels" INTEGER, "nfo:channels:graph" INTEGER, +"nfo:sideChannels" INTEGER, "nfo:sideChannels:graph" INTEGER, +"nfo:lfeChannels" INTEGER, "nfo:lfeChannels:graph" INTEGER, +"nfo:sampleCount" INTEGER, "nfo:sampleCount:graph" INTEGER, +"nfo:bitsPerSample" INTEGER, "nfo:bitsPerSample:graph" INTEGER, +"nfo:frontChannels" INTEGER, "nfo:frontChannels:graph" INTEGER, +"nfo:sampleRate" REAL, "nfo:sampleRate:graph" INTEGER, +"nfo:averageAudioBitrate" REAL, "nfo:averageAudioBitrate:graph" +INTEGER, "nfo:rearChannels" INTEGER, "nfo:rearChannels:graph" INTEGER, +"nfo:gain" INTEGER, "nfo:gain:graph" INTEGER, "nfo:peakGain" INTEGER, +"nfo:peakGain:graph" INTEGER, "nfo:audioOffset" REAL, +"nfo:audioOffset:graph" INTEGER); +CREATE TABLE "nfo:Bookmark" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:bookmarks" INTEGER, "nfo:bookmarks:graph" INTEGER, +"nfo:characterPosition" INTEGER, "nfo:characterPosition:graph" +INTEGER, "nfo:pageNumber" INTEGER, "nfo:pageNumber:graph" INTEGER, +"nfo:streamPosition" INTEGER, "nfo:streamPosition:graph" INTEGER, +"nfo:streamDuration" INTEGER, "nfo:streamDuration:graph" INTEGER); +CREATE TABLE "nfo:BookmarkFolder" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:BookmarkFolder_nfo:containsBookmark" (ID INTEGER NOT +NULL, "nfo:containsBookmark" INTEGER NOT NULL, +"nfo:containsBookmark:graph" INTEGER); +CREATE TABLE "nfo:BookmarkFolder_nfo:containsBookmarkFolder" (ID +INTEGER NOT NULL, "nfo:containsBookmarkFolder" INTEGER NOT NULL, +"nfo:containsBookmarkFolder:graph" INTEGER); +CREATE TABLE "nfo:CompressionType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Cursor" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:DataContainer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:DeletedResource" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:originalLocation" TEXT COLLATE NOCASE, +"nfo:originalLocation:graph" INTEGER, "nfo:deletionDate" INTEGER, +"nfo:deletionDate:graph" INTEGER, "nfo:deletionDate:localDate" +INTEGER, "nfo:deletionDate:localTime" INTEGER); +CREATE TABLE "nfo:Document" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:tableOfContents" TEXT COLLATE NOCASE, +"nfo:tableOfContents:graph" INTEGER); +CREATE TABLE "nfo:EmbeddedFileDataObject" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:encoding" TEXT COLLATE NOCASE, "nfo:encoding:graph" +INTEGER); +CREATE TABLE "nfo:Equipment" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:manufacturer" TEXT COLLATE NOCASE, "nfo:manufacturer:graph" +INTEGER, "nfo:model" TEXT COLLATE NOCASE, "nfo:model:graph" INTEGER, +"nfo:equipmentSoftware" TEXT COLLATE NOCASE, +"nfo:equipmentSoftware:graph" INTEGER); +CREATE TABLE "nfo:Executable" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:FileDataObject" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:fileLastAccessed" INTEGER, "nfo:fileLastAccessed:graph" INTEGER, +"nfo:fileLastAccessed:localDate" INTEGER, +"nfo:fileLastAccessed:localTime" INTEGER, "nfo:fileCreated" INTEGER, +"nfo:fileCreated:graph" INTEGER, "nfo:fileCreated:localDate" INTEGER, +"nfo:fileCreated:localTime" INTEGER, "nfo:fileSize" INTEGER, +"nfo:fileSize:graph" INTEGER, "nfo:permissions" TEXT COLLATE NOCASE, +"nfo:permissions:graph" INTEGER, "nfo:fileName" TEXT COLLATE NOCASE, +"nfo:fileName:graph" INTEGER, "nfo:hasHash" INTEGER, +"nfo:hasHash:graph" INTEGER, "nfo:fileOwner" INTEGER, +"nfo:fileOwner:graph" INTEGER, "nfo:fileLastModified" INTEGER, +"nfo:fileLastModified:graph" INTEGER, "nfo:fileLastModified:localDate" +INTEGER, "nfo:fileLastModified:localTime" INTEGER); +CREATE TABLE "nfo:FileHash" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:hashValue" TEXT COLLATE NOCASE, "nfo:hashValue:graph" INTEGER, +"nfo:hashAlgorithm" TEXT COLLATE NOCASE, "nfo:hashAlgorithm:graph" +INTEGER); +CREATE TABLE "nfo:Filesystem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:FilesystemImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Folder" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Font" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:fontFamily" TEXT COLLATE NOCASE, "nfo:fontFamily:graph" INTEGER, +"nfo:foundry" INTEGER, "nfo:foundry:graph" INTEGER); +CREATE TABLE "nfo:HardDiskPartition" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:HelpDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:HtmlDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Icon" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Image" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:verticalResolution" INTEGER, "nfo:verticalResolution:graph" +INTEGER, "nfo:horizontalResolution" INTEGER, +"nfo:horizontalResolution:graph" INTEGER, "nfo:orientation" INTEGER, +"nfo:orientation:graph" INTEGER); +CREATE TABLE "nfo:Image_nfo:depicts" (ID INTEGER NOT NULL, +"nfo:depicts" INTEGER NOT NULL, "nfo:depicts:graph" INTEGER); +CREATE TABLE "nfo:Image_nfo:hasRegionOfInterest" (ID INTEGER NOT NULL, +"nfo:hasRegionOfInterest" INTEGER NOT NULL, +"nfo:hasRegionOfInterest:graph" INTEGER); +CREATE TABLE "nfo:Media" (ID INTEGER NOT NULL PRIMARY KEY, "nfo:count" +INTEGER, "nfo:count:graph" INTEGER, "nfo:duration" INTEGER, +"nfo:duration:graph" INTEGER, "nfo:compressionType" INTEGER, +"nfo:compressionType:graph" INTEGER, "nfo:hasMediaStream" INTEGER, +"nfo:hasMediaStream:graph" INTEGER, "nfo:bitDepth" INTEGER, +"nfo:bitDepth:graph" INTEGER, "nfo:codec" TEXT COLLATE NOCASE, +"nfo:codec:graph" INTEGER, "nfo:encodedBy" TEXT COLLATE NOCASE, +"nfo:encodedBy:graph" INTEGER, "nfo:bitrateType" TEXT COLLATE NOCASE, +"nfo:bitrateType:graph" INTEGER, "nfo:averageBitrate" REAL, +"nfo:averageBitrate:graph" INTEGER, "nfo:genre" TEXT COLLATE NOCASE, +"nfo:genre:graph" INTEGER, "nfo:equipment" INTEGER, +"nfo:equipment:graph" INTEGER, "nfo:lastPlayedPosition" INTEGER, +"nfo:lastPlayedPosition:graph" INTEGER, "nmm:genre" TEXT COLLATE +NOCASE, "nmm:genre:graph" INTEGER, "nmm:skipCounter" INTEGER, +"nmm:skipCounter:graph" INTEGER, "nmm:dlnaProfile" TEXT COLLATE +NOCASE, "nmm:dlnaProfile:graph" INTEGER, "nmm:dlnaMime" TEXT COLLATE +NOCASE, "nmm:dlnaMime:graph" INTEGER, "nmm:uPnPShared" INTEGER, +"nmm:uPnPShared:graph" INTEGER, "mtp:credits" TEXT COLLATE NOCASE, +"mtp:credits:graph" INTEGER, "mtp:creator" TEXT COLLATE NOCASE, +"mtp:creator:graph" INTEGER); +CREATE TABLE "nfo:MediaFileListEntry" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:listPosition" REAL, "nfo:listPosition:graph" INTEGER, +"nfo:entryUrl" TEXT COLLATE NOCASE, "nfo:entryUrl:graph" INTEGER); +CREATE TABLE "nfo:MediaList" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:entryCounter" INTEGER, "nfo:entryCounter:graph" INTEGER, +"nfo:listDuration" INTEGER, "nfo:listDuration:graph" INTEGER); +CREATE TABLE "nfo:MediaList_nfo:hasMediaFileListEntry" (ID INTEGER NOT +NULL, "nfo:hasMediaFileListEntry" INTEGER NOT NULL, +"nfo:hasMediaFileListEntry:graph" INTEGER); +CREATE TABLE "nfo:MediaList_nfo:mediaListEntry" (ID INTEGER NOT NULL, +"nfo:mediaListEntry" INTEGER NOT NULL, "nfo:mediaListEntry:graph" +INTEGER); +CREATE TABLE "nfo:MediaStream" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Media_mtp:hidden" (ID INTEGER NOT NULL, "mtp:hidden" +INTEGER NOT NULL, "mtp:hidden:graph" INTEGER); +CREATE TABLE "nfo:Media_nmm:alternativeMedia" (ID INTEGER NOT NULL, +"nmm:alternativeMedia" INTEGER NOT NULL, "nmm:alternativeMedia:graph" +INTEGER); +CREATE TABLE "nfo:MindMap" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Note" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:OperatingSystem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Orientation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:PaginatedTextDocument" (ID INTEGER NOT NULL PRIMARY +KEY, "nfo:pageCount" INTEGER, "nfo:pageCount:graph" INTEGER); +CREATE TABLE "nfo:PlainTextDocument" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Presentation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RasterImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RegionOfInterest" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:regionOfInterestX" REAL, "nfo:regionOfInterestX:graph" INTEGER, +"nfo:regionOfInterestY" REAL, "nfo:regionOfInterestY:graph" INTEGER, +"nfo:regionOfInterestWidth" REAL, "nfo:regionOfInterestWidth:graph" +INTEGER, "nfo:regionOfInterestHeight" REAL, +"nfo:regionOfInterestHeight:graph" INTEGER, "nfo:regionOfInterestType" +INTEGER, "nfo:regionOfInterestType:graph" INTEGER, "nfo:roiRefersTo" +INTEGER, "nfo:roiRefersTo:graph" INTEGER); +CREATE TABLE "nfo:RegionOfInterestContent" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RemoteDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:RemotePortAddress" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Software" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:conflicts" INTEGER, "nfo:conflicts:graph" INTEGER, +"nfo:supercedes" INTEGER, "nfo:supercedes:graph" INTEGER, +"nfo:softwareIcon" INTEGER, "nfo:softwareIcon:graph" INTEGER, +"nfo:softwareCmdLine" TEXT COLLATE NOCASE, +"nfo:softwareCmdLine:graph" INTEGER); +CREATE TABLE "nfo:SoftwareApplication" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SoftwareCategory" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:softwareCategoryIcon" INTEGER, "nfo:softwareCategoryIcon:graph" +INTEGER); +CREATE TABLE "nfo:SoftwareItem" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SoftwareService" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:SourceCode" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:commentCharacterCount" INTEGER, "nfo:commentCharacterCount:graph" +INTEGER, "nfo:programmingLanguage" TEXT COLLATE NOCASE, +"nfo:programmingLanguage:graph" INTEGER, "nfo:definesClass" TEXT +COLLATE NOCASE, "nfo:definesClass:graph" INTEGER, +"nfo:definesFunction" TEXT COLLATE NOCASE, +"nfo:definesFunction:graph" INTEGER, "nfo:definesGlobalVariable" TEXT +COLLATE NOCASE, "nfo:definesGlobalVariable:graph" INTEGER); +CREATE TABLE "nfo:Spreadsheet" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:TextDocument" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:wordCount" INTEGER, "nfo:wordCount:graph" INTEGER, +"nfo:lineCount" INTEGER, "nfo:lineCount:graph" INTEGER, +"nfo:characterCount" INTEGER, "nfo:characterCount:graph" INTEGER); +CREATE TABLE "nfo:Trash" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:VectorImage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nfo:Video" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:frameRate" REAL, "nfo:frameRate:graph" INTEGER, "nfo:frameCount" +INTEGER, "nfo:frameCount:graph" INTEGER, "nfo:averageVideoBitrate" +REAL, "nfo:averageVideoBitrate:graph" INTEGER); +CREATE TABLE "nfo:Visual" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:contentCreated" INTEGER, "nie:contentCreated:graph" INTEGER, +"nie:contentCreated:localDate" INTEGER, "nie:contentCreated:localTime" +INTEGER, "nfo:aspectRatio" REAL, "nfo:aspectRatio:graph" INTEGER, +"nfo:heading" REAL, "nfo:heading:graph" INTEGER, "nfo:tilt" REAL, +"nfo:tilt:graph" INTEGER, "nfo:interlaceMode" INTEGER, +"nfo:interlaceMode:graph" INTEGER, "nfo:height" INTEGER, +"nfo:height:graph" INTEGER, "nfo:width" INTEGER, "nfo:width:graph" +INTEGER, "nfo:colorDepth" INTEGER, "nfo:colorDepth:graph" INTEGER); +CREATE TABLE "nfo:WebHistory" (ID INTEGER NOT NULL PRIMARY KEY, +"nfo:domain" TEXT COLLATE NOCASE, "nfo:domain:graph" INTEGER, +"nfo:uri" TEXT COLLATE NOCASE, "nfo:uri:graph" INTEGER); +CREATE TABLE "nfo:Website" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nid3:ID3Audio" (ID INTEGER NOT NULL PRIMARY KEY, +"nid3:title" TEXT COLLATE NOCASE, "nid3:title:graph" INTEGER, +"nid3:albumTitle" TEXT COLLATE NOCASE, "nid3:albumTitle:graph" +INTEGER, "nid3:contentType" TEXT COLLATE NOCASE, +"nid3:contentType:graph" INTEGER, "nid3:length" INTEGER, +"nid3:length:graph" INTEGER, "nid3:recordingYear" INTEGER, +"nid3:recordingYear:graph" INTEGER, "nid3:trackNumber" TEXT COLLATE +NOCASE, "nid3:trackNumber:graph" INTEGER, "nid3:partOfSet" TEXT +COLLATE NOCASE, "nid3:partOfSet:graph" INTEGER, "nid3:comments" TEXT +COLLATE NOCASE, "nid3:comments:graph" INTEGER); +CREATE TABLE "nid3:ID3Audio_nid3:leadArtist" (ID INTEGER NOT NULL, +"nid3:leadArtist" INTEGER NOT NULL, "nid3:leadArtist:graph" INTEGER); +CREATE TABLE "nie:DataObject" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:url" TEXT COLLATE NOCASE UNIQUE, "nie:url:graph" INTEGER, +"nie:byteSize" INTEGER, "nie:byteSize:graph" INTEGER, +"nie:interpretedAs" INTEGER, "nie:interpretedAs:graph" INTEGER, +"nie:lastRefreshed" INTEGER, "nie:lastRefreshed:graph" INTEGER, +"nie:lastRefreshed:localDate" INTEGER, "nie:lastRefreshed:localTime" +INTEGER, "nie:created" INTEGER, "nie:created:graph" INTEGER, +"nie:created:localDate" INTEGER, "nie:created:localTime" INTEGER, +"nfo:belongsToContainer" INTEGER, "nfo:belongsToContainer:graph" +INTEGER, "tracker:available" INTEGER, "tracker:available:graph" +INTEGER); +CREATE TABLE "nie:DataObject_nie:dataSource" (ID INTEGER NOT NULL, +"nie:dataSource" INTEGER NOT NULL, "nie:dataSource:graph" INTEGER); +CREATE TABLE "nie:DataObject_nie:isPartOf" (ID INTEGER NOT NULL, +"nie:isPartOf" INTEGER NOT NULL, "nie:isPartOf:graph" INTEGER); +CREATE TABLE "nie:DataSource" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nie:InformationElement" (ID INTEGER NOT NULL PRIMARY +KEY, "nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nie:contentLastModified" INTEGER, "nie:contentLastModified:graph" +INTEGER, "nie:contentLastModified:localDate" INTEGER, +"nie:contentLastModified:localTime" INTEGER, "nie:subject" TEXT +COLLATE NOCASE, "nie:subject:graph" INTEGER, "nie:mimeType" TEXT +COLLATE NOCASE, "nie:mimeType:graph" INTEGER, "nie:language" TEXT +COLLATE NOCASE, "nie:language:graph" INTEGER, "nie:plainTextContent" +TEXT COLLATE NOCASE, "nie:plainTextContent:graph" INTEGER, +"nie:legal" TEXT COLLATE NOCASE, "nie:legal:graph" INTEGER, +"nie:generator" TEXT COLLATE NOCASE, "nie:generator:graph" INTEGER, +"nie:description" TEXT COLLATE NOCASE, "nie:description:graph" +INTEGER, "nie:disclaimer" TEXT COLLATE NOCASE, "nie:disclaimer:graph" +INTEGER, "nie:depends" INTEGER, "nie:depends:graph" INTEGER, +"nie:links" INTEGER, "nie:links:graph" INTEGER, "nie:copyright" TEXT +COLLATE NOCASE, "nie:copyright:graph" INTEGER, "nie:comment" TEXT +COLLATE NOCASE, "nie:comment:graph" INTEGER, "nie:isStoredAs" +INTEGER, "nie:isStoredAs:graph" INTEGER, "nie:version" TEXT COLLATE +NOCASE, "nie:version:graph" INTEGER, "nie:contentCreated" INTEGER, +"nie:contentCreated:graph" INTEGER, "nie:contentCreated:localDate" +INTEGER, "nie:contentCreated:localTime" INTEGER, "nie:contentAccessed" +INTEGER, "nie:contentAccessed:graph" INTEGER, +"nie:contentAccessed:localDate" INTEGER, +"nie:contentAccessed:localTime" INTEGER, "nie:license" TEXT COLLATE +NOCASE, "nie:license:graph" INTEGER, "nie:identifier" TEXT COLLATE +NOCASE, "nie:identifier:graph" INTEGER, "nie:licenseType" TEXT +COLLATE NOCASE, "nie:licenseType:graph" INTEGER, "nie:characterSet" +TEXT COLLATE NOCASE, "nie:characterSet:graph" INTEGER, +"nie:contentSize" INTEGER, "nie:contentSize:graph" INTEGER, +"nie:rootElementOf" INTEGER, "nie:rootElementOf:graph" INTEGER, +"nie:usageCounter" INTEGER, "nie:usageCounter:graph" INTEGER, +"nco:publisher" INTEGER, "nco:publisher:graph" INTEGER, +"nfo:isContentEncrypted" INTEGER, "nfo:isContentEncrypted:graph" +INTEGER, "slo:location" INTEGER, "slo:location:graph" INTEGER, +"nfo:isBootable" INTEGER, "nfo:isBootable:graph" INTEGER, "osinfo:id" +TEXT COLLATE NOCASE, "osinfo:id:graph" INTEGER, "osinfo:mediaId" TEXT +COLLATE NOCASE, "osinfo:mediaId:graph" INTEGER); +CREATE TABLE "nie:InformationElement_mlo:location" (ID INTEGER NOT +NULL, "mlo:location" INTEGER NOT NULL, "mlo:location:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nao:hasProperty" (ID INTEGER NOT +NULL, "nao:hasProperty" INTEGER NOT NULL, "nao:hasProperty:graph" +INTEGER); +CREATE TABLE "nie:InformationElement_nco:contributor" (ID INTEGER NOT +NULL, "nco:contributor" INTEGER NOT NULL, "nco:contributor:graph" +INTEGER); +CREATE TABLE "nie:InformationElement_nco:creator" (ID INTEGER NOT +NULL, "nco:creator" INTEGER NOT NULL, "nco:creator:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:hasLogicalPart" (ID INTEGER +NOT NULL, "nie:hasLogicalPart" INTEGER NOT NULL, +"nie:hasLogicalPart:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:hasPart" (ID INTEGER NOT +NULL, "nie:hasPart" INTEGER NOT NULL, "nie:hasPart:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:informationElementDate" (ID +INTEGER NOT NULL, "nie:informationElementDate" INTEGER NOT NULL, +"nie:informationElementDate:graph" INTEGER, +"nie:informationElementDate:localDate" INTEGER NOT NULL, +"nie:informationElementDate:localTime" INTEGER NOT NULL); +CREATE TABLE "nie:InformationElement_nie:isLogicalPartOf" (ID INTEGER +NOT NULL, "nie:isLogicalPartOf" INTEGER NOT NULL, +"nie:isLogicalPartOf:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:keyword" (ID INTEGER NOT +NULL, "nie:keyword" TEXT NOT NULL, "nie:keyword:graph" INTEGER); +CREATE TABLE "nie:InformationElement_nie:relatedTo" (ID INTEGER NOT +NULL, "nie:relatedTo" INTEGER NOT NULL, "nie:relatedTo:graph" +INTEGER); +CREATE TABLE "nmm:AnalogRadio" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:modulation" INTEGER, "nmm:modulation:graph" INTEGER, +"nmm:frequency" INTEGER, "nmm:frequency:graph" INTEGER); +CREATE TABLE "nmm:Artist" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:artistName" TEXT COLLATE NOCASE, "nmm:artistName:graph" +INTEGER); +CREATE TABLE "nmm:DigitalRadio" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:streamingBitrate" INTEGER, "nmm:streamingBitrate:graph" INTEGER, +"nmm:encoding" TEXT COLLATE NOCASE, "nmm:encoding:graph" INTEGER, +"nmm:protocol" TEXT COLLATE NOCASE, "nmm:protocol:graph" INTEGER); +CREATE TABLE "nmm:Flash" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:ImageList" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:MeteringMode" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:MusicAlbum" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nmm:albumTrackCount" INTEGER, "nmm:albumTrackCount:graph" INTEGER, +"nmm:albumTitle" TEXT COLLATE NOCASE, "nmm:albumTitle:graph" INTEGER, +"nmm:albumDuration" INTEGER, "nmm:albumDuration:graph" INTEGER, +"nmm:albumGain" INTEGER, "nmm:albumGain:graph" INTEGER, +"nmm:albumPeakGain" INTEGER, "nmm:albumPeakGain:graph" INTEGER); +CREATE TABLE "nmm:MusicAlbumDisc" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:albumDiscAlbum" INTEGER, "nmm:albumDiscAlbum:graph" INTEGER, +"nmm:musicCDIdentifier" TEXT COLLATE NOCASE, +"nmm:musicCDIdentifier:graph" INTEGER, "nmm:setNumber" INTEGER, +"nmm:setNumber:graph" INTEGER); +CREATE TABLE "nmm:MusicAlbum_nmm:albumArtist" (ID INTEGER NOT NULL, +"nmm:albumArtist" INTEGER NOT NULL, "nmm:albumArtist:graph" INTEGER); +CREATE TABLE "nmm:MusicPiece" (ID INTEGER NOT NULL PRIMARY KEY, +"nie:title" TEXT COLLATE NOCASE, "nie:title:graph" INTEGER, +"nmm:musicAlbum" INTEGER, "nmm:musicAlbum:graph" INTEGER, +"nmm:musicAlbumDisc" INTEGER, "nmm:musicAlbumDisc:graph" INTEGER, +"nmm:beatsPerMinute" INTEGER, "nmm:beatsPerMinute:graph" INTEGER, +"nmm:performer" INTEGER, "nmm:performer:graph" INTEGER, "nmm:composer" +INTEGER, "nmm:composer:graph" INTEGER, "nmm:lyricist" INTEGER, +"nmm:lyricist:graph" INTEGER, "nmm:trackNumber" INTEGER, +"nmm:trackNumber:graph" INTEGER, +"nmm:internationalStandardRecordingCode" TEXT COLLATE NOCASE, +"nmm:internationalStandardRecordingCode:graph" INTEGER); +CREATE TABLE "nmm:MusicPiece_nmm:lyrics" (ID INTEGER NOT NULL, +"nmm:lyrics" INTEGER NOT NULL, "nmm:lyrics:graph" INTEGER); +CREATE TABLE "nmm:Photo" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:exposureTime" REAL, "nmm:exposureTime:graph" INTEGER, "nmm:flash" +INTEGER, "nmm:flash:graph" INTEGER, "nmm:fnumber" REAL, +"nmm:fnumber:graph" INTEGER, "nmm:focalLength" REAL, +"nmm:focalLength:graph" INTEGER, "nmm:isoSpeed" REAL, +"nmm:isoSpeed:graph" INTEGER, "nmm:meteringMode" INTEGER, +"nmm:meteringMode:graph" INTEGER, "nmm:whiteBalance" INTEGER, +"nmm:whiteBalance:graph" INTEGER, "nmm:isCropped" INTEGER, +"nmm:isCropped:graph" INTEGER, "nmm:isColorCorrected" INTEGER, +"nmm:isColorCorrected:graph" INTEGER); +CREATE TABLE "nmm:Playlist" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:RadioModulation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmm:RadioStation" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:radioIcon" INTEGER, "nmm:radioIcon:graph" INTEGER, "nmm:radioPTY" +INTEGER, "nmm:radioPTY:graph" INTEGER); +CREATE TABLE "nmm:RadioStation_nmm:carrier" (ID INTEGER NOT NULL, +"nmm:carrier" INTEGER NOT NULL, "nmm:carrier:graph" INTEGER); +CREATE TABLE "nmm:SynchronizedText" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:isForHearingImpaired" INTEGER, "nmm:isForHearingImpaired:graph" +INTEGER); +CREATE TABLE "nmm:Video" (ID INTEGER NOT NULL PRIMARY KEY, +"nmm:videoAlbum" INTEGER, "nmm:videoAlbum:graph" INTEGER, +"nmm:isSeries" INTEGER, "nmm:isSeries:graph" INTEGER, "nmm:season" +INTEGER, "nmm:season:graph" INTEGER, "nmm:episodeNumber" INTEGER, +"nmm:episodeNumber:graph" INTEGER, "nmm:runTime" INTEGER, +"nmm:runTime:graph" INTEGER, "nmm:synopsis" TEXT COLLATE NOCASE, +"nmm:synopsis:graph" INTEGER, "nmm:MPAARating" TEXT COLLATE NOCASE, +"nmm:MPAARating:graph" INTEGER, "nmm:category" TEXT COLLATE NOCASE, +"nmm:category:graph" INTEGER, "nmm:producedBy" INTEGER, +"nmm:producedBy:graph" INTEGER, "nmm:hasSubtitle" INTEGER, +"nmm:hasSubtitle:graph" INTEGER, "nmm:isContentEncrypted" INTEGER, +"nmm:isContentEncrypted:graph" INTEGER, "mtp:fourCC" TEXT COLLATE +NOCASE, "mtp:fourCC:graph" INTEGER, "mtp:waveformat" TEXT COLLATE +NOCASE, "mtp:waveformat:graph" INTEGER); +CREATE TABLE "nmm:Video_mtp:scantype" (ID INTEGER NOT NULL, +"mtp:scantype" INTEGER NOT NULL, "mtp:scantype:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:director" (ID INTEGER NOT NULL, +"nmm:director" INTEGER NOT NULL, "nmm:director:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:leadActor" (ID INTEGER NOT NULL, +"nmm:leadActor" INTEGER NOT NULL, "nmm:leadActor:graph" INTEGER); +CREATE TABLE "nmm:Video_nmm:subtitle" (ID INTEGER NOT NULL, +"nmm:subtitle" INTEGER NOT NULL, "nmm:subtitle:graph" INTEGER); +CREATE TABLE "nmm:WhiteBalance" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Attachment" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Call" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:sentDate" INTEGER, "nmo:sentDate:graph" INTEGER, +"nmo:sentDate:localDate" INTEGER, "nmo:sentDate:localTime" INTEGER, +"nmo:duration" INTEGER, "nmo:duration:graph" INTEGER); +CREATE TABLE "nmo:CommunicationChannel" (ID INTEGER NOT NULL PRIMARY +KEY, "nmo:lastMessageDate" INTEGER, "nmo:lastMessageDate:graph" +INTEGER, "nmo:lastMessageDate:localDate" INTEGER, +"nmo:lastMessageDate:localTime" INTEGER, +"nmo:lastSuccessfulMessageDate" INTEGER, +"nmo:lastSuccessfulMessageDate:graph" INTEGER, +"nmo:lastSuccessfulMessageDate:localDate" INTEGER, +"nmo:lastSuccessfulMessageDate:localTime" INTEGER); +CREATE TABLE "nmo:CommunicationChannel_nmo:hasParticipant" (ID INTEGER +NOT NULL, "nmo:hasParticipant" INTEGER NOT NULL, +"nmo:hasParticipant:graph" INTEGER); +CREATE TABLE "nmo:Conversation" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:DeliveryStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Email" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:hasContent" INTEGER, "nmo:hasContent:graph" INTEGER, +"nmo:isFlagged" INTEGER, "nmo:isFlagged:graph" INTEGER, "nmo:isRecent" +INTEGER, "nmo:isRecent:graph" INTEGER, "nmo:status" TEXT COLLATE +NOCASE, "nmo:status:graph" INTEGER, "nmo:responseType" TEXT COLLATE +NOCASE, "nmo:responseType:graph" INTEGER); +CREATE TABLE "nmo:Email_nmo:contentMimeType" (ID INTEGER NOT NULL, +"nmo:contentMimeType" TEXT NOT NULL, "nmo:contentMimeType:graph" +INTEGER); +CREATE TABLE "nmo:IMMessage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:MMSMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:mmsHasContent" INTEGER, "nmo:mmsHasContent:graph" INTEGER); +CREATE TABLE "nmo:MailAccount" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:accountName" TEXT COLLATE NOCASE, "nmo:accountName:graph" +INTEGER, "nmo:accountDisplayName" TEXT COLLATE NOCASE, +"nmo:accountDisplayName:graph" INTEGER, "nmo:fromAddress" INTEGER, +"nmo:fromAddress:graph" INTEGER, "nmo:signature" TEXT COLLATE NOCASE, +"nmo:signature:graph" INTEGER); +CREATE TABLE "nmo:MailFolder" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:folderName" TEXT COLLATE NOCASE, "nmo:folderName:graph" INTEGER, +"nmo:serverCount" INTEGER, "nmo:serverCount:graph" INTEGER, +"nmo:serverUnreadCount" INTEGER, "nmo:serverUnreadCount:graph" +INTEGER); +CREATE TABLE "nmo:MailboxDataObject" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Message" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:sentDate" INTEGER, "nmo:sentDate:graph" INTEGER, +"nmo:sentDate:localDate" INTEGER, "nmo:sentDate:localTime" INTEGER, +"nmo:from" INTEGER, "nmo:from:graph" INTEGER, "nmo:isAnswered" +INTEGER, "nmo:isAnswered:graph" INTEGER, "nmo:isDeleted" INTEGER, +"nmo:isDeleted:graph" INTEGER, "nmo:isDraft" INTEGER, +"nmo:isDraft:graph" INTEGER, "nmo:isRead" INTEGER, "nmo:isRead:graph" +INTEGER, "nmo:isSent" INTEGER, "nmo:isSent:graph" INTEGER, +"nmo:isEmergency" INTEGER, "nmo:isEmergency:graph" INTEGER, +"nmo:htmlMessageContent" TEXT COLLATE NOCASE, +"nmo:htmlMessageContent:graph" INTEGER, "nmo:messageId" TEXT COLLATE +NOCASE, "nmo:messageId:graph" INTEGER, "nmo:messageSubject" TEXT +COLLATE NOCASE, "nmo:messageSubject:graph" INTEGER, +"nmo:receivedDate" INTEGER, "nmo:receivedDate:graph" INTEGER, +"nmo:receivedDate:localDate" INTEGER, "nmo:receivedDate:localTime" +INTEGER, "nmo:replyTo" INTEGER, "nmo:replyTo:graph" INTEGER, +"nmo:sender" INTEGER, "nmo:sender:graph" INTEGER, "nmo:conversation" +INTEGER, "nmo:conversation:graph" INTEGER, "nmo:communicationChannel" +INTEGER, "nmo:communicationChannel:graph" INTEGER, +"nmo:deliveryStatus" INTEGER, "nmo:deliveryStatus:graph" INTEGER, +"nmo:reportDelivery" INTEGER, "nmo:reportDelivery:graph" INTEGER, +"nmo:sentWithReportRead" INTEGER, "nmo:sentWithReportRead:graph" +INTEGER, "nmo:reportReadStatus" INTEGER, "nmo:reportReadStatus:graph" +INTEGER, "nmo:mustAnswerReportRead" INTEGER, +"nmo:mustAnswerReportRead:graph" INTEGER, "nmo:mmsId" TEXT COLLATE +NOCASE, "nmo:mmsId:graph" INTEGER); +CREATE TABLE "nmo:MessageHeader" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:headerName" TEXT COLLATE NOCASE, "nmo:headerName:graph" INTEGER, +"nmo:headerValue" TEXT COLLATE NOCASE, "nmo:headerValue:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:bcc" (ID INTEGER NOT NULL, "nmo:bcc" +INTEGER NOT NULL, "nmo:bcc:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:cc" (ID INTEGER NOT NULL, "nmo:cc" +INTEGER NOT NULL, "nmo:cc:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:hasAttachment" (ID INTEGER NOT NULL, +"nmo:hasAttachment" INTEGER NOT NULL, "nmo:hasAttachment:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:inReplyTo" (ID INTEGER NOT NULL, +"nmo:inReplyTo" INTEGER NOT NULL, "nmo:inReplyTo:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:messageHeader" (ID INTEGER NOT NULL, +"nmo:messageHeader" INTEGER NOT NULL, "nmo:messageHeader:graph" +INTEGER); +CREATE TABLE "nmo:Message_nmo:recipient" (ID INTEGER NOT NULL, +"nmo:recipient" INTEGER NOT NULL, "nmo:recipient:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:references" (ID INTEGER NOT NULL, +"nmo:references" INTEGER NOT NULL, "nmo:references:graph" INTEGER); +CREATE TABLE "nmo:Message_nmo:to" (ID INTEGER NOT NULL, "nmo:to" +INTEGER NOT NULL, "nmo:to:graph" INTEGER); +CREATE TABLE "nmo:MimePart" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:charSet" TEXT COLLATE NOCASE, "nmo:charSet:graph" INTEGER, +"nmo:contentId" TEXT COLLATE NOCASE, "nmo:contentId:graph" INTEGER, +"nmo:contentTransferEncoding" TEXT COLLATE NOCASE, +"nmo:contentTransferEncoding:graph" INTEGER, "nmo:contentDescription" +TEXT COLLATE NOCASE, "nmo:contentDescription:graph" INTEGER, +"nmo:contentDisposition" TEXT COLLATE NOCASE, +"nmo:contentDisposition:graph" INTEGER); +CREATE TABLE "nmo:MimePart_nmo:mimeHeader" (ID INTEGER NOT NULL, +"nmo:mimeHeader" INTEGER NOT NULL, "nmo:mimeHeader:graph" INTEGER); +CREATE TABLE "nmo:Multipart" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:Multipart_nmo:partBoundary" (ID INTEGER NOT NULL, +"nmo:partBoundary" TEXT NOT NULL, "nmo:partBoundary:graph" INTEGER); +CREATE TABLE "nmo:PermanentChannel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:PhoneMessage" (ID INTEGER NOT NULL PRIMARY KEY, +"nmo:fromVCard" INTEGER, "nmo:fromVCard:graph" INTEGER, "nmo:encoding" +TEXT COLLATE NOCASE, "nmo:encoding:graph" INTEGER, +"nmo:phoneMessageId" INTEGER, "nmo:phoneMessageId:graph" INTEGER, +"nmo:validityPeriod" INTEGER, "nmo:validityPeriod:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder" (ID INTEGER NOT NULL PRIMARY +KEY, "nmo:phoneMessageFolderId" TEXT COLLATE NOCASE, +"nmo:phoneMessageFolderId:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder_nmo:containsPhoneMessage" (ID +INTEGER NOT NULL, "nmo:containsPhoneMessage" INTEGER NOT NULL, +"nmo:containsPhoneMessage:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder" +(ID INTEGER NOT NULL, "nmo:containsPhoneMessageFolder" INTEGER NOT +NULL, "nmo:containsPhoneMessageFolder:graph" INTEGER); +CREATE TABLE "nmo:PhoneMessage_nmo:toVCard" (ID INTEGER NOT NULL, +"nmo:toVCard" INTEGER NOT NULL, "nmo:toVCard:graph" INTEGER); +CREATE TABLE "nmo:ReportReadStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:SMSMessage" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:TransientChannel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nmo:VOIPCall" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "nrl:InverseFunctionalProperty" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "osinfo:Installer" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "poi:ObjectOfInterest" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "rdf:Property" (ID INTEGER NOT NULL PRIMARY KEY, +"rdfs:domain" INTEGER, "rdfs:domain:graph" INTEGER, "rdfs:range" +INTEGER, "rdfs:range:graph" INTEGER, "tracker:indexed" INTEGER, +"tracker:indexed:graph" INTEGER, "tracker:secondaryIndex" INTEGER, +"tracker:secondaryIndex:graph" INTEGER, "tracker:fulltextIndexed" +INTEGER, "tracker:fulltextIndexed:graph" INTEGER, +"tracker:fulltextNoLimit" INTEGER, "tracker:fulltextNoLimit:graph" +INTEGER, "tracker:transient" INTEGER, "tracker:transient:graph" +INTEGER, "tracker:weight" INTEGER, "tracker:weight:graph" INTEGER, +"tracker:defaultValue" TEXT COLLATE NOCASE, +"tracker:defaultValue:graph" INTEGER, "nrl:maxCardinality" INTEGER, +"nrl:maxCardinality:graph" INTEGER, "tracker:writeback" INTEGER, +"tracker:writeback:graph" INTEGER, "tracker:forceJournal" INTEGER, +"tracker:forceJournal:graph" INTEGER); +CREATE TABLE "rdf:Property_rdfs:subPropertyOf" (ID INTEGER NOT NULL, +"rdfs:subPropertyOf" INTEGER NOT NULL, "rdfs:subPropertyOf:graph" +INTEGER); +CREATE TABLE "rdfs:Class" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:notify" INTEGER, "tracker:notify:graph" INTEGER); +CREATE TABLE "rdfs:Class_rdfs:subClassOf" (ID INTEGER NOT NULL, +"rdfs:subClassOf" INTEGER NOT NULL, "rdfs:subClassOf:graph" INTEGER); +CREATE TABLE "rdfs:Class_tracker:domainIndex" (ID INTEGER NOT NULL, +"tracker:domainIndex" INTEGER NOT NULL, "tracker:domainIndex:graph" +INTEGER); +CREATE TABLE "rdfs:Literal" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "rdfs:Resource" (ID INTEGER NOT NULL PRIMARY KEY, +Available INTEGER NOT NULL, "rdfs:comment" TEXT COLLATE NOCASE, +"rdfs:comment:graph" INTEGER, "rdfs:label" TEXT COLLATE NOCASE, +"rdfs:label:graph" INTEGER, "tracker:added" INTEGER, +"tracker:added:graph" INTEGER, "tracker:added:localDate" INTEGER, +"tracker:added:localTime" INTEGER, "tracker:modified" INTEGER, +"tracker:modified:graph" INTEGER, "tracker:damaged" INTEGER, +"tracker:damaged:graph" INTEGER, "dc:title" TEXT COLLATE NOCASE, +"dc:title:graph" INTEGER, "dc:creator" TEXT COLLATE NOCASE, +"dc:creator:graph" INTEGER, "dc:subject" TEXT COLLATE NOCASE, +"dc:subject:graph" INTEGER, "dc:description" TEXT COLLATE NOCASE, +"dc:description:graph" INTEGER, "dc:publisher" TEXT COLLATE NOCASE, +"dc:publisher:graph" INTEGER, "dc:type" TEXT COLLATE NOCASE, +"dc:type:graph" INTEGER, "dc:format" TEXT COLLATE NOCASE, +"dc:format:graph" INTEGER, "dc:identifier" TEXT COLLATE NOCASE, +"dc:identifier:graph" INTEGER, "dc:language" TEXT COLLATE NOCASE, +"dc:language:graph" INTEGER, "dc:coverage" TEXT COLLATE NOCASE, +"dc:coverage:graph" INTEGER, "dc:rights" TEXT COLLATE NOCASE, +"dc:rights:graph" INTEGER, "nao:identifier" TEXT COLLATE NOCASE, +"nao:identifier:graph" INTEGER, "nao:numericRating" REAL, +"nao:numericRating:graph" INTEGER, "nao:lastModified" INTEGER, +"nao:lastModified:graph" INTEGER, "nao:lastModified:localDate" +INTEGER, "nao:lastModified:localTime" INTEGER); +CREATE TABLE "rdfs:Resource_dc:contributor" (ID INTEGER NOT NULL, +"dc:contributor" TEXT NOT NULL, "dc:contributor:graph" INTEGER); +CREATE TABLE "rdfs:Resource_dc:date" (ID INTEGER NOT NULL, "dc:date" +INTEGER NOT NULL, "dc:date:graph" INTEGER, "dc:date:localDate" INTEGER +NOT NULL, "dc:date:localTime" INTEGER NOT NULL); +CREATE TABLE "rdfs:Resource_dc:relation" (ID INTEGER NOT NULL, +"dc:relation" TEXT NOT NULL, "dc:relation:graph" INTEGER); +CREATE TABLE "rdfs:Resource_dc:source" (ID INTEGER NOT NULL, +"dc:source" INTEGER NOT NULL, "dc:source:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:deprecated" (ID INTEGER NOT NULL, +"nao:deprecated" INTEGER NOT NULL, "nao:deprecated:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:hasTag" (ID INTEGER NOT NULL, +"nao:hasTag" INTEGER NOT NULL, "nao:hasTag:graph" INTEGER); +CREATE TABLE "rdfs:Resource_nao:isRelated" (ID INTEGER NOT NULL, +"nao:isRelated" INTEGER NOT NULL, "nao:isRelated:graph" INTEGER); +CREATE TABLE "rdfs:Resource_rdf:type" (ID INTEGER NOT NULL, "rdf:type" +INTEGER NOT NULL, "rdf:type:graph" INTEGER); +CREATE TABLE "scal:AccessLevel" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:AttendanceStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Attendee" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:attendanceStatus" INTEGER, "scal:attendanceStatus:graph" +INTEGER, "scal:attendeeRole" INTEGER, "scal:attendeeRole:graph" +INTEGER, "scal:attendeeContact" INTEGER, "scal:attendeeContact:graph" +INTEGER, "scal:rsvp" INTEGER, "scal:rsvp:graph" INTEGER, +"scal:calendarUserType" INTEGER, "scal:calendarUserType:graph" +INTEGER); +CREATE TABLE "scal:AttendeeRole" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Attendee_scal:delegated-from" (ID INTEGER NOT NULL, +"scal:delegated-from" INTEGER NOT NULL, "scal:delegated-from:graph" +INTEGER); +CREATE TABLE "scal:Attendee_scal:delegated-to" (ID INTEGER NOT NULL, +"scal:delegated-to" INTEGER NOT NULL, "scal:delegated-to:graph" +INTEGER); +CREATE TABLE "scal:Attendee_scal:member" (ID INTEGER NOT NULL, +"scal:member" INTEGER NOT NULL, "scal:member:graph" INTEGER); +CREATE TABLE "scal:Attendee_scal:sent-by" (ID INTEGER NOT NULL, +"scal:sent-by" INTEGER NOT NULL, "scal:sent-by:graph" INTEGER); +CREATE TABLE "scal:Calendar" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:CalendarAlarm" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:alarmOffset" INTEGER, "scal:alarmOffset:graph" INTEGER); +CREATE TABLE "scal:CalendarAlarm_scal:alarmAttendee" (ID INTEGER NOT +NULL, "scal:alarmAttendee" INTEGER NOT NULL, +"scal:alarmAttendee:graph" INTEGER); +CREATE TABLE "scal:CalendarItem" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:textLocation" INTEGER, "scal:textLocation:graph" INTEGER, +"scal:resources" TEXT COLLATE NOCASE, "scal:resources:graph" INTEGER, +"scal:transparency" INTEGER, "scal:transparency:graph" INTEGER, +"scal:calendarItemAlarm" INTEGER, "scal:calendarItemAlarm:graph" +INTEGER, "scal:start" INTEGER, "scal:start:graph" INTEGER, "scal:end" +INTEGER, "scal:end:graph" INTEGER, "scal:isAllDay" INTEGER, +"scal:isAllDay:graph" INTEGER, "scal:priority" INTEGER, +"scal:priority:graph" INTEGER, "scal:rdate" INTEGER, +"scal:rdate:graph" INTEGER, "scal:exceptionRDate" INTEGER, +"scal:exceptionRDate:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:access" (ID INTEGER NOT NULL, +"scal:access" INTEGER NOT NULL, "scal:access:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:attachment" (ID INTEGER NOT NULL, +"scal:attachment" INTEGER NOT NULL, "scal:attachment:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:attendee" (ID INTEGER NOT NULL, +"scal:attendee" INTEGER NOT NULL, "scal:attendee:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:belongsToCalendar" (ID INTEGER +NOT NULL, "scal:belongsToCalendar" INTEGER NOT NULL, +"scal:belongsToCalendar:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:contact" (ID INTEGER NOT NULL, +"scal:contact" INTEGER NOT NULL, "scal:contact:graph" INTEGER); +CREATE TABLE "scal:CalendarItem_scal:rrule" (ID INTEGER NOT NULL, +"scal:rrule" INTEGER NOT NULL, "scal:rrule:graph" INTEGER); +CREATE TABLE "scal:CalendarUserType" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Event" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:eventStatus" INTEGER, "scal:eventStatus:graph" INTEGER); +CREATE TABLE "scal:EventStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:Journal" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:journalStatus" INTEGER, "scal:journalStatus:graph" INTEGER); +CREATE TABLE "scal:JournalStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:RSVPValues" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:RecurrenceRule" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:recurrencePattern" TEXT COLLATE NOCASE, +"scal:recurrencePattern:graph" INTEGER, "scal:recurrenceStartDate" +INTEGER, "scal:recurrenceStartDate:graph" INTEGER, "scal:exception" +INTEGER, "scal:exception:graph" INTEGER); +CREATE TABLE "scal:TimePoint" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:dateTime" INTEGER, "scal:dateTime:graph" INTEGER, +"scal:dateTime:localDate" INTEGER, "scal:dateTime:localTime" INTEGER, +"scal:TimeZone" TEXT COLLATE NOCASE, "scal:TimeZone:graph" INTEGER); +CREATE TABLE "scal:Todo" (ID INTEGER NOT NULL PRIMARY KEY, +"scal:todoStatus" INTEGER, "scal:todoStatus:graph" INTEGER, "scal:due" +INTEGER, "scal:due:graph" INTEGER, "scal:completed" INTEGER, +"scal:completed:graph" INTEGER, "scal:percentComplete" INTEGER, +"scal:percentComplete:graph" INTEGER); +CREATE TABLE "scal:TodoStatus" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "scal:TransparencyValues" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "slo:GeoLocation" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:latitude" REAL, "slo:latitude:graph" INTEGER, "slo:longitude" +REAL, "slo:longitude:graph" INTEGER, "slo:verticalAccuracy" REAL, +"slo:verticalAccuracy:graph" INTEGER, "slo:horizontalAccuracy" REAL, +"slo:horizontalAccuracy:graph" INTEGER, "slo:altitude" REAL, +"slo:altitude:graph" INTEGER, "slo:boundingLatitudeMin" REAL, +"slo:boundingLatitudeMin:graph" INTEGER, "slo:boundingLatitudeMax" +REAL, "slo:boundingLatitudeMax:graph" INTEGER, +"slo:boundingLongitudeMin" REAL, "slo:boundingLongitudeMin:graph" +INTEGER, "slo:boundingLongitudeMax" REAL, +"slo:boundingLongitudeMax:graph" INTEGER, "slo:radius" REAL, +"slo:radius:graph" INTEGER, "slo:timestamp" INTEGER, +"slo:timestamp:graph" INTEGER, "slo:timestamp:localDate" INTEGER, +"slo:timestamp:localTime" INTEGER, "slo:postalAddress" INTEGER, +"slo:postalAddress:graph" INTEGER); +CREATE TABLE "slo:Landmark" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:iconUrl" INTEGER, "slo:iconUrl:graph" INTEGER); +CREATE TABLE "slo:LandmarkCategory" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:isRemovable" INTEGER, "slo:isRemovable:graph" INTEGER, +"slo:categoryIconUrl" INTEGER, "slo:categoryIconUrl:graph" INTEGER); +CREATE TABLE "slo:Landmark_slo:belongsToCategory" (ID INTEGER NOT +NULL, "slo:belongsToCategory" INTEGER NOT NULL, +"slo:belongsToCategory:graph" INTEGER); +CREATE TABLE "slo:Landmark_slo:hasContact" (ID INTEGER NOT NULL, +"slo:hasContact" INTEGER NOT NULL, "slo:hasContact:graph" INTEGER); +CREATE TABLE "slo:Route" (ID INTEGER NOT NULL PRIMARY KEY, +"slo:startTime" INTEGER, "slo:startTime:graph" INTEGER, +"slo:startTime:localDate" INTEGER, "slo:startTime:localTime" INTEGER, +"slo:endTime" INTEGER, "slo:endTime:graph" INTEGER, +"slo:endTime:localDate" INTEGER, "slo:endTime:localTime" INTEGER); +CREATE TABLE "slo:Route_slo:routeDetails" (ID INTEGER NOT NULL, +"slo:routeDetails" TEXT NOT NULL, "slo:routeDetails:graph" INTEGER); +CREATE TABLE "tracker:Namespace" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:prefix" TEXT COLLATE NOCASE, "tracker:prefix:graph" +INTEGER); +CREATE TABLE "tracker:Ontology" (ID INTEGER NOT NULL PRIMARY KEY); +CREATE TABLE "tracker:Volume" (ID INTEGER NOT NULL PRIMARY KEY, +"tracker:isMounted" INTEGER, "tracker:isMounted:graph" INTEGER, +"tracker:unmountDate" INTEGER, "tracker:unmountDate:graph" INTEGER, +"tracker:unmountDate:localDate" INTEGER, +"tracker:unmountDate:localTime" INTEGER, "tracker:mountPoint" INTEGER, +"tracker:mountPoint:graph" INTEGER, "tracker:isRemovable" INTEGER, +"tracker:isRemovable:graph" INTEGER, "tracker:isOptical" INTEGER, +"tracker:isOptical:graph" INTEGER); +CREATE UNIQUE INDEX "mfo:FeedMessage_mfo:enclosureList_ID_ID" ON +"mfo:FeedMessage_mfo:enclosureList" (ID, "mfo:enclosureList"); +CREATE UNIQUE INDEX "mlo:GeoBoundingBox_mlo:bbNorthWest_ID_ID" ON +"mlo:GeoBoundingBox_mlo:bbNorthWest" (ID, "mlo:bbNorthWest"); +CREATE UNIQUE INDEX "mlo:GeoBoundingBox_mlo:bbSouthEast_ID_ID" ON +"mlo:GeoBoundingBox_mlo:bbSouthEast" (ID, "mlo:bbSouthEast"); +CREATE INDEX "mlo:GeoLocation_mlo:asBoundingBox_ID" ON +"mlo:GeoLocation_mlo:asBoundingBox" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asBoundingBox_ID_ID" ON +"mlo:GeoLocation_mlo:asBoundingBox" ("mlo:asBoundingBox", ID); +CREATE INDEX "mlo:GeoLocation_mlo:asGeoPoint_ID" ON +"mlo:GeoLocation_mlo:asGeoPoint" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asGeoPoint_ID_ID" ON +"mlo:GeoLocation_mlo:asGeoPoint" ("mlo:asGeoPoint", ID); +CREATE INDEX "mlo:GeoLocation_mlo:asPostalAddress_ID" ON +"mlo:GeoLocation_mlo:asPostalAddress" (ID); +CREATE UNIQUE INDEX "mlo:GeoLocation_mlo:asPostalAddress_ID_ID" ON +"mlo:GeoLocation_mlo:asPostalAddress" ("mlo:asPostalAddress", ID); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:address_ID_ID" ON +"mlo:GeoPoint_mlo:address" (ID, "mlo:address"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:altitude_ID_ID" ON +"mlo:GeoPoint_mlo:altitude" (ID, "mlo:altitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:city_ID_ID" ON +"mlo:GeoPoint_mlo:city" (ID, "mlo:city"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:country_ID_ID" ON +"mlo:GeoPoint_mlo:country" (ID, "mlo:country"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:latitude_ID_ID" ON +"mlo:GeoPoint_mlo:latitude" (ID, "mlo:latitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:longitude_ID_ID" ON +"mlo:GeoPoint_mlo:longitude" (ID, "mlo:longitude"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:state_ID_ID" ON +"mlo:GeoPoint_mlo:state" (ID, "mlo:state"); +CREATE UNIQUE INDEX "mlo:GeoPoint_mlo:timestamp_ID_ID" ON +"mlo:GeoPoint_mlo:timestamp" (ID, "mlo:timestamp"); +CREATE UNIQUE INDEX "mlo:GeoSphere_mlo:radius_ID_ID" ON +"mlo:GeoSphere_mlo:radius" (ID, "mlo:radius"); +CREATE UNIQUE INDEX "mlo:LandmarkCategory_mlo:isRemovable_ID_ID" ON +"mlo:LandmarkCategory_mlo:isRemovable" (ID, "mlo:isRemovable"); +CREATE UNIQUE INDEX "mlo:Landmark_mlo:belongsToCategory_ID_ID" ON +"mlo:Landmark_mlo:belongsToCategory" (ID, "mlo:belongsToCategory"); +CREATE UNIQUE INDEX "mlo:Landmark_mlo:poiLocation_ID_ID" ON +"mlo:Landmark_mlo:poiLocation" (ID, "mlo:poiLocation"); +CREATE UNIQUE INDEX "mlo:LocationBoundingBox_mlo:boxEastLimit_ID_ID" +ON "mlo:LocationBoundingBox_mlo:boxEastLimit" (ID, +"mlo:boxEastLimit"); +CREATE UNIQUE INDEX "mlo:LocationBoundingBox_mlo:boxNorthLimit_ID_ID" +ON "mlo:LocationBoundingBox_mlo:boxNorthLimit" (ID, +"mlo:boxNorthLimit"); +CREATE UNIQUE INDEX +"mlo:LocationBoundingBox_mlo:boxSouthWestCorner_ID_ID" ON +"mlo:LocationBoundingBox_mlo:boxSouthWestCorner" (ID, +"mlo:boxSouthWestCorner"); +CREATE UNIQUE INDEX +"mlo:LocationBoundingBox_mlo:boxVerticalLimit_ID_ID" ON +"mlo:LocationBoundingBox_mlo:boxVerticalLimit" (ID, +"mlo:boxVerticalLimit"); +CREATE UNIQUE INDEX "mlo:Route_mlo:endTime_ID_ID" ON +"mlo:Route_mlo:endTime" (ID, "mlo:endTime"); +CREATE UNIQUE INDEX "mlo:Route_mlo:routeDetails_ID_ID" ON +"mlo:Route_mlo:routeDetails" (ID, "mlo:routeDetails"); +CREATE UNIQUE INDEX "mlo:Route_mlo:startTime_ID_ID" ON +"mlo:Route_mlo:startTime" (ID, "mlo:startTime"); +CREATE UNIQUE INDEX "mto:Transfer_mto:transferList_ID_ID" ON +"mto:Transfer_mto:transferList" (ID, "mto:transferList"); +CREATE UNIQUE INDEX "mto:Transfer_mto:transferPrivacyLevel_ID_ID" ON +"mto:Transfer_mto:transferPrivacyLevel" (ID, +"mto:transferPrivacyLevel"); +CREATE UNIQUE INDEX "mto:UploadTransfer_mto:transferCategory_ID_ID" ON +"mto:UploadTransfer_mto:transferCategory" (ID, +"mto:transferCategory"); +CREATE UNIQUE INDEX "nao:Tag_tracker:isDefaultTag_ID_ID" ON +"nao:Tag_tracker:isDefaultTag" (ID, "tracker:isDefaultTag"); +CREATE UNIQUE INDEX "nao:Tag_tracker:tagRelatedTo_ID_ID" ON +"nao:Tag_tracker:tagRelatedTo" (ID, "tracker:tagRelatedTo"); +CREATE UNIQUE INDEX "ncal:Alarm_ncal:action_ID_ID" ON +"ncal:Alarm_ncal:action" (ID, "ncal:action"); +CREATE UNIQUE INDEX "ncal:BydayRulePart_ncal:bydayModifier_ID_ID" ON +"ncal:BydayRulePart_ncal:bydayModifier" (ID, "ncal:bydayModifier"); +CREATE UNIQUE INDEX "ncal:BydayRulePart_ncal:bydayWeekday_ID_ID" ON +"ncal:BydayRulePart_ncal:bydayWeekday" (ID, "ncal:bydayWeekday"); +CREATE UNIQUE INDEX "ncal:Calendar_ncal:component_ID_ID" ON +"ncal:Calendar_ncal:component" (ID, "ncal:component"); +CREATE UNIQUE INDEX "ncal:Freebusy_ncal:freebusy_ID_ID" ON +"ncal:Freebusy_ncal:freebusy" (ID, "ncal:freebusy"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byday_ID_ID" ON +"ncal:RecurrenceRule_ncal:byday" (ID, "ncal:byday"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byhour_ID_ID" ON +"ncal:RecurrenceRule_ncal:byhour" (ID, "ncal:byhour"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byminute_ID_ID" ON +"ncal:RecurrenceRule_ncal:byminute" (ID, "ncal:byminute"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bymonth_ID_ID" ON +"ncal:RecurrenceRule_ncal:bymonth" (ID, "ncal:bymonth"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bymonthday_ID_ID" ON +"ncal:RecurrenceRule_ncal:bymonthday" (ID, "ncal:bymonthday"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bysecond_ID_ID" ON +"ncal:RecurrenceRule_ncal:bysecond" (ID, "ncal:bysecond"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:bysetpos_ID_ID" ON +"ncal:RecurrenceRule_ncal:bysetpos" (ID, "ncal:bysetpos"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byweekno_ID_ID" ON +"ncal:RecurrenceRule_ncal:byweekno" (ID, "ncal:byweekno"); +CREATE UNIQUE INDEX "ncal:RecurrenceRule_ncal:byyearday_ID_ID" ON +"ncal:RecurrenceRule_ncal:byyearday" (ID, "ncal:byyearday"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:attach_ID_ID" ON +"ncal:UnionParentClass_ncal:attach" (ID, "ncal:attach"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:attendee_ID_ID" ON +"ncal:UnionParentClass_ncal:attendee" (ID, "ncal:attendee"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:categories_ID_ID" ON +"ncal:UnionParentClass_ncal:categories" (ID, "ncal:categories"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:exdate_ID_ID" ON +"ncal:UnionParentClass_ncal:exdate" (ID, "ncal:exdate"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:exrule_ID_ID" ON +"ncal:UnionParentClass_ncal:exrule" (ID, "ncal:exrule"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:hasAlarm_ID_ID" ON +"ncal:UnionParentClass_ncal:hasAlarm" (ID, "ncal:hasAlarm"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:ncalRelation_ID_ID" ON +"ncal:UnionParentClass_ncal:ncalRelation" (ID, "ncal:ncalRelation"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:rdate_ID_ID" ON +"ncal:UnionParentClass_ncal:rdate" (ID, "ncal:rdate"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:relatedToChild_ID_ID" +ON "ncal:UnionParentClass_ncal:relatedToChild" (ID, +"ncal:relatedToChild"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:relatedToParent_ID_ID" +ON "ncal:UnionParentClass_ncal:relatedToParent" (ID, +"ncal:relatedToParent"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:resources_ID_ID" ON +"ncal:UnionParentClass_ncal:resources" (ID, "ncal:resources"); +CREATE UNIQUE INDEX "ncal:UnionParentClass_ncal:rrule_ID_ID" ON +"ncal:UnionParentClass_ncal:rrule" (ID, "ncal:rrule"); +CREATE UNIQUE INDEX "nco:Affiliation_nco:title_ID_ID" ON +"nco:Affiliation_nco:title" (ID, "nco:title"); +CREATE UNIQUE INDEX "nco:ContactList_nco:containsContact_ID_ID" ON +"nco:ContactList_nco:containsContact" (ID, "nco:containsContact"); +CREATE UNIQUE INDEX "nco:Contact_ncal:anniversary_ID_ID" ON +"nco:Contact_ncal:anniversary" (ID, "ncal:anniversary"); +CREATE UNIQUE INDEX "nco:Contact_ncal:birthday_ID_ID" ON +"nco:Contact_ncal:birthday" (ID, "ncal:birthday"); +CREATE UNIQUE INDEX "nco:Contact_nco:belongsToGroup_ID_ID" ON +"nco:Contact_nco:belongsToGroup" (ID, "nco:belongsToGroup"); +CREATE UNIQUE INDEX "nco:Contact_nco:note_ID_ID" ON +"nco:Contact_nco:note" (ID, "nco:note"); +CREATE UNIQUE INDEX "nco:Contact_scal:anniversary_ID_ID" ON +"nco:Contact_scal:anniversary" (ID, "scal:anniversary"); +CREATE UNIQUE INDEX "nco:Contact_scal:birthday_ID_ID" ON +"nco:Contact_scal:birthday" (ID, "scal:birthday"); +CREATE UNIQUE INDEX "nco:IMAccount_nco:hasIMContact_ID_ID" ON +"nco:IMAccount_nco:hasIMContact" (ID, "nco:hasIMContact"); +CREATE UNIQUE INDEX "nco:IMAddress_nco:imCapability_ID_ID" ON +"nco:IMAddress_nco:imCapability" (ID, "nco:imCapability"); +CREATE UNIQUE INDEX "nco:PersonContact_nco:hasAffiliation_ID_ID" ON +"nco:PersonContact_nco:hasAffiliation" (ID, "nco:hasAffiliation"); +CREATE INDEX "nco:PersonContact_nco:nameFamily" ON "nco:PersonContact" +("nco:nameFamily"); +CREATE INDEX "nco:PhoneNumber_nco:phoneNumber" ON "nco:PhoneNumber" +("nco:phoneNumber"); +CREATE UNIQUE INDEX "nco:Role_nco:blogUrl_ID_ID" ON +"nco:Role_nco:blogUrl" (ID, "nco:blogUrl"); +CREATE UNIQUE INDEX "nco:Role_nco:foafUrl_ID_ID" ON +"nco:Role_nco:foafUrl" (ID, "nco:foafUrl"); +CREATE UNIQUE INDEX "nco:Role_nco:hasContactMedium_ID_ID" ON +"nco:Role_nco:hasContactMedium" (ID, "nco:hasContactMedium"); +CREATE INDEX "nco:Role_nco:hasEmailAddress_ID" ON +"nco:Role_nco:hasEmailAddress" (ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasEmailAddress_ID_ID" ON +"nco:Role_nco:hasEmailAddress" ("nco:hasEmailAddress", ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasIMAddress_ID_ID" ON +"nco:Role_nco:hasIMAddress" (ID, "nco:hasIMAddress"); +CREATE UNIQUE INDEX "nco:Role_nco:hasPhoneNumber_ID_ID" ON +"nco:Role_nco:hasPhoneNumber" (ID, "nco:hasPhoneNumber"); +CREATE INDEX "nco:Role_nco:hasPostalAddress_ID" ON +"nco:Role_nco:hasPostalAddress" (ID); +CREATE UNIQUE INDEX "nco:Role_nco:hasPostalAddress_ID_ID" ON +"nco:Role_nco:hasPostalAddress" ("nco:hasPostalAddress", ID); +CREATE UNIQUE INDEX "nco:Role_nco:url_ID_ID" ON "nco:Role_nco:url" +(ID, "nco:url"); +CREATE UNIQUE INDEX "nco:Role_nco:websiteUrl_ID_ID" ON +"nco:Role_nco:websiteUrl" (ID, "nco:websiteUrl"); +CREATE UNIQUE INDEX +"nfo:BookmarkFolder_nfo:containsBookmarkFolder_ID_ID" ON +"nfo:BookmarkFolder_nfo:containsBookmarkFolder" (ID, +"nfo:containsBookmarkFolder"); +CREATE UNIQUE INDEX "nfo:BookmarkFolder_nfo:containsBookmark_ID_ID" ON +"nfo:BookmarkFolder_nfo:containsBookmark" (ID, +"nfo:containsBookmark"); +CREATE INDEX "nfo:FileDataObject_nfo:fileLastModified" ON +"nfo:FileDataObject" ("nfo:fileLastModified"); +CREATE UNIQUE INDEX "nfo:Image_nfo:depicts_ID_ID" ON +"nfo:Image_nfo:depicts" (ID, "nfo:depicts"); +CREATE UNIQUE INDEX "nfo:Image_nfo:hasRegionOfInterest_ID_ID" ON +"nfo:Image_nfo:hasRegionOfInterest" (ID, "nfo:hasRegionOfInterest"); +CREATE UNIQUE INDEX "nfo:MediaList_nfo:hasMediaFileListEntry_ID_ID" ON +"nfo:MediaList_nfo:hasMediaFileListEntry" (ID, +"nfo:hasMediaFileListEntry"); +CREATE UNIQUE INDEX "nfo:MediaList_nfo:mediaListEntry_ID_ID" ON +"nfo:MediaList_nfo:mediaListEntry" (ID, "nfo:mediaListEntry"); +CREATE UNIQUE INDEX "nfo:Media_mtp:hidden_ID_ID" ON +"nfo:Media_mtp:hidden" (ID, "mtp:hidden"); +CREATE UNIQUE INDEX "nfo:Media_nmm:alternativeMedia_ID_ID" ON +"nfo:Media_nmm:alternativeMedia" (ID, "nmm:alternativeMedia"); +CREATE INDEX "nfo:Visual_nie:contentCreated" ON "nfo:Visual" +("nie:contentCreated"); +CREATE UNIQUE INDEX "nid3:ID3Audio_nid3:leadArtist_ID_ID" ON +"nid3:ID3Audio_nid3:leadArtist" (ID, "nid3:leadArtist"); +CREATE UNIQUE INDEX "nie:DataObject_nie:dataSource_ID_ID" ON +"nie:DataObject_nie:dataSource" (ID, "nie:dataSource"); +CREATE UNIQUE INDEX "nie:DataObject_nie:isPartOf_ID_ID" ON +"nie:DataObject_nie:isPartOf" (ID, "nie:isPartOf"); +CREATE INDEX "nie:DataObject_nie:url" ON "nie:DataObject" ("nie:url"); +CREATE INDEX "nie:InformationElement_mlo:location_ID" ON +"nie:InformationElement_mlo:location" (ID); +CREATE UNIQUE INDEX "nie:InformationElement_mlo:location_ID_ID" ON +"nie:InformationElement_mlo:location" ("mlo:location", ID); +CREATE UNIQUE INDEX "nie:InformationElement_nao:hasProperty_ID_ID" ON +"nie:InformationElement_nao:hasProperty" (ID, "nao:hasProperty"); +CREATE UNIQUE INDEX "nie:InformationElement_nco:contributor_ID_ID" ON +"nie:InformationElement_nco:contributor" (ID, "nco:contributor"); +CREATE UNIQUE INDEX "nie:InformationElement_nco:creator_ID_ID" ON +"nie:InformationElement_nco:creator" (ID, "nco:creator"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:hasLogicalPart_ID_ID" +ON "nie:InformationElement_nie:hasLogicalPart" (ID, +"nie:hasLogicalPart"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:hasPart_ID_ID" ON +"nie:InformationElement_nie:hasPart" (ID, "nie:hasPart"); +CREATE UNIQUE INDEX +"nie:InformationElement_nie:informationElementDate_ID_ID" ON +"nie:InformationElement_nie:informationElementDate" (ID, +"nie:informationElementDate"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:isLogicalPartOf_ID_ID" +ON "nie:InformationElement_nie:isLogicalPartOf" (ID, +"nie:isLogicalPartOf"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:keyword_ID_ID" ON +"nie:InformationElement_nie:keyword" (ID, "nie:keyword"); +CREATE UNIQUE INDEX "nie:InformationElement_nie:relatedTo_ID_ID" ON +"nie:InformationElement_nie:relatedTo" (ID, "nie:relatedTo"); +CREATE INDEX "nie:InformationElement_slo:location" ON +"nie:InformationElement" ("slo:location"); +CREATE INDEX "nmm:Artist_nmm:artistName" ON "nmm:Artist" ("nmm:artistName"); +CREATE INDEX "nmm:MusicAlbum_nie:title" ON "nmm:MusicAlbum" ("nie:title"); +CREATE UNIQUE INDEX "nmm:MusicAlbum_nmm:albumArtist_ID_ID" ON +"nmm:MusicAlbum_nmm:albumArtist" (ID, "nmm:albumArtist"); +CREATE INDEX "nmm:MusicPiece_nie:title" ON "nmm:MusicPiece" ("nie:title"); +CREATE UNIQUE INDEX "nmm:MusicPiece_nmm:lyrics_ID_ID" ON +"nmm:MusicPiece_nmm:lyrics" (ID, "nmm:lyrics"); +CREATE INDEX "nmm:MusicPiece_nmm:musicAlbum" ON "nmm:MusicPiece" +("nmm:musicAlbum"); +CREATE INDEX "nmm:MusicPiece_nmm:performer" ON "nmm:MusicPiece" +("nmm:performer"); +CREATE UNIQUE INDEX "nmm:RadioStation_nmm:carrier_ID_ID" ON +"nmm:RadioStation_nmm:carrier" (ID, "nmm:carrier"); +CREATE UNIQUE INDEX "nmm:Video_mtp:scantype_ID_ID" ON +"nmm:Video_mtp:scantype" (ID, "mtp:scantype"); +CREATE UNIQUE INDEX "nmm:Video_nmm:director_ID_ID" ON +"nmm:Video_nmm:director" (ID, "nmm:director"); +CREATE UNIQUE INDEX "nmm:Video_nmm:leadActor_ID_ID" ON +"nmm:Video_nmm:leadActor" (ID, "nmm:leadActor"); +CREATE UNIQUE INDEX "nmm:Video_nmm:subtitle_ID_ID" ON +"nmm:Video_nmm:subtitle" (ID, "nmm:subtitle"); +CREATE INDEX "nmo:Call_nmo:sentDate" ON "nmo:Call" ("nmo:sentDate"); +CREATE INDEX "nmo:CommunicationChannel_nmo:hasParticipant_ID" ON +"nmo:CommunicationChannel_nmo:hasParticipant" (ID); +CREATE UNIQUE INDEX +"nmo:CommunicationChannel_nmo:hasParticipant_ID_ID" ON +"nmo:CommunicationChannel_nmo:hasParticipant" ("nmo:hasParticipant", +ID); +CREATE INDEX "nmo:CommunicationChannel_nmo:lastMessageDate" ON +"nmo:CommunicationChannel" ("nmo:lastMessageDate"); +CREATE UNIQUE INDEX "nmo:Email_nmo:contentMimeType_ID_ID" ON +"nmo:Email_nmo:contentMimeType" (ID, "nmo:contentMimeType"); +CREATE UNIQUE INDEX "nmo:Message_nmo:bcc_ID_ID" ON +"nmo:Message_nmo:bcc" (ID, "nmo:bcc"); +CREATE UNIQUE INDEX "nmo:Message_nmo:cc_ID_ID" ON "nmo:Message_nmo:cc" +(ID, "nmo:cc"); +CREATE INDEX "nmo:Message_nmo:communicationChannel" ON "nmo:Message" +("nmo:communicationChannel", "nmo:receivedDate"); +CREATE INDEX "nmo:Message_nmo:conversation" ON "nmo:Message" +("nmo:conversation"); +CREATE INDEX "nmo:Message_nmo:from" ON "nmo:Message" ("nmo:from"); +CREATE UNIQUE INDEX "nmo:Message_nmo:hasAttachment_ID_ID" ON +"nmo:Message_nmo:hasAttachment" (ID, "nmo:hasAttachment"); +CREATE UNIQUE INDEX "nmo:Message_nmo:inReplyTo_ID_ID" ON +"nmo:Message_nmo:inReplyTo" (ID, "nmo:inReplyTo"); +CREATE UNIQUE INDEX "nmo:Message_nmo:messageHeader_ID_ID" ON +"nmo:Message_nmo:messageHeader" (ID, "nmo:messageHeader"); +CREATE UNIQUE INDEX "nmo:Message_nmo:recipient_ID_ID" ON +"nmo:Message_nmo:recipient" (ID, "nmo:recipient"); +CREATE UNIQUE INDEX "nmo:Message_nmo:references_ID_ID" ON +"nmo:Message_nmo:references" (ID, "nmo:references"); +CREATE INDEX "nmo:Message_nmo:sender" ON "nmo:Message" ("nmo:sender"); +CREATE INDEX "nmo:Message_nmo:sentDate" ON "nmo:Message" ("nmo:sentDate"); +CREATE INDEX "nmo:Message_nmo:to_ID" ON "nmo:Message_nmo:to" (ID); +CREATE UNIQUE INDEX "nmo:Message_nmo:to_ID_ID" ON "nmo:Message_nmo:to" +("nmo:to", ID); +CREATE UNIQUE INDEX "nmo:MimePart_nmo:mimeHeader_ID_ID" ON +"nmo:MimePart_nmo:mimeHeader" (ID, "nmo:mimeHeader"); +CREATE UNIQUE INDEX "nmo:Multipart_nmo:partBoundary_ID_ID" ON +"nmo:Multipart_nmo:partBoundary" (ID, "nmo:partBoundary"); +CREATE UNIQUE INDEX +"nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder_ID_ID" ON +"nmo:PhoneMessageFolder_nmo:containsPhoneMessageFolder" (ID, +"nmo:containsPhoneMessageFolder"); +CREATE UNIQUE INDEX +"nmo:PhoneMessageFolder_nmo:containsPhoneMessage_ID_ID" ON +"nmo:PhoneMessageFolder_nmo:containsPhoneMessage" (ID, +"nmo:containsPhoneMessage"); +CREATE UNIQUE INDEX "nmo:PhoneMessage_nmo:toVCard_ID_ID" ON +"nmo:PhoneMessage_nmo:toVCard" (ID, "nmo:toVCard"); +CREATE UNIQUE INDEX "rdf:Property_rdfs:subPropertyOf_ID_ID" ON +"rdf:Property_rdfs:subPropertyOf" (ID, "rdfs:subPropertyOf"); +CREATE UNIQUE INDEX "rdfs:Class_rdfs:subClassOf_ID_ID" ON +"rdfs:Class_rdfs:subClassOf" (ID, "rdfs:subClassOf"); +CREATE UNIQUE INDEX "rdfs:Class_tracker:domainIndex_ID_ID" ON +"rdfs:Class_tracker:domainIndex" (ID, "tracker:domainIndex"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:contributor_ID_ID" ON +"rdfs:Resource_dc:contributor" (ID, "dc:contributor"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:date_ID_ID" ON +"rdfs:Resource_dc:date" (ID, "dc:date"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:relation_ID_ID" ON +"rdfs:Resource_dc:relation" (ID, "dc:relation"); +CREATE UNIQUE INDEX "rdfs:Resource_dc:source_ID_ID" ON +"rdfs:Resource_dc:source" (ID, "dc:source"); +CREATE UNIQUE INDEX "rdfs:Resource_nao:deprecated_ID_ID" ON +"rdfs:Resource_nao:deprecated" (ID, "nao:deprecated"); +CREATE INDEX "rdfs:Resource_nao:hasTag_ID" ON "rdfs:Resource_nao:hasTag" (ID); +CREATE UNIQUE INDEX "rdfs:Resource_nao:hasTag_ID_ID" ON +"rdfs:Resource_nao:hasTag" ("nao:hasTag", ID); +CREATE UNIQUE INDEX "rdfs:Resource_nao:isRelated_ID_ID" ON +"rdfs:Resource_nao:isRelated" (ID, "nao:isRelated"); +CREATE UNIQUE INDEX "rdfs:Resource_rdf:type_ID_ID" ON +"rdfs:Resource_rdf:type" (ID, "rdf:type"); +CREATE INDEX "rdfs:Resource_tracker:added" ON "rdfs:Resource" ("tracker:added"); +CREATE UNIQUE INDEX "scal:Attendee_scal:delegated-from_ID_ID" ON +"scal:Attendee_scal:delegated-from" (ID, "scal:delegated-from"); +CREATE UNIQUE INDEX "scal:Attendee_scal:delegated-to_ID_ID" ON +"scal:Attendee_scal:delegated-to" (ID, "scal:delegated-to"); +CREATE UNIQUE INDEX "scal:Attendee_scal:member_ID_ID" ON +"scal:Attendee_scal:member" (ID, "scal:member"); +CREATE UNIQUE INDEX "scal:Attendee_scal:sent-by_ID_ID" ON +"scal:Attendee_scal:sent-by" (ID, "scal:sent-by"); +CREATE UNIQUE INDEX "scal:CalendarAlarm_scal:alarmAttendee_ID_ID" ON +"scal:CalendarAlarm_scal:alarmAttendee" (ID, "scal:alarmAttendee"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:access_ID_ID" ON +"scal:CalendarItem_scal:access" (ID, "scal:access"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:attachment_ID_ID" ON +"scal:CalendarItem_scal:attachment" (ID, "scal:attachment"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:attendee_ID_ID" ON +"scal:CalendarItem_scal:attendee" (ID, "scal:attendee"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:belongsToCalendar_ID_ID" +ON "scal:CalendarItem_scal:belongsToCalendar" (ID, +"scal:belongsToCalendar"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:contact_ID_ID" ON +"scal:CalendarItem_scal:contact" (ID, "scal:contact"); +CREATE UNIQUE INDEX "scal:CalendarItem_scal:rrule_ID_ID" ON +"scal:CalendarItem_scal:rrule" (ID, "scal:rrule"); +CREATE INDEX "slo:GeoLocation_slo:postalAddress" ON "slo:GeoLocation" +("slo:postalAddress"); +CREATE UNIQUE INDEX "slo:Landmark_slo:belongsToCategory_ID_ID" ON +"slo:Landmark_slo:belongsToCategory" (ID, "slo:belongsToCategory"); +CREATE UNIQUE INDEX "slo:Landmark_slo:hasContact_ID_ID" ON +"slo:Landmark_slo:hasContact" (ID, "slo:hasContact"); +CREATE UNIQUE INDEX "slo:Route_slo:routeDetails_ID_ID" ON +"slo:Route_slo:routeDetails" (ID, "slo:routeDetails"); + +EXPLAIN SELECT "1_u", (SELECT "nco:fullname" FROM "nco:Contact" WHERE +ID = "1_u") COLLATE NOCASE, (SELECT "nco:nameFamily" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nameGiven" FROM "nco:PersonContact" WHERE ID = "1_u") +COLLATE NOCASE, (SELECT "nco:nameAdditional" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nameHonorificPrefix" FROM "nco:PersonContact" WHERE ID = +"1_u") COLLATE NOCASE, (SELECT "nco:nameHonorificSuffix" FROM +"nco:PersonContact" WHERE ID = "1_u") COLLATE NOCASE, (SELECT +"nco:nickname" FROM "nco:Contact" WHERE ID = "1_u") COLLATE +NOCASE, strftime("%s",(SELECT "nco:birthDate" FROM +"nco:Contact" WHERE ID = "1_u")), (SELECT "nie:url" FROM +"nie:DataObject" WHERE ID = (SELECT "nco:photo" FROM +"nco:Contact" WHERE ID = "1_u")) COLLATE NOCASE, (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||COALESCE((SELECT +"nco:imProtocol" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +"nco:imID" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +"nco:imNickname" FROM "nco:IMAddress" WHERE ID = "3_u") COLLATE +NOCASE, ? COLLATE NOCASE), '\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation2"."nco:hasAffiliation" AS +"2_u", "nco:Role_nco:hasIMAddress3"."nco:hasIMAddress" AS +"3_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation2", +"nco:Role_nco:hasIMAddress" AS "nco:Role_nco:hasIMAddress3" WHERE +"1_u" = "nco:PersonContact_nco:hasAffiliation2"."ID" AND +"nco:PersonContact_nco:hasAffiliation2"."nco:hasAffiliation" = +"nco:Role_nco:hasIMAddress3"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||(SELECT "nco:phoneNumber" +FROM "nco:PhoneNumber" WHERE ID = "4_u") COLLATE NOCASE, '\n') +FROM (SELECT "nco:PersonContact_nco:hasAffiliation4"."nco:hasAffiliation" +AS "2_u", "nco:Role_nco:hasPhoneNumber5"."nco:hasPhoneNumber" AS +"4_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation4", +"nco:Role_nco:hasPhoneNumber" AS "nco:Role_nco:hasPhoneNumber5" +WHERE "1_u" = "nco:PersonContact_nco:hasAffiliation4"."ID" AND +"nco:PersonContact_nco:hasAffiliation4"."nco:hasAffiliation" = +"nco:Role_nco:hasPhoneNumber5"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||(SELECT "nco:emailAddress" +FROM "nco:EmailAddress" WHERE ID = "5_u") COLLATE NOCASE, ',') +FROM (SELECT "nco:PersonContact_nco:hasAffiliation6"."nco:hasAffiliation" +AS "2_u", "nco:Role_nco:hasEmailAddress7"."nco:hasEmailAddress" +AS "5_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation6", +"nco:Role_nco:hasEmailAddress" AS "nco:Role_nco:hasEmailAddress7" +WHERE "1_u" = "nco:PersonContact_nco:hasAffiliation6"."ID" AND +"nco:PersonContact_nco:hasAffiliation6"."nco:hasAffiliation" = +"nco:Role_nco:hasEmailAddress7"."ID")), (SELECT +GROUP_CONCAT("2_u"||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = +"nco:blogUrl"),',') FROM "nco:Role_nco:blogUrl" WHERE ID = +"2_u"), ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = +"nco:websiteUrl"),',') FROM "nco:Role_nco:websiteUrl" WHERE ID = +"2_u"), ? COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT +GROUP_CONCAT((SELECT Uri FROM Resource WHERE ID = "nco:url"),',') +FROM "nco:Role_nco:url" WHERE ID = "2_u"), ? COLLATE NOCASE), +'\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation8"."nco:hasAffiliation" AS +"2_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation8" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation8"."ID")), (SELECT +GROUP_CONCAT("6_u", ',') FROM (SELECT +"rdfs:Resource_nao:hasTag9"."nao:hasTag" AS "6_u" FROM +"rdfs:Resource_nao:hasTag" AS "rdfs:Resource_nao:hasTag9" WHERE +"1_u" = "rdfs:Resource_nao:hasTag9"."ID")), (SELECT Uri FROM +Resource WHERE ID = "1_u"), (SELECT GROUP_CONCAT("2_u"||? COLLATE +NOCASE||COALESCE((SELECT "nco:role" FROM "nco:Affiliation" WHERE +ID = "2_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:department" FROM "nco:Affiliation" +WHERE ID = "2_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT GROUP_CONCAT("nco:title",',') FROM +"nco:Affiliation_nco:title" WHERE ID = "2_u"), ? COLLATE NOCASE), +'\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation10"."nco:hasAffiliation" AS +"2_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation10" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation10"."ID")), (SELECT +GROUP_CONCAT("nco:note",',') FROM "nco:Contact_nco:note" WHERE ID += "1_u"), (SELECT "nco:gender" FROM "nco:PersonContact" WHERE ID += "1_u"), (SELECT GROUP_CONCAT("2_u"||? COLLATE +NOCASE||COALESCE((SELECT "nco:pobox" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:district" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:county" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:locality" FROM "nco:PostalAddress" +WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE NOCASE)||? COLLATE +NOCASE||COALESCE((SELECT "nco:postalcode" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:streetAddress" +FROM "nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? +COLLATE NOCASE)||? COLLATE NOCASE||COALESCE((SELECT Uri FROM +Resource WHERE ID = (SELECT "nco:addressLocation" FROM +"nco:PostalAddress" WHERE ID = "7_u")), ? COLLATE NOCASE)||? +COLLATE NOCASE||COALESCE((SELECT "nco:extendedAddress" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:country" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE)||? COLLATE NOCASE||COALESCE((SELECT "nco:region" FROM +"nco:PostalAddress" WHERE ID = "7_u") COLLATE NOCASE, ? COLLATE +NOCASE), '\n') FROM (SELECT +"nco:PersonContact_nco:hasAffiliation11"."nco:hasAffiliation" AS +"2_u", "nco:Role_nco:hasPostalAddress12"."nco:hasPostalAddress" +AS "7_u" FROM "nco:PersonContact_nco:hasAffiliation" AS +"nco:PersonContact_nco:hasAffiliation11", +"nco:Role_nco:hasPostalAddress" AS +"nco:Role_nco:hasPostalAddress12" WHERE "1_u" = +"nco:PersonContact_nco:hasAffiliation11"."ID" AND +"nco:PersonContact_nco:hasAffiliation11"."nco:hasAffiliation" = +"nco:Role_nco:hasPostalAddress12"."ID")), (SELECT +GROUP_CONCAT("10_u" COLLATE NOCASE, ',') FROM (SELECT +"nie:InformationElement_nao:hasProperty13"."nao:hasProperty" AS +"8_u", "nao:Property14"."nao:propertyName" AS "9_u", +"nao:Property14"."nao:propertyValue" AS "10_u" FROM +"nie:InformationElement_nao:hasProperty" AS +"nie:InformationElement_nao:hasProperty13", "nao:Property" AS +"nao:Property14" WHERE "1_u" = +"nie:InformationElement_nao:hasProperty13"."ID" AND +"nie:InformationElement_nao:hasProperty13"."nao:hasProperty" = +"nao:Property14"."ID" AND "9_u" IS NOT NULL AND "10_u" IS NOT +NULL AND ("9_u" COLLATE NOCASE = ? COLLATE NOCASE))) FROM (SELECT +"nco:PersonContact1"."ID" AS "1_u" FROM "nco:PersonContact" AS +"nco:PersonContact1") ORDER BY "1_u"; + } +} {/.* Goto .*/} + +# Crash reported by OSS-FUZZ on 2016-11-10 +do_catchsql_test fuzz-oss1-detach { + DETACH x IS #1; +} {1 {near "#1": syntax error}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz2.test new file mode 100644 index 0000000000000000000000000000000000000000..51dfce140b00d360e353c38483049e58605520ab --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz2.test @@ -0,0 +1,139 @@ +# 2007 May 10 +# +# 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. +# +# This file checks error recovery from malformed SQL strings. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +proc fuzzcatch {sql} { + return [lindex [catchsql $sql] 0] +} + +do_test fuzz2-1.1 { + fuzzcatch {SELECT ALL "AAAAAA" . * GROUP BY LIMIT round(1), #12} +} {1} +do_test fuzz2-2.0 { + fuzzcatch {SELECT + #100} +} {1} +do_test fuzz2-2.1 { + fuzzcatch {SELECT 1 WHERE ( #61 NOT MATCH ROUND( 1 ) )} +} {1} +do_test fuzz2-2.2 { + fuzzcatch {SELECT 1 LIMIT NOT #59 COLLATE AAAAAA NOT IN + ( "AAAAAA" NOTNULL <= x'414141414141' IS NULL , ( ROUND ( 1.0 ) ) )} +} {1} +do_test fuzz2-2.3 { + fuzzcatch {INSERT OR REPLACE INTO AAAAAA . "AAAAAA" ( "AAAAAA" ) SELECT DISTINCT * , ( SELECT #252 IN ( SELECT DISTINCT AAAAAA . * ) )} +} {1} +do_test fuzz2-2.4 { + fuzzcatch {SELECT 1 LIMIT NOT #59 COLLATE AAAAAA NOT IN round(1.0)} +} {1} +do_test fuzz2-2.5 { + fuzzcatch {SELECT( #239 )} +} {1} +do_test fuzz2-2.6 { + fuzzcatch {DELETE FROM AAAAAA WHERE #65 NOT NULL} +} {1} +do_test fuzz2-2.7 { + fuzzcatch {ATTACH ROUND( 1.0 ) in AAAAAA . "AAAAAA" AS #122 ISNULL} +} {1} +do_test fuzz2-2.8 { + fuzzcatch {SELECT 1 LIMIT #122 ISNULL} +} {1} +do_test fuzz2-2.9 { + fuzzcatch {CREATE VIEW AAAAAA . "AAAAAA" AS SELECT DISTINCT #162 IS NULL "AAAAAA"} +} {1} +do_test fuzz2-2.10 { + fuzzcatch {DELETE FROM AAAAAA WHERE #202 IS NOT NULL ISNULL} +} {1} +do_test fuzz2-2.11 { + fuzzcatch {UPDATE OR IGNORE "AAAAAA" . "AAAAAA" SET "AAAAAA" = NOT #96} +} {1} +do_test fuzz2-2.12 { + fuzzcatch {SELECT - #196} +} {1} + +ifcapable {trigger} { # Only do the following tests if triggers are enabled + +do_test fuzz2-3.0 { + fuzzcatch {CREATE TRIGGER "AAAAAA" . "AAAAAA" AFTER UPDATE OF "AAAAAA" , "AAAAAA" ON "AAAAAA" . "AAAAAA" FOR EACH ROW BEGIN UPDATE AAAAAA SET "AAAAAA" = #162; END} +} {1} +do_test fuzz2-3.1 { + fuzzcatch {CREATE TRIGGER IF NOT EXISTS "AAAAAA" UPDATE ON "AAAAAA" . AAAAAA FOR EACH ROW BEGIN DELETE FROM "AAAAAA" ; INSERT INTO AAAAAA ( "AAAAAA" ) SELECT DISTINCT "AAAAAA" "AAAAAA" , #167 AAAAAA , "AAAAAA" . * ORDER BY "AAAAAA" ASC , x'414141414141' BETWEEN RAISE ( FAIL , "AAAAAA" ) AND AAAAAA ( * ) NOT NULL DESC LIMIT AAAAAA ; REPLACE INTO AAAAAA ( AAAAAA ) VALUES ( AAAAAA ( * ) ) ; END} +} {1} +do_test fuzz2-3.2 { + fuzzcatch {CREATE TEMP TRIGGER IF NOT EXISTS AAAAAA . "AAAAAA" BEFORE UPDATE OF "AAAAAA" ON AAAAAA . "AAAAAA" BEGIN SELECT ALL * , #175 "AAAAAA" FROM "AAAAAA" . AAAAAA; END} +} {1} + +} ;# End of ifcapable {trigger} + +do_test fuzz2-4.0 { + fuzzcatch {ATTACH DATABASE #168 AS whatever} +} {1} +do_test fuzz2-4.1 { + fuzzcatch {DETACH #133} +} {1} +do_test fuzz2-5.0 { + fuzzcatch {SELECT 1 LIMIT ( SELECT DISTINCT * , AAAAAA , * , AAAAAA , "AAAAAA" . * FROM "AAAAAA" ON ROUND( 1 ) COLLATE AAAAAA OR "AAAAAA" USING ( AAAAAA , "AAAAAA" ) WHERE ROUND( 1 ) GROUP BY ORDER BY #84 ASC , #44 DESC , ( SELECT "AAAAAA" . * , "AAAAAA" . * FROM , ( ) "AAAAAA" USING ( )} +} {1} +do_test fuzz2-5.1 { + fuzzcatch {SELECT 1 WHERE 1 == AAAAAA ( * ) BETWEEN + - ~ + "AAAAAA" . AAAAAA | RAISE ( IGNORE ) COLLATE AAAAAA NOT IN ( SELECT DISTINCT "AAAAAA" . * , * , * WHERE ( SELECT ALL AAAAAA AS "AAAAAA" HAVING CAST ( "AAAAAA" . "AAAAAA" . "AAAAAA" AS AAAAAA ) ORDER BY , , IS NULL ASC , ~ AND DESC LIMIT ( ( "AAAAAA" ) NOT BETWEEN ( ) NOT IN ( ) AND AAAAAA ( ) IS NOT NULL ) OFFSET AAAAAA ( ALL , , ) ) GROUP BY ORDER BY "AAAAAA" . AAAAAA ASC , NULL IN ( SELECT UNION ALL SELECT ALL WHERE HAVING ORDER BY LIMIT UNION SELECT DISTINCT FROM ( ) WHERE + HAVING >> ORDER BY LIMIT . . , "AAAAAA" ) , CAST ( ~ "AAAAAA" . AAAAAA AS "AAAAAA" AAAAAA "AAAAAA" ( + 4294967295 , - 4294967296.0 ) ) ASC LIMIT AAAAAA INTERSECT SELECT ALL * GROUP BY , AAAAAA ( DISTINCT , ) != #241 NOT IN ( , , ) , , CTIME_KW HAVING AAAAAA ORDER BY #103 DESC , #81 ASC LIMIT AAAAAA OFFSET ~ AAAAAA ( ALL AAAAAA . AAAAAA >= AAAAAA . "AAAAAA" . "AAAAAA" ) ) NOTNULL NOT NULL} +} {1} +do_test fuzz2-5.2 { + fuzzcatch {SELECT 1 WHERE 1 == AAAAAA ( * ) BETWEEN + - ~ + "AAAAAA" . AAAAAA | RAISE ( IGNORE ) COLLATE AAAAAA NOT IN ( SELECT DISTINCT "AAAAAA" . * , * , * WHERE ( SELECT ALL AAAAAA AS "AAAAAA" HAVING CAST ( "AAAAAA" . "AAAAAA" . "AAAAAA" AS AAAAAA ) ORDER BY , , IS NULL ASC , ~ AND DESC LIMIT ( ( "AAAAAA" ) NOT BETWEEN ( ) NOT IN ( ) AND AAAAAA ( ) IS NOT NULL ) OFFSET AAAAAA ( ALL , , ) ) GROUP BY ORDER BY "AAAAAA" . AAAAAA ASC , NULL IN ( SELECT UNION ALL SELECT ALL WHERE HAVING ORDER BY LIMIT UNION SELECT DISTINCT FROM ( ) WHERE + HAVING >> ORDER BY LIMIT . . , "AAAAAA" ) , CAST ( ~ "AAAAAA" . AAAAAA AS "AAAAAA" AAAAAA "AAAAAA" ( + 4294967295 , - 4294967296.0 ) ) ASC LIMIT AAAAAA INTERSECT SELECT ALL * GROUP BY , AAAAAA ( DISTINCT , ) != #241 NOT IN ( , , ) , , CTIME_KW HAVING AAAAAA ORDER BY #103 DESC , #81 ASC LIMIT AAAAAA OFFSET ~ AAAAAA ( ALL AAAAAA . AAAAAA >= AAAAAA . "AAAAAA" . "AAAAAA" ) ) NOTNULL NOT NULL} +} {1} +do_test fuzz2-5.3 { + fuzzcatch {UPDATE "AAAAAA" SET "AAAAAA" = - EXISTS ( SELECT DISTINCT * , * ORDER BY #202 ASC , #147 , ~ AAAAAA . "AAAAAA" ASC LIMIT AAAAAA . "AAAAAA" , RAISE ( ABORT , AAAAAA ) UNION ALL SELECT DISTINCT AAAAAA . * , * FROM ( SELECT DISTINCT} +} {1} +do_test fuzz2-5.4 { + fuzzcatch {REPLACE INTO AAAAAA SELECT DISTINCT "AAAAAA" . * WHERE AAAAAA ( AAAAAA ( ) ) GROUP BY AAAAAA . AAAAAA . "AAAAAA" IN "AAAAAA" | AAAAAA ( ALL , ) ORDER BY #238, #92 DESC LIMIT 0 OFFSET - RAISE ( IGNORE ) NOT NULL > RAISE ( IGNORE ) IS NULL} +} {1} +do_test fuzz2-5.5 { + fuzzcatch {SELECT ALL * GROUP BY EXISTS ( SELECT "AAAAAA" . * , AAAAAA ( * ) AS AAAAAA FROM "AAAAAA" . "AAAAAA" AS "AAAAAA" USING ( AAAAAA , "AAAAAA" , "AAAAAA" ) WHERE AAAAAA ( DISTINCT ) - RAISE ( FAIL , "AAAAAA" ) HAVING "AAAAAA" . "AAAAAA" . AAAAAA ORDER BY #182 , #55 ) BETWEEN EXISTS ( SELECT ALL * FROM ( ( } +} {1} + +# Test cases discovered by Michal Zalewski on 2015-01-03 and reported on the +# sqlite-users mailing list. All of these cases cause segfaults in +# SQLite 3.8.7.4 and earlier. +# +do_test fuzz2-6.1 { + catchsql {SELECT n()AND+#0;} +} {1 {near "#0": syntax error}} +do_test fuzz2-6.2 { + catchsql {SELECT strftime()} +} {0 {{}}} +do_test fuzz2-6.3 { + catchsql {DETACH(SELECT group_concat(q));} +} {1 {no such column: q}} +do_test fuzz2-6.4a { + db eval {DROP TABLE IF EXISTS t0; CREATE TABLE t0(t);} + catchsql {INSERT INTO t0 SELECT strftime();} +} {0 {}} +do_test fuzz2-6.4b { + db eval {SELECT quote(t) FROM t0} +} {NULL} + +# Another test case discovered by Michal Zalewski, this on on 2015-01-22. +# Ticket 32b63d542433ca6757cd695aca42addf8ed67aa6 +# +do_test fuzz2-7.1 { + catchsql {select e.*,0 from(s,(L))e;} +} {1 {no such table: s}} +do_test fuzz2-7.2 { + catchsql {SELECT c.* FROM (a,b) AS c} +} {1 {no such table: a}} + + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz_malloc.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz_malloc.test new file mode 100644 index 0000000000000000000000000000000000000000..4449ea8fc439f7a390250126533897f924e315d6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzz_malloc.test @@ -0,0 +1,100 @@ +# +# 2007 May 10 +# +# 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 tests malloc failures in concert with fuzzy SQL generation. +# +# $Id: fuzz_malloc.test,v 1.10 2008/08/20 16:35:10 drh Exp $ + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +source $testdir/malloc_common.tcl +source $testdir/fuzz_common.tcl + +if {[info exists G(isquick)]} { + set ::REPEATS 20 +} elseif {[info exists G(issoak)]} { + set ::REPEATS 100 +} else { + set ::REPEATS 40 +} + +# +# Usage: do_fuzzy_malloc_test ?? +# +# -template +# -sqlprep +# -repeats +# +proc do_fuzzy_malloc_test {testname args} { + set ::fuzzyopts(-repeats) $::REPEATS + set ::fuzzyopts(-sqlprep) {} + array set ::fuzzyopts $args + + sqlite3_memdebug_fail -1 + db close + delete_file test.db test.db-journal + sqlite3 db test.db + set ::prep $::fuzzyopts(-sqlprep) + execsql $::prep + set jj 0 + for {set ii 0} {$ii < $::fuzzyopts(-repeats)} {incr ii} { + expr srand($jj) + incr jj + set ::sql [subst $::fuzzyopts(-template)] + # puts fuzyy-sql=\[$::sql\]; flush stdout + foreach {rc ::fmtres} [catchsql "$::sql"] {} + if {$rc==0} { + set nErr1 [set_test_counter errors] + do_faultsim_test $testname-$ii -faults oom* -body { + execsql $::sql + } -test { + if {$testrc && $testresult!="datatype mismatch"} { + faultsim_test_result {0 {}} + } + } + if {[set_test_counter errors]>$nErr1} { + puts "Previous fuzzy-sql=\[$::sql\]" + flush stdout + } + } else { + incr ii -1 + } + } +} + +#---------------------------------------------------------------- +# Test malloc failure during parsing (and execution) of a fuzzily +# generated expressions. +# +do_fuzzy_malloc_test fuzzy_malloc-1 -template {Select [Expr]} +do_fuzzy_malloc_test fuzzy_malloc-2 -template {[Select]} + +set ::SQLPREP { + BEGIN; + CREATE TABLE abc(a, b, c); + CREATE TABLE def(a, b, c); + CREATE TABLE ghi(a, b, c); + INSERT INTO abc VALUES(1.5, 3, 'a short string'); + INSERT INTO def VALUES(NULL, X'ABCDEF', + 'a longer string. Long enough that it doesn''t fit in Mem.zShort'); + INSERT INTO ghi VALUES(zeroblob(1000), 'hello world', -1257900987654321); + COMMIT; +} +set ::TableList [list abc def ghi] +set ::ColumnList [list a b c] + +do_fuzzy_malloc_test fuzzy_malloc-3 \ + -template {[Select]} \ + -sqlprep $::SQLPREP + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer1.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer1.test new file mode 100644 index 0000000000000000000000000000000000000000..5e361e9df0e220875816ae5a532676bcccfeb629 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer1.test @@ -0,0 +1,1820 @@ +# 2011 March 25 +# +# 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 TCL interface to the +# SQLite library. +# +# The focus of the tests is the word-fuzzer virtual table. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +set ::testprefix fuzzer1 +load_static_extension db fuzzer + +# Check configuration errors. +# +do_catchsql_test fuzzer1-1.1 { + CREATE VIRTUAL TABLE f USING fuzzer; +} {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}} + +do_catchsql_test fuzzer1-1.2 { + CREATE VIRTUAL TABLE f USING fuzzer(one, two); +} {1 {fuzzer: wrong number of CREATE VIRTUAL TABLE arguments}} + +do_catchsql_test fuzzer1-1.3 { + CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: main.nosuchtable}} + +do_catchsql_test fuzzer1-1.4 { + CREATE TEMP TABLE nosuchtable(a, b, c, d); + CREATE VIRTUAL TABLE f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: main.nosuchtable}} + +do_catchsql_test fuzzer1-1.5 { + DROP TABLE temp.nosuchtable; + CREATE TABLE nosuchtable(a, b, c, d); + CREATE VIRTUAL TABLE temp.f USING fuzzer(nosuchtable); +} {1 {fuzzer: no such table: temp.nosuchtable}} + +do_catchsql_test fuzzer1-1.6 { + DROP TABLE IF EXISTS f_rules; + CREATE TABLE f_rules(a, b, c); + CREATE VIRTUAL TABLE f USING fuzzer(f_rules); +} {1 {fuzzer: f_rules has 3 columns, expected 4}} + +do_catchsql_test fuzzer1-1.7 { + DROP TABLE IF EXISTS f_rules; + CREATE TABLE f_rules(a, b, c, d, e); + CREATE VIRTUAL TABLE f USING fuzzer(f_rules); +} {1 {fuzzer: f_rules has 5 columns, expected 4}} + + +do_execsql_test fuzzer1-2.1 { + CREATE TABLE f1_rules(ruleset DEFAULT 0, cfrom, cto, cost); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','a',1); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('a','e',10); + INSERT INTO f1_rules(cfrom, cto, cost) VALUES('e','o',100); + + CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules); +} {} + +do_execsql_test fuzzer1-2.1 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.4 { + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'b','x',1); + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'d','y',10); + INSERT INTO f1_rules(ruleset, cfrom, cto, cost) VALUES(1,'y','z',100); + + DROP TABLE f1; + CREATE VIRTUAL TABLE f1 USING fuzzer(f1_rules); +} {} + +do_execsql_test fuzzer1-2.5 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.6 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=0 +} { + abcde 0 abcda 1 ebcde 10 + ebcda 11 abcdo 100 ebcdo 110 + obcde 110 obcda 111 obcdo 210 +} + +do_execsql_test fuzzer1-2.7 { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND ruleset=1 +} { + abcde 0 axcde 1 abcye 10 + axcye 11 abcze 110 axcze 111 +} + +do_test fuzzer1-1.8 { + db eval { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<100 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11} +do_test fuzzer1-1.9 { + db eval { + SELECT word, distance FROM f1 WHERE word MATCH 'abcde' AND distance<=100 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100} +do_test fuzzer1-1.10 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<100 AND ruleset=0 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11} +do_test fuzzer1-1.11 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<=100 AND ruleset=0 + } +} {abcde 0 abcda 1 ebcde 10 ebcda 11 abcdo 100} +do_test fuzzer1-1.12 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<11 AND ruleset=1 + } +} {abcde 0 axcde 1 abcye 10} +do_test fuzzer1-1.13 { + db eval { + SELECT word, distance FROM f1 + WHERE word MATCH 'abcde' AND distance<=11 AND ruleset=1 + } +} {abcde 0 axcde 1 abcye 10 axcye 11} +do_test fuzzer1-1.14 { + catchsql {INSERT INTO f1 VALUES(1)} +} {1 {table f1 may not be modified}} +do_test fuzzer1-1.15 { + catchsql {DELETE FROM f1} +} {1 {table f1 may not be modified}} +do_test fuzzer1-1.16 { + catchsql {UPDATE f1 SET rowid=rowid+10000} +} {1 {table f1 may not be modified}} + + +do_test fuzzer1-2.0 { + execsql { + -- costs based on English letter frequencies + CREATE TEMP TABLE f2_rules(ruleset DEFAULT 0, cFrom, cTo, cost); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','e',24); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','o',47); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','u',50); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','a',23); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','i',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','o',37); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','e',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','y',33); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','a',41); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','e',46); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','u',57); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','o',58); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','i',33); + + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','th',70); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('th','t',66); + + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('a','',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','b',106); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('b','',106); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','c',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('c','',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','d',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('d','',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','e',83); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('e','',83); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','f',97); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('f','',97); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','g',99); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('g','',99); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','h',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('h','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','i',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('i','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','j',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('j','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','k',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('k','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','l',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('l','',89); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','m',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('m','',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','n',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('n','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','o',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('o','',85); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','p',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('p','',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','q',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('q','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','r',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('r','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','s',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('s','',86); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','t',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('t','',84); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','u',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('u','',94); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','v',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('v','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','w',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('w','',96); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','x',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('x','',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','y',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('y','',100); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('','z',120); + INSERT INTO f2_rules(cFrom,cTo,cost) VALUES('z','',120); + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 1, cFrom, cTo, 100 FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 2, cFrom, cTo, 200-cost FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + SELECT 3, cFrom, cTo, cost FROM f2_rules WHERE ruleset=0; + INSERT INTO f2_rules(ruleset,cFrom,cTo,cost) + VALUES(3, 'mallard','duck',50), + (3, 'duck', 'mallard', 50), + (3, 'rock', 'stone', 50), + (3, 'stone', 'rock', 50); + + + CREATE VIRTUAL TABLE temp.f2 USING fuzzer(f2_rules); + + -- Street names for the 28269 ZIPCODE. + -- + CREATE TEMP TABLE streetname(n TEXT UNIQUE); + INSERT INTO streetname VALUES('abbotsinch'); + INSERT INTO streetname VALUES('abbottsgate'); + INSERT INTO streetname VALUES('abbywood'); + INSERT INTO streetname VALUES('abner'); + INSERT INTO streetname VALUES('acacia ridge'); + INSERT INTO streetname VALUES('acorn creek'); + INSERT INTO streetname VALUES('acorn forest'); + INSERT INTO streetname VALUES('adel'); + INSERT INTO streetname VALUES('ainslie'); + INSERT INTO streetname VALUES('airways'); + INSERT INTO streetname VALUES('alabaster'); + INSERT INTO streetname VALUES('alba'); + INSERT INTO streetname VALUES('albertine'); + INSERT INTO streetname VALUES('alden glen'); + INSERT INTO streetname VALUES('alderson'); + INSERT INTO streetname VALUES('allen'); + INSERT INTO streetname VALUES('allen a brown'); + INSERT INTO streetname VALUES('allness glen'); + INSERT INTO streetname VALUES('aloysia'); + INSERT INTO streetname VALUES('alpine'); + INSERT INTO streetname VALUES('alwyn'); + INSERT INTO streetname VALUES('amaranthus'); + INSERT INTO streetname VALUES('amber glen'); + INSERT INTO streetname VALUES('amber leigh way'); + INSERT INTO streetname VALUES('amber meadows'); + INSERT INTO streetname VALUES('amberway'); + INSERT INTO streetname VALUES('ame'); + INSERT INTO streetname VALUES('amesbury hill'); + INSERT INTO streetname VALUES('anderson'); + INSERT INTO streetname VALUES('andrew thomas'); + INSERT INTO streetname VALUES('anduin falls'); + INSERT INTO streetname VALUES('ankeny'); + INSERT INTO streetname VALUES('annandale'); + INSERT INTO streetname VALUES('annbick'); + INSERT INTO streetname VALUES('antelope'); + INSERT INTO streetname VALUES('anzack'); + INSERT INTO streetname VALUES('apple glen'); + INSERT INTO streetname VALUES('applevalley'); + INSERT INTO streetname VALUES('appley mead'); + INSERT INTO streetname VALUES('aragorn'); + INSERT INTO streetname VALUES('arbor creek'); + INSERT INTO streetname VALUES('arbor day'); + INSERT INTO streetname VALUES('arbor meadows'); + INSERT INTO streetname VALUES('arbor spring'); + INSERT INTO streetname VALUES('arborview'); + INSERT INTO streetname VALUES('arklow'); + INSERT INTO streetname VALUES('armitage'); + INSERT INTO streetname VALUES('arvin'); + INSERT INTO streetname VALUES('ash cove'); + INSERT INTO streetname VALUES('ashford leigh'); + INSERT INTO streetname VALUES('ashmont'); + INSERT INTO streetname VALUES('atlas'); + INSERT INTO streetname VALUES('atwater'); + INSERT INTO streetname VALUES('auburn hill'); + INSERT INTO streetname VALUES('aulton link'); + INSERT INTO streetname VALUES('austin dekota'); + INSERT INTO streetname VALUES('austin knoll'); + INSERT INTO streetname VALUES('auten'); + INSERT INTO streetname VALUES('autumn harvest'); + INSERT INTO streetname VALUES('autumn oak'); + INSERT INTO streetname VALUES('autumn ridge'); + INSERT INTO streetname VALUES('avalon forest'); + INSERT INTO streetname VALUES('avalon loop'); + INSERT INTO streetname VALUES('avon farm'); + INSERT INTO streetname VALUES('avonhurst'); + INSERT INTO streetname VALUES('avonlea'); + INSERT INTO streetname VALUES('aynrand'); + INSERT INTO streetname VALUES('azure valley'); + INSERT INTO streetname VALUES('baberton'); + INSERT INTO streetname VALUES('baffin'); + INSERT INTO streetname VALUES('baggins'); + INSERT INTO streetname VALUES('balata'); + INSERT INTO streetname VALUES('ballantray'); + INSERT INTO streetname VALUES('ballston'); + INSERT INTO streetname VALUES('balsam tree'); + INSERT INTO streetname VALUES('bambi'); + INSERT INTO streetname VALUES('banwell'); + INSERT INTO streetname VALUES('barbee'); + INSERT INTO streetname VALUES('barefoot forest'); + INSERT INTO streetname VALUES('barnview'); + INSERT INTO streetname VALUES('baroda'); + INSERT INTO streetname VALUES('barson'); + INSERT INTO streetname VALUES('baskerville'); + INSERT INTO streetname VALUES('battle creek'); + INSERT INTO streetname VALUES('baucom'); + INSERT INTO streetname VALUES('bay pines'); + INSERT INTO streetname VALUES('beaker'); + INSERT INTO streetname VALUES('beard'); + INSERT INTO streetname VALUES('beardsley'); + INSERT INTO streetname VALUES('bearoak'); + INSERT INTO streetname VALUES('beauvista'); + INSERT INTO streetname VALUES('beaver creek'); + INSERT INTO streetname VALUES('beaver hollow'); + INSERT INTO streetname VALUES('bedlington'); + INSERT INTO streetname VALUES('beech cove'); + INSERT INTO streetname VALUES('beech crest'); + INSERT INTO streetname VALUES('beith'); + INSERT INTO streetname VALUES('bell glen'); + INSERT INTO streetname VALUES('bellmore'); + INSERT INTO streetname VALUES('bells mill'); + INSERT INTO streetname VALUES('bellville'); + INSERT INTO streetname VALUES('belmar place'); + INSERT INTO streetname VALUES('bembridge'); + INSERT INTO streetname VALUES('bennett neely'); + INSERT INTO streetname VALUES('bentgrass run'); + INSERT INTO streetname VALUES('benthaven'); + INSERT INTO streetname VALUES('bernardy'); + INSERT INTO streetname VALUES('bernbrook shadow'); + INSERT INTO streetname VALUES('berrybrook'); + INSERT INTO streetname VALUES('berrybush'); + INSERT INTO streetname VALUES('berwick'); + INSERT INTO streetname VALUES('betterton'); + INSERT INTO streetname VALUES('bickham'); + INSERT INTO streetname VALUES('billingham'); + INSERT INTO streetname VALUES('birchcroft'); + INSERT INTO streetname VALUES('birchstone'); + INSERT INTO streetname VALUES('birdwell'); + INSERT INTO streetname VALUES('bisaner'); + INSERT INTO streetname VALUES('bitterbush'); + INSERT INTO streetname VALUES('bitterroot'); + INSERT INTO streetname VALUES('black fox'); + INSERT INTO streetname VALUES('black maple'); + INSERT INTO streetname VALUES('black trail'); + INSERT INTO streetname VALUES('blackbird'); + INSERT INTO streetname VALUES('blake a dare'); + INSERT INTO streetname VALUES('blasdell'); + INSERT INTO streetname VALUES('blue aster'); + INSERT INTO streetname VALUES('blue finch'); + INSERT INTO streetname VALUES('blue lilac'); + INSERT INTO streetname VALUES('blue sky'); + INSERT INTO streetname VALUES('blue tick'); + INSERT INTO streetname VALUES('bob beatty'); + INSERT INTO streetname VALUES('bobcat'); + INSERT INTO streetname VALUES('bolton'); + INSERT INTO streetname VALUES('boomerang'); + INSERT INTO streetname VALUES('boulder'); + INSERT INTO streetname VALUES('boxer'); + INSERT INTO streetname VALUES('boxmeer'); + INSERT INTO streetname VALUES('brachnell view'); + INSERT INTO streetname VALUES('bradford lake'); + INSERT INTO streetname VALUES('bradwell'); + INSERT INTO streetname VALUES('brady'); + INSERT INTO streetname VALUES('braids bend'); + INSERT INTO streetname VALUES('bralers'); + INSERT INTO streetname VALUES('brandie glen'); + INSERT INTO streetname VALUES('brandy ridge'); + INSERT INTO streetname VALUES('brandybuck'); + INSERT INTO streetname VALUES('branthurst'); + INSERT INTO streetname VALUES('brassy creek'); + INSERT INTO streetname VALUES('brathay'); + INSERT INTO streetname VALUES('brawer farm'); + INSERT INTO streetname VALUES('breezy morn'); + INSERT INTO streetname VALUES('brenda'); + INSERT INTO streetname VALUES('brenly'); + INSERT INTO streetname VALUES('brenock'); + INSERT INTO streetname VALUES('brianwood'); + INSERT INTO streetname VALUES('briar rose'); + INSERT INTO streetname VALUES('briarcrest'); + INSERT INTO streetname VALUES('briarthorne'); + INSERT INTO streetname VALUES('brick dust'); + INSERT INTO streetname VALUES('bridgepath'); + INSERT INTO streetname VALUES('bridle ridge'); + INSERT INTO streetname VALUES('briggs'); + INSERT INTO streetname VALUES('brightleaf'); + INSERT INTO streetname VALUES('brigstock'); + INSERT INTO streetname VALUES('broad ridge'); + INSERT INTO streetname VALUES('brock'); + INSERT INTO streetname VALUES('brockhampton'); + INSERT INTO streetname VALUES('broken pine'); + INSERT INTO streetname VALUES('brompton'); + INSERT INTO streetname VALUES('brook falls'); + INSERT INTO streetname VALUES('brookings'); + INSERT INTO streetname VALUES('browne'); + INSERT INTO streetname VALUES('brownes creek'); + INSERT INTO streetname VALUES('brownes ferry'); + INSERT INTO streetname VALUES('brownestone view'); + INSERT INTO streetname VALUES('brumit'); + INSERT INTO streetname VALUES('bryn athyn'); + INSERT INTO streetname VALUES('buck'); + INSERT INTO streetname VALUES('bucklebury'); + INSERT INTO streetname VALUES('buckminister'); + INSERT INTO streetname VALUES('buckspring'); + INSERT INTO streetname VALUES('burch'); + INSERT INTO streetname VALUES('burch shire'); + INSERT INTO streetname VALUES('burkston'); + INSERT INTO streetname VALUES('burmith'); + INSERT INTO streetname VALUES('burnaby'); + INSERT INTO streetname VALUES('butterfly'); + INSERT INTO streetname VALUES('cabin creek'); + INSERT INTO streetname VALUES('cairns mill'); + INSERT INTO streetname VALUES('callender'); + INSERT INTO streetname VALUES('cambellton'); + INSERT INTO streetname VALUES('cambridge bay'); + INSERT INTO streetname VALUES('canary'); + INSERT INTO streetname VALUES('canbury'); + INSERT INTO streetname VALUES('candle leaf'); + INSERT INTO streetname VALUES('canipe'); + INSERT INTO streetname VALUES('canipe farm'); + INSERT INTO streetname VALUES('cannon'); + INSERT INTO streetname VALUES('canopy'); + INSERT INTO streetname VALUES('canso'); + INSERT INTO streetname VALUES('canterbrook'); + INSERT INTO streetname VALUES('cardinal glen'); + INSERT INTO streetname VALUES('cardinal point'); + INSERT INTO streetname VALUES('cardinals nest'); + INSERT INTO streetname VALUES('carlota'); + INSERT INTO streetname VALUES('carmathen'); + INSERT INTO streetname VALUES('carver'); + INSERT INTO streetname VALUES('carver pond'); + INSERT INTO streetname VALUES('casa loma'); + INSERT INTO streetname VALUES('caselton'); + INSERT INTO streetname VALUES('castello'); + INSERT INTO streetname VALUES('castle ridge'); + INSERT INTO streetname VALUES('castleglen'); + INSERT INTO streetname VALUES('castlemaine'); + INSERT INTO streetname VALUES('cavett'); + INSERT INTO streetname VALUES('caymus'); + INSERT INTO streetname VALUES('cedardale ridge'); + INSERT INTO streetname VALUES('cedarhurst'); + INSERT INTO streetname VALUES('cemkey way'); + INSERT INTO streetname VALUES('cerise'); + INSERT INTO streetname VALUES('chaceview'); + INSERT INTO streetname VALUES('chadsworth'); + INSERT INTO streetname VALUES('chadwell'); + INSERT INTO streetname VALUES('champions crest'); + INSERT INTO streetname VALUES('chandler haven'); + INSERT INTO streetname VALUES('chapel crossing'); + INSERT INTO streetname VALUES('chapel ridge'); + INSERT INTO streetname VALUES('charles crawford'); + INSERT INTO streetname VALUES('charminster'); + INSERT INTO streetname VALUES('chasewind'); + INSERT INTO streetname VALUES('chavel'); + INSERT INTO streetname VALUES('chelsea jade'); + INSERT INTO streetname VALUES('chestnut knoll'); + INSERT INTO streetname VALUES('cheviot'); + INSERT INTO streetname VALUES('chickadee'); + INSERT INTO streetname VALUES('chidley'); + INSERT INTO streetname VALUES('chimney ridge'); + INSERT INTO streetname VALUES('chimney springs'); + INSERT INTO streetname VALUES('chinaberry'); + INSERT INTO streetname VALUES('chinemist'); + INSERT INTO streetname VALUES('chinquapin'); + INSERT INTO streetname VALUES('chiswell'); + INSERT INTO streetname VALUES('christenbury'); + INSERT INTO streetname VALUES('christenbury hills'); + INSERT INTO streetname VALUES('churchill'); + INSERT INTO streetname VALUES('cindy'); + INSERT INTO streetname VALUES('cinnamon teal'); + INSERT INTO streetname VALUES('citadel'); + INSERT INTO streetname VALUES('clare olivia'); + INSERT INTO streetname VALUES('clarke creek'); + INSERT INTO streetname VALUES('clarke ridge'); + INSERT INTO streetname VALUES('clear day'); + INSERT INTO streetname VALUES('clear stream'); + INSERT INTO streetname VALUES('cleve brown'); + INSERT INTO streetname VALUES('cliff cameron'); + INSERT INTO streetname VALUES('cliffvale'); + INSERT INTO streetname VALUES('cloverside'); + INSERT INTO streetname VALUES('clymer'); + INSERT INTO streetname VALUES('coatbridge'); + INSERT INTO streetname VALUES('cobble glen'); + INSERT INTO streetname VALUES('cochran farm'); + INSERT INTO streetname VALUES('cochrane'); + INSERT INTO streetname VALUES('coleridge'); + INSERT INTO streetname VALUES('coleshire'); + INSERT INTO streetname VALUES('collins'); + INSERT INTO streetname VALUES('colvard'); + INSERT INTO streetname VALUES('colvard park'); + INSERT INTO streetname VALUES('condor'); + INSERT INTO streetname VALUES('conner ridge'); + INSERT INTO streetname VALUES('connery'); + INSERT INTO streetname VALUES('cooper run'); + INSERT INTO streetname VALUES('coopers ridge'); + INSERT INTO streetname VALUES('copper hill'); + INSERT INTO streetname VALUES('coppermine'); + INSERT INTO streetname VALUES('cornelia'); + INSERT INTO streetname VALUES('corner'); + INSERT INTO streetname VALUES('cornerstone'); + INSERT INTO streetname VALUES('cottage oaks'); + INSERT INTO streetname VALUES('cougar'); + INSERT INTO streetname VALUES('coves end'); + INSERT INTO streetname VALUES('cragland'); + INSERT INTO streetname VALUES('crail'); + INSERT INTO streetname VALUES('cranberry nook'); + INSERT INTO streetname VALUES('crawford brook'); + INSERT INTO streetname VALUES('crayton'); + INSERT INTO streetname VALUES('creek breeze'); + INSERT INTO streetname VALUES('crescent ridge'); + INSERT INTO streetname VALUES('crescent view'); + INSERT INTO streetname VALUES('cresta'); + INSERT INTO streetname VALUES('crestfield'); + INSERT INTO streetname VALUES('crestland'); + INSERT INTO streetname VALUES('crestwick'); + INSERT INTO streetname VALUES('crisfield'); + INSERT INTO streetname VALUES('crisp wood'); + INSERT INTO streetname VALUES('croft haven'); + INSERT INTO streetname VALUES('crofton springs'); + INSERT INTO streetname VALUES('cross'); + INSERT INTO streetname VALUES('crosspoint center'); + INSERT INTO streetname VALUES('crownvista'); + INSERT INTO streetname VALUES('crystal arms'); + INSERT INTO streetname VALUES('crystal crest'); + INSERT INTO streetname VALUES('crystal leaf'); + INSERT INTO streetname VALUES('cunningham park'); + INSERT INTO streetname VALUES('cypress pond'); + INSERT INTO streetname VALUES('daffodil'); + INSERT INTO streetname VALUES('daisyfield'); + INSERT INTO streetname VALUES('dalecrest'); + INSERT INTO streetname VALUES('dannelly park'); + INSERT INTO streetname VALUES('daphne'); + INSERT INTO streetname VALUES('daria'); + INSERT INTO streetname VALUES('dartmouth'); + INSERT INTO streetname VALUES('datha'); + INSERT INTO streetname VALUES('david cox'); + INSERT INTO streetname VALUES('davis'); + INSERT INTO streetname VALUES('davis crossing'); + INSERT INTO streetname VALUES('davis lake'); + INSERT INTO streetname VALUES('davis ridge'); + INSERT INTO streetname VALUES('dawnmist'); + INSERT INTO streetname VALUES('daybreak'); + INSERT INTO streetname VALUES('dearmon'); + INSERT INTO streetname VALUES('dearview'); + INSERT INTO streetname VALUES('deaton hill'); + INSERT INTO streetname VALUES('deer cross'); + INSERT INTO streetname VALUES('deerton'); + INSERT INTO streetname VALUES('degrasse'); + INSERT INTO streetname VALUES('delamere'); + INSERT INTO streetname VALUES('dellfield'); + INSERT INTO streetname VALUES('dellinger'); + INSERT INTO streetname VALUES('demington'); + INSERT INTO streetname VALUES('denmeade'); + INSERT INTO streetname VALUES('derita'); + INSERT INTO streetname VALUES('derita woods'); + INSERT INTO streetname VALUES('deruyter'); + INSERT INTO streetname VALUES('dervish'); + INSERT INTO streetname VALUES('devas'); + INSERT INTO streetname VALUES('devon croft'); + INSERT INTO streetname VALUES('devonbridge'); + INSERT INTO streetname VALUES('devongate'); + INSERT INTO streetname VALUES('devonhill'); + INSERT INTO streetname VALUES('dewmorn'); + INSERT INTO streetname VALUES('distribution center'); + INSERT INTO streetname VALUES('dominion crest'); + INSERT INTO streetname VALUES('dominion green'); + INSERT INTO streetname VALUES('dominion village'); + INSERT INTO streetname VALUES('dorshire'); + INSERT INTO streetname VALUES('double creek crossing'); + INSERT INTO streetname VALUES('dow'); + INSERT INTO streetname VALUES('downfield wood'); + INSERT INTO streetname VALUES('downing creek'); + INSERT INTO streetname VALUES('driscol'); + INSERT INTO streetname VALUES('driwood'); + INSERT INTO streetname VALUES('dry brook'); + INSERT INTO streetname VALUES('dumont'); + INSERT INTO streetname VALUES('dunblane'); + INSERT INTO streetname VALUES('dunfield'); + INSERT INTO streetname VALUES('dunoon'); + INSERT INTO streetname VALUES('dunslow'); + INSERT INTO streetname VALUES('dunstaff'); + INSERT INTO streetname VALUES('durham'); + INSERT INTO streetname VALUES('durston'); + INSERT INTO streetname VALUES('dusty cedar'); + INSERT INTO streetname VALUES('dusty trail'); + INSERT INTO streetname VALUES('dutchess'); + INSERT INTO streetname VALUES('duxford'); + INSERT INTO streetname VALUES('eagle creek'); + INSERT INTO streetname VALUES('eagles field'); + INSERT INTO streetname VALUES('eargle'); + INSERT INTO streetname VALUES('earlswood'); + INSERT INTO streetname VALUES('early mist'); + INSERT INTO streetname VALUES('earthenware'); + INSERT INTO streetname VALUES('eastfield park'); + INSERT INTO streetname VALUES('eastfield village'); + INSERT INTO streetname VALUES('easy'); + INSERT INTO streetname VALUES('eben'); + INSERT INTO streetname VALUES('edgepine'); + INSERT INTO streetname VALUES('edgewier'); + INSERT INTO streetname VALUES('edinburgh'); + INSERT INTO streetname VALUES('edinmeadow'); + INSERT INTO streetname VALUES('edmonton'); + INSERT INTO streetname VALUES('edwin jones'); + INSERT INTO streetname VALUES('elberon'); + INSERT INTO streetname VALUES('elderslie'); + INSERT INTO streetname VALUES('elementary view'); + INSERT INTO streetname VALUES('elendil'); + INSERT INTO streetname VALUES('elizabeth'); + INSERT INTO streetname VALUES('elm cove'); + INSERT INTO streetname VALUES('elrond'); + INSERT INTO streetname VALUES('elsenham'); + INSERT INTO streetname VALUES('elven'); + INSERT INTO streetname VALUES('emma lynn'); + INSERT INTO streetname VALUES('english setter'); + INSERT INTO streetname VALUES('enoch'); + INSERT INTO streetname VALUES('equipment'); + INSERT INTO streetname VALUES('ernest russell'); + INSERT INTO streetname VALUES('ernie'); + INSERT INTO streetname VALUES('esmeralda'); + INSERT INTO streetname VALUES('evergreen hollow'); + INSERT INTO streetname VALUES('eversfield'); + INSERT INTO streetname VALUES('ewen'); + INSERT INTO streetname VALUES('ewert cut'); + INSERT INTO streetname VALUES('exbury'); + INSERT INTO streetname VALUES('fair grounds park'); + INSERT INTO streetname VALUES('fairbourne'); + INSERT INTO streetname VALUES('fairchase'); + INSERT INTO streetname VALUES('faircreek'); + INSERT INTO streetname VALUES('fairglen'); + INSERT INTO streetname VALUES('fairlea'); + INSERT INTO streetname VALUES('fairmead'); + INSERT INTO streetname VALUES('fairmeadows'); + INSERT INTO streetname VALUES('fairstone'); + INSERT INTO streetname VALUES('fairvista'); + INSERT INTO streetname VALUES('fairway point'); + INSERT INTO streetname VALUES('falconcrest'); + INSERT INTO streetname VALUES('falls ridge'); + INSERT INTO streetname VALUES('falmouth'); + INSERT INTO streetname VALUES('far west'); + INSERT INTO streetname VALUES('farlow'); + INSERT INTO streetname VALUES('farris wheel'); + INSERT INTO streetname VALUES('fawndale'); + INSERT INTO streetname VALUES('feather bend'); + INSERT INTO streetname VALUES('fernledge'); + INSERT INTO streetname VALUES('fernmoss'); + INSERT INTO streetname VALUES('ferrell commons'); + INSERT INTO streetname VALUES('fieldstone'); + INSERT INTO streetname VALUES('fillian'); + INSERT INTO streetname VALUES('fincher'); + INSERT INTO streetname VALUES('foggy meadow'); + INSERT INTO streetname VALUES('fordyce'); + INSERT INTO streetname VALUES('forest grove'); + INSERT INTO streetname VALUES('forest path'); + INSERT INTO streetname VALUES('forestridge commons'); + INSERT INTO streetname VALUES('forestrock'); + INSERT INTO streetname VALUES('fortunes ridge'); + INSERT INTO streetname VALUES('founders club'); + INSERT INTO streetname VALUES('fountaingrass'); + INSERT INTO streetname VALUES('fox chase'); + INSERT INTO streetname VALUES('fox glen'); + INSERT INTO streetname VALUES('fox hill'); + INSERT INTO streetname VALUES('fox point'); + INSERT INTO streetname VALUES('fox trot'); + INSERT INTO streetname VALUES('foxbriar'); + INSERT INTO streetname VALUES('frank little'); + INSERT INTO streetname VALUES('franzia'); + INSERT INTO streetname VALUES('french woods'); + INSERT INTO streetname VALUES('frostmoor'); + INSERT INTO streetname VALUES('frye'); + INSERT INTO streetname VALUES('furlong'); + INSERT INTO streetname VALUES('galena view'); + INSERT INTO streetname VALUES('gallery pointe'); + INSERT INTO streetname VALUES('gammon'); + INSERT INTO streetname VALUES('garden grove'); + INSERT INTO streetname VALUES('gardendale'); + INSERT INTO streetname VALUES('garganey'); + INSERT INTO streetname VALUES('garnet field'); + INSERT INTO streetname VALUES('garrison'); + INSERT INTO streetname VALUES('garvin'); + INSERT INTO streetname VALUES('garvis'); + INSERT INTO streetname VALUES('gaskill'); + INSERT INTO streetname VALUES('gemstone'); + INSERT INTO streetname VALUES('gibbon'); + INSERT INTO streetname VALUES('gibbon terrace'); + INSERT INTO streetname VALUES('gibbons link'); + INSERT INTO streetname VALUES('gillman'); + INSERT INTO streetname VALUES('gladwood'); + INSERT INTO streetname VALUES('gladwyne'); + INSERT INTO streetname VALUES('glamorgan'); + INSERT INTO streetname VALUES('glaze'); + INSERT INTO streetname VALUES('glen brook'); + INSERT INTO streetname VALUES('glen cove'); + INSERT INTO streetname VALUES('glen hope'); + INSERT INTO streetname VALUES('glen manor'); + INSERT INTO streetname VALUES('glen olden'); + INSERT INTO streetname VALUES('glencairn'); + INSERT INTO streetname VALUES('glendock'); + INSERT INTO streetname VALUES('glenolden'); + INSERT INTO streetname VALUES('glenover'); + INSERT INTO streetname VALUES('glenshire'); + INSERT INTO streetname VALUES('glenstone'); + INSERT INTO streetname VALUES('gold dust'); + INSERT INTO streetname VALUES('golden pond'); + INSERT INTO streetname VALUES('goldenblush'); + INSERT INTO streetname VALUES('goldenfield'); + INSERT INTO streetname VALUES('goose landing'); + INSERT INTO streetname VALUES('gorham gate'); + INSERT INTO streetname VALUES('grabill'); + INSERT INTO streetname VALUES('graburns ford'); + INSERT INTO streetname VALUES('graham'); + INSERT INTO streetname VALUES('grahamson'); + INSERT INTO streetname VALUES('granard'); + INSERT INTO streetname VALUES('grand teton'); + INSERT INTO streetname VALUES('grande heights'); + INSERT INTO streetname VALUES('grandeur'); + INSERT INTO streetname VALUES('granite creek'); + INSERT INTO streetname VALUES('grasset'); + INSERT INTO streetname VALUES('graypark'); + INSERT INTO streetname VALUES('grays ridge'); + INSERT INTO streetname VALUES('great bear'); + INSERT INTO streetname VALUES('green clover'); + INSERT INTO streetname VALUES('green hedge'); + INSERT INTO streetname VALUES('green meadow'); + INSERT INTO streetname VALUES('green pasture'); + INSERT INTO streetname VALUES('greene'); + INSERT INTO streetname VALUES('greenloch'); + INSERT INTO streetname VALUES('greenock ridge'); + INSERT INTO streetname VALUES('greenware'); + INSERT INTO streetname VALUES('greenway village'); + INSERT INTO streetname VALUES('grenelefe village'); + INSERT INTO streetname VALUES('grey dogwood'); + INSERT INTO streetname VALUES('greyhound'); + INSERT INTO streetname VALUES('greylock ridge'); + INSERT INTO streetname VALUES('grosbeak'); + INSERT INTO streetname VALUES('grove'); + INSERT INTO streetname VALUES('groveton'); + INSERT INTO streetname VALUES('groveview'); + INSERT INTO streetname VALUES('hackberry creek'); + INSERT INTO streetname VALUES('hackberry grove'); + INSERT INTO streetname VALUES('hackett'); + INSERT INTO streetname VALUES('haddington'); + INSERT INTO streetname VALUES('hagler'); + INSERT INTO streetname VALUES('halcott'); + INSERT INTO streetname VALUES('half dome'); + INSERT INTO streetname VALUES('hallam'); + INSERT INTO streetname VALUES('hamilton russell'); + INSERT INTO streetname VALUES('hampton place'); + INSERT INTO streetname VALUES('hankins'); + INSERT INTO streetname VALUES('harburn forest'); + INSERT INTO streetname VALUES('harringham'); + INSERT INTO streetname VALUES('harrington woods'); + INSERT INTO streetname VALUES('harris corners'); + INSERT INTO streetname VALUES('harris cove'); + INSERT INTO streetname VALUES('harris glen'); + INSERT INTO streetname VALUES('harris hill'); + INSERT INTO streetname VALUES('harris oak'); + INSERT INTO streetname VALUES('harris pointe'); + INSERT INTO streetname VALUES('harris pond'); + INSERT INTO streetname VALUES('harris ridge'); + INSERT INTO streetname VALUES('harris technology'); + INSERT INTO streetname VALUES('harris woods'); + INSERT INTO streetname VALUES('hartfield downs'); + INSERT INTO streetname VALUES('hattie little'); + INSERT INTO streetname VALUES('hatwynn'); + INSERT INTO streetname VALUES('hawkins'); + INSERT INTO streetname VALUES('hawksnest'); + INSERT INTO streetname VALUES('haybridge'); + INSERT INTO streetname VALUES('hayden'); + INSERT INTO streetname VALUES('hazelcroft'); + INSERT INTO streetname VALUES('hazlitt'); + INSERT INTO streetname VALUES('hazy valley'); + INSERT INTO streetname VALUES('hearst'); + INSERT INTO streetname VALUES('heathcrest'); + INSERT INTO streetname VALUES('heathcroft'); + INSERT INTO streetname VALUES('hedge maple'); + INSERT INTO streetname VALUES('hedgecrest'); + INSERT INTO streetname VALUES('hedingham'); + INSERT INTO streetname VALUES('heman'); + INSERT INTO streetname VALUES('henderson'); + INSERT INTO streetname VALUES('henderson oaks'); + INSERT INTO streetname VALUES('henderson valley'); + INSERT INTO streetname VALUES('hendry'); + INSERT INTO streetname VALUES('heritage hills'); + INSERT INTO streetname VALUES('heritage woods'); + INSERT INTO streetname VALUES('heron cove'); + INSERT INTO streetname VALUES('heron glen'); + INSERT INTO streetname VALUES('hewitt'); + INSERT INTO streetname VALUES('hey rock'); + INSERT INTO streetname VALUES('heysham'); + INSERT INTO streetname VALUES('hickory cove'); + INSERT INTO streetname VALUES('hidden meadow'); + INSERT INTO streetname VALUES('high glen'); + INSERT INTO streetname VALUES('high laurel'); + INSERT INTO streetname VALUES('high valley'); + INSERT INTO streetname VALUES('highcroft'); + INSERT INTO streetname VALUES('highland'); + INSERT INTO streetname VALUES('highland commons'); + INSERT INTO streetname VALUES('highland creek'); + INSERT INTO streetname VALUES('highland glen'); + INSERT INTO streetname VALUES('highland park'); + INSERT INTO streetname VALUES('highlander'); + INSERT INTO streetname VALUES('highstream'); + INSERT INTO streetname VALUES('hilltop'); + INSERT INTO streetname VALUES('hobbitshire'); + INSERT INTO streetname VALUES('hoffman'); + INSERT INTO streetname VALUES('hogans way'); + INSERT INTO streetname VALUES('holbert'); + INSERT INTO streetname VALUES('hollow ridge'); + INSERT INTO streetname VALUES('holly vista'); + INSERT INTO streetname VALUES('hollywood'); + INSERT INTO streetname VALUES('hoover'); + INSERT INTO streetname VALUES('hopkins'); + INSERT INTO streetname VALUES('horace mann'); + INSERT INTO streetname VALUES('hornbeam'); + INSERT INTO streetname VALUES('horse pasture'); + INSERT INTO streetname VALUES('hosta'); + INSERT INTO streetname VALUES('howard'); + INSERT INTO streetname VALUES('hubbard'); + INSERT INTO streetname VALUES('hubbard falls'); + INSERT INTO streetname VALUES('hubbard woods'); + INSERT INTO streetname VALUES('hucks'); + INSERT INTO streetname VALUES('hunters creek'); + INSERT INTO streetname VALUES('hunters pointe'); + INSERT INTO streetname VALUES('hunters spring'); + INSERT INTO streetname VALUES('hunters whip'); + INSERT INTO streetname VALUES('huntmeadow'); + INSERT INTO streetname VALUES('hutchison mcdonald'); + INSERT INTO streetname VALUES('ingleton'); + INSERT INTO streetname VALUES('insdale'); + INSERT INTO streetname VALUES('interstate 85 service'); + INSERT INTO streetname VALUES('iola'); + INSERT INTO streetname VALUES('iredell'); + INSERT INTO streetname VALUES('iron brigade'); + INSERT INTO streetname VALUES('irwin valley'); + INSERT INTO streetname VALUES('irwin wood'); + INSERT INTO streetname VALUES('ivy brook'); + INSERT INTO streetname VALUES('ivy ridge'); + INSERT INTO streetname VALUES('jack russell'); + INSERT INTO streetname VALUES('jackson'); + INSERT INTO streetname VALUES('jacob martin'); + INSERT INTO streetname VALUES('jamison'); + INSERT INTO streetname VALUES('jane'); + INSERT INTO streetname VALUES('jaspar crest'); + INSERT INTO streetname VALUES('jessica'); + INSERT INTO streetname VALUES('jimmy oehler'); + INSERT INTO streetname VALUES('jocelyn'); + INSERT INTO streetname VALUES('johnston mill'); + INSERT INTO streetname VALUES('johnston oehler'); + INSERT INTO streetname VALUES('judal'); + INSERT INTO streetname VALUES('junipeous'); + INSERT INTO streetname VALUES('juniper'); + INSERT INTO streetname VALUES('juniperus'); + INSERT INTO streetname VALUES('kalispell'); + INSERT INTO streetname VALUES('karylsturn'); + INSERT INTO streetname VALUES('katelyn'); + INSERT INTO streetname VALUES('kayron'); + INSERT INTO streetname VALUES('keaton'); + INSERT INTO streetname VALUES('keble'); + INSERT INTO streetname VALUES('keels'); + INSERT INTO streetname VALUES('keith'); + INSERT INTO streetname VALUES('keithwood'); + INSERT INTO streetname VALUES('kelden walker'); + INSERT INTO streetname VALUES('kelsey emma'); + INSERT INTO streetname VALUES('kendrick'); + INSERT INTO streetname VALUES('kenmont'); + INSERT INTO streetname VALUES('kennerly cove'); + INSERT INTO streetname VALUES('kenninghall'); + INSERT INTO streetname VALUES('kent village'); + INSERT INTO streetname VALUES('kestral ridge'); + INSERT INTO streetname VALUES('kestrel'); + INSERT INTO streetname VALUES('kilmartin'); + INSERT INTO streetname VALUES('kilty'); + INSERT INTO streetname VALUES('kinglet'); + INSERT INTO streetname VALUES('kingsland'); + INSERT INTO streetname VALUES('kingsnorth'); + INSERT INTO streetname VALUES('kinsmore'); + INSERT INTO streetname VALUES('kirkgard'); + INSERT INTO streetname VALUES('kirkmont'); + INSERT INTO streetname VALUES('knightsgate'); + INSERT INTO streetname VALUES('kobuk'); + INSERT INTO streetname VALUES('kotlik'); + INSERT INTO streetname VALUES('kotz'); + INSERT INTO streetname VALUES('kyndall walk'); + INSERT INTO streetname VALUES('laborde'); + INSERT INTO streetname VALUES('lady bank'); + INSERT INTO streetname VALUES('lagrande'); + INSERT INTO streetname VALUES('lake'); + INSERT INTO streetname VALUES('lakeridge commons'); + INSERT INTO streetname VALUES('lakeview'); + INSERT INTO streetname VALUES('lakewood edge'); + INSERT INTO streetname VALUES('lakota'); + INSERT INTO streetname VALUES('lambrook'); + INSERT INTO streetname VALUES('lampkin'); + INSERT INTO streetname VALUES('lampkin park'); + INSERT INTO streetname VALUES('langham'); + INSERT INTO streetname VALUES('lanzerac manor'); + INSERT INTO streetname VALUES('larkmead forest'); + INSERT INTO streetname VALUES('lattice'); + INSERT INTO streetname VALUES('laurel crest'); + INSERT INTO streetname VALUES('laurel ridge'); + INSERT INTO streetname VALUES('laurel run'); + INSERT INTO streetname VALUES('laurenfield'); + INSERT INTO streetname VALUES('laveta'); + INSERT INTO streetname VALUES('lazy day'); + INSERT INTO streetname VALUES('leawood run'); + INSERT INTO streetname VALUES('lee marie'); + INSERT INTO streetname VALUES('legacy lake'); + INSERT INTO streetname VALUES('legacy park'); + INSERT INTO streetname VALUES('legato'); + INSERT INTO streetname VALUES('legolas'); + INSERT INTO streetname VALUES('leigh glen'); + INSERT INTO streetname VALUES('lence'); + INSERT INTO streetname VALUES('lenox hill'); + INSERT INTO streetname VALUES('leonine'); + INSERT INTO streetname VALUES('leslie'); + INSERT INTO streetname VALUES('lester hill'); + INSERT INTO streetname VALUES('levisey'); + INSERT INTO streetname VALUES('liberty bell'); + INSERT INTO streetname VALUES('linden berry'); + INSERT INTO streetname VALUES('lisbon'); + INSERT INTO streetname VALUES('little stoney'); + INSERT INTO streetname VALUES('livengood'); + INSERT INTO streetname VALUES('lochway'); + INSERT INTO streetname VALUES('lockman'); + INSERT INTO streetname VALUES('loganville'); + INSERT INTO streetname VALUES('lone tree'); + INSERT INTO streetname VALUES('long creek park'); + INSERT INTO streetname VALUES('long forest'); + INSERT INTO streetname VALUES('looking glass'); + INSERT INTO streetname VALUES('lookout point'); + INSERT INTO streetname VALUES('lowen'); + INSERT INTO streetname VALUES('lusby'); + INSERT INTO streetname VALUES('lyleton'); + INSERT INTO streetname VALUES('lynn lee'); + INSERT INTO streetname VALUES('lynnewood glen'); + INSERT INTO streetname VALUES('machrie'); + INSERT INTO streetname VALUES('mackinac'); + INSERT INTO streetname VALUES('maddox'); + INSERT INTO streetname VALUES('madison park'); + INSERT INTO streetname VALUES('mallard'); + INSERT INTO streetname VALUES('mallard cove'); + INSERT INTO streetname VALUES('mallard forest'); + INSERT INTO streetname VALUES('mallard grove'); + INSERT INTO streetname VALUES('mallard hill'); + INSERT INTO streetname VALUES('mallard park'); + INSERT INTO streetname VALUES('mallard ridge'); + INSERT INTO streetname VALUES('mallard view'); + INSERT INTO streetname VALUES('manbey'); + INSERT INTO streetname VALUES('manning'); + INSERT INTO streetname VALUES('mantario'); + INSERT INTO streetname VALUES('maple'); + INSERT INTO streetname VALUES('maple cove'); + INSERT INTO streetname VALUES('maple park'); + INSERT INTO streetname VALUES('marathon hill'); + INSERT INTO streetname VALUES('marbury'); + INSERT INTO streetname VALUES('marett'); + INSERT INTO streetname VALUES('marigold'); + INSERT INTO streetname VALUES('marionwood'); + INSERT INTO streetname VALUES('marshbank'); + INSERT INTO streetname VALUES('mason'); + INSERT INTO streetname VALUES('mayapple'); + INSERT INTO streetname VALUES('maylandia'); + INSERT INTO streetname VALUES('mayspring'); + INSERT INTO streetname VALUES('mcadam'); + INSERT INTO streetname VALUES('mcchesney'); + INSERT INTO streetname VALUES('mccurdy'); + INSERT INTO streetname VALUES('mcgrath'); + INSERT INTO streetname VALUES('mckendree'); + INSERT INTO streetname VALUES('mclaughlin'); + INSERT INTO streetname VALUES('mctaggart'); + INSERT INTO streetname VALUES('meadow green'); + INSERT INTO streetname VALUES('meadow knoll'); + INSERT INTO streetname VALUES('meadow post'); + INSERT INTO streetname VALUES('meadowmont'); + INSERT INTO streetname VALUES('meadowmont view'); + INSERT INTO streetname VALUES('meadowview hills'); + INSERT INTO streetname VALUES('melshire'); + INSERT INTO streetname VALUES('melstrand'); + INSERT INTO streetname VALUES('mentone'); + INSERT INTO streetname VALUES('meridale crossing'); + INSERT INTO streetname VALUES('merion hills'); + INSERT INTO streetname VALUES('merlot'); + INSERT INTO streetname VALUES('mersham'); + INSERT INTO streetname VALUES('metromont'); + INSERT INTO streetname VALUES('metromont industrial'); + INSERT INTO streetname VALUES('michaw'); + INSERT INTO streetname VALUES('milhaven'); + INSERT INTO streetname VALUES('milhof'); + INSERT INTO streetname VALUES('millstream ridge'); + INSERT INTO streetname VALUES('mineral ridge'); + INSERT INTO streetname VALUES('mint thistle'); + INSERT INTO streetname VALUES('mintleaf'); + INSERT INTO streetname VALUES('mintvale'); + INSERT INTO streetname VALUES('misty'); + INSERT INTO streetname VALUES('misty arbor'); + INSERT INTO streetname VALUES('misty creek'); + INSERT INTO streetname VALUES('misty oaks'); + INSERT INTO streetname VALUES('misty wood'); + INSERT INTO streetname VALUES('mitzi deborah'); + INSERT INTO streetname VALUES('mobile'); + INSERT INTO streetname VALUES('molly elizabeth'); + INSERT INTO streetname VALUES('monmouth'); + INSERT INTO streetname VALUES('montrose'); + INSERT INTO streetname VALUES('moonlight'); + INSERT INTO streetname VALUES('moose'); + INSERT INTO streetname VALUES('morning dew'); + INSERT INTO streetname VALUES('morningsong'); + INSERT INTO streetname VALUES('morningview'); + INSERT INTO streetname VALUES('morsey'); + INSERT INTO streetname VALUES('moss glen'); + INSERT INTO streetname VALUES('mossy bank'); + INSERT INTO streetname VALUES('motor sport'); + INSERT INTO streetname VALUES('mountain laurel'); + INSERT INTO streetname VALUES('mourning dove'); + INSERT INTO streetname VALUES('mozart'); + INSERT INTO streetname VALUES('munsing'); + INSERT INTO streetname VALUES('murray'); + INSERT INTO streetname VALUES('nathan'); + INSERT INTO streetname VALUES('netherhall'); + INSERT INTO streetname VALUES('netherton'); + INSERT INTO streetname VALUES('neuhoff'); + INSERT INTO streetname VALUES('nevin'); + INSERT INTO streetname VALUES('nevin brook'); + INSERT INTO streetname VALUES('nevin glen'); + INSERT INTO streetname VALUES('nevin place'); + INSERT INTO streetname VALUES('new england'); + INSERT INTO streetname VALUES('new house'); + INSERT INTO streetname VALUES('newbary'); + INSERT INTO streetname VALUES('newchurch'); + INSERT INTO streetname VALUES('newfane'); + INSERT INTO streetname VALUES('newgard'); + INSERT INTO streetname VALUES('nicholas'); + INSERT INTO streetname VALUES('nicole'); + INSERT INTO streetname VALUES('nobility'); + INSERT INTO streetname VALUES('norcroft'); + INSERT INTO streetname VALUES('northridge'); + INSERT INTO streetname VALUES('northside'); + INSERT INTO streetname VALUES('northwoods business'); + INSERT INTO streetname VALUES('norway'); + INSERT INTO streetname VALUES('nottinghill'); + INSERT INTO streetname VALUES('numenore'); + INSERT INTO streetname VALUES('nyewood'); + INSERT INTO streetname VALUES('oak'); + INSERT INTO streetname VALUES('oak cove'); + INSERT INTO streetname VALUES('oak pasture'); + INSERT INTO streetname VALUES('oakburn'); + INSERT INTO streetname VALUES('oakwinds'); + INSERT INTO streetname VALUES('oakwood'); + INSERT INTO streetname VALUES('obrien'); + INSERT INTO streetname VALUES('ocala'); + INSERT INTO streetname VALUES('old bridge'); + INSERT INTO streetname VALUES('old fox'); + INSERT INTO streetname VALUES('old potters'); + INSERT INTO streetname VALUES('old statesville'); + INSERT INTO streetname VALUES('old steine'); + INSERT INTO streetname VALUES('old stoney creek'); + INSERT INTO streetname VALUES('old sugar creek'); + INSERT INTO streetname VALUES('old timber'); + INSERT INTO streetname VALUES('old wagon'); + INSERT INTO streetname VALUES('old willow'); + INSERT INTO streetname VALUES('oldenway'); + INSERT INTO streetname VALUES('oneida'); + INSERT INTO streetname VALUES('ontario'); + INSERT INTO streetname VALUES('oriole'); + INSERT INTO streetname VALUES('orofino'); + INSERT INTO streetname VALUES('orr'); + INSERT INTO streetname VALUES('osage'); + INSERT INTO streetname VALUES('osceola'); + INSERT INTO streetname VALUES('osprey knoll'); + INSERT INTO streetname VALUES('oxford hill'); + INSERT INTO streetname VALUES('painted fern'); + INSERT INTO streetname VALUES('painted pony'); + INSERT INTO streetname VALUES('paisley'); + INSERT INTO streetname VALUES('pale moss'); + INSERT INTO streetname VALUES('palladium'); + INSERT INTO streetname VALUES('palmutum'); + INSERT INTO streetname VALUES('palustris'); + INSERT INTO streetname VALUES('panglemont'); + INSERT INTO streetname VALUES('panther'); + INSERT INTO streetname VALUES('panthersville'); + INSERT INTO streetname VALUES('paper whites'); + INSERT INTO streetname VALUES('park'); + INSERT INTO streetname VALUES('parker green'); + INSERT INTO streetname VALUES('parkhouse'); + INSERT INTO streetname VALUES('passour ridge'); + INSERT INTO streetname VALUES('pasture view'); + INSERT INTO streetname VALUES('patricia ann'); + INSERT INTO streetname VALUES('patton'); + INSERT INTO streetname VALUES('patton ridge'); + INSERT INTO streetname VALUES('pawpaw'); + INSERT INTO streetname VALUES('peach'); + INSERT INTO streetname VALUES('peakwood'); + INSERT INTO streetname VALUES('pebble creek'); + INSERT INTO streetname VALUES('pecan cove'); + INSERT INTO streetname VALUES('pedigree'); + INSERT INTO streetname VALUES('pelorus'); + INSERT INTO streetname VALUES('penmore'); + INSERT INTO streetname VALUES('pensfold'); + INSERT INTO streetname VALUES('pepperstone'); + INSERT INTO streetname VALUES('peregrine'); + INSERT INTO streetname VALUES('periwinkle'); + INSERT INTO streetname VALUES('perkins'); + INSERT INTO streetname VALUES('pete brown'); + INSERT INTO streetname VALUES('phillips'); + INSERT INTO streetname VALUES('pickway'); + INSERT INTO streetname VALUES('piercy woods'); + INSERT INTO streetname VALUES('pierpoint'); + INSERT INTO streetname VALUES('pine'); + INSERT INTO streetname VALUES('pine branch'); + INSERT INTO streetname VALUES('pine meadow'); + INSERT INTO streetname VALUES('pineleaf'); + INSERT INTO streetname VALUES('pinewood'); + INSERT INTO streetname VALUES('pintail'); + INSERT INTO streetname VALUES('pipestone'); + INSERT INTO streetname VALUES('placer maple'); + INSERT INTO streetname VALUES('plover'); + INSERT INTO streetname VALUES('plum'); + INSERT INTO streetname VALUES('po box'); + INSERT INTO streetname VALUES('pochard'); + INSERT INTO streetname VALUES('pointview'); + INSERT INTO streetname VALUES('polk and white'); + INSERT INTO streetname VALUES('pond valley'); + INSERT INTO streetname VALUES('pondridge'); + INSERT INTO streetname VALUES('pope farm'); + INSERT INTO streetname VALUES('poplar grove'); + INSERT INTO streetname VALUES('poplar springs'); + INSERT INTO streetname VALUES('portola'); + INSERT INTO streetname VALUES('potters glen'); + INSERT INTO streetname VALUES('powatan'); + INSERT INTO streetname VALUES('prairie valley'); + INSERT INTO streetname VALUES('prescott'); + INSERT INTO streetname VALUES('presmann'); + INSERT INTO streetname VALUES('prestigious'); + INSERT INTO streetname VALUES('princess'); + INSERT INTO streetname VALUES('prosperity'); + INSERT INTO streetname VALUES('prosperity church'); + INSERT INTO streetname VALUES('prosperity commons'); + INSERT INTO streetname VALUES('prosperity park'); + INSERT INTO streetname VALUES('prosperity point'); + INSERT INTO streetname VALUES('prosperity ridge'); + INSERT INTO streetname VALUES('prosperity view'); + INSERT INTO streetname VALUES('purple finch'); + INSERT INTO streetname VALUES('quail'); + INSERT INTO streetname VALUES('queensbury'); + INSERT INTO streetname VALUES('quinn'); + INSERT INTO streetname VALUES('racine'); + INSERT INTO streetname VALUES('radbourne'); + INSERT INTO streetname VALUES('raddington'); + INSERT INTO streetname VALUES('raku'); + INSERT INTO streetname VALUES('rancliffe'); + INSERT INTO streetname VALUES('ravencrest'); + INSERT INTO streetname VALUES('reames'); + INSERT INTO streetname VALUES('rebecca run'); + INSERT INTO streetname VALUES('red bluff'); + INSERT INTO streetname VALUES('red clay'); + INSERT INTO streetname VALUES('red clover'); + INSERT INTO streetname VALUES('red rose'); + INSERT INTO streetname VALUES('red shed'); + INSERT INTO streetname VALUES('red tail'); + INSERT INTO streetname VALUES('redbridge'); + INSERT INTO streetname VALUES('redstart'); + INSERT INTO streetname VALUES('redstone view'); + INSERT INTO streetname VALUES('reedmont'); + INSERT INTO streetname VALUES('reeves'); + INSERT INTO streetname VALUES('regal'); + INSERT INTO streetname VALUES('reinbeck'); + INSERT INTO streetname VALUES('retriever'); + INSERT INTO streetname VALUES('ribbonwalk'); + INSERT INTO streetname VALUES('richardson park'); + INSERT INTO streetname VALUES('richfield'); + INSERT INTO streetname VALUES('riddings'); + INSERT INTO streetname VALUES('ridge'); + INSERT INTO streetname VALUES('ridge cliff'); + INSERT INTO streetname VALUES('ridge path'); + INSERT INTO streetname VALUES('ridge peak'); + INSERT INTO streetname VALUES('ridgefield'); + INSERT INTO streetname VALUES('ridgeline'); + INSERT INTO streetname VALUES('ridgeview commons'); + INSERT INTO streetname VALUES('riley'); + INSERT INTO streetname VALUES('riley woods'); + INSERT INTO streetname VALUES('rillet'); + INSERT INTO streetname VALUES('rindle'); + INSERT INTO streetname VALUES('rivendell'); + INSERT INTO streetname VALUES('robin'); + INSERT INTO streetname VALUES('robins nest'); + INSERT INTO streetname VALUES('robur'); + INSERT INTO streetname VALUES('robyns glen'); + INSERT INTO streetname VALUES('rock stream'); + INSERT INTO streetname VALUES('rockwell'); + INSERT INTO streetname VALUES('rockwell church'); + INSERT INTO streetname VALUES('rocky brook'); + INSERT INTO streetname VALUES('rocky ford club'); + INSERT INTO streetname VALUES('rotary'); + INSERT INTO streetname VALUES('rouda'); + INSERT INTO streetname VALUES('royal bluff'); + INSERT INTO streetname VALUES('royal celadon'); + INSERT INTO streetname VALUES('rubin lura'); + INSERT INTO streetname VALUES('runswyck'); + INSERT INTO streetname VALUES('ruth ferrell'); + INSERT INTO streetname VALUES('ruth polk'); + INSERT INTO streetname VALUES('ryan jay'); + INSERT INTO streetname VALUES('sackett'); + INSERT INTO streetname VALUES('saddle pace'); + INSERT INTO streetname VALUES('saddle run'); + INSERT INTO streetname VALUES('saddle trail'); + INSERT INTO streetname VALUES('saguaro'); + INSERT INTO streetname VALUES('saint audrey'); + INSERT INTO streetname VALUES('saint bernard'); + INSERT INTO streetname VALUES('saint frances'); + INSERT INTO streetname VALUES('sam roper'); + INSERT INTO streetname VALUES('samara'); + INSERT INTO streetname VALUES('sanders creek'); + INSERT INTO streetname VALUES('saquache'); + INSERT INTO streetname VALUES('sarnia'); + INSERT INTO streetname VALUES('savannah springs'); + INSERT INTO streetname VALUES('sawgrass ridge'); + INSERT INTO streetname VALUES('saxonbury'); + INSERT INTO streetname VALUES('scotch moss'); + INSERT INTO streetname VALUES('seasons'); + INSERT INTO streetname VALUES('serenity'); + INSERT INTO streetname VALUES('seths'); + INSERT INTO streetname VALUES('shadow lawn'); + INSERT INTO streetname VALUES('shadow oaks'); + INSERT INTO streetname VALUES('shadow pine'); + INSERT INTO streetname VALUES('shadyside'); + INSERT INTO streetname VALUES('shallow oak'); + INSERT INTO streetname VALUES('shelley'); + INSERT INTO streetname VALUES('shining oak'); + INSERT INTO streetname VALUES('ship'); + INSERT INTO streetname VALUES('shore haven'); + INSERT INTO streetname VALUES('shuman'); + INSERT INTO streetname VALUES('sidney'); + INSERT INTO streetname VALUES('silver birch'); + INSERT INTO streetname VALUES('silvermere'); + INSERT INTO streetname VALUES('simonton'); + INSERT INTO streetname VALUES('singing hills'); + INSERT INTO streetname VALUES('singing oak'); + INSERT INTO streetname VALUES('sipes'); + INSERT INTO streetname VALUES('six point'); + INSERT INTO streetname VALUES('skycrest'); + INSERT INTO streetname VALUES('skyline'); + INSERT INTO streetname VALUES('small'); + INSERT INTO streetname VALUES('smith corners'); + INSERT INTO streetname VALUES('smithwood'); + INSERT INTO streetname VALUES('snow hill'); + INSERT INTO streetname VALUES('soapstone'); + INSERT INTO streetname VALUES('sobeck'); + INSERT INTO streetname VALUES('socata'); + INSERT INTO streetname VALUES('solace'); + INSERT INTO streetname VALUES('solway'); + INSERT INTO streetname VALUES('song sparrow'); + INSERT INTO streetname VALUES('sorrento'); + INSERT INTO streetname VALUES('spector'); + INSERT INTO streetname VALUES('spin drift'); + INSERT INTO streetname VALUES('spring crest'); + INSERT INTO streetname VALUES('spring lee'); + INSERT INTO streetname VALUES('spring park'); + INSERT INTO streetname VALUES('spring terrace'); + INSERT INTO streetname VALUES('spring trace'); + INSERT INTO streetname VALUES('springhaven'); + INSERT INTO streetname VALUES('squirrel trail'); + INSERT INTO streetname VALUES('stardust'); + INSERT INTO streetname VALUES('stargaze'); + INSERT INTO streetname VALUES('starita'); + INSERT INTO streetname VALUES('starmount'); + INSERT INTO streetname VALUES('statesville'); + INSERT INTO streetname VALUES('steed'); + INSERT INTO streetname VALUES('steelewood'); + INSERT INTO streetname VALUES('steepleglen'); + INSERT INTO streetname VALUES('stephens farm'); + INSERT INTO streetname VALUES('stewarton'); + INSERT INTO streetname VALUES('stone park'); + INSERT INTO streetname VALUES('stonebrook'); + INSERT INTO streetname VALUES('stonefield'); + INSERT INTO streetname VALUES('stoneglen'); + INSERT INTO streetname VALUES('stonemarsh'); + INSERT INTO streetname VALUES('stoney garden'); + INSERT INTO streetname VALUES('stoney run'); + INSERT INTO streetname VALUES('stoney valley'); + INSERT INTO streetname VALUES('stoneykirk'); + INSERT INTO streetname VALUES('stream bank'); + INSERT INTO streetname VALUES('stream ridge'); + INSERT INTO streetname VALUES('suburban'); + INSERT INTO streetname VALUES('suffield'); + INSERT INTO streetname VALUES('sugar creek'); + INSERT INTO streetname VALUES('sugarberry'); + INSERT INTO streetname VALUES('sugarstone'); + INSERT INTO streetname VALUES('summer creek'); + INSERT INTO streetname VALUES('summer valley'); + INSERT INTO streetname VALUES('summercrest'); + INSERT INTO streetname VALUES('summercroft'); + INSERT INTO streetname VALUES('summerford'); + INSERT INTO streetname VALUES('summergold'); + INSERT INTO streetname VALUES('sunbeam'); + INSERT INTO streetname VALUES('sunbridge'); + INSERT INTO streetname VALUES('sunpath'); + INSERT INTO streetname VALUES('sunset'); + INSERT INTO streetname VALUES('sunset ridge'); + INSERT INTO streetname VALUES('sunstone'); + INSERT INTO streetname VALUES('suntrace'); + INSERT INTO streetname VALUES('sunwalk'); + INSERT INTO streetname VALUES('sutters hill'); + INSERT INTO streetname VALUES('suttonview'); + INSERT INTO streetname VALUES('swallow tail'); + INSERT INTO streetname VALUES('swanston'); + INSERT INTO streetname VALUES('sweet grove'); + INSERT INTO streetname VALUES('sweet rose'); + INSERT INTO streetname VALUES('sweetbriar ridge'); + INSERT INTO streetname VALUES('sweetfield'); + INSERT INTO streetname VALUES('sydney overlook'); + INSERT INTO streetname VALUES('sylvan'); + INSERT INTO streetname VALUES('symphony woods'); + INSERT INTO streetname VALUES('tallia'); + INSERT INTO streetname VALUES('tallu'); + INSERT INTO streetname VALUES('talwyn'); + INSERT INTO streetname VALUES('tanager'); + INSERT INTO streetname VALUES('tanager park'); + INSERT INTO streetname VALUES('tangley'); + INSERT INTO streetname VALUES('taranasay'); + INSERT INTO streetname VALUES('tarby'); + INSERT INTO streetname VALUES('tarland'); + INSERT INTO streetname VALUES('tarpway'); + INSERT INTO streetname VALUES('tauten'); + INSERT INTO streetname VALUES('taymouth'); + INSERT INTO streetname VALUES('ten trees'); + INSERT INTO streetname VALUES('terrace view'); + INSERT INTO streetname VALUES('terrier'); + INSERT INTO streetname VALUES('tesh'); + INSERT INTO streetname VALUES('teton'); + INSERT INTO streetname VALUES('tewkesbury'); + INSERT INTO streetname VALUES('thelema'); + INSERT INTO streetname VALUES('thistle bloom'); + INSERT INTO streetname VALUES('thistledown'); + INSERT INTO streetname VALUES('thomas ridge'); + INSERT INTO streetname VALUES('thornbrook'); + INSERT INTO streetname VALUES('tifton grass'); + INSERT INTO streetname VALUES('tigerton'); + INSERT INTO streetname VALUES('tomsie efird'); + INSERT INTO streetname VALUES('tor'); + INSERT INTO streetname VALUES('torphin'); + INSERT INTO streetname VALUES('torrence'); + INSERT INTO streetname VALUES('towering pine'); + INSERT INTO streetname VALUES('towhee'); + INSERT INTO streetname VALUES('toxaway'); + INSERT INTO streetname VALUES('tracy glenn'); + INSERT INTO streetname VALUES('tradition view'); + INSERT INTO streetname VALUES('trailer'); + INSERT INTO streetname VALUES('transport'); + INSERT INTO streetname VALUES('trehurst'); + INSERT INTO streetname VALUES('trexler'); + INSERT INTO streetname VALUES('trillium fields'); + INSERT INTO streetname VALUES('trimbach'); + INSERT INTO streetname VALUES('tucker'); + INSERT INTO streetname VALUES('tullamore'); + INSERT INTO streetname VALUES('tullock creek'); + INSERT INTO streetname VALUES('tunston'); + INSERT INTO streetname VALUES('tupelo'); + INSERT INTO streetname VALUES('turnabout'); + INSERT INTO streetname VALUES('turney'); + INSERT INTO streetname VALUES('turtle cross'); + INSERT INTO streetname VALUES('turtleback'); + INSERT INTO streetname VALUES('twelvestone'); + INSERT INTO streetname VALUES('twin'); + INSERT INTO streetname VALUES('twin brook'); + INSERT INTO streetname VALUES('twin lakes'); + INSERT INTO streetname VALUES('twisted pine'); + INSERT INTO streetname VALUES('tyler finley'); + INSERT INTO streetname VALUES('university station'); + INSERT INTO streetname VALUES('uphill'); + INSERT INTO streetname VALUES('valeview'); + INSERT INTO streetname VALUES('valhalla'); + INSERT INTO streetname VALUES('van'); + INSERT INTO streetname VALUES('vance davis'); + INSERT INTO streetname VALUES('vanhoy'); + INSERT INTO streetname VALUES('veckman'); + INSERT INTO streetname VALUES('victoria'); + INSERT INTO streetname VALUES('victory'); + INSERT INTO streetname VALUES('village glen'); + INSERT INTO streetname VALUES('vireo'); + INSERT INTO streetname VALUES('viscount'); + INSERT INTO streetname VALUES('voeltz'); + INSERT INTO streetname VALUES('wade e morgan'); + INSERT INTO streetname VALUES('wake'); + INSERT INTO streetname VALUES('wales'); + INSERT INTO streetname VALUES('wallace ridge'); + INSERT INTO streetname VALUES('waltham'); + INSERT INTO streetname VALUES('wanamassa'); + INSERT INTO streetname VALUES('warbler wood'); + INSERT INTO streetname VALUES('washington'); + INSERT INTO streetname VALUES('water'); + INSERT INTO streetname VALUES('waterelm'); + INSERT INTO streetname VALUES('waterford hills'); + INSERT INTO streetname VALUES('waterford valley'); + INSERT INTO streetname VALUES('waterloo'); + INSERT INTO streetname VALUES('waterton leas'); + INSERT INTO streetname VALUES('waverly lynn'); + INSERT INTO streetname VALUES('waverlyglen'); + INSERT INTO streetname VALUES('wayside'); + INSERT INTO streetname VALUES('westbury lake'); + INSERT INTO streetname VALUES('westray'); + INSERT INTO streetname VALUES('whistlers chase'); + INSERT INTO streetname VALUES('whistley green'); + INSERT INTO streetname VALUES('whistling oak'); + INSERT INTO streetname VALUES('whitcomb'); + INSERT INTO streetname VALUES('white aspen'); + INSERT INTO streetname VALUES('white cascade'); + INSERT INTO streetname VALUES('white mist'); + INSERT INTO streetname VALUES('white rock'); + INSERT INTO streetname VALUES('white stag'); + INSERT INTO streetname VALUES('whitegate'); + INSERT INTO streetname VALUES('whitehill'); + INSERT INTO streetname VALUES('whitetail'); + INSERT INTO streetname VALUES('whitewood'); + INSERT INTO streetname VALUES('wilburn park'); + INSERT INTO streetname VALUES('wild garden'); + INSERT INTO streetname VALUES('wild rose'); + INSERT INTO streetname VALUES('wilkins terrace'); + INSERT INTO streetname VALUES('william ficklen'); + INSERT INTO streetname VALUES('wiltshire ridge'); + INSERT INTO streetname VALUES('windchase'); + INSERT INTO streetname VALUES('winding jordan'); + INSERT INTO streetname VALUES('windy meadow'); + INSERT INTO streetname VALUES('winghaven'); + INSERT INTO streetname VALUES('wingmont'); + INSERT INTO streetname VALUES('winslow'); + INSERT INTO streetname VALUES('winter pine'); + INSERT INTO streetname VALUES('winter view'); + INSERT INTO streetname VALUES('wolf creek'); + INSERT INTO streetname VALUES('wondering oak'); + INSERT INTO streetname VALUES('woodard'); + INSERT INTO streetname VALUES('woodfire'); + INSERT INTO streetname VALUES('woodland commons'); + INSERT INTO streetname VALUES('woodland hills'); + INSERT INTO streetname VALUES('woodnotch'); + INSERT INTO streetname VALUES('woodstone'); + INSERT INTO streetname VALUES('worsley'); + INSERT INTO streetname VALUES('wren creek'); + INSERT INTO streetname VALUES('wrens nest'); + INSERT INTO streetname VALUES('wrexham'); + INSERT INTO streetname VALUES('wt harris'); + INSERT INTO streetname VALUES('wylie meadow'); + INSERT INTO streetname VALUES('wynborough'); + INSERT INTO streetname VALUES('wynbrook'); + INSERT INTO streetname VALUES('wyndham hill'); + INSERT INTO streetname VALUES('yandem'); + INSERT INTO streetname VALUES('yellow rose'); + INSERT INTO streetname VALUES('yellow spaniel'); + INSERT INTO streetname VALUES('yorkford'); + INSERT INTO streetname VALUES('ziegler'); + INSERT INTO streetname VALUES('zion renaissance'); + + SELECT count(*) FROM streetname; + } +} {1228} + +do_test fuzzer1-2.1 { + execsql { + SELECT n, distance FROM f2, streetname + WHERE f2.word MATCH 'wersley' + AND f2.distance<=150 + AND f2.word=streetname.n + } +} {worsley 37} +do_test fuzzer1-2.2 { + execsql { + SELECT n, distance FROM f2, streetname + WHERE f2.word MATCH 'testledown' + AND f2.distance<=150 + AND f2.word=streetname.n + } +} {thistledown 103} +do_test fuzzer1-2.3 { + execsql { + SELECT DISTINCT streetname.n FROM f2, streetname + WHERE f2.word MATCH 'tayle' + AND f2.distance<=200 + AND streetname.n>=f2.word AND streetname.n<=(f2.word || x'F7BFBFBF') + } +} {{tyler finley} trailer taymouth steelewood tallia tallu talwyn thelema} +do_test fuzzer1-2.4 { + execsql { + SELECT DISTINCT streetname.n + FROM f2 JOIN streetname + ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz')) + WHERE f2.word MATCH 'duck' + AND f2.distance<150 + AND f2.ruleset=3 + ORDER BY 1 + } +} {mallard {mallard cove} {mallard forest} {mallard grove} {mallard hill} {mallard park} {mallard ridge} {mallard view}} +do_test fuzzer1-2.5 { + execsql { + SELECT DISTINCT streetname.n + FROM f2 JOIN streetname + ON (streetname.n>=f2.word AND streetname.n<=(f2.word || 'zzzzzz')) + WHERE f2.word MATCH 'duck' + AND f2.distance<150 + AND f2.ruleset=2 + ORDER BY 1 + } +} {} + +forcedelete test.db2 +do_execsql_test fuzzer1-4.1 { + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.f3_rules(ruleset, cfrom, cto, cost); + INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(0, 'x','y', 10); + INSERT INTO f3_rules(ruleset, cfrom, cto, cost) VALUES(1, 'a','b', 10); + CREATE VIRTUAL TABLE aux.f3 USING fuzzer(f3_rules); + SELECT word FROM f3 WHERE word MATCH 'ax' +} {ax ay} + +#------------------------------------------------------------------------- +# +# 1.5.1 - Check things work with a fuzzer data table name that requires +# quoting. Also that NULL entries in the "from" column of the +# data table are treated as zero length strings (''). +# +# 1.5.2 - Check that no-op rules (i.e. C->C) are ignored. Test NULL in +# the "to" column of a fuzzer data table. +# +# 1.5.3 - Test out-of-range values for the cost field of the data table. +# +# 1.5.4 - Test out-of-range values for the string fields of the data table. +# +# 1.5.5 - Test out-of-range values for the ruleset field of the data table. +# +do_execsql_test 5.1 { + CREATE TABLE "fuzzer [x] rules table"(a, b, c, d); + INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, 'abc', 10); + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + SELECT word, distance FROM x WHERE word MATCH '123' LIMIT 4; +} {123 0 abc123 10 1abc23 10 12abc3 10} + +do_execsql_test 5.2 { + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', NULL, 20); + INSERT INTO "fuzzer [x] rules table" VALUES(0, NULL, NULL, 10); + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'x', 'x', 10); + + DROP TABLE x; + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + + SELECT word, distance FROM x WHERE word MATCH 'xx'; +} {xx 0 x 20 {} 40} + +do_execsql_test 5.3.1 { + DROP TABLE IF EXISTS x; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'c', 'd', 1001); +} +do_catchsql_test 5.3.2 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.3.3 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', 0); +} +do_catchsql_test 5.3.4 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.3.5 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(0, 'd', 'c', -20); +} +do_catchsql_test 5.3.6 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: cost must be between 1 and 1000}} + +do_execsql_test 5.4.1 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, 'x', '12345678901234567890123456789012345678901234567890', 2 + ); + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); + SELECT word FROM x WHERE word MATCH 'x'; +} {x 12345678901234567890123456789012345678901234567890} + +do_execsql_test 5.4.2 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, 'x', '123456789012345678901234567890123456789012345678901', 2 + ); +} +do_catchsql_test 5.4.3 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: maximum string length is 50}} + +do_execsql_test 5.4.4 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES( + 0, '123456789012345678901234567890123456789012345678901', 'x', 2 + ); +} +do_catchsql_test 5.4.5 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: maximum string length is 50}} + +do_execsql_test 5.5.1 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES(-1, 'x', 'y', 2); +} +do_catchsql_test 5.5.2 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: ruleset must be between 0 and 2147483647}} + +do_execsql_test 5.5.3 { + DROP TABLE IF EXISTS x; + DELETE FROM "fuzzer [x] rules table"; + INSERT INTO "fuzzer [x] rules table" VALUES((1<<32)+100, 'x', 'y', 2); +} +do_catchsql_test 5.5.4 { + CREATE VIRTUAL TABLE x USING fuzzer('fuzzer [x] rules table'); +} {1 {fuzzer: ruleset must be between 0 and 2147483647}} + +#------------------------------------------------------------------------- +# Test using different types of quotes with CREATE VIRTUAL TABLE +# arguments. +# +do_execsql_test 7.1 { + CREATE TABLE [x2 "rules] (a, b, c, d); + INSERT INTO [x2 "rules] VALUES(0, 'a', 'b', 5); +} +foreach {tn sql} { + 1 { CREATE VIRTUAL TABLE x2 USING fuzzer( [x2 "rules] ) } + 2 { CREATE VIRTUAL TABLE x2 USING fuzzer( "x2 ""rules" ) } + 3 { CREATE VIRTUAL TABLE x2 USING fuzzer( 'x2 "rules' ) } + 4 { CREATE VIRTUAL TABLE x2 USING fuzzer( `x2 "rules` ) } +} { + do_execsql_test 7.2.$tn.1 { DROP TABLE IF EXISTS x2 } + do_execsql_test 7.2.$tn.2 $sql + do_execsql_test 7.2.$tn.3 { + SELECT word FROM x2 WHERE word MATCH 'aaa' + } {aaa baa aba aab bab abb bba bbb} +} + +#------------------------------------------------------------------------- +# Test using a fuzzer table in different contexts. +# +do_execsql_test 8.1 { + CREATE TABLE x3_rules(rule_set, cFrom, cTo, cost); + INSERT INTO x3_rules VALUES(2, 'a', 'x', 10); + INSERT INTO x3_rules VALUES(2, 'a', 'y', 9); + INSERT INTO x3_rules VALUES(2, 'a', 'z', 8); + CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules); +} + +do_execsql_test 8.2.1 { + SELECT cFrom, cTo, word + FROM x3_rules CROSS JOIN x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo; +} {a x x a y y a z z} + +do_execsql_test 8.2.2 { + SELECT cFrom, cTo, word + FROM x3 CROSS JOIN x3_rules + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC +} {a z z a y y a x x} + +do_execsql_test 8.2.3 { + SELECT cFrom, cTo, word + FROM x3_rules, x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.4 { + SELECT cFrom, cTo, word + FROM x3, x3_rules + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.5 { + CREATE INDEX i1 ON x3_rules(cost); + SELECT cFrom, cTo, word + FROM x3_rules, x3 + WHERE word MATCH 'a' AND cost=distance AND ruleset=2 + ORDER BY +cTo DESC; +} {a z z a y y a x x} + +do_execsql_test 8.2.5 { + SELECT word FROM x3_rules, x3 WHERE word MATCH x3_rules.cFrom AND ruleset=2 +} {a z y x a z y x a z y x} + +do_execsql_test 8.2.6 { + SELECT word FROM x3_rules, x3 + WHERE word MATCH x3_rules.cFrom + AND ruleset=2 + AND x3_rules.cost=8; +} {a z y x} + +do_execsql_test 8.2.7 { + CREATE TABLE t1(a, b); + CREATE INDEX i2 ON t1(b); + SELECT word, distance FROM x3, t1 + WHERE x3.word MATCH t1.a AND ruleset=2 AND distance=t1.b; +} {} + +do_execsql_test 8.2.8 { + INSERT INTO x3_rules VALUES(1, 'a', 't', 5); + INSERT INTO x3_rules VALUES(1, 'a', 'u', 4); + INSERT INTO x3_rules VALUES(1, 'a', 'v', 3); + DROP TABLE x3; + CREATE VIRTUAL TABLE x3 USING fuzzer(x3_rules); + SELECT * FROM x3_rules; +} { + 2 a x 10 + 2 a y 9 + 2 a z 8 + 1 a t 5 + 1 a u 4 + 1 a v 3 +} + +do_catchsql_test 8.2.9 { + SELECT word FROM x3 WHERE ruleset=2 AND word MATCH 'a' AND WORD MATCH 'b'; +} {1 {unable to use function MATCH in the requested context}} + +do_execsql_test 8.2.10 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' +} {a v u t} + +# The term "ruleset<=1" is not handled by the fuzzer module. Instead, it +# is handled by SQLite, which assumes that all rows have a NULL value in +# the ruleset column. Since NULL<=1 is never true, this query returns +# no rows. +do_execsql_test 8.2.11 { + SELECT word FROM x3 WHERE ruleset<=1 AND word MATCH 'a' +} {} + +do_execsql_test 8.2.12 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance ASC; +} {a v u t} + +do_execsql_test 8.2.13 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY distance DESC; +} {t u v a} + +do_execsql_test 8.2.13 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word ASC; +} {a t u v} + +do_execsql_test 8.2.14 { + SELECT word FROM x3 WHERE ruleset=1 AND word MATCH 'a' ORDER BY word DESC; +} {v u t a} + +#------------------------------------------------------------------------- +# +do_execsql_test 9.1 { + CREATE TABLE x4_rules(a, b, c, d); + INSERT INTO x4_rules VALUES(0, 'a', 'b', 10); + INSERT INTO x4_rules VALUES(0, 'a', 'c', 11); + INSERT INTO x4_rules VALUES(0, 'bx', 'zz', 20); + INSERT INTO x4_rules VALUES(0, 'cx', 'yy', 15); + INSERT INTO x4_rules VALUES(0, 'zz', '!!', 50); + CREATE VIRTUAL TABLE x4 USING fuzzer(x4_rules); +} + +do_execsql_test 9.2 { + SELECT word, distance FROM x4 WHERE word MATCH 'ax'; +} {ax 0 bx 10 cx 11 yy 26 zz 30 !! 80} + + +do_execsql_test 10.1 { + CREATE TABLE x5_rules(a, b, c, d); + CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules); +} + +do_execsql_test 10.2 { + SELECT word, distance FROM x5 WHERE word MATCH + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' || + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' || + 'aaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaaXaaaaaaaaa' +} {} + +do_execsql_test 10.3 { + INSERT INTO x5_rules VALUES(0, 'a', '0.1.2.3.4.5.6.7.8.9.a', 1); + DROP TABLE x5; + CREATE VIRTUAL TABLE x5 USING fuzzer(x5_rules); + SELECT length(word) FROM x5 WHERE word MATCH 'a' LIMIT 50; +} {1 21 41 61 81} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer2.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer2.test new file mode 100644 index 0000000000000000000000000000000000000000..44ee9e312c540cdf0a9d9b32ffed3f3f251d4ac6 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzer2.test @@ -0,0 +1,72 @@ +# 2016 February 4 +# +# 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. +# +#*********************************************************************** +# The focus of the tests is the word-fuzzer virtual table. The tests +# in this file are slower than those in fuzzer1.test. So this file does +# not run as part of veryquick.test etc. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +ifcapable !vtab { + finish_test + return +} + +set ::testprefix fuzzer2 +load_static_extension db fuzzer + +#------------------------------------------------------------------------- +# This test uses a fuzzer table with many rules. There is one rule to +# map each possible two character string, where characters are lower-case +# letters used in the English language, to all other possible two character +# strings. In total, (26^4)-(26^2) mappings (the subtracted term represents +# the no-op mappings discarded automatically by the fuzzer). +# +# +do_execsql_test 1.1.1 { + DROP TABLE IF EXISTS x1; + DROP TABLE IF EXISTS x1_rules; + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); +} +puts "This test is slow - perhaps around 7 seconds on an average pc" +do_test 1.1.2 { + set LETTERS {a b c d e f g h i j k l m n o p q r s t u v w x y z} + set cost 1 + db transaction { + foreach c1 $LETTERS { + foreach c2 $LETTERS { + foreach c3 $LETTERS { + foreach c4 $LETTERS { + db eval {INSERT INTO x1_rules VALUES(0, $c1||$c2, $c3||$c4, $cost)} + set cost [expr ($cost%1000) + 1] + } + } + } + } + db eval {UPDATE x1_rules SET cost = 20 WHERE cost<20 AND cFrom!='xx'} + } +} {} + +do_execsql_test 1.2 { + SELECT count(*) FROM x1_rules WHERE cTo!=cFrom; +} [expr 26*26*26*26 - 26*26] + +do_execsql_test 1.2.1 { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT word FROM x1 WHERE word MATCH 'xx' LIMIT 10; +} {xx hw hx hy hz ia ib ic id ie} +do_execsql_test 1.2.2 { + SELECT cTo FROM x1_rules WHERE cFrom='xx' + ORDER BY cost asc, rowid asc LIMIT 9; +} {hw hx hy hz ia ib ic id ie} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzerfault.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzerfault.test new file mode 100644 index 0000000000000000000000000000000000000000..e281cb592e6c0acd5dc400e032489e43e297b260 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzerfault.test @@ -0,0 +1,111 @@ +# 2012 February 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 implements regression tests for TCL interface to the +# SQLite library. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +ifcapable !vtab { finish_test ; return } +set ::testprefix fuzzerfault + +load_static_extension db fuzzer + +do_test 1-pre1 { + execsql { + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x1_rules VALUES(0, 'a', 'b', 1); + INSERT INTO x1_rules VALUES(0, 'a', 'c', 2); + INSERT INTO x1_rules VALUES(0, 'a', 'd', 3); + } + faultsim_save_and_close +} {} +do_faultsim_test 1 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT word FROM x1 WHERE word MATCH 'xax'; + } +} -test { + faultsim_test_result {0 {xax xbx xcx xdx}} \ + {1 {vtable constructor failed: x1}} +} + +do_test 2-pre1 { + faultsim_delete_and_reopen + load_static_extension db fuzzer + execsql { + CREATE TABLE x2_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x2_rules VALUES(0, 'a', 'x', 1); + INSERT INTO x2_rules VALUES(0, 'b', 'x', 2); + INSERT INTO x2_rules VALUES(0, 'c', 'x', 3); + CREATE VIRTUAL TABLE x2 USING fuzzer(x2_rules); + } + faultsim_save_and_close +} {} + +do_faultsim_test 2 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + SELECT count(*) FROM x2 WHERE word MATCH 'abc'; + } +} -test { + faultsim_test_result {0 8} {1 {vtable constructor failed: x2}} +} + +do_test 3-pre1 { + faultsim_delete_and_reopen + execsql { + CREATE TABLE x1_rules(ruleset, cFrom, cTo, cost); + INSERT INTO x1_rules VALUES(0, 'a', + '123456789012345678901234567890a1234567890123456789', 10 + ); + } + faultsim_save_and_close +} {} + +do_faultsim_test 3 -prep { + faultsim_restore_and_reopen + load_static_extension db fuzzer +} -body { + execsql { + CREATE VIRTUAL TABLE x1 USING fuzzer(x1_rules); + SELECT count(*) FROM (SELECT * FROM x1 WHERE word MATCH 'a' LIMIT 2); + } +} -test { + faultsim_test_result {0 2} {1 {vtable constructor failed: x1}} +} + +#------------------------------------------------------------------------- +reset_db +do_execsql_test 4.0 { + CREATE TABLE t1_a(a INTEFDR PRIMARY KEY, b TEXT); + CREATE TABLE t3_a(k FnTEGER PRIMARY KEY, v TEXT); + CREATE TABLE t3_b(k INTEÀ5R PRIMARY KEY, v TEXT); + CREATE VIEW t3 AS SELECT * FROM t3_a UNION ALL SELECT * FROM t3_b; +} +faultsim_save_and_close + +do_faultsim_test 4 -faults oom-t* -prep { + faultsim_restore_and_reopen +} -body { + execsql { + SELECT 1 FROM t1_a LEFT JOIN t3 ON ((1+1) AND k=1) + } +} -test { + faultsim_test_result {0 {}} +} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzinvariants.c b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzinvariants.c new file mode 100644 index 0000000000000000000000000000000000000000..c8aae6e3dd65a35ea370b34d222da48d924b0cae --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/fuzzinvariants.c @@ -0,0 +1,557 @@ +/* +** 2022-06-14 +** +** 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 library is used by fuzzcheck to test query invariants. +** +** An sqlite3_stmt is passed in that has just returned SQLITE_ROW. This +** routine does: +** +** * Record the output of the current row +** * Construct an alternative query that should return the same row +** * Run the alternative query and verify that it does in fact return +** the same row +** +*/ +#include "sqlite3.h" +#include +#include +#include +#include + +/* 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 *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 */ +); + +/* +** Special parameter binding, for testing and debugging purposes. +** +** $int_NNN -> integer value NNN +** $text_TTTT -> floating point value TTT with destructor +*/ +static void bindDebugParameters(sqlite3_stmt *pStmt){ + int nVar = sqlite3_bind_parameter_count(pStmt); + int i; + for(i=1; i<=nVar; i++){ + const char *zVar = sqlite3_bind_parameter_name(pStmt, i); + if( zVar==0 ) continue; + if( strncmp(zVar, "$int_", 5)==0 ){ + sqlite3_bind_int(pStmt, i, atoi(&zVar[5])); + }else + if( strncmp(zVar, "$text_", 6)==0 ){ + size_t szVar = strlen(zVar); + char *zBuf = sqlite3_malloc64( szVar-5 ); + if( zBuf ){ + memcpy(zBuf, &zVar[6], szVar-5); + sqlite3_bind_text64(pStmt, i, zBuf, szVar-6, sqlite3_free, SQLITE_UTF8); + } + } + } +} + +/* +** Do an invariant check on pStmt. iCnt determines which invariant check to +** perform. The first check is iCnt==0. +** +** *pbCorrupt is a flag that, if true, indicates that the database file +** is known to be corrupt. A value of non-zero means "yes, the database +** is corrupt". A zero value means "we do not know whether or not the +** database is corrupt". The value might be set prior to entry, or this +** routine might set the value. +** +** Return values: +** +** SQLITE_OK This check was successful. +** +** SQLITE_DONE iCnt is out of range. The caller typically sets +** up a loop on iCnt starting with zero, and increments +** iCnt until this code is returned. +** +** SQLITE_CORRUPT The invariant failed, but the underlying database +** file is indicating that it is corrupt, which might +** be the cause of the malfunction. The *pCorrupt +** value will also be set. +** +** SQLITE_INTERNAL The invariant failed, and the database file is not +** corrupt. (This never happens because this function +** will call abort() following an invariant failure.) +** +** (other) Some other kind of error occurred. +*/ +int fuzz_invariant( + sqlite3 *db, /* The database connection */ + sqlite3_stmt *pStmt, /* Test statement stopped on an SQLITE_ROW */ + int iCnt, /* Invariant sequence number, starting at 0 */ + 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 */ + unsigned int dbOpt /* Default optimization flags */ +){ + char *zTest; + sqlite3_stmt *pTestStmt = 0; + int rc; + 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", + sqlite3_errmsg(db), zTest); + } + sqlite3_free(zTest); + sqlite3_finalize(pTestStmt); + return rc; + } + sqlite3_free(zTest); + bindDebugParameters(pTestStmt); + nCol = sqlite3_column_count(pStmt); + for(i=0; i=2 ){ + char *zSql = sqlite3_expanded_sql(pTestStmt); + printf("invariant-sql row=%d #%d:\n%s\n", iRow, iCnt, zSql); + sqlite3_free(zSql); + } + while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){ + for(i=0; i=nCol ) break; + } + if( rc==SQLITE_DONE ){ + /* No matching output row found */ + sqlite3_stmt *pCk = 0; + int iOrigRSO; + + + /* This is not a fault if the database file is corrupt, because anything + ** can happen with a corrupt database file */ + rc = sqlite3_prepare_v2(db, "PRAGMA integrity_check", -1, &pCk, 0); + if( rc ){ + sqlite3_finalize(pCk); + sqlite3_finalize(pTestStmt); + return rc; + } + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #1:\n%s\n", zSql); + sqlite3_free(zSql); + } + + rc = sqlite3_step(pCk); + if( rc!=SQLITE_ROW + || sqlite3_column_text(pCk, 0)==0 + || strcmp((const char*)sqlite3_column_text(pCk,0),"ok")!=0 + ){ + *pbCorrupt = 1; + sqlite3_finalize(pCk); + sqlite3_finalize(pTestStmt); + return SQLITE_CORRUPT; + } + sqlite3_finalize(pCk); + + /* + ** If inverting the scan order also results in a miss, assume that the + ** query is ambiguous and do not report a fault. + */ + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, -1, &iOrigRSO); + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, !iOrigRSO, 0); + sqlite3_prepare_v2(db, sqlite3_sql(pStmt), -1, &pCk, 0); + sqlite3_db_config(db, SQLITE_DBCONFIG_REVERSE_SCANORDER, iOrigRSO, 0); + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #2:\n%s\n", zSql); + sqlite3_free(zSql); + } + bindDebugParameters(pCk); + while( (rc = sqlite3_step(pCk))==SQLITE_ROW ){ + for(i=0; i=nCol ) break; + } + sqlite3_finalize(pCk); + if( rc==SQLITE_DONE ){ + sqlite3_finalize(pTestStmt); + return SQLITE_DONE; + } + + /* The original sameValue() comparison assumed a collating sequence + ** of "binary". It can sometimes get an incorrect result for different + ** collating sequences. So rerun the test with no assumptions about + ** collations. + */ + rc = sqlite3_prepare_v2(db, + "SELECT ?1=?2 OR ?1=?2 COLLATE nocase OR ?1=?2 COLLATE rtrim", + -1, &pCk, 0); + if( rc==SQLITE_OK ){ + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #3:\n%s\n", zSql); + sqlite3_free(zSql); + } + + sqlite3_reset(pTestStmt); + bindDebugParameters(pCk); + while( (rc = sqlite3_step(pTestStmt))==SQLITE_ROW ){ + for(i=0; i=nCol ){ + sqlite3_finalize(pCk); + goto not_a_fault; + } + } + } + sqlite3_finalize(pCk); + + /* Invariants do not necessarily work if there are virtual tables + ** involved in the query */ + rc = sqlite3_prepare_v2(db, + "SELECT 1 FROM bytecode(?1) WHERE opcode='VOpen'", -1, &pCk, 0); + if( rc==SQLITE_OK ){ + if( eVerbosity>=2 ){ + char *zSql = sqlite3_expanded_sql(pCk); + printf("invariant-validity-check #4:\n%s\n", zSql); + sqlite3_free(zSql); + } + sqlite3_bind_pointer(pCk, 1, pStmt, "stmt-pointer", 0); + rc = sqlite3_step(pCk); + } + sqlite3_finalize(pCk); + if( rc==SQLITE_DONE ){ + 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"); + } + } +not_a_fault: + sqlite3_finalize(pTestStmt); + return SQLITE_OK; +} + +/* +** Generate SQL used to test a statement invariant. +** +** Return 0 if the iCnt is out of range. +** +** iCnt meanings: +** +** 0 SELECT * FROM () +** 1 SELECT DISTINCT * FROM () +** 2 SELECT * FROM () WHERE ORDER BY 1 +** 3 SELECT DISTINCT * FROM () ORDER BY 1 +** 4 SELECT * FROM () WHERE = +** 5 SELECT DISTINCT * FROM () WHERE ) WHERE = ORDER BY 1 +** 7 SELECT DISTINCT * FROM () WHERE = +** ORDER BY 1 +** N+0 SELECT * FROM () WHERE = +** N+1 SELECT DISTINCT * FROM () WHERE = +** N+2 SELECT * FROM () WHERE = ORDER BY 1 +** N+3 SELECT DISTINCT * FROM () WHERE = +** ORDER BY N +** +*/ +static char *fuzz_invariant_sql(sqlite3_stmt *pStmt, int iCnt){ + const char *zIn; + size_t nIn; + const char *zAnd = "WHERE"; + int i, j; + sqlite3_str *pTest; + sqlite3_stmt *pBase = 0; + sqlite3 *db = sqlite3_db_handle(pStmt); + int rc; + int nCol = sqlite3_column_count(pStmt); + int mxCnt; + int bDistinct = 0; + int bOrderBy = 0; + int nParam = sqlite3_bind_parameter_count(pStmt); + + switch( iCnt % 4 ){ + case 1: bDistinct = 1; break; + case 2: bOrderBy = 1; break; + case 3: bDistinct = bOrderBy = 1; break; + } + iCnt /= 4; + mxCnt = nCol; + if( iCnt<0 || iCnt>mxCnt ) return 0; + zIn = sqlite3_sql(pStmt); + if( zIn==0 ) return 0; + nIn = strlen(zIn); + while( nIn>0 && (isspace(zIn[nIn-1]) || zIn[nIn-1]==';') ) nIn--; + if( strchr(zIn, '?') ) return 0; + pTest = sqlite3_str_new(0); + sqlite3_str_appendf(pTest, "SELECT %s* FROM (", + bDistinct ? "DISTINCT " : ""); + sqlite3_str_append(pTest, zIn, (int)nIn); + sqlite3_str_append(pTest, ")", 1); + rc = sqlite3_prepare_v2(db, sqlite3_str_value(pTest), -1, &pBase, 0); + if( rc ){ + sqlite3_finalize(pBase); + pBase = pStmt; + } + bindDebugParameters(pBase); + for(i=0; i'3' || isdigit(zSuffix[2])) + ){ + /* This is a randomized column name and so cannot be used in the + ** WHERE clause. */ + continue; + } + for(j=0; j1 && i+2!=iCnt ) continue; + if( zColName==0 ) continue; + if( sqlite3_column_type(pStmt, i)==SQLITE_NULL ){ + sqlite3_str_appendf(pTest, " %s \"%w\" ISNULL", zAnd, zColName); + }else{ + sqlite3_str_appendf(pTest, " %s \"%w\"=?%d", zAnd, zColName, + i+1+nParam); + } + zAnd = "AND"; + } + if( pBase!=pStmt ) sqlite3_finalize(pBase); + if( bOrderBy ){ + sqlite3_str_appendf(pTest, " ORDER BY %d", iCnt>2 ? iCnt-1 : 1); + } + return sqlite3_str_finish(pTest); +} + +/* +** Return true if and only if v1 and is the same as v2. +*/ +static int sameValue( + sqlite3_stmt *pS1, int i1, /* Value to text on the left */ + sqlite3_stmt *pS2, int i2, /* Value to test on the right */ + sqlite3_stmt *pTestCompare /* COLLATE comparison statement or NULL */ +){ + int x = 1; + int t1 = sqlite3_column_type(pS1,i1); + int t2 = sqlite3_column_type(pS2,i2); + if( t1!=t2 ){ + if( (t1==SQLITE_INTEGER && t2==SQLITE_FLOAT) + || (t1==SQLITE_FLOAT && t2==SQLITE_INTEGER) + ){ + /* Comparison of numerics is ok */ + }else{ + return 0; + } + } + switch( sqlite3_column_type(pS1,i1) ){ + case SQLITE_INTEGER: { + x = sqlite3_column_int64(pS1,i1)==sqlite3_column_int64(pS2,i2); + break; + } + case SQLITE_FLOAT: { + x = sqlite3_column_double(pS1,i1)==sqlite3_column_double(pS2,i2); + break; + } + case SQLITE_TEXT: { + int e1 = sqlite3_value_encoding(sqlite3_column_value(pS1,i1)); + int e2 = sqlite3_value_encoding(sqlite3_column_value(pS2,i2)); + if( e1!=e2 ){ + const char *z1 = (const char*)sqlite3_column_text(pS1,i1); + const char *z2 = (const char*)sqlite3_column_text(pS2,i2); + x = ((z1==0 && z2==0) || (z1!=0 && z2!=0 && strcmp(z1,z1)==0)); + printf("Encodings differ. %d on left and %d on right\n", e1, e2); + abort(); + } + if( pTestCompare ){ + sqlite3_bind_value(pTestCompare, 1, sqlite3_column_value(pS1,i1)); + sqlite3_bind_value(pTestCompare, 2, sqlite3_column_value(pS2,i2)); + x = sqlite3_step(pTestCompare)==SQLITE_ROW + && sqlite3_column_int(pTestCompare,0)!=0; + sqlite3_reset(pTestCompare); + break; + } + if( e1!=SQLITE_UTF8 ){ + int len1 = sqlite3_column_bytes16(pS1,i1); + const unsigned char *b1 = sqlite3_column_blob(pS1,i1); + int len2 = sqlite3_column_bytes16(pS2,i2); + const unsigned char *b2 = sqlite3_column_blob(pS2,i2); + if( len1!=len2 ){ + x = 0; + }else if( len1==0 ){ + x = 1; + }else{ + x = (b1!=0 && b2!=0 && memcmp(b1,b2,len1)==0); + } + break; + } + /* Fall through into the SQLITE_BLOB case */ + } + case SQLITE_BLOB: { + int len1 = sqlite3_column_bytes(pS1,i1); + const unsigned char *b1 = sqlite3_column_blob(pS1,i1); + int len2 = sqlite3_column_bytes(pS2,i2); + const unsigned char *b2 = sqlite3_column_blob(pS2,i2); + if( len1!=len2 ){ + x = 0; + }else if( len1==0 ){ + x = 1; + }else{ + x = (b1!=0 && b2!=0 && memcmp(b1,b2,len1)==0); + } + break; + } + } + return x; +} + +/* +** Print binary data as hex +*/ +static void printHex(const unsigned char *a, int n, int mx){ + int j; + for(j=0; j'blank'), + b TEXT, + y TEXT AS (substr(b,m/2,m/2+2)) STORED, + c ANY, + PRIMARY KEY(b,a) + ) WITHOUT ROWID; + } +} { + catch {db close} + sqlite3 db :memory: + db eval $schema + do_execsql_test gencol1-2.$tn.100 { + INSERT INTO t1(a,b,c) VALUES(1,'abcdef',5.5),(3,'cantaloupe',NULL); + SELECT w, x, y, '|' FROM t1 ORDER BY a; + } {10 real abc | 30 null ntalo |} + do_execsql_test gencol1-2.$tn.101 { + SELECT w, x, y, '|' FROM t1 ORDER BY w; + } {10 real abc | 30 null ntalo |} + do_execsql_test gencol1-2.$tn.102 { + SELECT a FROM t1 WHERE w=30; + } {3} + do_execsql_test gencol1-2.$tn.103 { + SELECT a FROM t1 WHERE x='real'; + } {1} + do_execsql_test gencol1-2.$tn.104 { + SELECT a FROM t1 WHERE y LIKE '%tal%' OR x='real' ORDER BY b; + } {1 3} + do_execsql_test gencol1-2.$tn.110 { + CREATE INDEX t1w ON t1(w); + SELECT a FROM t1 WHERE w=10; + } {1} + do_execsql_test gencol1-2.$tn.120 { + CREATE INDEX t1x ON t1(x) WHERE w BETWEEN 20 AND 40; + SELECT a FROM t1 WHERE x='null' AND w BETWEEN 20 AND 40; + } {3} + do_execsql_test gencol1-2.$tn.121 { + SELECT a FROM t1 WHERE x='real'; + } {1} + do_execsql_test gencol1-2.$tn.130 { + VACUUM; + PRAGMA integrity_check; + } {ok} + do_execsql_test gencol1-2.$tn.140 { + UPDATE t1 SET a=a+100 WHERE w<20; + SELECT a, w, '|' FROM t1 ORDER BY w; + } {3 30 | 101 1010 |} + do_execsql_test gencol1-2.$tn.150 { + INSERT INTO t1 VALUES(4,'jambalaya','Chef John'),(15,87719874135,0); + SELECT w, x, y, '|' FROM t1 ORDER BY w; + } {30 null ntalo | 40 text balaya | 150 integer {} | 1010 real {} |} +} + +# 2019-10-31 ticket b9befa4b83a660cc +db close +sqlite3 db :memory: +do_execsql_test gencol1-3.100 { + PRAGMA foreign_keys = true; + CREATE TABLE t0(c0 PRIMARY KEY, c1, c2 AS (c0+c1-c3) REFERENCES t0, c3); + INSERT INTO t0 VALUES (0, 0, 0), (11, 5, 5); + UPDATE t0 SET c1 = c0, c3 = c0; + SELECT *, '|' FROM t0 ORDER BY +c0; +} {0 0 0 0 | 11 11 11 11 |} +do_catchsql_test gencol1-3.110 { + UPDATE t0 SET c1 = c0, c3 = c0+1; +} {1 {FOREIGN KEY constraint failed}} + +# 2019-11-01 ticket c28a01da72f8957c +db close +sqlite3 db :memory: +do_execsql_test gencol1-4.100 { + CREATE TABLE t0 ( + c0, + c1 a UNIQUE AS (1), + c2, + c3 REFERENCES t0(c1) + ); + PRAGMA foreign_keys = true; + INSERT INTO t0(c0,c2,c3) VALUES(0,0,1); +} {} +do_catchsql_test gencol1-4.110 { + REPLACE INTO t0(c0,c2,c3) VALUES(0,0,0),(0,0,0); +} {1 {FOREIGN KEY constraint failed}} + +# 2019-11-01 Problem found while adding new foreign key test cases in TH3. +db close +sqlite3 db :memory: +do_execsql_test gencol1-5.100 { + PRAGMA foreign_keys=ON; + CREATE TABLE t1( + gcb AS (b*1), + a INTEGER PRIMARY KEY, + gcc AS (c+0), + b UNIQUE, + gca AS (1*a+0), + c UNIQUE + ) WITHOUT ROWID; + INSERT INTO t1 VALUES(1,2,3); + INSERT INTO t1 VALUES(4,5,6); + INSERT INTO t1 VALUES(7,8,9); + CREATE TABLE t1a( + gcx AS (x+0) REFERENCES t1(a) ON DELETE CASCADE, + id, + x, + gcid AS (1*id) + ); + INSERT INTO t1a VALUES(1, 1); + INSERT INTO t1a VALUES(2, 4); + INSERT INTO t1a VALUES(3, 7); + DELETE FROM t1 WHERE b=5; + SELECT id,x,'|' FROM t1a ORDER BY id; +} {1 1 | 3 7 |} + +do_catchsql_test gencol1-6.10 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0(c0 NOT NULL AS(c1), c1); + REPLACE INTO t0(c1) VALUES(NULL); +} {1 {NOT NULL constraint failed: t0.c0}} + +# 2019-11-06 ticket https://www.sqlite.org/src/info/2399f5986134f79c +# 2019-12-27 ticket https://www.sqlite.org/src/info/5fbc159eeb092130 +# 2019-12-27 ticket https://www.sqlite.org/src/info/37823501c68a09f9 +# +# All of the above tickets deal with NOT NULL ON CONFLICT REPLACE +# constraints on tables that have generated columns. +# +reset_db +do_execsql_test gencol1-7.10 { + CREATE TABLE t0 (c0 GENERATED ALWAYS AS (1), c1 UNIQUE, c2 UNIQUE); + INSERT INTO t0(c1) VALUES (1); + SELECT quote(0 = t0.c2 OR t0.c1 BETWEEN t0.c2 AND 1) FROM t0; +} {NULL} +do_execsql_test gencol1-7.11 { + DROP TABLE t0; + CREATE TABLE t0(c0 NOT NULL DEFAULT 'xyz', c1 AS(c0) NOT NULL); + REPLACE INTO t0(c0) VALUES(NULL); + SELECT * FROM t0; +} {xyz xyz} +do_execsql_test gencol1-7.12 { + DROP TABLE t0; + CREATE TABLE t0(c0 NOT NULL DEFAULT 'xyz', c1 AS(c0) STORED NOT NULL); + REPLACE INTO t0(c0) VALUES(NULL); + SELECT * FROM t0; +} {xyz xyz} +do_execsql_test gencol1-7.20 { + CREATE TABLE t1( + a NOT NULL DEFAULT 'aaa', + b AS(c) NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t1(a,c) VALUES(NULL,NULL); + SELECT * FROM t1; +} {aaa ccc ccc} +do_execsql_test gencol1-7.21 { + DROP TABLE t1; + CREATE TABLE t1( + a NOT NULL DEFAULT 'aaa', + b AS(c) STORED NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t1(a,c) VALUES(NULL,NULL); + SELECT * FROM t1; +} {aaa ccc ccc} +do_execsql_test gencol1-7.30 { + CREATE TABLE t2( + a NOT NULL DEFAULT 'aaa', + b AS(a) NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t2(a,c) VALUES(NULL,NULL); + SELECT * FROM t2; +} {aaa aaa ccc} +do_execsql_test gencol1-7.31 { + DROP TABLE t2; + CREATE TABLE t2( + a NOT NULL DEFAULT 'aaa', + b AS(a) STORED NOT NULL, + c NOT NULL DEFAULT 'ccc'); + REPLACE INTO t2(a,c) VALUES(NULL,NULL); + SELECT * FROM t2; +} {aaa aaa ccc} +do_execsql_test gencol1-7.40 { + CREATE TABLE t3(a NOT NULL DEFAULT 123, b AS(a) UNIQUE); + REPLACE INTO t3 VALUES(NULL); + SELECT * FROM t3; +} {123 123} +do_execsql_test gencol1-7.41 { + SELECT * FROM t3 WHERE b=123; +} {123 123} +do_execsql_test gencol1-7.50 { + CREATE TABLE t4(a NOT NULL DEFAULT 123, b AS(a*10+4) STORED UNIQUE); + REPLACE INTO t4 VALUES(NULL); + SELECT * FROM t4; +} {123 1234} +do_execsql_test gencol1-7.51 { + SELECT * FROM t4 WHERE b=1234; +} {123 1234} + +# 2019-11-06 ticket 4fc08501f4e56692 +do_execsql_test gencol1-8.10 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0( + c0 AS (('a', 9) < ('b', c1)), + c1 AS (1), + c2 CHECK (1 = c1) + ); + INSERT INTO t0 VALUES (0),(99); + SELECT * FROM t0; +} {1 1 0 1 1 99} +do_catchsql_test gencol1-8.20 { + DROP TABLE IF EXISTS t0; + CREATE TABLE t0( + c0, + c1 AS(c0 + c2), + c2 AS(c1) CHECK(c2) + ); + UPDATE t0 SET c0 = NULL; +} {1 {generated column loop on "c2"}} + +# 2019-11-21 Problems in the new generated column logic +# reported by Yongheng Chen and Rui Zhong +reset_db +do_execsql_test gencol1-9.10 { + PRAGMA foreign_keys=OFF; + CREATE TABLE t1(aa , bb AS (17) UNIQUE); + INSERT INTO t1 VALUES(17); + CREATE TABLE t2(cc); + INSERT INTO t2 VALUES(41); + SELECT * FROM t2 JOIN t1 WHERE t1.bb=t1.aa AND t1.bb=17; +} {41 17 17} +do_execsql_test gencol1-9.20 { + CREATE TABLE t3(aa INT PRIMARY KEY, bb UNIQUE AS(aa)); + INSERT INTO t3 VALUES(1); + SELECT 100, * FROM t3; + DELETE FROM t3 WHERE (SELECT bb FROM t3); + SELECT 200, * FROM t3; +} {100 1 1} + +# 2019-12-04 Generated column in a CREATE TABLE IF NOT EXISTS that +# does already exist. +# +sqlite3 db :memory: +do_execsql_test gencol1-10.10 { + CREATE TABLE t1(aa,bb); + CREATE TABLE IF NOT EXISTS t1(aa, bb AS (aa+1)); + PRAGMA integrity_check; +} {ok} + +# 2019-12-06 Found by mrigger +# +sqlite3 db :memory: +do_execsql_test gencol1-11.10 { + PRAGMA foreign_keys = true; + CREATE TABLE t0( + c0, + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + c3 BLOB GENERATED ALWAYS AS (1), + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.20 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.30 { + DROP TABLE t0; + CREATE TABLE t0( + c0, + c1 INTEGER PRIMARY KEY, + c3 BLOB GENERATED ALWAYS AS (1), + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.40 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.50 { + DROP TABLE t0; + CREATE TABLE t0( + c0, + c3 BLOB GENERATED ALWAYS AS (1), + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.60 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} +do_execsql_test gencol1-11.70 { + DROP TABLE t0; + CREATE TABLE t0( + c3 BLOB GENERATED ALWAYS AS (1), + c0, + c1 INTEGER PRIMARY KEY, + c2 BLOB UNIQUE DEFAULT x'00', + FOREIGN KEY(c1) REFERENCES t0(c2) + ); +} +do_catchsql_test gencol1-11.80 { + INSERT OR REPLACE INTO t0(c0, c1) VALUES (2, 1), (1, 0) +} {1 {FOREIGN KEY constraint failed}} + +# 2019-12-09 ticket bd8c280671ba44a7 +# With generated columns, the sqlite3ExprGetColumnOfTable() routine might +# generate a code sequence that does not end with OP_Column. So check to +# make sure that the last instruction generated is an OP_column prior to +# applying the OPFLAG_TYPEOFARG optimization to NOT NULL checks in the +# PRAGMA integrity_check code. +# +sqlite3 db :memory: +do_execsql_test gencol1-12.10 { + CREATE TABLE t0 (c0, c1 NOT NULL AS (c0==0)); + INSERT INTO t0(c0) VALUES (0); + PRAGMA integrity_check; +} {ok} + +# 2019-12-09 bug report from Yongheng Chen +# Ensure that the SrcList_item.colUsed field is set correctly when a +# generated column appears in the USING clause of a join. +# +do_execsql_test gencol1-13.10 { + CREATE TABLE t1(x, y AS(x+1)); + INSERT INTO t1 VALUES(10); + SELECT y FROM t1 JOIN t1 USING (y,y); +} {11} +do_execsql_test gencol1-13.11 { + SELECT 123 FROM t1 JOIN t1 USING (x); +} {123} +do_execsql_test gencol1-13.11 { + SELECT 456 FROM t1 JOIN t1 USING (x,x); +} {456} +do_execsql_test gencol1-13.20 { + CREATE INDEX t1y ON t1(y); + SELECT y FROM t1 JOIN t1 USING (y,y); +} {11} +do_execsql_test gencol1-13.21 { + CREATE INDEX t1x ON t1(x); + SELECT 123 FROM t1 JOIN t1 USING (x); +} {123} +do_execsql_test gencol1-13.22 { + SELECT 456 FROM t1 JOIN t1 USING (x,x); +} {456} + +# 2019-12-14 ticket b439bfcfb7deedc6 +# +sqlite3 db :memory: +do_execsql_test gencol1-14.10 { + CREATE TABLE t0(c0 AS(1 >= 1), c1 UNIQUE AS(TYPEOF(c0)), c2); + INSERT INTO t0 VALUES(0); + REINDEX; + SELECT * FROM t0; +} {1 integer 0} +do_catchsql_test gencol1-14.10 { + INSERT INTO t0 VALUES(2); +} {1 {UNIQUE constraint failed: t0.c1}} + +# 2019-12-14 gramfuzz1 find +# The schema is malformed in that it has a subquery on a generated +# column expression. This will be loaded if writable_schema=ON. SQLite +# must not use such an expression during code generation as the code generator +# will add bits of content to the expression tree that might be allocated +# from lookaside. But the schema is not tied to a particular database +# connection, so the use of lookaside memory is prohibited. The fix +# is to change the generated column expression to NULL before adding it +# to the schema. +# +reset_db +do_test gencol1-15.10 { + sqlite3 db {} + db deserialize [decode_hexdb { +| size 8192 pagesize 4096 filename c27.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 01 00 00 00 02 .....@ ........ +| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04 ................ +| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................ +| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................ +| 96: 00 2e 3f d8 0d 00 00 00 01 0f ba 00 0f ba 00 00 ..?............. +| 4016: 00 00 00 00 00 00 00 00 00 00 44 01 06 17 11 11 ..........D..... +| 4032: 01 75 74 61 62 6c 65 74 31 74 31 02 43 52 45 41 .utablet1t1.CREA +| 4048: 54 45 20 54 41 42 4c 45 20 74 31 28 61 20 49 4e TE TABLE t1(a IN +| 4064: 54 2c 20 62 20 41 53 28 28 56 41 4c 55 45 53 28 T, b AS((VALUES( +| 4080: 31 29 29 20 49 53 20 75 6e 6b 6e 6f 77 6e 29 29 1)) IS unknown)) +| page 2 offset 4096 +| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................ +| end c27.db +}]} {} +do_execsql_test gencol1-15.20 { + PRAGMA writable_schema=ON; + REPLACE INTO t1 VALUES(9); + SELECT a, quote(b) FROM t1 +} {9 NULL} + +# 2019-12-16 ticket 3b84b42943644d6f +# When a table is the right table of a LEFT JOIN and the ON clause is +# false, make sure any generated columns evaluate to NULL. +reset_db +do_execsql_test gencol1-16.10 { + CREATE TABLE t0(c0); + CREATE TABLE t1(c1, c2 AS(1)); + INSERT INTO t0 VALUES(0); + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1; +} {0 {} {}} +do_execsql_test gencol1-16.20 { + DROP TABLE t1; + CREATE TABLE t1(c1, c2 AS (c1 ISNULL)); + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1; +} {0 {} {}} +do_execsql_test gencol1-16.30 { + INSERT INTO t1(c1) VALUES(1),(NULL); + SELECT * FROM t1; +} {1 0 {} 1} +do_execsql_test gencol1-16.40 { + SELECT c0, c1, c2 FROM t0 LEFT JOIN t1 ON c0=c1; +} {0 {} {}} + +# 2019-12-20 ticket e0a8120553f4b082 +# Generated columns with REAL affinity need to have an OP_RealAffinity +# opcode applied, even when the column value is extracted from an index. +# +reset_db +do_execsql_test gencol1-17.10 { + CREATE TABLE t0(c0 REAL AS(1) UNIQUE, c1 INT); + INSERT INTO t0 VALUES(''); + SELECT quote(c0), quote(c1) from t0; +} {1.0 ''} +do_execsql_test gencol1-17.20 { + SELECT *, (1 BETWEEN CAST(t0.c0 AS TEXT) AND t0.c0) FROM t0; +} {1.0 {} 0} +do_execsql_test gencol1-17.30 { + SELECT * FROM t0 WHERE (1 BETWEEN CAST(t0.c0 AS TEXT) AND t0.c0); +} {} +do_execsql_test gencol1-17.40 { + CREATE TABLE t1(a TEXT AS(b) COLLATE nocase, b TEXT, c INT, d DEFAULT 1); + INSERT INTO t1(b,c) VALUES('abc',11),('DEF',22),('ghi',33); + SELECT a FROM t1 WHERE b='DEF' AND a='def'; +} {DEF} +do_execsql_test gencol1-17.50 { + CREATE INDEX t1bca ON t1(b,c,a); + SELECT a FROM t1 WHERE b='DEF' AND a='def'; +} {DEF} + +# 2019-12-26 ticket ec8abb025e78f40c +# An index on a virtual column with a constant value (why would anybody +# ever do such a thing?) can cause problems for a one-pass DELETE. +# +reset_db +do_execsql_test gencol1-18.10 { + CREATE TABLE t0(c0 UNIQUE AS(0), c1, c2); + INSERT INTO t0(c1) VALUES(0); + SELECT * FROM t0; +} {0 0 {}} +do_execsql_test gencol1-18.20 { + UPDATE t0 SET c1=0, c2=0 WHERE c0>=0; + SELECT * FROM t0; +} {0 0 0} + +# 2019-12-27 ticket de4b04149b9fdeae +# +reset_db +do_catchsql_test gencol1-19.10 { + CREATE TABLE t0( + c0 INT AS(2) UNIQUE, + c1 TEXT UNIQUE, + FOREIGN KEY(c0) REFERENCES t0(c1) + ); + INSERT INTO t0(c1) VALUES(0.16334143182538696), (0); +} {1 {UNIQUE constraint failed: t0.c0}} + +# 2020-06-29 forum bug report. +# https://sqlite.org/forum/forumpost/73b9a8ccfb +# +do_execsql_test gencol1-20.1 { + CREATE TEMPORARY TABLE tab ( + prim DATE PRIMARY KEY, + a INTEGER, + comp INTEGER AS (a), + b INTEGER, + x INTEGER + ); + -- Add some data + INSERT INTO tab (prim, a, b) VALUES ('2001-01-01', 0, 0); + -- Check that each column is 0 like I expect + SELECT * FROM tab; +} {2001-01-01 0 0 0 {}} +do_execsql_test gencol1-20.2 { + -- Do an UPSERT on the b column + INSERT INTO tab (prim, b) + VALUES ('2001-01-01',5) + ON CONFLICT(prim) DO UPDATE SET b=excluded.b; + -- Now b is NULL rather than 5 + SELECT * FROM tab; +} {2001-01-01 0 0 5 {}} + +# 2021-07-30 forum https://sqlite.org/forum/forumpost/ff3ffe09251c105b?t=h +# +ifcapable vtab { +reset_db + do_execsql_test gencol1-21.1 { + CREATE TABLE t1( + a integer primary key, + b int generated always as (a+5), + c text GENERATED ALWAYS as (printf('%08x',a)), + d Generated + Always + AS ('xyzzy'), + e int Always default(5) + ); + INSERT INTO t1(a) VALUES(5); + SELECT name, type FROM pragma_table_xinfo('t1'); + } {a INTEGER b INT c TEXT d {} e INT} +} + +# 2021-09-07 forum https://sqlite.org/forum/forumpost/699b44b3ee +# +reset_db +do_execsql_test gencol1-22.1 { + CREATE TABLE t0(a PRIMARY KEY,b TEXT AS ('2') UNIQUE); + INSERT INTO t0(a) VALUES(2); + SELECT * FROM t0 AS x JOIN t0 AS y + WHERE x.b='2' + AND (y.a=2 OR (x.b LIKE '2*' AND y.a=x.b)); +} {2 2 2 2} + + +# 2023-03-02 dbsqlfuzz 65f5eb57f8859344d5f1f33e08c77ee12960ed83 +# +set typelist {ANY INT REAL BLOB TEXT {}} +set cnt 0 +foreach t1 $typelist { + foreach t2 $typelist { + incr cnt + db eval " + DROP TABLE IF EXISTS t1; + CREATE TABLE t1( + x $t1, + a $t2 AS (x) VIRTUAL, + b BLOB AS (x) VIRTUAL + ); + CREATE INDEX x2 ON t1(a); + INSERT INTO t1(x) VALUES(NULL),('1'),(2),(3.5),('xyz'); + " + set x1 [lsort [db eval {SELECT typeof(b) FROM t1}]] + do_test gencol1-23.1.$cnt { + lsort [db eval {SELECT typeof(b) FROM t1 INDEXED BY x2}] + } $x1 + } +} +do_execsql_test gencol1-23.2 { + DROP TABLE t1; + CREATE TABLE t1( + x, + a INT AS (x) VIRTUAL, + b BLOB AS (x) VIRTUAL + ); + CREATE INDEX x2 ON t1(a); + INSERT INTO t1(x) VALUES(NULL),('1'),('xyz'),(2),(3.5); + SELECT quote(a) FROM t1 INDEXED BY x2; +} {NULL 1 2 3.5 'xyz'} +do_execsql_test gencol1-23.3 { + EXPLAIN SELECT a FROM t1 INDEXED BY x2; +} {~/Column 0/} +# ^^^^^^^^---- verfies that x2 acts like a covering index +do_execsql_test gencol1-23.4 { + EXPLAIN SELECT b FROM t1 INDEXED BY x2; +} {/Column 0/} +# ^^^^^^^^^^--- Must reference the original table in this case because +# of the different datatype on column b. + +# 2023-03-07 https://sqlite.org/forum/forumpost/b312e075b5 +# +do_catchsql_test gencol1-23.5 { + CREATE TABLE v0(c1 INT, c2 AS (RAISE(IGNORE))); +} {1 {RAISE() may only be used within a trigger-program}} + +finish_test diff --git a/local-test-sqlite3-delta-01/afc-sqlite3/test/having.test b/local-test-sqlite3-delta-01/afc-sqlite3/test/having.test new file mode 100644 index 0000000000000000000000000000000000000000..3bfa8120a1aeb8abc78d14f37a95c087669125e2 --- /dev/null +++ b/local-test-sqlite3-delta-01/afc-sqlite3/test/having.test @@ -0,0 +1,191 @@ +# 2017 April 30 +# +# 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. +# +#*********************************************************************** +# +# Test the HAVING->WHERE optimization. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl +set testprefix having + +do_execsql_test 1.0 { + CREATE TABLE t2(c, d); + + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 1); + INSERT INTO t1 VALUES(2, 2); + INSERT INTO t1 VALUES(1, 3); + INSERT INTO t1 VALUES(2, 4); + INSERT INTO t1 VALUES(1, 5); + INSERT INTO t1 VALUES(2, 6); +} {} + +foreach {tn sql res} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2" {2 12} + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2 AND sum(b)>10" {2 12} + 3 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING sum(b)>12" {} +} { + do_execsql_test 1.$tn $sql $res +} + +# Run an EXPLAIN command for both SQL statements. Return true if +# the outputs are identical, or false otherwise. +# +proc compare_vdbe {sql1 sql2} { + set r1 [list] + set r2 [list] + db eval "explain $sql1" { lappend r1 $opcode $p1 $p2 $p3 $p4 $p5} + db eval "explain $sql2" { lappend r2 $opcode $p1 $p2 $p3 $p4 $p5} + return [expr {$r1==$r2}] +} + +proc do_compare_vdbe_test {tn sql1 sql2 res} { + uplevel [list do_test $tn [list compare_vdbe $sql1 $sql2] $res] +} + +#------------------------------------------------------------------------- +# Test that various statements that are eligible for the optimization +# produce the same VDBE code as optimizing by hand does. +# +foreach {tn sql1 sql2} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a" + + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING sum(b)>5 AND a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a HAVING sum(b)>5" + + 3 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE binary HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a COLLATE binary" + + 5 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE binary HAVING 1" + "SELECT a, sum(b) FROM t1 WHERE 1 GROUP BY a COLLATE binary" + + 6 "SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d HAVING b=d" + "SELECT count(*) FROM t1,t2 WHERE a=c AND b=d GROUP BY b, d" + + 7 { + SELECT count(*) FROM t1,t2 WHERE a=c GROUP BY b, d + HAVING b=d COLLATE nocase + } { + SELECT count(*) FROM t1,t2 WHERE a=c AND b=d COLLATE nocase + GROUP BY b, d + } + + 8 "SELECT a, sum(b) FROM t1 GROUP BY a||b HAVING substr(a||b, 1, 1)='a'" + "SELECT a, sum(b) FROM t1 WHERE substr(a||b, 1, 1)='a' GROUP BY a||b" +} { + do_compare_vdbe_test 2.$tn $sql1 $sql2 1 +} + +# The (4) test in the above set used to generate identical bytecode, but +# that is no longer the case. The byte code is equivalent, though. +# +do_execsql_test 2.4a { + SELECT x,y FROM ( + SELECT a AS x, sum(b) AS y FROM t1 + GROUP BY a + ) WHERE x BETWEEN 2 AND 9999 +} {2 12} +do_execsql_test 2.4b { + SELECT x,y FROM ( + SELECT a AS x, sum(b) AS y FROM t1 + WHERE x BETWEEN 2 AND 9999 + GROUP BY a + ) +} {2 12} + + +#------------------------------------------------------------------------- +# 1: Test that the optimization is only applied if the GROUP BY term +# uses BINARY collation. +# +# 2: Not applied if there is a non-deterministic function in the HAVING +# term. +# +foreach {tn sql1 sql2} { + 1 "SELECT a, sum(b) FROM t1 GROUP BY a COLLATE nocase HAVING a=2" + "SELECT a, sum(b) FROM t1 WHERE a=2 GROUP BY a COLLATE nocase" + + 2 "SELECT a, sum(b) FROM t1 GROUP BY a HAVING randomblob(a)