mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
sync up our in tree sqlite with the 3.3.13 official release. Commit to follow to finish this process on the windows build.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4351 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: all.test,v 1.35 2006/01/17 15:36:33 danielk1977 Exp $
|
||||
# $Id: all.test,v 1.36 2006/11/23 21:09:11 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -56,6 +56,7 @@ set EXCLUDE {
|
||||
malloc.test
|
||||
misuse.test
|
||||
memleak.test
|
||||
speed1.test
|
||||
}
|
||||
|
||||
# Files to include in the test. If this list is empty then everything
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# file format change that may be used in the future to implement
|
||||
# "ALTER TABLE ... ADD COLUMN".
|
||||
#
|
||||
# $Id: alter2.test,v 1.5 2006/01/03 00:33:50 drh Exp $
|
||||
# $Id: alter2.test,v 1.6 2007/01/04 14:36:02 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -25,7 +25,7 @@ ifcapable {!pragma} return
|
||||
# These tests do not work if there is a codec. The
|
||||
# btree_open command does not know how to handle codecs.
|
||||
#
|
||||
if {[catch {sqlite3 -has_codec} r] || $r} return
|
||||
#if {[catch {sqlite3 -has_codec} r] || $r} return
|
||||
|
||||
# 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
|
||||
@@ -68,17 +68,13 @@ proc get_file_format {{fname test.db}} {
|
||||
#
|
||||
proc alter_table {tbl sql {file_format 2}} {
|
||||
sqlite3 dbat test.db
|
||||
puts one
|
||||
dbat eval {
|
||||
PRAGMA writable_schema = 1;
|
||||
UPDATE sqlite_master SET sql = $sql WHERE name = $tbl AND type = 'table';
|
||||
PRAGMA writable_schema = 0;
|
||||
}
|
||||
puts two
|
||||
dbat close
|
||||
puts three
|
||||
set_file_format 2
|
||||
puts four
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
@@ -96,7 +92,6 @@ do_test alter2-1.2 {
|
||||
# ALTER TABLE abc ADD COLUMN c;
|
||||
alter_table abc {CREATE TABLE abc(a, b, c);}
|
||||
} {}
|
||||
exit
|
||||
do_test alter2-1.3 {
|
||||
execsql {
|
||||
SELECT * FROM abc;
|
||||
@@ -127,7 +122,7 @@ do_test alter2-1.8 {
|
||||
execsql {
|
||||
SELECT sum(a), c FROM abc GROUP BY c;
|
||||
}
|
||||
} {8.0 {} 1.0 10}
|
||||
} {8 {} 1 10}
|
||||
do_test alter2-1.9 {
|
||||
# ALTER TABLE abc ADD COLUMN d;
|
||||
alter_table abc {CREATE TABLE abc(a, b, c, d);}
|
||||
@@ -234,12 +229,12 @@ ifcapable trigger {
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Check that an error occurs if the database is upgraded to a file
|
||||
# format that SQLite does not support (in this case 4). Note: The
|
||||
# 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 {
|
||||
set_file_format 4
|
||||
set_file_format 5
|
||||
} {}
|
||||
do_test alter2-4.2 {
|
||||
catchsql {
|
||||
@@ -341,7 +336,7 @@ do_test alter2-7.5 {
|
||||
execsql {
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer -123.0 real 5 text}
|
||||
} {1 integer -123 integer 5 text}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Test that UPDATE trigger tables work with default values, and that when
|
||||
@@ -367,11 +362,11 @@ do_test alter2-8.2 {
|
||||
UPDATE t1 SET c = 10 WHERE a = 1;
|
||||
SELECT a, typeof(a), b, typeof(b), c, typeof(c) FROM t1 LIMIT 1;
|
||||
}
|
||||
} {1 integer -123.0 real 10 text}
|
||||
} {1 integer -123 integer 10 text}
|
||||
ifcapable trigger {
|
||||
do_test alter2-8.3 {
|
||||
set ::val
|
||||
} {-123 real 5 text -123 real 10 text}
|
||||
} {-123 integer 5 text -123 integer 10 text}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
@@ -395,7 +390,7 @@ ifcapable trigger {
|
||||
DELETE FROM t1 WHERE a = 2;
|
||||
}
|
||||
set ::val
|
||||
} {-123 real 5 text}
|
||||
} {-123 integer 5 text}
|
||||
}
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is btree database backend
|
||||
#
|
||||
# $Id: btree.test,v 1.37 2006/08/16 16:42:48 drh Exp $
|
||||
# $Id: btree.test,v 1.38 2007/01/03 23:37:29 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -548,7 +548,6 @@ do_test btree-8.1 {
|
||||
} {}
|
||||
btree_page_dump $::b1 1
|
||||
btree_page_dump $::b1 2
|
||||
btree_page_dump $::b1 3
|
||||
do_test btree-8.1.1 {
|
||||
lindex [btree_pager_stats $::b1] 1
|
||||
} {1}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# 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.32 2006/08/16 16:42:48 drh Exp $
|
||||
# $Id: capi2.test,v 1.33 2007/01/03 23:37:29 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -71,7 +71,7 @@ do_test capi2-1.6 {
|
||||
do_test capi2-1.7 {
|
||||
list [sqlite3_column_count $VM] [get_row_values $VM] [get_column_names $VM]
|
||||
} {2 {} {name rowid text INTEGER}}
|
||||
do_test capi2-1.8 {
|
||||
do_test capi2-1.8-misuse {
|
||||
sqlite3_step $VM
|
||||
} {SQLITE_MISUSE}
|
||||
|
||||
@@ -208,7 +208,7 @@ do_test capi2-3.11 {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_OK}
|
||||
do_test capi2-3.11b {db changes} {1}
|
||||
do_test capi2-3.12 {
|
||||
do_test capi2-3.12-misuse {
|
||||
sqlite3_finalize $VM
|
||||
} {SQLITE_MISUSE}
|
||||
do_test capi2-3.13 {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# 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.46 2006/08/16 16:42:48 drh Exp $
|
||||
# $Id: capi3.test,v 1.47 2007/01/03 23:37:29 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -152,14 +152,14 @@ do_test capi3-3.4 {
|
||||
do_test capi3-3.5 {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-3.6.1 {
|
||||
do_test capi3-3.6.1-misuse {
|
||||
sqlite3_close $db2
|
||||
} {SQLITE_MISUSE}
|
||||
do_test capi3-3.6.2 {
|
||||
do_test capi3-3.6.2-misuse {
|
||||
sqlite3_errmsg $db2
|
||||
} {library routine called out of sequence}
|
||||
ifcapable {utf16} {
|
||||
do_test capi3-3.6.3 {
|
||||
do_test capi3-3.6.3-misuse {
|
||||
utf8 [sqlite3_errmsg16 $db2]
|
||||
} {library routine called out of sequence}
|
||||
}
|
||||
@@ -612,7 +612,7 @@ check_data $STMT capi3-6.3 {INTEGER} {1} {1.0} {1}
|
||||
do_test capi3-6.3 {
|
||||
sqlite3_finalize $STMT
|
||||
} {SQLITE_OK}
|
||||
do_test capi3-6.4 {
|
||||
do_test capi3-6.4-misuse {
|
||||
db cache flush
|
||||
sqlite3_close $DB
|
||||
} {SQLITE_OK}
|
||||
@@ -991,7 +991,7 @@ if {[llength [info commands sqlite3_sleep]]>0} {
|
||||
|
||||
# Ticket #1219: Make sure binding APIs can handle a NULL pointer.
|
||||
#
|
||||
do_test capi3-14.1 {
|
||||
do_test capi3-14.1-misuse {
|
||||
set rc [catch {sqlite3_bind_text 0 1 hello 5} msg]
|
||||
lappend rc $msg
|
||||
} {1 SQLITE_MISUSE}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate1.test,v 1.4 2005/11/01 15:48:25 drh Exp $
|
||||
# $Id: collate1.test,v 1.5 2007/02/01 23:02:46 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -90,6 +90,21 @@ do_test collate1-1.4 {
|
||||
}
|
||||
} {{} 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;
|
||||
}
|
||||
@@ -133,7 +148,59 @@ do_test collate1-2.6 {
|
||||
ORDER BY 1 COLLATE binary ASC, 2 COLLATE hex ASC;
|
||||
}
|
||||
} {{} {} 11 0x11 11 0x101 5 0xA 5 0x11 7 0xA}
|
||||
do_test collate1-2.7 {
|
||||
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;
|
||||
}
|
||||
@@ -180,6 +247,12 @@ do_test collate1-3.5 {
|
||||
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;
|
||||
@@ -220,6 +293,11 @@ do_test collate1-4.4 {
|
||||
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;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: collate2.test,v 1.4 2005/01/21 03:12:16 danielk1977 Exp $
|
||||
# $Id: collate2.test,v 1.5 2007/02/01 23:02:46 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -98,16 +98,67 @@ do_test collate2-1.1 {
|
||||
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.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;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# This file implements tests for the conflict resolution extension
|
||||
# to SQLite.
|
||||
#
|
||||
# $Id: conflict.test,v 1.27 2006/01/17 09:35:02 danielk1977 Exp $
|
||||
# $Id: conflict.test,v 1.28 2007/01/03 23:37:29 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -309,6 +309,7 @@ foreach {i conf1 cmd t0 t1 t2 t3} {
|
||||
if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
|
||||
execsql {pragma temp_store=file}
|
||||
set ::sqlite_opentemp_count 0
|
||||
if {$i==2} btree_breakpoint
|
||||
set r0 [catch {execsql [subst {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing date and time functions.
|
||||
#
|
||||
# $Id: date.test,v 1.17 2006/09/25 18:03:29 drh Exp $
|
||||
# $Id: date.test,v 1.19 2007/01/08 16:19:07 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -123,6 +123,17 @@ 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.22 {strftime('%W %j',2454109.04140978)} {02 008}
|
||||
datetest 3.11.22 {strftime('%W %j',2454109.04140979)} {02 008}
|
||||
datetest 3.11.22 {strftime('%W %j',2454109.04140980)} {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
|
||||
@@ -284,5 +295,19 @@ do_test date-13.1 {
|
||||
}
|
||||
} {{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}
|
||||
|
||||
|
||||
finish_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 FTS1 module.
|
||||
#
|
||||
# $Id: fts1e.test,v 1.1 2006/10/19 23:28:35 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS1 is defined, omit this file.
|
||||
ifcapable !fts1 {
|
||||
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 fts1(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 fts1f-1.1 {
|
||||
execsql {SELECT COUNT(*) FROM t1}
|
||||
} {14}
|
||||
|
||||
do_test fts1e-2.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
|
||||
} {3 5 9 11 15 17 21}
|
||||
|
||||
do_test fts1e-2.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'}
|
||||
} {2 3 6 11 14 15 18}
|
||||
|
||||
do_test fts1e-2.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'}
|
||||
} {5 6 12 14 15 20 21}
|
||||
|
||||
do_test fts1e-2.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'}
|
||||
} {8 9 11 12 14 15}
|
||||
|
||||
do_test fts1e-2.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'}
|
||||
} {17 18 20 21}
|
||||
|
||||
finish_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 FTS1 module.
|
||||
#
|
||||
# $Id: fts1f.test,v 1.1 2006/10/19 23:28:35 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS1 is defined, omit this file.
|
||||
ifcapable !fts1 {
|
||||
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 fts1(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 fts1f-1.1 {
|
||||
execsql {SELECT COUNT(*) FROM t1}
|
||||
} {16}
|
||||
|
||||
do_test fts1e-2.0 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'update'}
|
||||
} {1 8 15}
|
||||
|
||||
do_test fts1e-2.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
|
||||
} {1 3 5 9 11 17 21}
|
||||
|
||||
do_test fts1e-2.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'}
|
||||
} {2 3 6 8 11 14 18 22}
|
||||
|
||||
do_test fts1e-2.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'}
|
||||
} {1 5 6 12 14 20 21 22}
|
||||
|
||||
do_test fts1e-2.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'}
|
||||
} {9 11 12 14}
|
||||
|
||||
do_test fts1e-2.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'}
|
||||
} {8 17 18 20 21 22}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,88 @@
|
||||
# 2007 January 17
|
||||
#
|
||||
# The author disclaims copyright to this source code.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite fts1 library. The
|
||||
# focus here is testing handling of UPDATE when using UTF-16-encoded
|
||||
# databases.
|
||||
#
|
||||
# $Id: fts1i.test,v 1.2 2007/01/24 03:43:20 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS1 is defined, omit this file.
|
||||
ifcapable !fts1 {
|
||||
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 fts1(content);
|
||||
}
|
||||
|
||||
do_test fts1i-1.0 {
|
||||
execsql {PRAGMA encoding}
|
||||
} {UTF-16le}
|
||||
|
||||
do_test fts1i-1.1 {
|
||||
execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')}
|
||||
execsql {SELECT content FROM t1 WHERE rowid = 1}
|
||||
} {one}
|
||||
|
||||
do_test fts1i-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 fts1i-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 fts1i-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 fts1i-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
|
||||
@@ -0,0 +1,89 @@
|
||||
# 2007 February 6
|
||||
#
|
||||
# The author disclaims copyright to this source code.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. This
|
||||
# tests creating fts1 tables in an attached database.
|
||||
#
|
||||
# $Id: fts1j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS1 is defined, omit this file.
|
||||
ifcapable !fts1 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Clean up anything left over from a previous pass.
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
|
||||
db eval {
|
||||
CREATE VIRTUAL TABLE t3 USING fts1(content);
|
||||
INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
|
||||
}
|
||||
|
||||
db2 eval {
|
||||
CREATE VIRTUAL TABLE t1 USING fts1(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");
|
||||
}
|
||||
|
||||
# This has always worked because the t1_* tables used by fts1 will be
|
||||
# the defaults.
|
||||
do_test fts1j-1.1 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
|
||||
DETACH DATABASE two;
|
||||
}
|
||||
} {1 2}
|
||||
# Make certain we're detached if there was an error.
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
# In older code, this appears to work fine, but the t2_* tables used
|
||||
# by fts1 will be created in database 'main' instead of database
|
||||
# 'two'. It appears to work fine because the tables end up being the
|
||||
# defaults, but obviously is badly broken if you hope to use things
|
||||
# other than in the exact same ATTACH setup.
|
||||
do_test fts1j-1.2 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
CREATE VIRTUAL TABLE two.t2 USING fts1(content);
|
||||
INSERT INTO t2 (rowid, content) VALUES(1, "hello world");
|
||||
INSERT INTO t2 (rowid, content) VALUES(2, "hello there");
|
||||
INSERT INTO t2 (rowid, content) VALUES(3, "cruel world");
|
||||
SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
|
||||
DETACH DATABASE two;
|
||||
}
|
||||
} {1 2}
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
# In older code, this broke because the fts1 code attempted to create
|
||||
# t3_* tables in database 'main', but they already existed. Normally
|
||||
# this wouldn't happen without t3 itself existing, in which case the
|
||||
# fts1 code would never be called in the first place.
|
||||
do_test fts1j-1.3 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
|
||||
CREATE VIRTUAL TABLE two.t3 USING fts1(content);
|
||||
INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there");
|
||||
INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world");
|
||||
SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
|
||||
|
||||
DETACH DATABASE two;
|
||||
} db2
|
||||
} {2}
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
catch {db2 close}
|
||||
file delete -force test2.db
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,186 @@
|
||||
# 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 FTS2 module.
|
||||
#
|
||||
# $Id: fts2a.test,v 1.1 2006/10/19 23:36:26 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
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 fts2(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 fts2a-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 fts2a-1.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two'}
|
||||
} {3 7 11 15 19 23 27 31}
|
||||
do_test fts2a-1.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one'}
|
||||
} {3 7 11 15 19 23 27 31}
|
||||
do_test fts2a-1.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two three'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one three two'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.6 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two three one'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.7 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two one three'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.8 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three one two'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.9 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three two one'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.10 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one two THREE'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-1.11 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH ' ONE Two three '}
|
||||
} {7 15 23 31}
|
||||
|
||||
do_test fts2a-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 fts2a-2.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two"'}
|
||||
} {3 7 11 15 19 23 27 31}
|
||||
do_test fts2a-2.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"two one"'}
|
||||
} {}
|
||||
do_test fts2a-2.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three"'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2a-2.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two"'}
|
||||
} {}
|
||||
do_test fts2a-2.6 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one two three four"'}
|
||||
} {15 31}
|
||||
do_test fts2a-2.7 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three two four"'}
|
||||
} {}
|
||||
do_test fts2a-2.8 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three five"'}
|
||||
} {21}
|
||||
do_test fts2a-2.9 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" five'}
|
||||
} {21 29}
|
||||
do_test fts2a-2.10 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three"'}
|
||||
} {21 29}
|
||||
do_test fts2a-2.11 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five "one three" four'}
|
||||
} {29}
|
||||
do_test fts2a-2.12 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five four "one three"'}
|
||||
} {29}
|
||||
do_test fts2a-2.13 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '"one three" four five'}
|
||||
} {29}
|
||||
|
||||
do_test fts2a-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 fts2a-3.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one -two'}
|
||||
} {1 5 9 13 17 21 25 29}
|
||||
do_test fts2a-3.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH '-two one'}
|
||||
} {1 5 9 13 17 21 25 29}
|
||||
|
||||
do_test fts2a-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 fts2a-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 fts2a-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 fts2a-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 fts2a-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 fts2a-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 fts2a-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 fts2a-5.1 {
|
||||
execsql {INSERT INTO t1(content) VALUES(NULL)}
|
||||
} {}
|
||||
do_test fts2a-5.2 {
|
||||
set rowid [db last_insert_rowid]
|
||||
execsql {SELECT content FROM t1 WHERE rowid=$rowid}
|
||||
} {{}}
|
||||
do_test fts2a-5.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH NULL}
|
||||
} {}
|
||||
|
||||
|
||||
|
||||
finish_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 FTS2 module.
|
||||
#
|
||||
# $Id: fts2b.test,v 1.1 2006/10/19 23:36:26 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
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 fts2(english,spanish,german);
|
||||
}
|
||||
fill_multilanguage_fulltext_t1
|
||||
|
||||
do_test fts2b-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 fts2b-1.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE spanish MATCH 'one'}
|
||||
} {}
|
||||
do_test fts2b-1.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE german MATCH 'one'}
|
||||
} {}
|
||||
do_test fts2b-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 fts2b-1.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'one dos drei'}
|
||||
} {7 15 23 31}
|
||||
do_test fts2b-1.6 {
|
||||
execsql {SELECT english, spanish, german FROM t1 WHERE rowid=1}
|
||||
} {one un eine}
|
||||
do_test fts2b-1.7 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"one un"'}
|
||||
} {}
|
||||
|
||||
do_test fts2b-2.1 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t2 USING fts2(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 fts2([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 fts2b-4.1 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one'}
|
||||
} {1 3 5 7 9 11 13 15}
|
||||
do_test fts2b-4.2 {
|
||||
execsql {SELECT rowid FROM t4 WHERE norm MATCH 'one'}
|
||||
} {1 3 5 7 9 11 13 15}
|
||||
do_test fts2b-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 fts2b-4.4 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:one'}
|
||||
} {2 4 6 8 10 12 14}
|
||||
do_test fts2b-4.5 {
|
||||
execsql {SELECT rowid FROM t4 WHERE plusone MATCH 'one'}
|
||||
} {2 4 6 8 10 12 14}
|
||||
do_test fts2b-4.6 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one plusone:two'}
|
||||
} {1 5 9 13}
|
||||
do_test fts2b-4.7 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'norm:one two'}
|
||||
} {1 3 5 7 9 11 13 15}
|
||||
do_test fts2b-4.8 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'plusone:two norm:one'}
|
||||
} {1 5 9 13}
|
||||
do_test fts2b-4.9 {
|
||||
execsql {SELECT rowid FROM t4 WHERE t4 MATCH 'two norm:one'}
|
||||
} {1 3 5 7 9 11 13 15}
|
||||
|
||||
|
||||
finish_test
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
# 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 FTS2 module, and in particular
|
||||
# the Porter stemmer.
|
||||
#
|
||||
# $Id: fts2d.test,v 1.1 2006/10/19 23:36:26 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
do_test fts2d-1.1 {
|
||||
execsql {
|
||||
CREATE VIRTUAL TABLE t1 USING fts2(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 fts2d-1.2 {
|
||||
execsql {
|
||||
SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'run jump';
|
||||
}
|
||||
} {{<b>running</b> and <b>jumping</b>}}
|
||||
do_test fts2d-1.3 {
|
||||
execsql {
|
||||
INSERT INTO t1(rowid, content)
|
||||
VALUES(2, 'abcdefghijklmnopqrstuvwyxz');
|
||||
SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijqrstuvwyxz'
|
||||
}
|
||||
} {2 <b>abcdefghijklmnopqrstuvwyxz</b>}
|
||||
do_test fts2d-1.4 {
|
||||
execsql {
|
||||
SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH 'abcdefghijXXXXqrstuvwyxz'
|
||||
}
|
||||
} {2 <b>abcdefghijklmnopqrstuvwyxz</b>}
|
||||
do_test fts2d-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 <b>123456789</b>}}
|
||||
do_test fts2d-1.6 {
|
||||
execsql {
|
||||
SELECT rowid, snippet(t1) FROM t1 WHERE t1 MATCH '123000000789'
|
||||
}
|
||||
} {3 {The value is <b>123456789</b>}}
|
||||
|
||||
|
||||
finish_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 FTS2 module.
|
||||
#
|
||||
# $Id: fts2e.test,v 1.1 2006/10/19 23:36:26 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
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 fts2(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 fts2f-1.1 {
|
||||
execsql {SELECT COUNT(*) FROM t1}
|
||||
} {14}
|
||||
|
||||
do_test fts2e-2.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
|
||||
} {3 5 9 11 15 17 21}
|
||||
|
||||
do_test fts2e-2.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'}
|
||||
} {2 3 6 11 14 15 18}
|
||||
|
||||
do_test fts2e-2.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'}
|
||||
} {5 6 12 14 15 20 21}
|
||||
|
||||
do_test fts2e-2.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'}
|
||||
} {8 9 11 12 14 15}
|
||||
|
||||
do_test fts2e-2.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'}
|
||||
} {17 18 20 21}
|
||||
|
||||
finish_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 FTS2 module.
|
||||
#
|
||||
# $Id: fts2f.test,v 1.1 2006/10/19 23:36:26 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
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 fts2(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 fts2f-1.1 {
|
||||
execsql {SELECT COUNT(*) FROM t1}
|
||||
} {16}
|
||||
|
||||
do_test fts2e-2.0 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'update'}
|
||||
} {1 8 15}
|
||||
|
||||
do_test fts2e-2.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'one'}
|
||||
} {1 3 5 9 11 17 21}
|
||||
|
||||
do_test fts2e-2.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'two'}
|
||||
} {2 3 6 8 11 14 18 22}
|
||||
|
||||
do_test fts2e-2.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'three'}
|
||||
} {1 5 6 12 14 20 21 22}
|
||||
|
||||
do_test fts2e-2.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'four'}
|
||||
} {9 11 12 14}
|
||||
|
||||
do_test fts2e-2.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE content MATCH 'five'}
|
||||
} {8 17 18 20 21 22}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,77 @@
|
||||
# 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 FTS2 module query logic.
|
||||
#
|
||||
# $Id: fts2g.test,v 1.1 2006/10/25 20:27:40 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
db eval {
|
||||
CREATE VIRTUAL TABLE t1 USING fts2(content);
|
||||
INSERT INTO t1 (rowid, content) VALUES(1, 'this is a test');
|
||||
}
|
||||
|
||||
# No hits at all. Returns empty doclists from termSelect().
|
||||
do_test fts2g-1.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'}
|
||||
} {}
|
||||
|
||||
# Empty left in docListExceptMerge().
|
||||
do_test fts2g-1.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this something'}
|
||||
} {}
|
||||
|
||||
# Empty right in docListExceptMerge().
|
||||
do_test fts2g-1.3 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this -something'}
|
||||
} {1}
|
||||
|
||||
# Empty left in docListPhraseMerge().
|
||||
do_test fts2g-1.4 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"this something"'}
|
||||
} {}
|
||||
|
||||
# Empty right in docListPhraseMerge().
|
||||
do_test fts2g-1.5 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH '"something is"'}
|
||||
} {}
|
||||
|
||||
# Empty left in docListOrMerge().
|
||||
do_test fts2g-1.6 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something OR this'}
|
||||
} {1}
|
||||
|
||||
# Empty right in docListOrMerge().
|
||||
do_test fts2g-1.7 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR something'}
|
||||
} {1}
|
||||
|
||||
# Empty left in docListAndMerge().
|
||||
do_test fts2g-1.8 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something this'}
|
||||
} {}
|
||||
|
||||
# Empty right in docListAndMerge().
|
||||
do_test fts2g-1.9 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this something'}
|
||||
} {}
|
||||
|
||||
# No support for all-except queries.
|
||||
do_test fts2g-1.10 {
|
||||
catchsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this -something'}
|
||||
} {1 {SQL logic error or missing database}}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,76 @@
|
||||
# 2006 October 31 (scaaarey)
|
||||
#
|
||||
# The author disclaims copyright to this source code.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. The focus
|
||||
# here is testing correct handling of excessively long terms.
|
||||
#
|
||||
# $Id: fts2h.test,v 1.1 2006/11/29 21:03:01 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Generate a term of len copies of char.
|
||||
proc bigterm {char len} {
|
||||
for {set term ""} {$len>0} {incr len -1} {
|
||||
append term $char
|
||||
}
|
||||
return $term
|
||||
}
|
||||
|
||||
# Generate a document of bigterms based on characters from the list
|
||||
# chars.
|
||||
proc bigtermdoc {chars len} {
|
||||
set doc ""
|
||||
foreach char $chars {
|
||||
append doc " " [bigterm $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 [bigterm a $len]
|
||||
set bterm [bigterm b $len]
|
||||
set xterm [bigterm x $len]
|
||||
|
||||
db eval {
|
||||
CREATE VIRTUAL TABLE t1 USING fts2(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 fts2h-1.1 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'}
|
||||
} {}
|
||||
|
||||
do_test fts2h-1.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH $aterm}
|
||||
} {1 3}
|
||||
|
||||
do_test fts2h-1.2 {
|
||||
execsql {SELECT rowid FROM t1 WHERE t1 MATCH $xterm}
|
||||
} {}
|
||||
|
||||
do_test fts2h-1.3 {
|
||||
execsql "SELECT rowid FROM t1 WHERE t1 MATCH '$aterm -$xterm'"
|
||||
} {1 3}
|
||||
|
||||
do_test fts2h-1.4 {
|
||||
execsql "SELECT rowid FROM t1 WHERE t1 MATCH '\"$aterm $bterm\"'"
|
||||
} {1}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,87 @@
|
||||
# 2007 January 17
|
||||
#
|
||||
# The author disclaims copyright to this source code.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite fts2 library. The
|
||||
# focus here is testing handling of UPDATE when using UTF-16-encoded
|
||||
# databases.
|
||||
#
|
||||
# $Id: fts2i.test,v 1.2 2007/01/24 03:46:35 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
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 fts2(content);
|
||||
}
|
||||
|
||||
do_test fts2i-1.0 {
|
||||
execsql {PRAGMA encoding}
|
||||
} {UTF-16le}
|
||||
|
||||
do_test fts2i-1.1 {
|
||||
execsql {INSERT INTO t1 (rowid, content) VALUES(1, 'one')}
|
||||
execsql {SELECT content FROM t1 WHERE rowid = 1}
|
||||
} {one}
|
||||
|
||||
do_test fts2i-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 fts2i-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 fts2i-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 fts2i-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
|
||||
@@ -0,0 +1,89 @@
|
||||
# 2007 February 6
|
||||
#
|
||||
# The author disclaims copyright to this source code.
|
||||
#
|
||||
#*************************************************************************
|
||||
# This file implements regression tests for SQLite library. This
|
||||
# tests creating fts2 tables in an attached database.
|
||||
#
|
||||
# $Id: fts2j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
||||
ifcapable !fts2 {
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
# Clean up anything left over from a previous pass.
|
||||
file delete -force test2.db
|
||||
file delete -force test2.db-journal
|
||||
sqlite3 db2 test2.db
|
||||
|
||||
db eval {
|
||||
CREATE VIRTUAL TABLE t3 USING fts2(content);
|
||||
INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
|
||||
}
|
||||
|
||||
db2 eval {
|
||||
CREATE VIRTUAL TABLE t1 USING fts2(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");
|
||||
}
|
||||
|
||||
# This has always worked because the t1_* tables used by fts2 will be
|
||||
# the defaults.
|
||||
do_test fts2j-1.1 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
|
||||
DETACH DATABASE two;
|
||||
}
|
||||
} {1 2}
|
||||
# Make certain we're detached if there was an error.
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
# In older code, this appears to work fine, but the t2_* tables used
|
||||
# by fts2 will be created in database 'main' instead of database
|
||||
# 'two'. It appears to work fine because the tables end up being the
|
||||
# defaults, but obviously is badly broken if you hope to use things
|
||||
# other than in the exact same ATTACH setup.
|
||||
do_test fts2j-1.2 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
CREATE VIRTUAL TABLE two.t2 USING fts2(content);
|
||||
INSERT INTO t2 (rowid, content) VALUES(1, "hello world");
|
||||
INSERT INTO t2 (rowid, content) VALUES(2, "hello there");
|
||||
INSERT INTO t2 (rowid, content) VALUES(3, "cruel world");
|
||||
SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
|
||||
DETACH DATABASE two;
|
||||
}
|
||||
} {1 2}
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
# In older code, this broke because the fts2 code attempted to create
|
||||
# t3_* tables in database 'main', but they already existed. Normally
|
||||
# this wouldn't happen without t3 itself existing, in which case the
|
||||
# fts2 code would never be called in the first place.
|
||||
do_test fts2j-1.3 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test2.db' AS two;
|
||||
|
||||
CREATE VIRTUAL TABLE two.t3 USING fts2(content);
|
||||
INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there");
|
||||
INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world");
|
||||
SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
|
||||
|
||||
DETACH DATABASE two;
|
||||
} db2
|
||||
} {2}
|
||||
catch {db eval {DETACH DATABASE two}}
|
||||
|
||||
catch {db2 close}
|
||||
file delete -force test2.db
|
||||
|
||||
finish_test
|
||||
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing built-in functions.
|
||||
#
|
||||
# $Id: func.test,v 1.55 2006/09/16 21:45:14 drh Exp $
|
||||
# $Id: func.test,v 1.57 2007/01/29 17:58:28 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -296,6 +296,35 @@ do_test func-9.1 {
|
||||
SELECT random() is not null;
|
||||
}
|
||||
} {1}
|
||||
do_test func-9.2 {
|
||||
execsql {
|
||||
SELECT typeof(random());
|
||||
}
|
||||
} {integer}
|
||||
do_test func-9.3 {
|
||||
execsql {
|
||||
SELECT randomblob(32) is not null;
|
||||
}
|
||||
} {1}
|
||||
do_test func-9.4 {
|
||||
execsql {
|
||||
SELECT typeof(randomblob(32));
|
||||
}
|
||||
} {blob}
|
||||
do_test func-9.5 {
|
||||
execsql {
|
||||
SELECT length(randomblob(32)), length(randomblob(-5)),
|
||||
length(randomblob(2000))
|
||||
}
|
||||
} {32 1 2000}
|
||||
|
||||
# The "hex()" function was added in order to be able to render blobs
|
||||
# generated by randomblob(). So this seems like a good place to test
|
||||
# hex().
|
||||
#
|
||||
do_test func-9.10 {
|
||||
execsql {SELECT hex(x'00112233445566778899aAbBcCdDeEfF')}
|
||||
} {00112233445566778899AABBCCDDEEFF}
|
||||
|
||||
# Use the "sqlite_register_test_function" TCL command which is part of
|
||||
# the text fixture in order to verify correct operation of some of
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# The tests in this file use special facilities that are only
|
||||
# available in the SQLite test fixture.
|
||||
#
|
||||
# $Id: ioerr.test,v 1.27 2006/09/15 07:28:51 drh Exp $
|
||||
# $Id: ioerr.test,v 1.29 2007/01/04 14:58:14 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -46,6 +46,9 @@ do_ioerr_test ioerr-1 -erc 1 -sqlprep {
|
||||
DELETE FROM t1 WHERE a<100;
|
||||
} -exclude [expr [string match [execsql {pragma auto_vacuum}] 1] ? 4 : 0]
|
||||
|
||||
finish_test
|
||||
return
|
||||
|
||||
# Test for IO errors during a VACUUM.
|
||||
#
|
||||
# The first IO call is excluded from the test. This call attempts to read
|
||||
@@ -165,6 +168,7 @@ ifcapable crashtest {
|
||||
# These tests can't be run on windows because the windows version of
|
||||
# SQLite holds a mandatory exclusive lock on journal files it has open.
|
||||
#
|
||||
btree_breakpoint
|
||||
if {$tcl_platform(platform)!="windows"} {
|
||||
do_ioerr_test ioerr-7 -tclprep {
|
||||
db close
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
# special feature is used to see what happens in the library if a malloc
|
||||
# were to really fail due to an out-of-memory situation.
|
||||
#
|
||||
# $Id: malloc.test,v 1.35 2006/10/04 11:55:50 drh Exp $
|
||||
# $Id: malloc.test,v 1.36 2006/10/18 23:26:39 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -229,7 +229,10 @@ do_malloc_test 5 -sqlbody {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE TABLE t2(x,y);
|
||||
CREATE TRIGGER r1 AFTER INSERT ON t1 BEGIN
|
||||
INSERT INTO t2(x,y) VALUES(new.rowid,1);
|
||||
INSERT INTO t2(x,y) VALUES(new.rowid,1);
|
||||
UPDATE t2 SET y=y+1 WHERE x=new.rowid;
|
||||
SELECT 123;
|
||||
DELETE FROM t2 WHERE x=new.rowid;
|
||||
END;
|
||||
INSERT INTO t1(a,b) VALUES(2,3);
|
||||
COMMIT;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# This file implements tests for miscellanous features that were
|
||||
# left out of other test files.
|
||||
#
|
||||
# $Id: misc5.test,v 1.15 2006/08/12 12:33:15 drh Exp $
|
||||
# $Id: misc5.test,v 1.16 2007/01/03 23:37:29 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -573,7 +573,7 @@ do_test misc5-7.1 {
|
||||
|
||||
# Check the MISUSE return from sqlitee3_busy_timeout
|
||||
#
|
||||
do_test misc5-8.1 {
|
||||
do_test misc5-8.1-misuse {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
db close
|
||||
sqlite3_busy_timeout $DB 1000
|
||||
|
||||
+156
-16
@@ -12,7 +12,7 @@
|
||||
#
|
||||
# This file implements tests for the PRAGMA command.
|
||||
#
|
||||
# $Id: pragma.test,v 1.44 2006/08/14 14:23:43 drh Exp $
|
||||
# $Id: pragma.test,v 1.51 2007/01/27 14:26:07 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -42,7 +42,8 @@ ifcapable !pragma {
|
||||
# that the "all.test" script does.
|
||||
#
|
||||
db close
|
||||
file delete test.db
|
||||
file delete test.db test.db-journal
|
||||
file delete test3.db test3.db-journal
|
||||
sqlite3 db test.db; set DB [sqlite3_connection_pointer db]
|
||||
|
||||
ifcapable pager_pragmas {
|
||||
@@ -258,12 +259,143 @@ if {![sqlite3 -has-codec] && $sqlite_options(integrityck)} {
|
||||
btree_close $db
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {{rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.3 {
|
||||
execsql {PRAGMA integrity_check=1}
|
||||
} {{rowid 1 missing from index i2}}
|
||||
do_test pragma-3.4 {
|
||||
execsql {
|
||||
ATTACH DATABASE 'test.db' AS t2;
|
||||
PRAGMA integrity_check
|
||||
}
|
||||
} {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.5 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=3
|
||||
}
|
||||
} {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2}}
|
||||
do_test pragma-3.6 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=xyz
|
||||
}
|
||||
} {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.7 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=0
|
||||
}
|
||||
} {{rowid 1 missing from index i2} {wrong # of entries in index i2} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
|
||||
# Add additional corruption by appending unused pages to the end of
|
||||
# the database file testerr.db
|
||||
#
|
||||
do_test pragma-3.8 {
|
||||
execsql {DETACH t2}
|
||||
file delete -force testerr.db testerr.db-journal
|
||||
set out [open testerr.db w]
|
||||
fconfigure $out -translation binary
|
||||
set in [open test.db r]
|
||||
fconfigure $in -translation binary
|
||||
puts -nonewline $out [read $in]
|
||||
seek $in 0
|
||||
puts -nonewline $out [read $in]
|
||||
close $in
|
||||
close $out
|
||||
execsql {REINDEX t2}
|
||||
execsql {PRAGMA integrity_check}
|
||||
} {ok}
|
||||
do_test pragma-3.9 {
|
||||
execsql {
|
||||
ATTACH 'testerr.db' AS t2;
|
||||
PRAGMA integrity_check
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.10 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=1
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used}}
|
||||
do_test pragma-3.11 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=5
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.12 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=4
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2}}
|
||||
do_test pragma-3.13 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=3
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used}}
|
||||
do_test pragma-3.14 {
|
||||
execsql {
|
||||
PRAGMA integrity_check(2)
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used}}
|
||||
do_test pragma-3.15 {
|
||||
execsql {
|
||||
ATTACH 'testerr.db' AS t3;
|
||||
PRAGMA integrity_check
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2}}
|
||||
do_test pragma-3.16 {
|
||||
execsql {
|
||||
PRAGMA integrity_check(9)
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2}}
|
||||
do_test pragma-3.17 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=7
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2} {wrong # of entries in index i2} {*** in database t3 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used}}
|
||||
do_test pragma-3.18 {
|
||||
execsql {
|
||||
PRAGMA integrity_check=4
|
||||
}
|
||||
} {{*** in database t2 ***
|
||||
Page 4 is never used
|
||||
Page 5 is never used
|
||||
Page 6 is never used} {rowid 1 missing from index i2}}
|
||||
}
|
||||
do_test pragma-3.3 {
|
||||
execsql {
|
||||
DROP INDEX i2;
|
||||
}
|
||||
} {}
|
||||
do_test pragma-3.99 {
|
||||
catchsql {DETACH t3}
|
||||
catchsql {DETACH t2}
|
||||
file delete -force testerr.db testerr.db-journal
|
||||
catchsql {DROP INDEX i2}
|
||||
} {0 {}}
|
||||
|
||||
# Test modifying the cache_size of an attached database.
|
||||
ifcapable pager_pragmas {
|
||||
@@ -351,12 +483,20 @@ do_test pragma-6.2 {
|
||||
pragma table_info(t2)
|
||||
}
|
||||
} {0 a {} 0 {} 0 1 b {} 0 {} 0 2 c {} 0 {} 0}
|
||||
db nullvalue <<NULL>>
|
||||
do_test pragma-6.2.2 {
|
||||
execsql {
|
||||
CREATE TABLE t5(a TEXT DEFAULT CURRENT_TIMESTAMP, b DEFAULT (5+3));
|
||||
CREATE TABLE t5(
|
||||
a TEXT DEFAULT CURRENT_TIMESTAMP,
|
||||
b DEFAULT (5+3),
|
||||
c TEXT,
|
||||
d INTEGER DEFAULT NULL,
|
||||
e TEXT DEFAULT ''
|
||||
);
|
||||
PRAGMA table_info(t5);
|
||||
}
|
||||
} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0}
|
||||
} {0 a TEXT 0 CURRENT_TIMESTAMP 0 1 b {} 0 5+3 0 2 c TEXT 0 <<NULL>> 0 3 d INTEGER 0 NULL 0 4 e TEXT 0 '' 0}
|
||||
db nullvalue {}
|
||||
ifcapable {foreignkey} {
|
||||
do_test pragma-6.3 {
|
||||
execsql {
|
||||
@@ -438,10 +578,10 @@ do_test pragma-8.1.1 {
|
||||
}
|
||||
} {}
|
||||
do_test pragma-8.1.2 {
|
||||
execsql {
|
||||
execsql2 {
|
||||
PRAGMA schema_version;
|
||||
}
|
||||
} 105
|
||||
} {schema_version 105}
|
||||
do_test pragma-8.1.3 {
|
||||
execsql {
|
||||
PRAGMA schema_version = 106;
|
||||
@@ -540,20 +680,20 @@ do_test pragma-8.1.18 {
|
||||
# Now test that the user-version can be read and written (and that we aren't
|
||||
# accidentally manipulating the schema-version instead).
|
||||
do_test pragma-8.2.1 {
|
||||
execsql {
|
||||
execsql2 {
|
||||
PRAGMA user_version;
|
||||
}
|
||||
} {0}
|
||||
} {user_version 0}
|
||||
do_test pragma-8.2.2 {
|
||||
execsql {
|
||||
PRAGMA user_version = 2;
|
||||
}
|
||||
} {}
|
||||
do_test pragma-8.2.3.1 {
|
||||
execsql {
|
||||
execsql2 {
|
||||
PRAGMA user_version;
|
||||
}
|
||||
} {2}
|
||||
} {user_version 2}
|
||||
do_test pragma-8.2.3.2 {
|
||||
db close
|
||||
sqlite3 db test.db
|
||||
@@ -686,7 +826,7 @@ do_test pragma-9.6 {
|
||||
execsql {
|
||||
PRAGMA temp_store_directory;
|
||||
}
|
||||
} [pwd]
|
||||
} [list [pwd]]
|
||||
do_test pragma-9.7 {
|
||||
catchsql {
|
||||
PRAGMA temp_store_directory='/NON/EXISTENT/PATH/FOOBAR';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: quick.test,v 1.45 2006/06/23 08:05:38 danielk1977 Exp $
|
||||
# $Id: quick.test,v 1.47 2006/11/23 21:09:11 drh Exp $
|
||||
|
||||
proc lshift {lvar} {
|
||||
upvar $lvar l
|
||||
@@ -50,6 +50,7 @@ set EXCLUDE {
|
||||
memleak.test
|
||||
misuse.test
|
||||
quick.test
|
||||
speed1.test
|
||||
|
||||
autovacuum_crash.test
|
||||
btree8.test
|
||||
@@ -63,9 +64,17 @@ if {[sqlite3 -has-codec]} {
|
||||
# conflict.test
|
||||
}
|
||||
|
||||
|
||||
# Files to include in the test. If this list is empty then everything
|
||||
# that is not in the EXCLUDE list is run.
|
||||
#
|
||||
set INCLUDE {
|
||||
}
|
||||
|
||||
foreach testfile [lsort -dictionary [glob $testdir/*.test]] {
|
||||
set tail [file tail $testfile]
|
||||
if {[lsearch -exact $EXCLUDE $tail]>=0} continue
|
||||
if {[llength $INCLUDE]>0 && [lsearch -exact $INCLUDE $tail]<0} continue
|
||||
source $testfile
|
||||
catch {db close}
|
||||
if {$sqlite_open_file_count>0} {
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
# 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 file tests the various conditions under which an SQLITE_SCHEMA
|
||||
# error should be returned. This is a copy of schema.test that
|
||||
# has been altered to use sqlite3_prepare_v2 instead of sqlite3_prepare
|
||||
#
|
||||
# $Id: schema2.test,v 1.1 2006/11/09 00:24:55 drh Exp $
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# When any of the following types of SQL statements or actions are
|
||||
# executed, all pre-compiled statements are invalidated. An attempt
|
||||
# to execute an invalidated statement always returns SQLITE_SCHEMA.
|
||||
#
|
||||
# CREATE/DROP TABLE...................................schema2-1.*
|
||||
# CREATE/DROP VIEW....................................schema2-2.*
|
||||
# CREATE/DROP TRIGGER.................................schema2-3.*
|
||||
# CREATE/DROP INDEX...................................schema2-4.*
|
||||
# DETACH..............................................schema2-5.*
|
||||
# Deleting a user-function............................schema2-6.*
|
||||
# Deleting a collation sequence.......................schema2-7.*
|
||||
# Setting or changing the authorization function......schema2-8.*
|
||||
#
|
||||
# Test cases schema2-9.* and schema2-10.* test some specific bugs
|
||||
# that came up during development.
|
||||
#
|
||||
# Test cases schema2-11.* test that it is impossible to delete or
|
||||
# change a collation sequence or user-function while SQL statements
|
||||
# are executing. Adding new collations or functions is allowed.
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test schema2-1.1 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-1.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-1.3 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
DROP TABLE abc;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-1.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
|
||||
ifcapable view {
|
||||
do_test schema2-2.1 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
CREATE VIEW v1 AS SELECT * FROM sqlite_master;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-2.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-2.3 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
DROP VIEW v1;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-2.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
}
|
||||
|
||||
ifcapable trigger {
|
||||
do_test schema2-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
CREATE TRIGGER abc_trig AFTER INSERT ON abc BEGIN
|
||||
SELECT 1, 2, 3;
|
||||
END;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-3.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-3.3 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
DROP TRIGGER abc_trig;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-3.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
}
|
||||
|
||||
do_test schema2-4.1 {
|
||||
catchsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
CREATE INDEX abc_index ON abc(a);
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-4.2 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-4.3 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
execsql {
|
||||
DROP INDEX abc_index;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-4.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Tests 5.1 to 5.4 check that prepared statements are invalidated when
|
||||
# a database is DETACHed (but not when one is ATTACHed).
|
||||
#
|
||||
do_test schema2-5.1 {
|
||||
set sql {SELECT * FROM abc;}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
execsql {
|
||||
ATTACH 'test2.db' AS aux;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-5.2 {
|
||||
sqlite3_reset $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-5.3 {
|
||||
execsql {
|
||||
DETACH aux;
|
||||
}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-5.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Tests 6.* check that prepared statements are invalidated when
|
||||
# a user-function is deleted (but not when one is added).
|
||||
do_test schema2-6.1 {
|
||||
set sql {SELECT * FROM abc;}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
db function hello_function {}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-6.2 {
|
||||
sqlite3_reset $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-6.3 {
|
||||
sqlite_delete_function $::DB hello_function
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-6.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Tests 7.* check that prepared statements are invalidated when
|
||||
# a collation sequence is deleted (but not when one is added).
|
||||
#
|
||||
ifcapable utf16 {
|
||||
do_test schema2-7.1 {
|
||||
set sql {SELECT * FROM abc;}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
add_test_collate $::DB 1 1 1
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-7.2 {
|
||||
sqlite3_reset $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-7.3 {
|
||||
add_test_collate $::DB 0 0 0
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_DONE}
|
||||
do_test schema2-7.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Tests 8.1 and 8.2 check that prepared statements are invalidated when
|
||||
# the authorization function is set.
|
||||
#
|
||||
ifcapable auth {
|
||||
do_test schema2-8.1 {
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB {SELECT * FROM sqlite_master} -1 TAIL]
|
||||
db auth {}
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-8.3 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# schema2-9.1: Test that if a table is dropped by one database connection,
|
||||
# other database connections are aware of the schema change.
|
||||
# schema2-9.2: Test that if a view is dropped by one database connection,
|
||||
# other database connections are aware of the schema change.
|
||||
#
|
||||
do_test schema2-9.1 {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
DROP TABLE abc;
|
||||
} db2
|
||||
db2 close
|
||||
catchsql {
|
||||
SELECT * FROM abc;
|
||||
}
|
||||
} {1 {no such table: abc}}
|
||||
execsql {
|
||||
CREATE TABLE abc(a, b, c);
|
||||
}
|
||||
ifcapable view {
|
||||
do_test schema2-9.2 {
|
||||
execsql {
|
||||
CREATE VIEW abcview AS SELECT * FROM abc;
|
||||
}
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
DROP VIEW abcview;
|
||||
} db2
|
||||
db2 close
|
||||
catchsql {
|
||||
SELECT * FROM abcview;
|
||||
}
|
||||
} {1 {no such table: abcview}}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Test that if a CREATE TABLE statement fails because there are other
|
||||
# btree cursors open on the same database file it does not corrupt
|
||||
# the sqlite_master table.
|
||||
#
|
||||
do_test schema2-10.1 {
|
||||
execsql {
|
||||
INSERT INTO abc VALUES(1, 2, 3);
|
||||
}
|
||||
set sql {SELECT * FROM abc}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-10.2 {
|
||||
catchsql {
|
||||
CREATE TABLE t2(a, b, c);
|
||||
}
|
||||
} {1 {database table is locked}}
|
||||
do_test schema2-10.3 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-10.4 {
|
||||
sqlite3 db2 test.db
|
||||
execsql {
|
||||
SELECT * FROM abc
|
||||
} db2
|
||||
} {1 2 3}
|
||||
do_test schema2-10.5 {
|
||||
db2 close
|
||||
} {}
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Attempting to delete or replace a user-function or collation sequence
|
||||
# while there are active statements returns an SQLITE_BUSY error.
|
||||
#
|
||||
# schema2-11.1 - 11.4: User function.
|
||||
# schema2-11.5 - 11.8: Collation sequence.
|
||||
#
|
||||
do_test schema2-11.1 {
|
||||
db function tstfunc {}
|
||||
set sql {SELECT * FROM abc}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-11.2 {
|
||||
sqlite_delete_function $::DB tstfunc
|
||||
} {SQLITE_BUSY}
|
||||
do_test schema2-11.3 {
|
||||
set rc [catch {
|
||||
db function tstfunc {}
|
||||
} msg]
|
||||
list $rc $msg
|
||||
} {1 {Unable to delete/modify user-function due to active statements}}
|
||||
do_test schema2-11.4 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
do_test schema2-11.5 {
|
||||
db collate tstcollate {}
|
||||
set sql {SELECT * FROM abc}
|
||||
set ::STMT [sqlite3_prepare_v2 $::DB $sql -1 TAIL]
|
||||
sqlite3_step $::STMT
|
||||
} {SQLITE_ROW}
|
||||
do_test schema2-11.6 {
|
||||
sqlite_delete_collation $::DB tstcollate
|
||||
} {SQLITE_BUSY}
|
||||
do_test schema2-11.7 {
|
||||
set rc [catch {
|
||||
db collate tstcollate {}
|
||||
} msg]
|
||||
list $rc $msg
|
||||
} {1 {Unable to delete/modify collation sequence due to active statements}}
|
||||
do_test schema2-11.8 {
|
||||
sqlite3_finalize $::STMT
|
||||
} {SQLITE_OK}
|
||||
|
||||
finish_test
|
||||
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing SELECT statements that contain
|
||||
# subqueries in their FROM clause.
|
||||
#
|
||||
# $Id: select6.test,v 1.24 2006/06/11 23:41:56 drh Exp $
|
||||
# $Id: select6.test,v 1.26 2006/11/30 13:06:00 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# focus of this file is testing compute SELECT statements and nested
|
||||
# views.
|
||||
#
|
||||
# $Id: select7.test,v 1.7 2005/03/29 03:11:00 danielk1977 Exp $
|
||||
# $Id: select7.test,v 1.8 2006/10/13 15:34:17 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
@@ -71,5 +71,39 @@ ifcapable subquery {
|
||||
}
|
||||
} [list 0 [execsql {SELECT * FROM sqlite_master ORDER BY name}]]
|
||||
}
|
||||
finish_test
|
||||
|
||||
# Ticket #2018 - Make sure names are resolved correctly on all
|
||||
# SELECT statements of a compound subquery.
|
||||
#
|
||||
ifcapable {subquery && compound} {
|
||||
do_test select7-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE IF NOT EXISTS photo(pk integer primary key, x);
|
||||
CREATE TABLE IF NOT EXISTS tag(pk integer primary key, fk int, name);
|
||||
|
||||
SELECT P.pk from PHOTO P WHERE NOT EXISTS (
|
||||
SELECT T2.pk from TAG T2 WHERE T2.fk = P.pk
|
||||
EXCEPT
|
||||
SELECT T3.pk from TAG T3 WHERE T3.fk = P.pk AND T3.name LIKE '%foo%'
|
||||
);
|
||||
}
|
||||
} {}
|
||||
do_test select7-4.2 {
|
||||
execsql {
|
||||
INSERT INTO photo VALUES(1,1);
|
||||
INSERT INTO photo VALUES(2,2);
|
||||
INSERT INTO photo VALUES(3,3);
|
||||
INSERT INTO tag VALUES(11,1,'one');
|
||||
INSERT INTO tag VALUES(12,1,'two');
|
||||
INSERT INTO tag VALUES(21,1,'one-b');
|
||||
SELECT P.pk from PHOTO P WHERE NOT EXISTS (
|
||||
SELECT T2.pk from TAG T2 WHERE T2.fk = P.pk
|
||||
EXCEPT
|
||||
SELECT T3.pk from TAG T3 WHERE T3.fk = P.pk AND T3.name LIKE '%foo%'
|
||||
);
|
||||
}
|
||||
} {2 3}
|
||||
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
# 2006 November 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 script is measuring executing speed.
|
||||
#
|
||||
# $Id: speed1.test,v 1.2 2006/11/30 13:06:00 drh Exp $
|
||||
#
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
set sqlout [open speed1.txt w]
|
||||
proc tracesql {sql} {
|
||||
puts $::sqlout $sql\;
|
||||
}
|
||||
db trace tracesql
|
||||
|
||||
# The number_name procedure below converts its argment (an integer)
|
||||
# into a string which is the English-language name for that number.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# puts [number_name 123] -> "one hundred twenty three"
|
||||
#
|
||||
set ones {zero one two three four five six seven eight nine
|
||||
ten eleven twelve thirteen fourteen fifteen sixteen seventeen
|
||||
eighteen nineteen}
|
||||
set tens {{} ten twenty thirty forty fifty sixty seventy eighty ninety}
|
||||
proc number_name {n} {
|
||||
if {$n>=1000} {
|
||||
set txt "[number_name [expr {$n/1000}]] thousand"
|
||||
set n [expr {$n%1000}]
|
||||
} else {
|
||||
set txt {}
|
||||
}
|
||||
if {$n>=100} {
|
||||
append txt " [lindex $::ones [expr {$n/100}]] hundred"
|
||||
set n [expr {$n%100}]
|
||||
}
|
||||
if {$n>=20} {
|
||||
append txt " [lindex $::tens [expr {$n/10}]]"
|
||||
set n [expr {$n%10}]
|
||||
}
|
||||
if {$n>0} {
|
||||
append txt " [lindex $::ones $n]"
|
||||
}
|
||||
set txt [string trim $txt]
|
||||
if {$txt==""} {set txt zero}
|
||||
return $txt
|
||||
}
|
||||
|
||||
# Create a database schema.
|
||||
#
|
||||
do_test speed1-1.0 {
|
||||
execsql {
|
||||
pragma page_size=4096;
|
||||
CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
|
||||
CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT);
|
||||
CREATE INDEX i2a ON t2(a);
|
||||
CREATE INDEX i2b ON t2(b);
|
||||
SELECT name FROM sqlite_master ORDER BY 1;
|
||||
}
|
||||
} {i2a i2b t1 t2}
|
||||
|
||||
|
||||
# 50000 INSERTs on an unindexed table
|
||||
#
|
||||
set sql {}
|
||||
for {set i 1} {$i<=50000} {incr i} {
|
||||
set r [expr {int(rand()*500000)}]
|
||||
append sql "INSERT INTO t1 VALUES($i,$r,'[number_name $r]');\n"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-insert1 50000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 50000 INSERTs on an indexed table
|
||||
#
|
||||
set sql {}
|
||||
for {set i 1} {$i<=50000} {incr i} {
|
||||
set r [expr {int(rand()*500000)}]
|
||||
append sql "INSERT INTO t2 VALUES($i,$r,'[number_name $r]');\n"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-insert2 50000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
|
||||
|
||||
# 50 SELECTs on an integer comparison. There is no index so
|
||||
# a full table scan is required.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 0} {$i<50} {incr i} {
|
||||
set lwr [expr {$i*100}]
|
||||
set upr [expr {($i+10)*100}]
|
||||
append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select1 [expr {50*50000}] row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 50 SELECTs on an LIKE comparison. There is no index so a full
|
||||
# table scan is required.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 0} {$i<50} {incr i} {
|
||||
append sql \
|
||||
"SELECT count(*), avg(b) FROM t1 WHERE c LIKE '%[number_name $i]%';"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select2 [expr {50*50000}] row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# Create indices
|
||||
#
|
||||
db eval BEGIN
|
||||
speed_trial speed1-createidx 150000 row {
|
||||
CREATE INDEX i1a ON t1(a);
|
||||
CREATE INDEX i1b ON t1(b);
|
||||
CREATE INDEX i1c ON t1(c);
|
||||
}
|
||||
db eval COMMIT
|
||||
|
||||
# 5000 SELECTs on an integer comparison where the integer is
|
||||
# indexed.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 0} {$i<5000} {incr i} {
|
||||
set lwr [expr {$i*100}]
|
||||
set upr [expr {($i+10)*100}]
|
||||
append sql "SELECT count(*), avg(b) FROM t1 WHERE b>=$lwr AND b<$upr;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select3 5000 stmt $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 100000 random SELECTs against rowid.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 1} {$i<=100000} {incr i} {
|
||||
set id [expr {int(rand()*50000)+1}]
|
||||
append sql "SELECT c FROM t1 WHERE rowid=$id;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select4 100000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 100000 random SELECTs against a unique indexed column.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 1} {$i<=100000} {incr i} {
|
||||
set id [expr {int(rand()*50000)+1}]
|
||||
append sql "SELECT c FROM t1 WHERE a=$id;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select5 100000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 50000 random SELECTs against an indexed column text column
|
||||
#
|
||||
set sql {}
|
||||
db eval {SELECT c FROM t1 ORDER BY random() LIMIT 50000} {
|
||||
append sql "SELECT c FROM t1 WHERE c='$c';"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-select6 50000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
|
||||
# Vacuum
|
||||
speed_trial speed1-vacuum 100000 row VACUUM
|
||||
|
||||
# 5000 updates of ranges where the field being compared is indexed.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 0} {$i<5000} {incr i} {
|
||||
set lwr [expr {$i*2}]
|
||||
set upr [expr {($i+1)*2}]
|
||||
append sql "UPDATE t1 SET b=b*2 WHERE a>=$lwr AND a<$upr;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-update1 5000 stmt $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 50000 single-row updates. An index is used to find the row quickly.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 0} {$i<50000} {incr i} {
|
||||
set r [expr {int(rand()*500000)}]
|
||||
append sql "UPDATE t1 SET b=$r WHERE a=$i;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-update2 50000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# 1 big text update that touches every row in the table.
|
||||
#
|
||||
speed_trial speed1-update3 50000 row {
|
||||
UPDATE t1 SET c=a;
|
||||
}
|
||||
|
||||
# Many individual text updates. Each row in the table is
|
||||
# touched through an index.
|
||||
#
|
||||
set sql {}
|
||||
for {set i 1} {$i<=50000} {incr i} {
|
||||
set r [expr {int(rand()*500000)}]
|
||||
append sql "UPDATE t1 SET c='[number_name $r]' WHERE a=$i;"
|
||||
}
|
||||
db eval BEGIN
|
||||
speed_trial speed1-update4 50000 row $sql
|
||||
db eval COMMIT
|
||||
|
||||
# Delete all content in a table.
|
||||
#
|
||||
speed_trial speed1-delete1 50000 row {DELETE FROM t1}
|
||||
|
||||
# Copy one table into another
|
||||
#
|
||||
speed_trial speed1-copy1 50000 row {INSERT INTO t1 SELECT * FROM t2}
|
||||
|
||||
# Delete all content in a table, one row at a time.
|
||||
#
|
||||
speed_trial speed1-delete2 50000 row {DELETE FROM t1 WHERE 1}
|
||||
|
||||
# Refill the table yet again
|
||||
#
|
||||
speed_trial speed1-copy2 50000 row {INSERT INTO t1 SELECT * FROM t2}
|
||||
|
||||
# Drop the table and recreate it without its indices.
|
||||
#
|
||||
db eval BEGIN
|
||||
speed_trial speed1-drop1 50000 row {
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1(a INTEGER, b INTEGER, c TEXT);
|
||||
}
|
||||
db eval COMMIT
|
||||
|
||||
# Refill the table yet again. This copy should be faster because
|
||||
# there are no indices to deal with.
|
||||
#
|
||||
speed_trial speed1-copy3 50000 row {INSERT INTO t1 SELECT * FROM t2}
|
||||
|
||||
# Select 20000 rows from the table at random.
|
||||
#
|
||||
speed_trial speed1-random1 50000 row {
|
||||
SELECT rowid FROM t1 ORDER BY random() LIMIT 20000
|
||||
}
|
||||
|
||||
# Delete 20000 random rows from the table.
|
||||
#
|
||||
speed_trial speed1-random-del1 20000 row {
|
||||
DELETE FROM t1 WHERE rowid IN
|
||||
(SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
|
||||
}
|
||||
do_test speed1-1.1 {
|
||||
db one {SELECT count(*) FROM t1}
|
||||
} 30000
|
||||
|
||||
|
||||
# Delete 20000 more rows at random from the table.
|
||||
#
|
||||
speed_trial speed1-random-del2 20000 row {
|
||||
DELETE FROM t1 WHERE rowid IN
|
||||
(SELECT rowid FROM t1 ORDER BY random() LIMIT 20000)
|
||||
}
|
||||
do_test speed1-1.2 {
|
||||
db one {SELECT count(*) FROM t1}
|
||||
} 10000
|
||||
|
||||
finish_test
|
||||
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing the sqlite_exec_printf() and
|
||||
# sqlite_get_table_printf() APIs.
|
||||
#
|
||||
# $Id: tableapi.test,v 1.11 2006/06/27 20:39:05 drh Exp $
|
||||
# $Id: tableapi.test,v 1.12 2007/01/05 00:14:28 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -208,7 +208,7 @@ do_test tableapi-5.2 {
|
||||
|
||||
do_test tableapi-6.1 {
|
||||
sqlite3_get_table_printf $::dbx {PRAGMA user_version} {}
|
||||
} {0 1 1 {} 0}
|
||||
} {0 1 1 user_version 0}
|
||||
|
||||
do_test tableapi-99.0 {
|
||||
sqlite3_close $::dbx
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# This file implements some common TCL routines used for regression
|
||||
# testing the SQLite library
|
||||
#
|
||||
# $Id: tester.tcl,v 1.69 2006/10/04 11:55:50 drh Exp $
|
||||
# $Id: tester.tcl,v 1.72 2007/01/04 14:58:14 drh Exp $
|
||||
|
||||
# Make sure tclsqlite3 was compiled correctly. Abort now with an
|
||||
# error message if not.
|
||||
@@ -78,6 +78,9 @@ set nTest 0
|
||||
set skip_test 0
|
||||
set failList {}
|
||||
set maxErr 1000
|
||||
if {![info exists speedTest]} {
|
||||
set speedTest 0
|
||||
}
|
||||
|
||||
# Invoke the do_test procedure to run a single test
|
||||
#
|
||||
@@ -118,6 +121,21 @@ proc do_test {name cmd expected} {
|
||||
}
|
||||
}
|
||||
|
||||
# Run an SQL script.
|
||||
# Return the number of microseconds per statement.
|
||||
#
|
||||
proc speed_trial {name numstmt units sql} {
|
||||
puts -nonewline [format {%-20.20s } $name...]
|
||||
flush stdout
|
||||
set speed [time {sqlite3_exec_nr db $sql}]
|
||||
set tm [lindex $speed 0]
|
||||
set per [expr {$tm/(1.0*$numstmt)}]
|
||||
set rate [expr {1000000.0*$numstmt/$tm}]
|
||||
set u1 us/$units
|
||||
set u2 $units/s
|
||||
puts [format {%20.3f %-7s %20.5f %s} $per $u1 $rate $u2]
|
||||
}
|
||||
|
||||
# The procedure uses the special "sqlite_malloc_stat" command
|
||||
# (which is only available if SQLite is compiled with -DSQLITE_DEBUG=1)
|
||||
# to see how many malloc()s have not been free()ed. The number
|
||||
@@ -334,10 +352,13 @@ proc do_ioerr_test {testname args} {
|
||||
set ::ioerropts(-start) 1
|
||||
set ::ioerropts(-cksum) 0
|
||||
set ::ioerropts(-erc) 0
|
||||
set ::ioerropts(-count) 100000000
|
||||
array set ::ioerropts $args
|
||||
|
||||
set ::go 1
|
||||
for {set n $::ioerropts(-start)} {$::go} {incr n} {
|
||||
incr ::ioerropts(-count) -1
|
||||
if {$::ioerropts(-count)<0} break
|
||||
|
||||
# Skip this IO error if it was specified with the "-exclude" option.
|
||||
if {[info exists ::ioerropts(-exclude)]} {
|
||||
|
||||
@@ -39,12 +39,13 @@ volatile int all_stop = 0;
|
||||
** global variable to stop all other activity. Print the error message
|
||||
** or print OK if the string "ok" is seen.
|
||||
*/
|
||||
int check_callback(void *notUsed, int argc, char **argv, char **notUsed2){
|
||||
int check_callback(void *pid, int argc, char **argv, char **notUsed2){
|
||||
int id = (int)pid;
|
||||
if( strcmp(argv[0],"ok") ){
|
||||
all_stop = 1;
|
||||
fprintf(stderr,"pid=%d. %s\n", getpid(), argv[0]);
|
||||
fprintf(stderr,"id: %s\n", id, argv[0]);
|
||||
}else{
|
||||
/* fprintf(stderr,"pid=%d. OK\n", getpid()); */
|
||||
/* fprintf(stderr,"%d: OK\n", id); */
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -53,13 +54,13 @@ int check_callback(void *notUsed, int argc, char **argv, char **notUsed2){
|
||||
** Do an integrity check on the database. If the first integrity check
|
||||
** fails, try it a second time.
|
||||
*/
|
||||
int integrity_check(sqlite *db){
|
||||
int integrity_check(sqlite *db, int id){
|
||||
int rc;
|
||||
if( all_stop ) return 0;
|
||||
/* fprintf(stderr,"pid=%d: CHECK\n", getpid()); */
|
||||
/* fprintf(stderr,"%d: CHECK\n", id); */
|
||||
rc = sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
|
||||
if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){
|
||||
fprintf(stderr,"pid=%d, Integrity check returns %d\n", getpid(), rc);
|
||||
fprintf(stderr,"%d, Integrity check returns %d\n", id, rc);
|
||||
}
|
||||
if( all_stop ){
|
||||
sqlite3_exec(db, "pragma integrity_check", check_callback, 0, 0);
|
||||
@@ -70,21 +71,24 @@ int integrity_check(sqlite *db){
|
||||
/*
|
||||
** This is the worker thread
|
||||
*/
|
||||
void *worker(void *notUsed){
|
||||
void *worker(void *workerArg){
|
||||
sqlite *db;
|
||||
int id = (int)workerArg;
|
||||
int rc;
|
||||
int cnt = 0;
|
||||
fprintf(stderr, "Starting worker %d\n", id);
|
||||
while( !all_stop && cnt++<10000 ){
|
||||
if( cnt%1000==0 ) printf("pid=%d: %d\n", getpid(), cnt);
|
||||
if( cnt%100==0 ) printf("%d: %d\n", id, cnt);
|
||||
while( (sqlite3_open(DB_FILE, &db))!=SQLITE_OK ) sched_yield();
|
||||
sqlite3_exec(db, "PRAGMA synchronous=OFF", 0, 0, 0);
|
||||
integrity_check(db);
|
||||
/* integrity_check(db, id); */
|
||||
if( all_stop ){ sqlite3_close(db); break; }
|
||||
/* fprintf(stderr, "pid=%d: BEGIN\n", getpid()); */
|
||||
/* fprintf(stderr, "%d: BEGIN\n", id); */
|
||||
rc = sqlite3_exec(db, "INSERT INTO t1 VALUES('bogus data')", 0, 0, 0);
|
||||
/* fprintf(stderr, "pid=%d: END rc=%d\n", getpid(), rc); */
|
||||
/* fprintf(stderr, "%d: END rc=%d\n", id, rc); */
|
||||
sqlite3_close(db);
|
||||
}
|
||||
fprintf(stderr, "Worker %d finished\n", id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -100,7 +104,7 @@ int main(int argc, char **argv){
|
||||
char *zJournal = sqlite3_mprintf("%s-journal", DB_FILE);
|
||||
unlink(DB_FILE);
|
||||
unlink(zJournal);
|
||||
free(zJournal);
|
||||
sqlite3_free(zJournal);
|
||||
}
|
||||
sqlite3_open(DB_FILE, &db);
|
||||
if( db==0 ){
|
||||
@@ -114,7 +118,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
sqlite3_close(db);
|
||||
for(i=0; i<sizeof(aThread)/sizeof(aThread[0]); i++){
|
||||
pthread_create(&aThread[i], 0, worker, 0);
|
||||
pthread_create(&aThread[i], 0, worker, (void*)i);
|
||||
}
|
||||
for(i=0; i<sizeof(aThread)/sizeof(aThread[i]); i++){
|
||||
pthread_join(aThread[i], 0);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# 2007 January 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library.
|
||||
#
|
||||
# This file implements tests to verify that ticket #2141 has been
|
||||
# fixed.
|
||||
#
|
||||
#
|
||||
# $Id: tkt2141.test,v 1.1 2007/01/04 01:20:29 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
do_test tkt2141-1.1 {
|
||||
execsql {
|
||||
CREATE TABLE tab1 (t1_id integer PRIMARY KEY, t1_desc);
|
||||
INSERT INTO tab1 VALUES(1,'rec 1 tab 1');
|
||||
CREATE TABLE tab2 (t2_id integer PRIMARY KEY, t2_id_t1, t2_desc);
|
||||
INSERT INTO tab2 VALUES(1,1,'rec 1 tab 2');
|
||||
CREATE TABLE tab3 (t3_id integer PRIMARY KEY, t3_id_t2, t3_desc);
|
||||
INSERT INTO tab3 VALUES(1,1,'aa');
|
||||
SELECT *
|
||||
FROM tab1 t1 LEFT JOIN tab2 t2 ON t1.t1_id = t2.t2_id_t1
|
||||
WHERE t2.t2_id IN
|
||||
(SELECT t2_id FROM tab2, tab3 ON t2_id = t3_id_t2
|
||||
WHERE t3_id IN (1,2) GROUP BY t2_id);
|
||||
}
|
||||
} {1 {rec 1 tab 1} 1 1 {rec 1 tab 2}}
|
||||
do_test tkt2141-1.2 {
|
||||
execsql {
|
||||
SELECT *
|
||||
FROM tab1 t1 LEFT JOIN tab2 t2 ON t1.t1_id = t2.t2_id_t1
|
||||
WHERE t2.t2_id IN
|
||||
(SELECT t2_id FROM tab2, tab3 ON t2_id = t3_id_t2
|
||||
WHERE t3_id IN (1,2));
|
||||
}
|
||||
} {1 {rec 1 tab 1} 1 1 {rec 1 tab 2}}
|
||||
do_test tkt2141-1.3 {
|
||||
execsql {
|
||||
SELECT *
|
||||
FROM tab1 t1 LEFT JOIN tab2 t2
|
||||
WHERE t2.t2_id IN
|
||||
(SELECT t2_id FROM tab2, tab3 ON t2_id = t3_id_t2
|
||||
WHERE t3_id IN (1,2));
|
||||
}
|
||||
} {1 {rec 1 tab 1} 1 1 {rec 1 tab 2}}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,136 @@
|
||||
# 2007 January 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.
|
||||
#
|
||||
# This file implements tests to verify that ticket #2192 has been
|
||||
# fixed.
|
||||
#
|
||||
#
|
||||
# $Id: tkt2192.test,v 1.1 2007/01/26 19:04:00 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
|
||||
do_test tkt2191-1.1 {
|
||||
execsql {
|
||||
-- Raw data (RBS) --------
|
||||
|
||||
create table records (
|
||||
date real,
|
||||
type text,
|
||||
description text,
|
||||
value integer,
|
||||
acc_name text,
|
||||
acc_no text
|
||||
);
|
||||
|
||||
-- Direct Debits ----------------
|
||||
create view direct_debits as
|
||||
select * from records where type = 'D/D';
|
||||
|
||||
create view monthly_direct_debits as
|
||||
select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
|
||||
from direct_debits
|
||||
group by strftime('%Y-%m', date);
|
||||
|
||||
-- Expense Categories ---------------
|
||||
create view energy as
|
||||
select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
|
||||
from direct_debits
|
||||
where description like '%NPOWER%'
|
||||
group by strftime('%Y-%m', date);
|
||||
|
||||
create view phone_internet as
|
||||
select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
|
||||
from direct_debits
|
||||
where description like '%BT DIRECT%'
|
||||
or description like '%SUPANET%'
|
||||
or description like '%ORANGE%'
|
||||
group by strftime('%Y-%m', date);
|
||||
|
||||
create view credit_cards as
|
||||
select strftime('%Y-%m', date) as date, (-1 * sum(value)) as value
|
||||
from direct_debits where description like '%VISA%'
|
||||
group by strftime('%Y-%m', date);
|
||||
|
||||
-- Overview ---------------------
|
||||
|
||||
create view expense_overview as
|
||||
select 'Energy' as expense, date, value from energy
|
||||
union
|
||||
select 'Phone/Internet' as expense, date, value from phone_internet
|
||||
union
|
||||
select 'Credit Card' as expense, date, value from credit_cards;
|
||||
|
||||
create view jan as
|
||||
select 'jan', expense, value from expense_overview
|
||||
where date like '%-01';
|
||||
|
||||
create view nov as
|
||||
select 'nov', expense, value from expense_overview
|
||||
where date like '%-11';
|
||||
|
||||
create view summary as
|
||||
select * from jan join nov on (jan.expense = nov.expense);
|
||||
}
|
||||
} {}
|
||||
do_test tkt2192-1.2 {
|
||||
# set ::sqlite_addop_trace 1
|
||||
execsql {
|
||||
select * from summary;
|
||||
}
|
||||
} {}
|
||||
do_test tkt2192-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE t1(a,b);
|
||||
CREATE VIEW v1 AS
|
||||
SELECT * FROM t1 WHERE b%7=0 UNION SELECT * FROM t1 WHERE b%5=0;
|
||||
INSERT INTO t1 VALUES(1,7);
|
||||
INSERT INTO t1 VALUES(2,10);
|
||||
INSERT INTO t1 VALUES(3,14);
|
||||
INSERT INTO t1 VALUES(4,15);
|
||||
INSERT INTO t1 VALUES(1,16);
|
||||
INSERT INTO t1 VALUES(2,17);
|
||||
INSERT INTO t1 VALUES(3,20);
|
||||
INSERT INTO t1 VALUES(4,21);
|
||||
INSERT INTO t1 VALUES(1,22);
|
||||
INSERT INTO t1 VALUES(2,24);
|
||||
INSERT INTO t1 VALUES(3,25);
|
||||
INSERT INTO t1 VALUES(4,26);
|
||||
INSERT INTO t1 VALUES(1,27);
|
||||
|
||||
SELECT b FROM v1 ORDER BY b;
|
||||
}
|
||||
} {7 10 14 15 20 21 25}
|
||||
do_test tkt2192-2.2 {
|
||||
execsql {
|
||||
SELECT * FROM v1 ORDER BY a, b;
|
||||
}
|
||||
} {1 7 2 10 3 14 3 20 3 25 4 15 4 21}
|
||||
do_test tkt2192-2.3 {
|
||||
execsql {
|
||||
SELECT x.a || '/' || x.b || '/' || y.b
|
||||
FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
|
||||
ORDER BY x.a, x.b, y.b
|
||||
}
|
||||
} {3/14/20 3/14/25 3/20/25 4/15/21}
|
||||
do_test tkt2192-2.4 {
|
||||
execsql {
|
||||
CREATE VIEW v2 AS
|
||||
SELECT x.a || '/' || x.b || '/' || y.b AS z
|
||||
FROM v1 AS x JOIN v1 AS y ON x.a=y.a AND x.b<y.b
|
||||
ORDER BY x.a, x.b, y.b;
|
||||
SELECT * FROM v2;
|
||||
}
|
||||
} {3/14/20 3/14/25 3/20/25 4/15/21}
|
||||
|
||||
finish_test
|
||||
@@ -0,0 +1,30 @@
|
||||
# 2007 Febuary 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 to verify that ticket #2213 has been
|
||||
# fixed.
|
||||
#
|
||||
#
|
||||
# $Id: tkt2213.test,v 1.1 2007/02/05 14:21:48 danielk1977 Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_test tkt2213-1 {
|
||||
sqlite3_create_function db
|
||||
catchsql {
|
||||
SELECT tkt2213func(tkt2213func('abcd'));
|
||||
}
|
||||
} {0 abcd}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -194,7 +194,7 @@ do_test trigger4-7.2 {
|
||||
} {101 1001 102 2002 227 2127 228 2128}
|
||||
|
||||
integrity_check trigger4-99.9
|
||||
|
||||
db close
|
||||
file delete -force trigtest.db trigtest.db-journal
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#***********************************************************************
|
||||
# This file runs all tests.
|
||||
#
|
||||
# $Id: utf16.test,v 1.5 2006/01/09 23:40:26 drh Exp $
|
||||
# $Id: utf16.test,v 1.6 2007/01/04 16:37:04 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -23,7 +23,7 @@ if { [llength $argv]>0 } {
|
||||
set argv [list]
|
||||
} else {
|
||||
set F {
|
||||
alter.test alter2.test alter3.test
|
||||
alter.test alter3.test
|
||||
auth.test bind.test blob.test capi2.test capi3.test collate1.test
|
||||
collate2.test collate3.test collate4.test collate5.test collate6.test
|
||||
conflict.test date.test delete.test expr.test fkey1.test func.test
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is creating and dropping virtual tables.
|
||||
#
|
||||
# $Id: vtab1.test,v 1.38 2006/09/16 21:45:14 drh Exp $
|
||||
# $Id: vtab1.test,v 1.39 2007/01/09 14:01:14 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -96,6 +96,29 @@ do_test vtab1-1.6 {
|
||||
}
|
||||
} {}
|
||||
|
||||
# Ticket #2156. Using the sqlite3_prepare_v2() API, make sure that
|
||||
# a CREATE VIRTUAL TABLE statement can be used multiple times.
|
||||
#
|
||||
do_test vtab1-1.2152.1 {
|
||||
set DB [sqlite3_connection_pointer db]
|
||||
set sql {CREATE VIRTUAL TABLE t2152a USING echo(t2152b)}
|
||||
set STMT [sqlite3_prepare_v2 $DB $sql -1 TAIL]
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ERROR
|
||||
do_test vtab-1.2152.2 {
|
||||
sqlite3_reset $STMT
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_ERROR
|
||||
do_test vtab-1.2152.3 {
|
||||
sqlite3_reset $STMT
|
||||
db eval {CREATE TABLE t2152b(x,y)}
|
||||
sqlite3_step $STMT
|
||||
} SQLITE_DONE
|
||||
do_test vtab-1.2152.4 {
|
||||
sqlite3_finalize $STMT
|
||||
db eval {DROP TABLE t2152a; DROP TABLE t2152b}
|
||||
} {}
|
||||
|
||||
# Test to make sure nothing goes wrong and no memory is leaked if we
|
||||
# select an illegal table-name (i.e a reserved name or the name of a
|
||||
# table that already exists).
|
||||
|
||||
@@ -9,11 +9,19 @@
|
||||
#
|
||||
#***********************************************************************
|
||||
#
|
||||
# $Id: vtab_err.test,v 1.3 2006/08/15 14:21:16 drh Exp $
|
||||
# $Id: vtab_err.test,v 1.4 2007/01/02 18:41:58 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Only run these tests if memory debugging is turned on.
|
||||
#
|
||||
if {[info command sqlite_malloc_stat]==""} {
|
||||
puts "Skipping vtab_err tests: not compiled with -DSQLITE_MEMDEBUG=1"
|
||||
finish_test
|
||||
return
|
||||
}
|
||||
|
||||
ifcapable !vtab {
|
||||
finish_test
|
||||
return
|
||||
|
||||
+225
-8
@@ -11,7 +11,7 @@
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the use of indices in WHERE clases.
|
||||
#
|
||||
# $Id: where.test,v 1.38 2005/11/14 22:29:06 drh Exp $
|
||||
# $Id: where.test,v 1.41 2007/02/06 23:41:34 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -589,22 +589,22 @@ do_test where-6.21 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid, y LIMIT 3;
|
||||
}
|
||||
} {4 9 16 sort}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.22 {
|
||||
cksort {
|
||||
SELECT y FROM t1 ORDER BY rowid, y DESC LIMIT 3;
|
||||
}
|
||||
} {4 9 16 sort}
|
||||
} {4 9 16 nosort}
|
||||
do_test where-6.23 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>4 ORDER BY rowid, w, x LIMIT 3;
|
||||
}
|
||||
} {9 16 25 sort}
|
||||
} {9 16 25 nosort}
|
||||
do_test where-6.24 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>=9 ORDER BY rowid, x DESC, w LIMIT 3;
|
||||
}
|
||||
} {9 16 25 sort}
|
||||
} {9 16 25 nosort}
|
||||
do_test where-6.25 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y>4 AND y<25 ORDER BY rowid;
|
||||
@@ -619,7 +619,7 @@ do_test where-6.27 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<=25 ORDER BY _rowid_, w+y;
|
||||
}
|
||||
} {4 9 16 25 sort}
|
||||
} {4 9 16 25 nosort}
|
||||
|
||||
|
||||
# Tests for reverse-order sorting.
|
||||
@@ -793,7 +793,7 @@ do_test where-7.34 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<25 AND y>4 ORDER BY rowid DESC, y DESC
|
||||
}
|
||||
} {16 9 sort}
|
||||
} {16 9 nosort}
|
||||
do_test where-7.35 {
|
||||
cksort {
|
||||
SELECT y FROM t1 WHERE y<25 AND y>=4 ORDER BY rowid DESC
|
||||
@@ -874,7 +874,6 @@ do_test where-10.4 {
|
||||
# that array.
|
||||
#
|
||||
do_test where-11.1 {
|
||||
btree_breakpoint
|
||||
execsql {
|
||||
CREATE TABLE t99(Dte INT, X INT);
|
||||
DELETE FROM t99 WHERE (Dte = 2451337) OR (Dte = 2451339) OR
|
||||
@@ -902,6 +901,224 @@ btree_breakpoint
|
||||
}
|
||||
} {}
|
||||
|
||||
# Ticket #2116: Make sure sorting by index works well with nn INTEGER PRIMARY
|
||||
# KEY.
|
||||
#
|
||||
do_test where-12.1 {
|
||||
execsql {
|
||||
CREATE TABLE t6(a INTEGER PRIMARY KEY, b TEXT);
|
||||
INSERT INTO t6 VALUES(1,'one');
|
||||
INSERT INTO t6 VALUES(4,'four');
|
||||
CREATE INDEX t6i1 ON t6(b);
|
||||
}
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-12.2 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b, a;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-12.3 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-12.4 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a, b;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-12.5 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-12.6 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b DESC, a DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-12.7 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b DESC, a ASC;
|
||||
}
|
||||
} {1 one 4 four sort}
|
||||
do_test where-12.8 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY b ASC, a DESC;
|
||||
}
|
||||
} {4 four 1 one sort}
|
||||
do_test where-12.9 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a DESC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-12.10 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a DESC, b DESC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-12.11 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a DESC, b ASC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-12.12 {
|
||||
cksort {
|
||||
SELECT * FROM t6 ORDER BY a ASC, b DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-13.1 {
|
||||
execsql {
|
||||
CREATE TABLE t7(a INTEGER PRIMARY KEY, b TEXT);
|
||||
INSERT INTO t7 VALUES(1,'one');
|
||||
INSERT INTO t7 VALUES(4,'four');
|
||||
CREATE INDEX t7i1 ON t7(b);
|
||||
}
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-13.2 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b, a;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-13.3 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-13.4 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a, b;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-13.5 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-13.6 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b DESC, a DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
do_test where-13.7 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b DESC, a ASC;
|
||||
}
|
||||
} {1 one 4 four sort}
|
||||
do_test where-13.8 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY b ASC, a DESC;
|
||||
}
|
||||
} {4 four 1 one sort}
|
||||
do_test where-13.9 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a DESC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-13.10 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a DESC, b DESC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-13.11 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a DESC, b ASC;
|
||||
}
|
||||
} {4 four 1 one nosort}
|
||||
do_test where-13.12 {
|
||||
cksort {
|
||||
SELECT * FROM t7 ORDER BY a ASC, b DESC;
|
||||
}
|
||||
} {1 one 4 four nosort}
|
||||
|
||||
# Ticket #2211.
|
||||
#
|
||||
# When optimizing out ORDER BY clauses, make sure that trailing terms
|
||||
# of the ORDER BY clause do not reference other tables in a join.
|
||||
#
|
||||
do_test where-14.1 {
|
||||
execsql {
|
||||
CREATE TABLE t8(a INTEGER PRIMARY KEY, b TEXT UNIQUE);
|
||||
INSERT INTO t8 VALUES(1,'one');
|
||||
INSERT INTO t8 VALUES(4,'four');
|
||||
}
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b
|
||||
}
|
||||
} {1/4 1/1 4/4 4/1 sort}
|
||||
do_test where-14.2 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, y.b DESC
|
||||
}
|
||||
} {1/1 1/4 4/1 4/4 sort}
|
||||
do_test where-14.3 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b
|
||||
}
|
||||
} {1/1 1/4 4/1 4/4 nosort}
|
||||
do_test where-14.4 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.a, x.b DESC
|
||||
}
|
||||
} {1/1 1/4 4/1 4/4 nosort}
|
||||
btree_breakpoint
|
||||
do_test where-14.5 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 nosort}
|
||||
do_test where-14.6 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||x.b DESC
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 nosort}
|
||||
do_test where-14.7 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 sort}
|
||||
do_test where-14.7.1 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a, y.a||y.b
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 sort}
|
||||
do_test where-14.7.2 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a, x.a||x.b
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 nosort}
|
||||
do_test where-14.8 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||y.b DESC
|
||||
}
|
||||
} {4/4 4/1 1/4 1/1 sort}
|
||||
do_test where-14.9 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||y.b
|
||||
}
|
||||
} {4/4 4/1 1/4 1/1 sort}
|
||||
do_test where-14.10 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, x.a||y.b DESC
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 sort}
|
||||
do_test where-14.11 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||x.b
|
||||
}
|
||||
} {4/1 4/4 1/1 1/4 sort}
|
||||
do_test where-14.12 {
|
||||
cksort {
|
||||
SELECT x.a || '/' || y.a FROM t8 x, t8 y ORDER BY x.b, y.a||x.b DESC
|
||||
}
|
||||
} {4/4 4/1 1/4 1/1 sort}
|
||||
|
||||
|
||||
integrity_check {where-99.0}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing the use of indices in WHERE clauses
|
||||
# based on recent changes to the optimizer.
|
||||
#
|
||||
# $Id: where2.test,v 1.9 2006/05/11 13:26:26 drh Exp $
|
||||
# $Id: where2.test,v 1.10 2006/11/06 15:10:06 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -451,4 +451,33 @@ ifcapable subquery {
|
||||
}
|
||||
} {}
|
||||
}
|
||||
|
||||
# Make sure WHERE clauses of the form A=1 AND (B=2 OR B=3) are optimized
|
||||
# when we have an index on A and B.
|
||||
#
|
||||
ifcapable or_opt {
|
||||
do_test where2-9.1 {
|
||||
execsql {
|
||||
BEGIN;
|
||||
CREATE TABLE t10(a,b,c);
|
||||
INSERT INTO t10 VALUES(1,1,1);
|
||||
INSERT INTO t10 VALUES(1,2,2);
|
||||
INSERT INTO t10 VALUES(1,3,3);
|
||||
}
|
||||
for {set i 4} {$i<=1000} {incr i} {
|
||||
execsql {INSERT INTO t10 VALUES(1,$i,$i)}
|
||||
}
|
||||
execsql {
|
||||
CREATE INDEX i10 ON t10(a,b);
|
||||
COMMIT;
|
||||
SELECT count(*) FROM t10;
|
||||
}
|
||||
} 1000
|
||||
do_test where2-9.2 {
|
||||
count {
|
||||
SELECT * FROM t10 WHERE a=1 AND (b=2 OR b=3)
|
||||
}
|
||||
} {1 2 2 1 3 3 7}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# focus of this file is testing the join reordering optimization
|
||||
# in cases that include a LEFT JOIN.
|
||||
#
|
||||
# $Id: where3.test,v 1.2 2006/06/06 11:45:55 drh Exp $
|
||||
# $Id: where3.test,v 1.3 2006/12/16 16:25:17 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@@ -78,4 +78,85 @@ do_test where3-1.2 {
|
||||
}
|
||||
} {1 {Value for C1.1} {Value for C2.1} 2 {} {Value for C2.2} 3 {Value for C1.3} {Value for C2.3}}
|
||||
|
||||
# This procedure executes the SQL. Then it appends
|
||||
# the ::sqlite_query_plan variable.
|
||||
#
|
||||
proc queryplan {sql} {
|
||||
set ::sqlite_sort_count 0
|
||||
set data [execsql $sql]
|
||||
return [concat $data $::sqlite_query_plan]
|
||||
}
|
||||
|
||||
|
||||
# If you have a from clause of the form: A B C left join D
|
||||
# then make sure the query optimizer is able to reorder the
|
||||
# A B C part anyway it wants.
|
||||
#
|
||||
# Following the fix to ticket #1652, there was a time when
|
||||
# the C table would not reorder. So the following reorderings
|
||||
# were possible:
|
||||
#
|
||||
# A B C left join D
|
||||
# B A C left join D
|
||||
#
|
||||
# But these reorders were not allowed
|
||||
#
|
||||
# C A B left join D
|
||||
# A C B left join D
|
||||
# C B A left join D
|
||||
# B C A left join D
|
||||
#
|
||||
# The following tests are here to verify that the latter four
|
||||
# reorderings are allowed again.
|
||||
#
|
||||
do_test where3-2.1 {
|
||||
execsql {
|
||||
CREATE TABLE tA(apk integer primary key, ax);
|
||||
CREATE TABLE tB(bpk integer primary key, bx);
|
||||
CREATE TABLE tC(cpk integer primary key, cx);
|
||||
CREATE TABLE tD(dpk integer primary key, dx);
|
||||
}
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE cpk=bx AND bpk=ax
|
||||
}
|
||||
} {tA {} tB * tC * tD *}
|
||||
do_test where3-2.2 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE cpk=bx AND apk=bx
|
||||
}
|
||||
} {tB {} tA * tC * tD *}
|
||||
do_test where3-2.3 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE cpk=bx AND apk=bx
|
||||
}
|
||||
} {tB {} tA * tC * tD *}
|
||||
do_test where3-2.4 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE apk=cx AND bpk=ax
|
||||
}
|
||||
} {tC {} tA * tB * tD *}
|
||||
do_test where3-2.5 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE cpk=ax AND bpk=cx
|
||||
}
|
||||
} {tA {} tC * tB * tD *}
|
||||
do_test where3-2.5 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE bpk=cx AND apk=bx
|
||||
}
|
||||
} {tC {} tB * tA * tD *}
|
||||
do_test where3-2.6 {
|
||||
queryplan {
|
||||
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
|
||||
WHERE cpk=bx AND apk=cx
|
||||
}
|
||||
} {tB {} tC * tA * tD *}
|
||||
|
||||
|
||||
finish_test
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
# 2006 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.
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this file is testing the use of indices in WHERE clauses.
|
||||
# This file was created when support for optimizing IS NULL phrases
|
||||
# was added. And so the principle purpose of this file is to test
|
||||
# that IS NULL phrases are correctly optimized. But you can never
|
||||
# have too many tests, so some other tests are thrown in as well.
|
||||
#
|
||||
# $Id: where4.test,v 1.2 2007/01/25 16:56:08 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
# Build some test data
|
||||
#
|
||||
do_test where4-1.0 {
|
||||
execsql {
|
||||
CREATE TABLE t1(w, x, y);
|
||||
CREATE INDEX i1wxy ON t1(w,x,y);
|
||||
INSERT INTO t1 VALUES(1,2,3);
|
||||
INSERT INTO t1 VALUES(1,NULL,3);
|
||||
INSERT INTO t1 VALUES('a','b','c');
|
||||
INSERT INTO t1 VALUES('a',NULL,'c');
|
||||
INSERT INTO t1 VALUES(X'78',x'79',x'7a');
|
||||
INSERT INTO t1 VALUES(X'78',NULL,X'7A');
|
||||
INSERT INTO t1 VALUES(NULL,NULL,NULL);
|
||||
SELECT count(*) FROM t1;
|
||||
}
|
||||
} {7}
|
||||
|
||||
# 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]
|
||||
}
|
||||
|
||||
# Verify that queries use an index. We are using the special variable
|
||||
# "sqlite_search_count" which tallys the number of executions of MoveTo
|
||||
# and Next operators in the VDBE. By verifing that the search count is
|
||||
# small we can be assured that indices are being used properly.
|
||||
#
|
||||
do_test where4-1.1 {
|
||||
count {SELECT rowid FROM t1 WHERE w IS NULL}
|
||||
} {7 2}
|
||||
do_test where4-1.2 {
|
||||
count {SELECT rowid FROM t1 WHERE +w IS NULL}
|
||||
} {7 6}
|
||||
do_test where4-1.3 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND x IS NULL}
|
||||
} {2 2}
|
||||
do_test where4-1.4 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND +x IS NULL}
|
||||
} {2 3}
|
||||
do_test where4-1.5 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND x>0}
|
||||
} {1 2}
|
||||
do_test where4-1.6 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND x<9}
|
||||
} {1 3}
|
||||
do_test where4-1.7 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND x IS NULL AND y=3}
|
||||
} {2 2}
|
||||
do_test where4-1.8 {
|
||||
count {SELECT rowid FROM t1 WHERE w=1 AND x IS NULL AND y>2}
|
||||
} {2 2}
|
||||
do_test where4-1.9 {
|
||||
count {SELECT rowid FROM t1 WHERE w='a' AND x IS NULL AND y='c'}
|
||||
} {4 2}
|
||||
do_test where4-1.10 {
|
||||
count {SELECT rowid FROM t1 WHERE w=x'78' AND x IS NULL}
|
||||
} {6 2}
|
||||
do_test where4-1.11 {
|
||||
count {SELECT rowid FROM t1 WHERE w=x'78' AND x IS NULL AND y=123}
|
||||
} {1}
|
||||
do_test where4-1.12 {
|
||||
count {SELECT rowid FROM t1 WHERE w=x'78' AND x IS NULL AND y=x'7A'}
|
||||
} {6 2}
|
||||
do_test where4-1.13 {
|
||||
count {SELECT rowid FROM t1 WHERE w IS NULL AND x IS NULL}
|
||||
} {7 2}
|
||||
do_test where4-1.14 {
|
||||
count {SELECT rowid FROM t1 WHERE w IS NULL AND x IS NULL AND y IS NULL}
|
||||
} {7 2}
|
||||
do_test where4-1.15 {
|
||||
count {SELECT rowid FROM t1 WHERE w IS NULL AND x IS NULL AND y<0}
|
||||
} {2}
|
||||
do_test where4-1.16 {
|
||||
count {SELECT rowid FROM t1 WHERE w IS NULL AND x IS NULL AND y>=0}
|
||||
} {1}
|
||||
|
||||
do_test where4-2.1 {
|
||||
execsql {SELECT rowid FROM t1 ORDER BY w, x, y}
|
||||
} {7 2 1 4 3 6 5}
|
||||
do_test where4-2.2 {
|
||||
execsql {SELECT rowid FROM t1 ORDER BY w DESC, x, y}
|
||||
} {6 5 4 3 2 1 7}
|
||||
do_test where4-2.3 {
|
||||
execsql {SELECT rowid FROM t1 ORDER BY w, x DESC, y}
|
||||
} {7 1 2 3 4 5 6}
|
||||
|
||||
|
||||
# Ticket #2177
|
||||
#
|
||||
# Suppose you have a left join where the right table of the left
|
||||
# join (the one that can be NULL) has an index on two columns.
|
||||
# The first indexed column is used in the ON clause of the join.
|
||||
# The second indexed column is used in the WHERE clause with an IS NULL
|
||||
# constraint. It is not allowed to use the IS NULL optimization to
|
||||
# optimize the query because the second column might be NULL because
|
||||
# the right table did not match - something the index does not know
|
||||
# about.
|
||||
#
|
||||
do_test where4-3.1 {
|
||||
execsql {
|
||||
CREATE TABLE t2(a);
|
||||
INSERT INTO t2 VALUES(1);
|
||||
INSERT INTO t2 VALUES(2);
|
||||
INSERT INTO t2 VALUES(3);
|
||||
CREATE TABLE t3(x,y,UNIQUE(x,y));
|
||||
INSERT INTO t3 VALUES(1,11);
|
||||
INSERT INTO t3 VALUES(2,NULL);
|
||||
|
||||
SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE +y IS NULL;
|
||||
}
|
||||
} {2 2 {} 3 {} {}}
|
||||
do_test where4-3.2 {
|
||||
execsql {
|
||||
SELECT * FROM t2 LEFT JOIN t3 ON a=x WHERE y IS NULL;
|
||||
}
|
||||
} {2 2 {} 3 {} {}}
|
||||
|
||||
# Ticket #2189. Probably the same bug as #2177.
|
||||
#
|
||||
do_test where4-4.1 {
|
||||
execsql {
|
||||
CREATE TABLE test(col1 TEXT PRIMARY KEY);
|
||||
INSERT INTO test(col1) values('a');
|
||||
INSERT INTO test(col1) values('b');
|
||||
INSERT INTO test(col1) values('c');
|
||||
CREATE TABLE test2(col1 TEXT PRIMARY KEY);
|
||||
INSERT INTO test2(col1) values('a');
|
||||
INSERT INTO test2(col1) values('b');
|
||||
INSERT INTO test2(col1) values('c');
|
||||
SELECT * FROM test t1 LEFT OUTER JOIN test2 t2 ON t1.col1 = t2.col1
|
||||
WHERE +t2.col1 IS NULL;
|
||||
}
|
||||
} {}
|
||||
do_test where4-4.2 {
|
||||
execsql {
|
||||
SELECT * FROM test t1 LEFT OUTER JOIN test2 t2 ON t1.col1 = t2.col1
|
||||
WHERE t2.col1 IS NULL;
|
||||
}
|
||||
} {}
|
||||
do_test where4-4.3 {
|
||||
execsql {
|
||||
SELECT * FROM test t1 LEFT OUTER JOIN test2 t2 ON t1.col1 = t2.col1
|
||||
WHERE +t1.col1 IS NULL;
|
||||
}
|
||||
} {}
|
||||
do_test where4-4.4 {
|
||||
execsql {
|
||||
SELECT * FROM test t1 LEFT OUTER JOIN test2 t2 ON t1.col1 = t2.col1
|
||||
WHERE t1.col1 IS NULL;
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
integrity_check {where4-99.0}
|
||||
|
||||
finish_test
|
||||
Reference in New Issue
Block a user