⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc1.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# 2001 September 15.## The author disclaims copyright to this source code.  In place of# a legal notice, here is a blessing:##    May you do good and not evil.#    May you find forgiveness for yourself and forgive others.#    May you share freely, never taking more than you give.##***********************************************************************# This file implements regression tests for SQLite library.## This file implements tests for miscellanous features that were# left out of other test files.## $Id: misc1.test,v 1.41 2006/06/27 20:06:45 drh Exp $set testdir [file dirname $argv0]source $testdir/tester.tcl# Mimic the SQLite 2 collation type NUMERIC.db collate numeric numeric_collateproc numeric_collate {lhs rhs} {  if {$lhs == $rhs} {return 0}   return [expr ($lhs>$rhs)?1:-1]}# Mimic the SQLite 2 collation type TEXT.db collate text text_collateproc numeric_collate {lhs rhs} {  return [string compare $lhs $rhs]}# Test the creation and use of tables that have a large number# of columns.#do_test misc1-1.1 {  set cmd "CREATE TABLE manycol(x0 text"  for {set i 1} {$i<=99} {incr i} {    append cmd ",x$i text"  }  append cmd ")";  execsql $cmd  set cmd "INSERT INTO manycol VALUES(0"  for {set i 1} {$i<=99} {incr i} {    append cmd ",$i"  }  append cmd ")";  execsql $cmd  execsql "SELECT x99 FROM manycol"} 99do_test misc1-1.2 {  execsql {SELECT x0, x10, x25, x50, x75 FROM manycol}} {0 10 25 50 75}do_test misc1-1.3.1 {  for {set j 100} {$j<=1000} {incr j 100} {    set cmd "INSERT INTO manycol VALUES($j"    for {set i 1} {$i<=99} {incr i} {      append cmd ",[expr {$i+$j}]"    }    append cmd ")"    execsql $cmd  }  execsql {SELECT x50 FROM manycol ORDER BY x80+0}} {50 150 250 350 450 550 650 750 850 950 1050}do_test misc1-1.3.2 {  execsql {SELECT x50 FROM manycol ORDER BY x80}} {1050 150 250 350 450 550 650 750 50 850 950}do_test misc1-1.4 {  execsql {SELECT x75 FROM manycol WHERE x50=350}} 375do_test misc1-1.5 {  execsql {SELECT x50 FROM manycol WHERE x99=599}} 550do_test misc1-1.6 {  execsql {CREATE INDEX manycol_idx1 ON manycol(x99)}  execsql {SELECT x50 FROM manycol WHERE x99=899}} 850do_test misc1-1.7 {  execsql {SELECT count(*) FROM manycol}} 11do_test misc1-1.8 {  execsql {DELETE FROM manycol WHERE x98=1234}  execsql {SELECT count(*) FROM manycol}} 11do_test misc1-1.9 {  execsql {DELETE FROM manycol WHERE x98=998}  execsql {SELECT count(*) FROM manycol}} 10do_test misc1-1.10 {  execsql {DELETE FROM manycol WHERE x99=500}  execsql {SELECT count(*) FROM manycol}} 10do_test misc1-1.11 {  execsql {DELETE FROM manycol WHERE x99=599}  execsql {SELECT count(*) FROM manycol}} 9# Check GROUP BY expressions that name two or more columns.#do_test misc1-2.1 {  execsql {    BEGIN TRANSACTION;    CREATE TABLE agger(one text, two text, three text, four text);    INSERT INTO agger VALUES(1, 'one', 'hello', 'yes');    INSERT INTO agger VALUES(2, 'two', 'howdy', 'no');    INSERT INTO agger VALUES(3, 'thr', 'howareya', 'yes');    INSERT INTO agger VALUES(4, 'two', 'lothere', 'yes');    INSERT INTO agger VALUES(5, 'one', 'atcha', 'yes');    INSERT INTO agger VALUES(6, 'two', 'hello', 'no');    COMMIT  }  execsql {SELECT count(*) FROM agger}} 6do_test misc1-2.2 {  execsql {SELECT sum(one), two, four FROM agger           GROUP BY two, four ORDER BY sum(one) desc}} {8 two no 6 one yes 4 two yes 3 thr yes}do_test misc1-2.3 {  execsql {SELECT sum((one)), (two), (four) FROM agger           GROUP BY (two), (four) ORDER BY sum(one) desc}} {8 two no 6 one yes 4 two yes 3 thr yes}# Here's a test for a bug found by Joel Lucsy.  The code below# was causing an assertion failure.#do_test misc1-3.1 {  set r [execsql {    CREATE TABLE t1(a);    INSERT INTO t1 VALUES('hi');    PRAGMA full_column_names=on;    SELECT rowid, * FROM t1;  }]  lindex $r 1} {hi}# Here's a test for yet another bug found by Joel Lucsy.  The code# below was causing an assertion failure.#do_test misc1-4.1 {  execsql {    BEGIN;    CREATE TABLE t2(a);    INSERT INTO t2 VALUES('This is a long string to use up a lot of disk -');    UPDATE t2 SET a=a||a||a||a;    INSERT INTO t2 SELECT '1 - ' || a FROM t2;    INSERT INTO t2 SELECT '2 - ' || a FROM t2;    INSERT INTO t2 SELECT '3 - ' || a FROM t2;    INSERT INTO t2 SELECT '4 - ' || a FROM t2;    INSERT INTO t2 SELECT '5 - ' || a FROM t2;    INSERT INTO t2 SELECT '6 - ' || a FROM t2;    COMMIT;    SELECT count(*) FROM t2;  }} {64}# Make sure we actually see a semicolon or end-of-file in the SQL input# before executing a command.  Thus if "WHERE" is misspelled on an UPDATE,# the user won't accidently update every record.#do_test misc1-5.1 {  catchsql {    CREATE TABLE t3(a,b);    INSERT INTO t3 VALUES(1,2);    INSERT INTO t3 VALUES(3,4);    UPDATE t3 SET a=0 WHEREwww b=2;  }} {1 {near "WHEREwww": syntax error}}do_test misc1-5.2 {  execsql {    SELECT * FROM t3 ORDER BY a;  }} {1 2 3 4}# Certain keywords (especially non-standard keywords like "REPLACE") can# also be used as identifiers.  The way this works in the parser is that# the parser first detects a syntax error, the error handling routine# sees that the special keyword caused the error, then replaces the keyword# with "ID" and tries again.## Check the operation of this logic.#do_test misc1-6.1 {  catchsql {    CREATE TABLE t4(      abort, asc, begin, cluster, conflict, copy, delimiters, desc, end,      explain, fail, ignore, key, offset, pragma, replace, temp,      vacuum, view    );  }} {0 {}}do_test misc1-6.2 {  catchsql {    INSERT INTO t4       VALUES(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19);  }} {0 {}}do_test misc1-6.3 {  execsql {    SELECT * FROM t4  }} {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19}do_test misc1-6.4 {  execsql {    SELECT abort+asc,max(key,pragma,temp) FROM t4  }} {3 17}# Test for multi-column primary keys, and for multiple primary keys.#do_test misc1-7.1 {  catchsql {    CREATE TABLE error1(      a TYPE PRIMARY KEY,      b TYPE PRIMARY KEY    );  }} {1 {table "error1" has more than one primary key}}do_test misc1-7.2 {  catchsql {    CREATE TABLE error1(      a INTEGER PRIMARY KEY,      b TYPE PRIMARY KEY    );  }} {1 {table "error1" has more than one primary key}}do_test misc1-7.3 {  execsql {    CREATE TABLE t5(a,b,c,PRIMARY KEY(a,b));    INSERT INTO t5 VALUES(1,2,3);    SELECT * FROM t5 ORDER BY a;  }} {1 2 3}do_test misc1-7.4 {  catchsql {    INSERT INTO t5 VALUES(1,2,4);  }} {1 {columns a, b are not unique}}do_test misc1-7.5 {  catchsql {    INSERT INTO t5 VALUES(0,2,4);  }} {0 {}}do_test misc1-7.6 {  execsql {    SELECT * FROM t5 ORDER BY a;  }} {0 2 4 1 2 3}do_test misc1-8.1 {  catchsql {    SELECT *;  }} {1 {no tables specified}}do_test misc1-8.2 {  catchsql {    SELECT t1.*;  }} {1 {no such table: t1}}execsql {  DROP TABLE t1;  DROP TABLE t2;  DROP TABLE t3;  DROP TABLE t4;}# 64-bit integers are represented exactly.#do_test misc1-9.1 {  catchsql {    CREATE TABLE t1(a unique not null, b unique not null);    INSERT INTO t1 VALUES('a',1234567890123456789);    INSERT INTO t1 VALUES('b',1234567891123456789);    INSERT INTO t1 VALUES('c',1234567892123456789);    SELECT * FROM t1;  }} {0 {a 1234567890123456789 b 1234567891123456789 c 1234567892123456789}}# A WHERE clause is not allowed to contain more than 99 terms.  Check to# make sure this limit is enforced.## 2005-07-16: There is no longer a limit on the number of terms in a# WHERE clause.  But keep these tests just so that we have some tests# that use a large number of terms in the WHERE clause.#do_test misc1-10.0 {  execsql {SELECT count(*) FROM manycol}} {9}do_test misc1-10.1 {  set ::where {WHERE x0>=0}  for {set i 1} {$i<=99} {incr i} {    append ::where " AND x$i<>0"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -