blob: 4eceab0811c90add0236aa0e59b9f5ecc07b0cb5 [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drhcc85b412000-06-07 15:11:27 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drhcc85b412000-06-07 15:11:27 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
drhcc85b412000-06-07 15:11:27 +00009#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is exercising the code in main.c.
13#
drhc22bd472002-05-10 13:14:07 +000014# $Id: main.test,v 1.10 2002/05/10 13:14:08 drh Exp $
drhcc85b412000-06-07 15:11:27 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19# Tests of the sqlite_complete() function.
20#
21do_test main-1.1 {
22 db complete {This is a test}
23} {0}
24do_test main-1.2 {
25 db complete {
26 }
27} {0}
28do_test main-1.3 {
29 db complete {
30 -- a comment ;
31 }
32} {0}
33do_test main-1.4 {
34 db complete {
35 -- a comment ;
36 ;
37 }
38} {1}
drh8c82b352000-12-10 18:23:50 +000039do_test main-1.5 {
40 db complete {DROP TABLE 'xyz;}
41} {0}
42do_test main-1.6 {
43 db complete {DROP TABLE 'xyz';}
44} {1}
45do_test main-1.7 {
46 db complete {DROP TABLE "xyz;}
47} {0}
48do_test main-1.8 {
49 db complete {DROP TABLE "xyz';}
50} {0}
51do_test main-1.9 {
52 db complete {DROP TABLE "xyz";}
53} {1}
54do_test main-1.10 {
55 db complete {DROP TABLE xyz; hi}
56} {0}
57do_test main-1.11 {
58 db complete {DROP TABLE xyz; }
59} {1}
60do_test main-1.12 {
61 db complete {DROP TABLE xyz; -- hi }
62} {1}
63do_test main-1.13 {
64 db complete {DROP TABLE xyz; -- hi
65 }
66} {1}
drhc4a3c772001-04-04 11:48:57 +000067do_test main-1.14 {
68 db complete {SELECT a-b FROM t1; }
69} {1}
70do_test main-1.15 {
71 db complete {SELECT a-b FROM t1 }
72} {0}
drhcc85b412000-06-07 15:11:27 +000073
drh3fc190c2001-09-14 03:24:23 +000074# Try to open a database with a corrupt database file.
drhcc85b412000-06-07 15:11:27 +000075#
76do_test main-2.0 {
77 catch {db close}
drh3fc190c2001-09-14 03:24:23 +000078 file delete -force test.db
79 set fd [open test.db w]
drhcc85b412000-06-07 15:11:27 +000080 puts $fd hi!
81 close $fd
drh3fc190c2001-09-14 03:24:23 +000082 set v [catch {sqlite db test.db} msg]
drhc22bd472002-05-10 13:14:07 +000083 if {$v} {lappend v $msg} {lappend v {}}
drhcc85b412000-06-07 15:11:27 +000084} {0 {}}
85
drhc837e702000-06-08 16:26:24 +000086# Here are some tests for tokenize.c.
87#
88do_test main-3.1 {
89 catch {db close}
drh3494ffe2001-03-20 12:55:13 +000090 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
drhc837e702000-06-08 16:26:24 +000091 file delete -force testdb
92 sqlite db testdb
93 set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
94 lappend v $msg
95} {1 {unrecognized token: "!!"}}
96do_test main-3.2 {
97 catch {db close}
drh3494ffe2001-03-20 12:55:13 +000098 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
drhc837e702000-06-08 16:26:24 +000099 file delete -force testdb
100 sqlite db testdb
drhbf4133c2001-10-13 02:59:08 +0000101 set v [catch {execsql {SELECT * from T1 where @x}} msg]
drhc837e702000-06-08 16:26:24 +0000102 lappend v $msg
drhbf4133c2001-10-13 02:59:08 +0000103} {1 {unrecognized token: "@"}}
drhc837e702000-06-08 16:26:24 +0000104
105do_test main-3.3 {
106 catch {db close}
drh3494ffe2001-03-20 12:55:13 +0000107 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
drhc837e702000-06-08 16:26:24 +0000108 file delete -force testdb
109 sqlite db testdb
110 execsql {
111 create table T1(X REAL);
112 insert into T1 values(.5);
113 insert into T1 values(0.5e2);
114 insert into T1 values(0.5e-002);
115 insert into T1 values(5e-002);
116 insert into T1 values(-5.0e-2);
117 insert into T1 values(-5.1e-2);
118 insert into T1 values(.5e2);
119 insert into T1 values(.5E+02);
120 insert into T1 values(5E+02);
121 insert into T1 values(5.E+03);
122 select x*10 from T1 order by x*5;
123 }
124} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
125do_test main-3.4 {
126 set v [catch {execsql {create bogus}} msg]
127 lappend v $msg
128} {1 {near "bogus": syntax error}}
129do_test main-3.5 {
130 set v [catch {execsql {create}} msg]
131 lappend v $msg
132} {1 {near "create": syntax error}}
133
drhcc85b412000-06-07 15:11:27 +0000134finish_test