mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
Merge the latest trunk changes into the sessions branch.
FossilOrigin-Name: 6883580e6c8973010a42d1d2c5bde04c6b2f4eb7
This commit is contained in:
@@ -989,9 +989,9 @@ do_execsql_test e_createtable-3.7.4 {
|
||||
SELECT quote(a), quote(b) FROM t6;
|
||||
} {1 2 'X' 3 1 4 'X' 5}
|
||||
|
||||
# EVIDENCE-OF: R-18683-56219 If the default value of a column is
|
||||
# CURRENT_TIME, CURRENT_DATE or CURRENT_DATETIME, then the value used in
|
||||
# the new row is a text representation of the current UTC date and/or
|
||||
# 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
|
||||
|
||||
@@ -24,6 +24,8 @@ ifcapable !fts3 {
|
||||
return
|
||||
}
|
||||
|
||||
set ::testprefix fts3token
|
||||
|
||||
proc escape_string {str} {
|
||||
set out ""
|
||||
foreach char [split $str ""] {
|
||||
@@ -165,10 +167,21 @@ ifcapable icu {
|
||||
do_icu_test fts3token-4.6 MiddleOfTheOcean $input $output
|
||||
do_icu_test fts3token-4.7 th_TH $input $output
|
||||
do_icu_test fts3token-4.8 en_US $input $output
|
||||
|
||||
do_execsql_test 5.1 {
|
||||
CREATE VIRTUAL TABLE x1 USING fts3(name,TOKENIZE icu en_US);
|
||||
insert into x1 (name) values (NULL);
|
||||
insert into x1 (name) values (NULL);
|
||||
delete from x1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
do_test fts3token-internal {
|
||||
execsql { SELECT fts3_tokenizer_internal_test() }
|
||||
} {ok}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ do_execsql_test 1.2 {
|
||||
six 1 1 three 4 6 two 1 1
|
||||
}
|
||||
|
||||
do_execsql_test 1.3 {
|
||||
DELETE FROM t1;
|
||||
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');
|
||||
|
||||
139
test/fts3conf.test
Normal file
139
test/fts3conf.test
Normal file
@@ -0,0 +1,139 @@
|
||||
# 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" 1 1 {{a b c d} {e f g h}}
|
||||
12 "UPDATE OR ABORT $T3" 1 1 {{a b c d} {e f g h} {i j k l}}
|
||||
13 "UPDATE OR FAIL $T3" 1 1 {{a b c d} {e f g h} {i j k l}}
|
||||
14 "UPDATE OR IGNORE $T3" 1 0 {{a b c d} {e f g h} {i j k l}}
|
||||
15 "UPDATE OR REPLACE $T3" 1 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
|
||||
|
||||
finish_test
|
||||
108
test/fts3sort.test
Normal file
108
test/fts3sort.test
Normal file
@@ -0,0 +1,108 @@
|
||||
# 2011 May 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. The
|
||||
# focus of this script is testing the FTS3 module.
|
||||
#
|
||||
|
||||
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 fts3sort
|
||||
|
||||
proc build_database {nRow} {
|
||||
db close
|
||||
forcedelete test.db
|
||||
sqlite3 db test.db
|
||||
|
||||
set vocab [list aa ab ac ba bb bc ca cb cc da]
|
||||
expr srand(0)
|
||||
|
||||
execsql { CREATE VIRTUAL TABLE t1 USING fts4 }
|
||||
for {set i 0} {$i < $nRow} {incr i} {
|
||||
set v [expr int(rand()*1000000)]
|
||||
set doc [list]
|
||||
for {set div 1} {$div < 1000000} {set div [expr $div*10]} {
|
||||
lappend doc [lindex $vocab [expr ($v/$div) % 10]]
|
||||
}
|
||||
execsql { INSERT INTO t1 VALUES($doc) }
|
||||
}
|
||||
}
|
||||
|
||||
set nRow 1000
|
||||
do_test 1.0 {
|
||||
build_database $nRow
|
||||
execsql { SELECT count(*) FROM t1 }
|
||||
} $nRow
|
||||
|
||||
foreach {tn query} {
|
||||
1 "SELECT docid, * FROM t1"
|
||||
2 "SELECT docid, * FROM t1 WHERE t1 MATCH 'aa'"
|
||||
3 "SELECT docid, * FROM t1 WHERE t1 MATCH 'a*'"
|
||||
4 "SELECT docid, quote(matchinfo(t1)) FROM t1 WHERE t1 MATCH 'a*'"
|
||||
5 "SELECT docid, quote(matchinfo(t1,'pcnxals')) FROM t1 WHERE t1 MATCH 'b*'"
|
||||
6 "SELECT docid, * FROM t1 WHERE t1 MATCH 'a* b* c*'"
|
||||
7 "SELECT docid, * FROM t1 WHERE t1 MATCH 'aa OR da'"
|
||||
8 "SELECT docid, * FROM t1 WHERE t1 MATCH 'nosuchtoken'"
|
||||
9 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR da'"
|
||||
10 "SELECT docid, snippet(t1) FROM t1 WHERE t1 MATCH 'aa OR nosuchtoken'"
|
||||
} {
|
||||
|
||||
unset -nocomplain A B C D
|
||||
set A_list [list]
|
||||
set B_list [list]
|
||||
set C_list [list]
|
||||
set D_list [list]
|
||||
|
||||
unset -nocomplain X
|
||||
db eval "$query ORDER BY rowid ASC" X {
|
||||
set A($X(docid)) [array get X]
|
||||
lappend A_list $X(docid)
|
||||
}
|
||||
unset -nocomplain X
|
||||
db eval "$query ORDER BY rowid DESC" X {
|
||||
set B($X(docid)) [array get X]
|
||||
lappend B_list $X(docid)
|
||||
}
|
||||
unset -nocomplain X
|
||||
db eval "$query ORDER BY docid ASC" X {
|
||||
set C($X(docid)) [array get X]
|
||||
lappend C_list $X(docid)
|
||||
}
|
||||
unset -nocomplain X
|
||||
db eval "$query ORDER BY docid DESC" X {
|
||||
set D($X(docid)) [array get X]
|
||||
lappend D_list $X(docid)
|
||||
}
|
||||
|
||||
do_test 1.$tn.1 { set A_list } [lsort -integer -increasing $A_list]
|
||||
do_test 1.$tn.2 { set B_list } [lsort -integer -decreasing $B_list]
|
||||
do_test 1.$tn.3 { set C_list } [lsort -integer -increasing $C_list]
|
||||
do_test 1.$tn.4 { set D_list } [lsort -integer -decreasing $D_list]
|
||||
|
||||
unset -nocomplain DATA
|
||||
unset -nocomplain X
|
||||
db eval "$query" X {
|
||||
set DATA($X(docid)) [array get X]
|
||||
}
|
||||
|
||||
do_test 1.$tn.5 { lsort [array get A] } [lsort [array get DATA]]
|
||||
do_test 1.$tn.6 { lsort [array get B] } [lsort [array get DATA]]
|
||||
do_test 1.$tn.7 { lsort [array get C] } [lsort [array get DATA]]
|
||||
do_test 1.$tn.8 { lsort [array get D] } [lsort [array get DATA]]
|
||||
}
|
||||
|
||||
finish_test
|
||||
@@ -326,4 +326,64 @@ do_test insert4-6.7 {
|
||||
}
|
||||
} {1 {constraint failed}}
|
||||
|
||||
# Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
|
||||
# Disable the xfer optimization if the destination table contains
|
||||
# a foreign key constraint
|
||||
#
|
||||
ifcapable foreignkey {
|
||||
do_test insert4-7.1 {
|
||||
set ::sqlite3_xferopt_count 0
|
||||
execsql {
|
||||
CREATE TABLE t7a(x INTEGER PRIMARY KEY); INSERT INTO t7a VALUES(123);
|
||||
CREATE TABLE t7b(y INTEGER REFERENCES t7a);
|
||||
CREATE TABLE t7c(z INT); INSERT INTO t7c VALUES(234);
|
||||
INSERT INTO t7b SELECT * FROM t7c;
|
||||
SELECT * FROM t7b;
|
||||
}
|
||||
} {234}
|
||||
do_test insert4-7.2 {
|
||||
set ::sqlite3_xferopt_count
|
||||
} {1}
|
||||
do_test insert4-7.3 {
|
||||
set ::sqlite3_xferopt_count 0
|
||||
execsql {
|
||||
DELETE FROM t7b;
|
||||
PRAGMA foreign_keys=ON;
|
||||
}
|
||||
catchsql {
|
||||
INSERT INTO t7b SELECT * FROM t7c;
|
||||
}
|
||||
} {1 {foreign key constraint failed}}
|
||||
do_test insert4-7.4 {
|
||||
execsql {SELECT * FROM t7b}
|
||||
} {}
|
||||
do_test insert4-7.5 {
|
||||
set ::sqlite3_xferopt_count
|
||||
} {0}
|
||||
do_test insert4-7.6 {
|
||||
set ::sqlite3_xferopt_count 0
|
||||
execsql {
|
||||
DELETE FROM t7b; DELETE FROM t7c;
|
||||
INSERT INTO t7c VALUES(123);
|
||||
INSERT INTO t7b SELECT * FROM t7c;
|
||||
SELECT * FROM t7b;
|
||||
}
|
||||
} {123}
|
||||
do_test insert4-7.7 {
|
||||
set ::sqlite3_xferopt_count
|
||||
} {0}
|
||||
do_test insert4-7.7 {
|
||||
set ::sqlite3_xferopt_count 0
|
||||
execsql {
|
||||
PRAGMA foreign_keys=OFF;
|
||||
DELETE FROM t7b;
|
||||
INSERT INTO t7b SELECT * FROM t7c;
|
||||
SELECT * FROM t7b;
|
||||
}
|
||||
} {123}
|
||||
do_test insert4-7.8 {
|
||||
set ::sqlite3_xferopt_count
|
||||
} {1}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -753,6 +753,17 @@ proc integrity_check {name {db db}} {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Return true if the SQL statement passed as the second argument uses a
|
||||
# statement transaction.
|
||||
#
|
||||
proc sql_uses_stmt {db sql} {
|
||||
set stmt [sqlite3_prepare $db $sql -1 dummy]
|
||||
set uses [uses_stmt_journal $stmt]
|
||||
sqlite3_finalize $stmt
|
||||
return $uses
|
||||
}
|
||||
|
||||
proc fix_ifcapable_expr {expr} {
|
||||
set ret ""
|
||||
set state 0
|
||||
|
||||
Reference in New Issue
Block a user