aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2017-12-29 13:35:09 +0000
committerdrh <drh@noemail.net>2017-12-29 13:35:09 +0000
commit7a8573bafaba8b341ec033a0ecc810afeceda94e (patch)
tree67a72353c4313c2cadb24a46a54af0cf87104317 /test
parent2fc865c1153d739208657ea652f74426bf20f678 (diff)
parentee052a1c941920dab3fab38785fbf03237677b7a (diff)
downloadsqlite-7a8573bafaba8b341ec033a0ecc810afeceda94e.tar.gz
sqlite-7a8573bafaba8b341ec033a0ecc810afeceda94e.zip
Merge recent enhancements from trunk.
FossilOrigin-Name: 6251e438f2a76170fd1e95aa512a46086ed88ab93b9b97a1dba97c4558689305
Diffstat (limited to 'test')
-rw-r--r--test/capi2.test2
-rw-r--r--test/colname.test40
-rw-r--r--test/fkey1.test14
-rw-r--r--test/misc1.test20
-rw-r--r--test/speedtest1.c76
-rw-r--r--test/tester.tcl8
-rw-r--r--test/trace.test2
7 files changed, 156 insertions, 6 deletions
diff --git a/test/capi2.test b/test/capi2.test
index 39f50dd07..5e5187181 100644
--- a/test/capi2.test
+++ b/test/capi2.test
@@ -184,7 +184,7 @@ do_test capi2-3.5 {
} {1 {(1) no such column: bogus} {;;x;}}
do_test capi2-3.6 {
set rc [catch {
- sqlite3_prepare $DB {select 5/0} -1 TAIL
+ sqlite3_prepare $DB {select 5/0;} -1 TAIL
} VM]
lappend rc $TAIL
} {0 {}}
diff --git a/test/colname.test b/test/colname.test
index 2e4ae8900..358ea77e0 100644
--- a/test/colname.test
+++ b/test/colname.test
@@ -378,6 +378,46 @@ do_test colname-9.210 {
execsql2 {SELECT t1.a, v3.a AS n FROM t1 JOIN v3}
} {a 1 n 3}
+# 2017-12-23: Ticket https://www.sqlite.org/src/info/3b4450072511e621
+# Inconsistent column names in CREATE TABLE AS
+#
+# Verify that the names of columns in the created table of a CREATE TABLE AS
+# are the same as the names of result columns in the SELECT statement.
+#
+do_execsql_test colname-9.300 {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE TABLE t1(aaa INT);
+ INSERT INTO t1(aaa) VALUES(123);
+}
+do_test colname-9.310 {
+ execsql2 {SELECT BBb FROM (SELECT aaa AS Bbb FROM t1)}
+} {Bbb 123}
+do_execsql_test colname-9.320 {
+ CREATE TABLE t2 AS SELECT BBb FROM (SELECT aaa AS Bbb FROM t1);
+ SELECT name FROM pragma_table_info('t2');
+} {Bbb}
+
+# Issue detected by OSSFuzz on 2017-12-24 (Christmas Eve)
+# caused by check-in https://sqlite.org/src/info/6b2ff26c25
+#
+# Prior to being fixed, the following CREATE TABLE was dereferencing
+# a NULL pointer and segfaulting.
+#
+do_catchsql_test colname-9.400 {
+ CREATE TABLE t4 AS SELECT #0;
+} {1 {near "#0": syntax error}}
+
+# Issue detected by OSSFuzz on 2017-12-25 (Christmas Day)
+# also caused by check-in https://sqlite.org/src/info/6b2ff26c25
+#
+# Prior to being fixed, the following CREATE TABLE caused an
+# assertion fault.
+#
+do_catchsql_test colname-9.410 {
+ CREATE TABLE t5 AS SELECT RAISE(abort,a);
+} {1 {RAISE() may only be used within a trigger-program}}
+
# Make sure the quotation marks get removed from the column names
# when constructing a new table from an aggregate SELECT.
# Email from Juergen Palm on 2017-07-11.
diff --git a/test/fkey1.test b/test/fkey1.test
index d9b038a02..2530327fc 100644
--- a/test/fkey1.test
+++ b/test/fkey1.test
@@ -171,6 +171,20 @@ do_catchsql_test fkey1-5.2 {
INSERT OR REPLACE INTO t11 VALUES (2, 3);
} {1 {FOREIGN KEY constraint failed}}
+# Make sure sqlite3_trace() output works with triggers used to implement
+# FK constraints
+#
+proc sqltrace {txt} {
+ global traceoutput
+ lappend traceoutput $txt
+}
+do_test fkey1-5.2.1 {
+ unset -nocomplain traceoutput
+ db trace sqltrace
+ catch {db eval {INSERT OR REPLACE INTO t11 VALUES(2,3);}}
+ set traceoutput
+} {{INSERT OR REPLACE INTO t11 VALUES(2,3);} {INSERT OR REPLACE INTO t11 VALUES(2,3);} {INSERT OR REPLACE INTO t11 VALUES(2,3);}}
+
# A similar test to the above.
do_execsql_test fkey1-5.3 {
CREATE TABLE Foo (
diff --git a/test/misc1.test b/test/misc1.test
index 2acfa5c2d..05b1b1980 100644
--- a/test/misc1.test
+++ b/test/misc1.test
@@ -722,4 +722,24 @@ do_execsql_test misc1-26.0 {
SELECT randomblob(min(max(coalesce(EXISTS (SELECT 1 FROM ( SELECT (SELECT 2147483647) NOT IN (SELECT 2147483649 UNION ALL SELECT DISTINCT -1) IN (SELECT 2147483649), 'fault', (SELECT ALL -1 INTERSECT SELECT 'experiments') IN (SELECT ALL 56.1 ORDER BY 'experiments' DESC) FROM (SELECT DISTINCT 2147483648, 'hardware' UNION ALL SELECT -2147483648, 'experiments' ORDER BY 2147483648 LIMIT 1 OFFSET 123456789.1234567899) GROUP BY (SELECT ALL 0 INTERSECT SELECT 'in') IN (SELECT DISTINCT 'experiments' ORDER BY zeroblob(1000) LIMIT 56.1 OFFSET -456) HAVING EXISTS (SELECT 'fault' EXCEPT SELECT DISTINCT 56.1) UNION SELECT 'The', 'The', 2147483649 UNION ALL SELECT DISTINCT 'hardware', 'first', 'experiments' ORDER BY 'hardware' LIMIT 123456789.1234567899 OFFSET -2147483647)) NOT IN (SELECT (SELECT DISTINCT (SELECT 'The') FROM abc ORDER BY EXISTS (SELECT -1 INTERSECT SELECT ALL NULL) ASC) IN (SELECT DISTINCT EXISTS (SELECT ALL 123456789.1234567899 ORDER BY 1 ASC, NULL DESC) FROM sqlite_master INTERSECT SELECT 456)), (SELECT ALL 'injection' UNION ALL SELECT ALL (SELECT DISTINCT 'first' UNION SELECT DISTINCT 'The') FROM (SELECT 456, 'in', 2147483649))),1), 500)), 'first', EXISTS (SELECT DISTINCT 456 FROM abc ORDER BY 'experiments' DESC) FROM abc;
} {}
+# 2017-12-29
+#
+# The following behaviors (duplicate column names on an INSERT or UPDATE)
+# are undocumented. These tests are added to ensure that historical behavior
+# does not change accidentally.
+#
+# For duplication columns on an INSERT, the first value is used.
+# For duplication columns on an UPDATE, the last value is used.
+#
+do_execsql_test misc1-27.0 {
+ CREATE TABLE dup1(a,b,c);
+ INSERT INTO dup1(a,b,c,a,b,c) VALUES(1,2,3,4,5,6);
+ SELECT a,b,c FROM dup1;
+} {1 2 3}
+do_execsql_test misc1-27.1 {
+ UPDATE dup1 SET a=7, b=8, c=9, a=10, b=11, c=12;
+ SELECT a,b,c FROM dup1;
+} {10 11 12}
+
+
finish_test
diff --git a/test/speedtest1.c b/test/speedtest1.c
index b92801a20..9342da79b 100644
--- a/test/speedtest1.c
+++ b/test/speedtest1.c
@@ -32,7 +32,7 @@ static const char zHelp[] =
" --size N Relative test size. Default=100\n"
" --stats Show statistics at the end\n"
" --temp N N from 0 to 9. 0: no temp table. 9: all temp tables\n"
- " --testset T Run test-set T (main, cte, rtree, orm, debug)\n"
+ " --testset T Run test-set T (main, cte, rtree, orm, fp, debug)\n"
" --trace Turn on SQL tracing\n"
" --threads N Use up to N threads for sorting\n"
" --utf16be Set text encoding to UTF-16BE\n"
@@ -1120,7 +1120,77 @@ void testset_cte(void){
);
speedtest1_run();
speedtest1_end_test();
+}
+
+/*
+** Compute a pseudo-random floating point ascii number.
+*/
+void speedtest1_random_ascii_fp(char *zFP){
+ int x = speedtest1_random();
+ int y = speedtest1_random();
+ int z;
+ z = y%10;
+ if( z<0 ) z = -z;
+ y /= 10;
+ sqlite3_snprintf(100,zFP,"%d.%de%d",y,z,x%200);
+}
+
+/*
+** A testset for floating-point numbers.
+*/
+void testset_fp(void){
+ int n;
+ int i;
+ char zFP1[100];
+ char zFP2[100];
+
+ n = g.szTest*5000;
+ speedtest1_begin_test(100, "Fill a table with %d FP values", n*2);
+ speedtest1_exec("BEGIN");
+ speedtest1_exec("CREATE%s TABLE t1(a REAL %s, b REAL %s);",
+ isTemp(1), g.zNN, g.zNN);
+ speedtest1_prepare("INSERT INTO t1 VALUES(?1,?2); -- %d times", n);
+ for(i=1; i<=n; i++){
+ speedtest1_random_ascii_fp(zFP1);
+ speedtest1_random_ascii_fp(zFP2);
+ sqlite3_bind_text(g.pStmt, 1, zFP1, -1, SQLITE_STATIC);
+ sqlite3_bind_text(g.pStmt, 2, zFP2, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_exec("COMMIT");
+ speedtest1_end_test();
+
+ n = g.szTest/25 + 2;
+ speedtest1_begin_test(110, "%d range queries", n);
+ speedtest1_prepare("SELECT sum(b) FROM t1 WHERE a BETWEEN ?1 AND ?2");
+ for(i=1; i<=n; i++){
+ speedtest1_random_ascii_fp(zFP1);
+ speedtest1_random_ascii_fp(zFP2);
+ sqlite3_bind_text(g.pStmt, 1, zFP1, -1, SQLITE_STATIC);
+ sqlite3_bind_text(g.pStmt, 2, zFP2, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_end_test();
+ speedtest1_begin_test(120, "CREATE INDEX three times");
+ speedtest1_exec("BEGIN;");
+ speedtest1_exec("CREATE INDEX t1a ON t1(a);");
+ speedtest1_exec("CREATE INDEX t1b ON t1(b);");
+ speedtest1_exec("CREATE INDEX t1ab ON t1(a,b);");
+ speedtest1_exec("COMMIT;");
+ speedtest1_end_test();
+
+ n = g.szTest/3 + 2;
+ speedtest1_begin_test(130, "%d indexed range queries", n);
+ speedtest1_prepare("SELECT sum(b) FROM t1 WHERE a BETWEEN ?1 AND ?2");
+ for(i=1; i<=n; i++){
+ speedtest1_random_ascii_fp(zFP1);
+ speedtest1_random_ascii_fp(zFP2);
+ sqlite3_bind_text(g.pStmt, 1, zFP1, -1, SQLITE_STATIC);
+ sqlite3_bind_text(g.pStmt, 2, zFP2, -1, SQLITE_STATIC);
+ speedtest1_run();
+ }
+ speedtest1_end_test();
}
#ifdef SQLITE_ENABLE_RTREE
@@ -1873,6 +1943,8 @@ int main(int argc, char **argv){
testset_orm();
}else if( strcmp(zTSet,"cte")==0 ){
testset_cte();
+ }else if( strcmp(zTSet,"fp")==0 ){
+ testset_fp();
}else if( strcmp(zTSet,"rtree")==0 ){
#ifdef SQLITE_ENABLE_RTREE
testset_rtree(6, 147);
@@ -1881,7 +1953,7 @@ int main(int argc, char **argv){
"the R-Tree tests\n");
#endif
}else{
- fatal_error("unknown testset: \"%s\"\nChoices: main debug1 cte rtree\n",
+ fatal_error("unknown testset: \"%s\"\nChoices: main debug1 cte rtree fp\n",
zTSet);
}
speedtest1_final();
diff --git a/test/tester.tcl b/test/tester.tcl
index 10a20a47d..d0d6c92a6 100644
--- a/test/tester.tcl
+++ b/test/tester.tcl
@@ -2271,13 +2271,17 @@ proc test_restore_config_pagecache {} {
sqlite3 db test.db
}
-proc test_find_binary {nm} {
+proc test_binary_name {nm} {
if {$::tcl_platform(platform)=="windows"} {
set ret "$nm.exe"
} else {
set ret $nm
}
- set ret [file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $ret]]
+ file normalize [file join $::cmdlinearg(TESTFIXTURE_HOME) $ret]
+}
+
+proc test_find_binary {nm} {
+ set ret [test_binary_name $nm]
if {![file executable $ret]} {
finish_test
return ""
diff --git a/test/trace.test b/test/trace.test
index fd51d7ab6..37914857f 100644
--- a/test/trace.test
+++ b/test/trace.test
@@ -197,7 +197,7 @@ ifcapable trigger {
UPDATE t1 SET a=a+1;
}
set TRACE_OUT
- } {{UPDATE t1 SET a=a+1;} {-- TRIGGER r1t1} {-- TRIGGER r1t2} {-- TRIGGER r1t1} {-- TRIGGER r1t2} {-- TRIGGER r1t1} {-- TRIGGER r1t2}}
+ } {{UPDATE t1 SET a=a+1;} {-- TRIGGER r1t1} {-- UPDATE t2 SET a=new.a WHERE rowid=new.rowid} {-- TRIGGER r1t2} {-- SELECT 'hello'} {-- TRIGGER r1t1} {-- UPDATE t2 SET a=new.a WHERE rowid=new.rowid} {-- TRIGGER r1t2} {-- SELECT 'hello'} {-- TRIGGER r1t1} {-- UPDATE t2 SET a=new.a WHERE rowid=new.rowid} {-- TRIGGER r1t2} {-- SELECT 'hello'}}
}
# With 3.6.21, we add the ability to expand host parameters in the trace