xref: /illumos-gate/usr/src/lib/libsqlite/test/main.test (revision 8119dad84d6416f13557b0ba8e2aaf9064cbcfd3)
1#
2# 2001 September 15
3#
4# The author disclaims copyright to this source code.  In place of
5# a legal notice, here is a blessing:
6#
7#    May you do good and not evil.
8#    May you find forgiveness for yourself and forgive others.
9#    May you share freely, never taking more than you give.
10#
11#***********************************************************************
12# This file implements regression tests for SQLite library.  The
13# focus of this file is exercising the code in main.c.
14#
15# $Id: main.test,v 1.14 2003/05/04 17:58:27 drh Exp $
16
17set testdir [file dirname $argv0]
18source $testdir/tester.tcl
19
20# Tests of the sqlite_complete() function.
21#
22do_test main-1.1 {
23  db complete {This is a test}
24} {0}
25do_test main-1.2 {
26  db complete {
27  }
28} {1}
29do_test main-1.3 {
30  db complete {
31     -- a comment ;
32  }
33} {1}
34do_test main-1.4 {
35  db complete {
36     -- a comment ;
37     ;
38  }
39} {1}
40do_test main-1.5 {
41  db complete {DROP TABLE 'xyz;}
42} {0}
43do_test main-1.6 {
44  db complete {DROP TABLE 'xyz';}
45} {1}
46do_test main-1.7 {
47  db complete {DROP TABLE "xyz;}
48} {0}
49do_test main-1.8 {
50  db complete {DROP TABLE "xyz';}
51} {0}
52do_test main-1.9 {
53  db complete {DROP TABLE "xyz";}
54} {1}
55do_test main-1.10 {
56  db complete {DROP TABLE xyz; hi}
57} {0}
58do_test main-1.11 {
59  db complete {DROP TABLE xyz; }
60} {1}
61do_test main-1.12 {
62  db complete {DROP TABLE xyz; -- hi }
63} {1}
64do_test main-1.13 {
65  db complete {DROP TABLE xyz; -- hi
66  }
67} {1}
68do_test main-1.14 {
69  db complete {SELECT a-b FROM t1; }
70} {1}
71do_test main-1.15 {
72  db complete {SELECT a-b FROM t1 }
73} {0}
74do_test main-1.16 {
75  db complete {
76    CREATE TABLE abc(x,y);
77  }
78} {1}
79do_test main-1.17 {
80  db complete {
81    CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
82  }
83} {0}
84do_test main-1.18 {
85  db complete {
86    CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
87  }
88} {1}
89do_test main-1.19 {
90  db complete {
91    CREATE TRIGGER xyz AFTER DELETE abc BEGIN
92       UPDATE pqr;
93       unknown command;
94  }
95} {0}
96do_test main-1.20 {
97  db complete {
98    CREATE TRIGGER xyz AFTER DELETE backend BEGIN
99       UPDATE pqr;
100  }
101} {0}
102do_test main-1.21 {
103  db complete {
104    CREATE TRIGGER xyz AFTER DELETE end BEGIN
105       SELECT a, b FROM end;
106  }
107} {0}
108do_test main-1.22 {
109  db complete {
110    CREATE TRIGGER xyz AFTER DELETE end BEGIN
111       SELECT a, b FROM end;
112    END;
113  }
114} {1}
115do_test main-1.23 {
116  db complete {
117    CREATE TRIGGER xyz AFTER DELETE end BEGIN
118       SELECT a, b FROM end;
119    END;
120    SELECT a, b FROM end;
121  }
122} {1}
123do_test main-1.24 {
124  db complete {
125    CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
126       UPDATE pqr;
127  }
128} {0}
129do_test main-1.25 {
130  db complete {
131    CREATE TRIGGER xyz AFTER DELETE backend BEGIN
132       UPDATE pqr SET a=[;end;];;;
133  }
134} {0}
135do_test main-1.26 {
136  db complete {
137    CREATE -- a comment
138    TRIGGER xyz AFTER DELETE backend BEGIN
139       UPDATE pqr SET a=5;
140  }
141} {0}
142do_test main-1.27.1 {
143  db complete {
144    CREATE -- a comment
145    TRIGGERX xyz AFTER DELETE backend BEGIN
146       UPDATE pqr SET a=5;
147  }
148} {1}
149do_test main-1.27.2 {
150  db complete {
151    CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
152       UPDATE pqr SET a=5;
153  }
154} {0}
155do_test main-1.27.3 {
156  db complete {
157    /* */ EXPLAIN -- A comment
158    CREATE/**/TRIGGER xyz AFTER DELETE backend BEGIN
159       UPDATE pqr SET a=5;
160  }
161} {0}
162do_test main-1.27.4 {
163  db complete {
164    BOGUS token
165    CREATE  TRIGGER xyz AFTER DELETE backend BEGIN
166       UPDATE pqr SET a=5;
167  }
168} {1}
169do_test main-1.27.5 {
170  db complete {
171    EXPLAIN
172    CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
173       UPDATE pqr SET a=5;
174  }
175} {0}
176do_test main-1.28 {
177  db complete {
178    CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
179       UPDATE pqr SET a=5;
180  }
181} {0}
182do_test main-1.29 {
183  db complete {
184    CREATE TRIGGER xyz AFTER DELETE backend BEGIN
185       UPDATE pqr SET a=5;
186       EXPLAIN select * from xyz;
187  }
188} {0}
189do_test main-1.30 {
190  db complete {
191     CREATE TABLE /* In comment ; */
192  }
193} {0}
194do_test main-1.31 {
195  db complete {
196     CREATE TABLE /* In comment ; */ hi;
197  }
198} {1}
199do_test main-1.31 {
200  db complete {
201     CREATE TABLE /* In comment ; */;
202  }
203} {1}
204do_test main-1.32 {
205  db complete {
206     stuff;
207     /*
208       CREATE TABLE
209       multiple lines
210       of text
211     */
212  }
213} {1}
214do_test main-1.33 {
215  db complete {
216     /*
217       CREATE TABLE
218       multiple lines
219       of text;
220  }
221} {0}
222do_test main-1.34 {
223  db complete {
224     /*
225       CREATE TABLE
226       multiple lines "*/
227       of text;
228  }
229} {1}
230do_test main-1.35 {
231  db complete {hi /**/ there;}
232} {1}
233do_test main-1.36 {
234  db complete {hi there/***/;}
235} {1}
236
237
238# Try to open a database with a corrupt database file.
239#
240do_test main-2.0 {
241  catch {db close}
242  file delete -force test.db
243  set fd [open test.db w]
244  puts $fd hi!
245  close $fd
246  set v [catch {sqlite db test.db} msg]
247  if {$v} {lappend v $msg} {lappend v {}}
248} {0 {}}
249
250# Here are some tests for tokenize.c.
251#
252do_test main-3.1 {
253  catch {db close}
254  foreach f [glob -nocomplain testdb/*] {file delete -force $f}
255  file delete -force testdb
256  sqlite db testdb
257  set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
258  lappend v $msg
259} {1 {unrecognized token: "!!"}}
260do_test main-3.2 {
261  catch {db close}
262  foreach f [glob -nocomplain testdb/*] {file delete -force $f}
263  file delete -force testdb
264  sqlite db testdb
265  set v [catch {execsql {SELECT * from T1 where @x}} msg]
266  lappend v $msg
267} {1 {unrecognized token: "@"}}
268
269do_test main-3.3 {
270  catch {db close}
271  foreach f [glob -nocomplain testdb/*] {file delete -force $f}
272  file delete -force testdb
273  sqlite db testdb
274  execsql {
275    create table T1(X REAL);
276    insert into T1 values(0.5);
277    insert into T1 values(0.5e2);
278    insert into T1 values(0.5e-002);
279    insert into T1 values(5e-002);
280    insert into T1 values(-5.0e-2);
281    insert into T1 values(-5.1e-2);
282    insert into T1 values(0.5e2);
283    insert into T1 values(0.5E+02);
284    insert into T1 values(5E+02);
285    insert into T1 values(5.0E+03);
286    select x*10 from T1 order by x*5;
287  }
288} {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000}
289do_test main-3.4 {
290  set v [catch {execsql {create bogus}} msg]
291  lappend v $msg
292} {1 {near "bogus": syntax error}}
293do_test main-3.5 {
294  set v [catch {execsql {create}} msg]
295  lappend v $msg
296} {1 {near "create": syntax error}}
297
298finish_test
299