123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- # 2001 September 15
- #
- # The author disclaims copyright to this source code. In place of
- # a legal notice, here is a blessing:
- #
- # May you do good and not evil.
- # May you find forgiveness for yourself and forgive others.
- # May you share freely, never taking more than you give.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library. The
- # focus of this file is exercising the code in main.c.
- #
- # $Id: main.test,v 1.11 2002/05/15 14:17:45 drh Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- # Tests of the sqlite_complete() function.
- #
- do_test main-1.1 {
- db complete {This is a test}
- } {0}
- do_test main-1.2 {
- db complete {
- }
- } {0}
- do_test main-1.3 {
- db complete {
- -- a comment ;
- }
- } {0}
- do_test main-1.4 {
- db complete {
- -- a comment ;
- ;
- }
- } {1}
- do_test main-1.5 {
- db complete {DROP TABLE 'xyz;}
- } {0}
- do_test main-1.6 {
- db complete {DROP TABLE 'xyz';}
- } {1}
- do_test main-1.7 {
- db complete {DROP TABLE "xyz;}
- } {0}
- do_test main-1.8 {
- db complete {DROP TABLE "xyz';}
- } {0}
- do_test main-1.9 {
- db complete {DROP TABLE "xyz";}
- } {1}
- do_test main-1.10 {
- db complete {DROP TABLE xyz; hi}
- } {0}
- do_test main-1.11 {
- db complete {DROP TABLE xyz; }
- } {1}
- do_test main-1.12 {
- db complete {DROP TABLE xyz; -- hi }
- } {1}
- do_test main-1.13 {
- db complete {DROP TABLE xyz; -- hi
- }
- } {1}
- do_test main-1.14 {
- db complete {SELECT a-b FROM t1; }
- } {1}
- do_test main-1.15 {
- db complete {SELECT a-b FROM t1 }
- } {0}
- do_test main-1.16 {
- db complete {
- CREATE TABLE abc(x,y);
- }
- } {1}
- do_test main-1.17 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
- }
- } {0}
- do_test main-1.18 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
- }
- } {1}
- do_test main-1.19 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE abc BEGIN
- UPDATE pqr;
- unknown command;
- }
- } {0}
- do_test main-1.20 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE backend BEGIN
- UPDATE pqr;
- }
- } {0}
- do_test main-1.21 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE end BEGIN
- SELECT a, b FROM end;
- }
- } {0}
- do_test main-1.22 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE end BEGIN
- SELECT a, b FROM end;
- END;
- }
- } {1}
- do_test main-1.23 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE end BEGIN
- SELECT a, b FROM end;
- END;
- SELECT a, b FROM end;
- }
- } {1}
- do_test main-1.24 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
- UPDATE pqr;
- }
- } {0}
- do_test main-1.25 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE backend BEGIN
- UPDATE pqr SET a=[;end;];;;
- }
- } {0}
- do_test main-1.26 {
- db complete {
- CREATE -- a comment
- TRIGGER xyz AFTER DELETE backend BEGIN
- UPDATE pqr SET a=5;
- }
- } {0}
- do_test main-1.27 {
- db complete {
- CREATE -- a comment
- TRIGGERX xyz AFTER DELETE backend BEGIN
- UPDATE pqr SET a=5;
- }
- } {1}
- do_test main-1.28 {
- db complete {
- CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
- UPDATE pqr SET a=5;
- }
- } {1}
- do_test main-1.29 {
- db complete {
- CREATE TRIGGER xyz AFTER DELETE backend BEGIN
- UPDATE pqr SET a=5;
- EXPLAIN select * from xyz;
- }
- } {0}
- # Try to open a database with a corrupt database file.
- #
- do_test main-2.0 {
- catch {db close}
- file delete -force test.db
- set fd [open test.db w]
- puts $fd hi!
- close $fd
- set v [catch {sqlite db test.db} msg]
- if {$v} {lappend v $msg} {lappend v {}}
- } {0 {}}
- # Here are some tests for tokenize.c.
- #
- do_test main-3.1 {
- catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
- sqlite db testdb
- set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
- lappend v $msg
- } {1 {unrecognized token: "!!"}}
- do_test main-3.2 {
- catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
- sqlite db testdb
- set v [catch {execsql {SELECT * from T1 where @x}} msg]
- lappend v $msg
- } {1 {unrecognized token: "@"}}
- do_test main-3.3 {
- catch {db close}
- foreach f [glob -nocomplain testdb/*] {file delete -force $f}
- file delete -force testdb
- sqlite db testdb
- execsql {
- create table T1(X REAL);
- insert into T1 values(.5);
- insert into T1 values(0.5e2);
- insert into T1 values(0.5e-002);
- insert into T1 values(5e-002);
- insert into T1 values(-5.0e-2);
- insert into T1 values(-5.1e-2);
- insert into T1 values(.5e2);
- insert into T1 values(.5E+02);
- insert into T1 values(5E+02);
- insert into T1 values(5.E+03);
- select x*10 from T1 order by x*5;
- }
- } {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
- do_test main-3.4 {
- set v [catch {execsql {create bogus}} msg]
- lappend v $msg
- } {1 {near "bogus": syntax error}}
- do_test main-3.5 {
- set v [catch {execsql {create}} msg]
- lappend v $msg
- } {1 {near "create": syntax error}}
- finish_test
|