First public contribution.
3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # 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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this file is exercising the code in main.c.
14 # $Id: main.test,v 1.29 2008/07/12 14:52:20 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 # Only do the next group of tests if the sqlite3_complete API is available
21 ifcapable {complete} {
23 # Tests of the sqlite_complete() function.
26 db complete {This is a test}
44 db complete {DROP TABLE 'xyz;}
47 db complete {DROP TABLE 'xyz';}
50 db complete {DROP TABLE "xyz;}
53 db complete {DROP TABLE "xyz';}
56 db complete {DROP TABLE "xyz";}
59 db complete {DROP TABLE xyz; hi}
62 db complete {DROP TABLE xyz; }
65 db complete {DROP TABLE xyz; -- hi }
68 db complete {DROP TABLE xyz; -- hi
72 db complete {SELECT a-b FROM t1; }
75 db complete {SELECT a/e FROM t1 }
79 CREATE TABLE abc(x,y);
85 CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
90 CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
95 CREATE TRIGGER xyz AFTER DELETE abc BEGIN
102 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
108 CREATE TRIGGER xyz AFTER DELETE end BEGIN
109 SELECT a, b FROM end;
114 CREATE TRIGGER xyz AFTER DELETE end BEGIN
115 SELECT a, b FROM end;
121 CREATE TRIGGER xyz AFTER DELETE end BEGIN
122 SELECT a, b FROM end;
124 SELECT a, b FROM end;
129 CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
135 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
136 UPDATE cantor SET a=[;end;];;;
142 TRIGGER exy AFTER DELETE backend BEGIN
146 do_test main-1.27.1 {
149 TRIGGERX tangentxx AFTER DELETE backend BEGIN
153 do_test main-1.27.2 {
155 CREATE/**/TRIGGER tiger00 AFTER DELETE backend BEGIN
159 ifcapable {explain} {
160 do_test main-1.27.3 {
162 /* */ EXPLAIN -- A comment
163 CREATE/**/TRIGGER ezxyz12 AFTER DELETE backend BEGIN
168 do_test main-1.27.4 {
171 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
175 ifcapable {explain} {
176 do_test main-1.27.5 {
179 CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
186 CREATE TEMPORARY TRIGGER xyz AFTER DELETE backend BEGIN
192 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
194 EXPLAIN select * from xyz;
198 } ;# end ifcapable {complete}
203 CREATE TABLE /* In comment ; */
208 CREATE TABLE /* In comment ; */ hi;
213 CREATE TABLE /* In comment ; */;
243 db complete {hi /**/ there;}
246 db complete {hi there/***/;}
249 db complete {hi there/**}
252 db complete {hi [there}
255 ifcapable {trigger} {
256 # Characters less than \040 can never be part of an identifier.
257 # Characters greater than \u177 are always identifier characters.
259 db complete "create \037\036\035\034trigger\001\002;"
262 db complete "create trigger\200;"
265 db complete "create \200trigger;"
270 # Try to open a database with a corrupt database file.
274 file delete -force test.db
275 set fd [open test.db w]
278 set v [catch {sqlite3 db test.db} msg]
279 if {$v} {lappend v $msg} {lappend v {}}
282 # Here are some tests for tokenize.c.
286 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
287 file delete -force testdb
289 set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
291 } {1 {unrecognized token: "!!"}}
294 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
295 file delete -force testdb
297 set v [catch {execsql {SELECT * from T1 where ^x}} msg]
299 } {1 {unrecognized token: "^"}}
301 catchsql {select 'abc}
302 } {1 {unrecognized token: "'abc"}}
304 catchsql {select "abc}
305 } {1 {unrecognized token: ""abc"}}
307 catchsql {select [abc}
308 } {1 {unrecognized token: "[abc"}}
310 catchsql {select x'4869}
311 } {1 {unrecognized token: "x'4869"}}
313 catchsql {select x'4869'}
316 catchsql {select x'48695'}
317 } {1 {unrecognized token: "x'48695'"}}
319 catchsql {select x'486x'}
320 } {1 {unrecognized token: "x'486x'"}}
322 catchsql {select $abc(}
323 } {1 {unrecognized token: "$abc("}}
324 do_test main-3.2.10 {
325 catchsql {select $abc(x}
326 } {1 {unrecognized token: "$abc(x"}}
328 do_test main-3.2.11 {
329 catchsql {select $::xyz}
331 namespace eval ::testnamespace {
334 do_test main-3.2.12 {
335 catchsql {select $testnamespace::xyz}
337 do_test main-3.2.13 {
338 catchsql {select $(abc)}
339 } {1 {unrecognized token: "$"}}
340 do_test main-3.2.14 {
342 db eval "select \$hi\u1234x"
344 do_test main-3.2.15 {
345 catchsql "select 456\u1234"
346 } [list 1 "unrecognized token: \"456\u1234\""]
347 do_test main-3.2.16 {
348 catchsql {select cast(3.14e+4 AS integer)}
350 do_test main-3.2.17 {
351 catchsql {select cast(3.14e+04 AS integer)}
353 do_test main-3.2.18 {
354 catchsql {select cast(3.14e+004 AS integer)}
356 do_test main-3.2.19 {
357 catchsql {select cast(3.14e4 AS integer)}
359 do_test main-3.2.20 {
360 catchsql {select cast(3.14e04 AS integer)}
362 do_test main-3.2.21 {
363 catchsql {select cast(3.14e004 AS integer)}
365 do_test main-3.2.16 {
366 catchsql {select cast(3.14E+4 AS integer)}
368 do_test main-3.2.17 {
369 catchsql {select cast(3.14E+04 AS integer)}
371 do_test main-3.2.18 {
372 catchsql {select cast(3.14E+004 AS integer)}
374 do_test main-3.2.19 {
375 catchsql {select cast(3.14E4 AS integer)}
377 do_test main-3.2.20 {
378 catchsql {select cast(3.14E04 AS integer)}
380 do_test main-3.2.21 {
381 catchsql {select cast(3.14E004 AS integer)}
383 do_test main-3.2.22 {
384 catchsql {select cast(3.14e-4 * 1e8 AS integer)}
386 do_test main-3.2.23 {
387 catchsql {select cast(3.14E-04 * 1E08 AS integer)}
389 do_test main-3.2.24 {
390 catchsql {select cast(3.14e-004 * 01.0E+8 AS integer)}
392 do_test main-3.2.25 {
393 catchsql {select 123/*abc}
395 do_test main-3.2.26 {
396 catchsql {select 123/***abc}
398 do_test main-3.2.27 {
399 catchsql {select 123/*/*2}
401 do_test main-3.2.28 {
402 catchsql {select 123/**/*2}
404 do_test main-3.2.29 {
405 catchsql {select 123/}
406 } {1 {near "/": syntax error}}
407 do_test main-3.2.30 {
408 catchsql {select 123--5}
414 foreach f [glob -nocomplain testdb/*] {file delete -force $f}
415 file delete -force testdb
418 create table T1(X REAL); /* C-style comments allowed */
419 insert into T1 values(0.5);
420 insert into T1 values(0.5e2);
421 insert into T1 values(0.5e-002);
422 insert into T1 values(5e-002);
423 insert into T1 values(-5.0e-2);
424 insert into T1 values(-5.1e-2);
425 insert into T1 values(0.5e2);
426 insert into T1 values(0.5E+02);
427 insert into T1 values(5E+02);
428 insert into T1 values(5.0E+03);
429 select x*10 from T1 order by x*5;
431 } {-0.51 -0.5 0.05 0.5 5.0 500.0 500.0 500.0 5000.0 50000.0}
433 set v [catch {execsql {create bogus}} msg]
435 } {1 {near "bogus": syntax error}}
437 set v [catch {execsql {create}} msg]
439 } {1 {near "create": syntax error}}
441 catchsql {SELECT 'abc' + #9}
442 } {1 {near "#9": syntax error}}
444 # The following test-case tests the linked list code used to manage
445 # sqlite3_vfs structures.
446 if {$::tcl_platform(platform)=="unix"} {
447 ifcapable threadsafe {
450 sqlite3_crash_enable 1
451 sqlite3_crash_enable 0
453 sqlite3async_enable 1
454 sqlite3async_enable 0
456 sqlite3_crash_enable 1
457 sqlite3async_enable 1
458 sqlite3_crash_enable 0
459 sqlite3async_enable 0
461 sqlite3_crash_enable 1
462 sqlite3async_enable 1
463 sqlite3async_enable 0
464 sqlite3_crash_enable 0
466 sqlite3async_enable 1
467 sqlite3_crash_enable 1
468 sqlite3_crash_enable 0
469 sqlite3async_enable 0
471 sqlite3async_enable 1
472 sqlite3_crash_enable 1
473 sqlite3async_enable 0
474 sqlite3_crash_enable 0
477 set rc [catch {sqlite3 db test.db -vfs crash} msg]
479 } {1 {no such vfs: crash}}
481 set rc [catch {sqlite3 db test.db -vfs async} msg]
483 } {1 {no such vfs: async}}