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.32 2009/04/28 04:51:29 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}
63 db complete {DROP TABLE 'xyz;}
66 db complete {DROP TABLE 'xyz';}
69 db complete {DROP TABLE "xyz;}
72 db complete {DROP TABLE "xyz';}
75 db complete {DROP TABLE "xyz";}
78 db complete {DROP TABLE xyz; hi}
81 db complete {DROP TABLE xyz; }
84 db complete {DROP TABLE xyz; -- hi }
87 db complete {DROP TABLE xyz; -- hi
91 db complete {SELECT a-b FROM t1; }
94 db complete {SELECT a/e FROM t1 }
98 CREATE TABLE abc(x,y);
101 ifcapable {trigger} {
104 CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
107 do_test main-1.17.2 {
109 EXPLAIN CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
112 do_test main-1.17.3 {
114 EXPLAIN QUERY PLAN CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr;
119 CREATE TRIGGER xyz AFTER DELETE abc BEGIN UPDATE pqr; END;
124 CREATE TRIGGER xyz AFTER DELETE abc BEGIN
131 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
137 CREATE TRIGGER xyz AFTER DELETE end BEGIN
138 SELECT a, b FROM end;
143 CREATE TRIGGER xyz AFTER DELETE end BEGIN
144 SELECT a, b FROM end;
150 CREATE TRIGGER xyz AFTER DELETE end BEGIN
151 SELECT a, b FROM end;
153 SELECT a, b FROM end;
158 CREATE TRIGGER xyz AFTER DELETE [;end;] BEGIN
164 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
165 UPDATE cantor SET a=[;end;];;;
171 TRIGGER exy AFTER DELETE backend BEGIN
175 do_test main-1.27.1 {
178 TRIGGERX tangentxx AFTER DELETE backend BEGIN
182 do_test main-1.27.2 {
184 CREATE/**/TRIGGER tiger00 AFTER DELETE backend BEGIN
188 ifcapable {explain} {
189 do_test main-1.27.3 {
191 /* */ EXPLAIN -- A comment
192 CREATE/**/TRIGGER ezxyz12 AFTER DELETE backend BEGIN
197 do_test main-1.27.4 {
200 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
204 ifcapable {explain} {
205 do_test main-1.27.5 {
208 CREATE TEMP TRIGGER xyz AFTER DELETE backend BEGIN
215 CREATE TEMPORARY TRIGGER xyz AFTER DELETE backend BEGIN
221 CREATE TRIGGER xyz AFTER DELETE backend BEGIN
223 EXPLAIN select * from xyz;
227 } ;# end ifcapable {complete}
232 CREATE TABLE /* In comment ; */
237 CREATE TABLE /* In comment ; */ hi;
242 CREATE TABLE /* In comment ; */;
272 db complete {hi /**/ there;}
275 db complete {hi there/***/;}
278 db complete {hi there/**}
281 db complete {hi [there}
284 ifcapable {trigger} {
285 # Characters less than \040 can never be part of an identifier.
286 # Characters greater than \u177 are always identifier characters.
288 db complete "create \037\036\035\034trigger\001\002;"
291 db complete "create trigger\200;"
294 db complete "create \200trigger;"
299 # Try to open a database with a corrupt database file.
301 if {[permutation] == ""} {
305 set fd [open test.db w]
308 set v [catch {sqlite3 db test.db} msg]
309 if {$v} {lappend v $msg} {lappend v {}}
313 # Here are some tests for tokenize.c.
317 foreach f [glob -nocomplain testdb/*] {forcedelete $f}
320 set v [catch {execsql {SELECT * from T1 where x!!5}} msg]
322 } {1 {unrecognized token: "!"}}
325 foreach f [glob -nocomplain testdb/*] {forcedelete $f}
328 set v [catch {execsql {SELECT * from T1 where ^x}} msg]
330 } {1 {unrecognized token: "^"}}
332 catchsql {select 'abc}
333 } {1 {unrecognized token: "'abc"}}
335 catchsql {select "abc}
336 } {1 {unrecognized token: ""abc"}}
338 catchsql {select [abc}
339 } {1 {unrecognized token: "[abc"}}
341 catchsql {select x'4869}
342 } {1 {unrecognized token: "x'4869"}}
344 catchsql {select x'4869'}
347 catchsql {select x'48695'}
348 } {1 {unrecognized token: "x'48695'"}}
350 catchsql {select x'486x'}
351 } {1 {unrecognized token: "x'486x'"}}
353 catchsql {select $abc(}
354 } {1 {unrecognized token: "$abc("}}
355 do_test main-3.2.10 {
356 catchsql {select $abc(x}
357 } {1 {unrecognized token: "$abc(x"}}
359 do_test main-3.2.11 {
360 catchsql {select $::xyz}
362 namespace eval ::testnamespace {
365 do_test main-3.2.12 {
366 catchsql {select $testnamespace::xyz}
368 do_test main-3.2.13 {
369 catchsql {select $(abc)}
370 } {1 {unrecognized token: "$"}}
371 do_test main-3.2.14 {
373 db eval "select \$hi\u1234x"
375 do_test main-3.2.15 {
376 catchsql "select 456\u1234"
377 } [list 1 "unrecognized token: \"456\u1234\""]
378 do_test main-3.2.16 {
379 catchsql {select cast(3.14e+4 AS integer)}
381 do_test main-3.2.17 {
382 catchsql {select cast(3.14e+04 AS integer)}
384 do_test main-3.2.18 {
385 catchsql {select cast(3.14e+004 AS integer)}
387 do_test main-3.2.19 {
388 catchsql {select cast(3.14e4 AS integer)}
390 do_test main-3.2.20 {
391 catchsql {select cast(3.14e04 AS integer)}
393 do_test main-3.2.21 {
394 catchsql {select cast(3.14e004 AS integer)}
396 do_test main-3.2.16 {
397 catchsql {select cast(3.14E+4 AS integer)}
399 do_test main-3.2.17 {
400 catchsql {select cast(3.14E+04 AS integer)}
402 do_test main-3.2.18 {
403 catchsql {select cast(3.14E+004 AS integer)}
405 do_test main-3.2.19 {
406 catchsql {select cast(3.14E4 AS integer)}
408 do_test main-3.2.20 {
409 catchsql {select cast(3.14E04 AS integer)}
411 do_test main-3.2.21 {
412 catchsql {select cast(3.14E004 AS integer)}
414 do_test main-3.2.22 {
415 catchsql {select cast(3.14e-4 * 1e8 AS integer)}
417 do_test main-3.2.23 {
418 catchsql {select cast(3.14E-04 * 1E08 AS integer)}
420 do_test main-3.2.24 {
421 catchsql {select cast(3.14e-004 * 01.0E+8 AS integer)}
423 do_test main-3.2.25 {
424 catchsql {select 123/*abc}
426 do_test main-3.2.26 {
427 catchsql {select 123/***abc}
429 do_test main-3.2.27 {
430 catchsql {select 123/*/*2}
432 do_test main-3.2.28 {
433 catchsql {select 123/**/*2}
435 do_test main-3.2.29 {
436 catchsql {select 123/}
437 } {1 {incomplete input}}
438 do_test main-3.2.30 {
439 catchsql {select 123--5}
445 foreach f [glob -nocomplain testdb/*] {forcedelete $f}
449 create table T1(X REAL); /* C-style comments allowed */
450 insert into T1 values(0.5);
451 insert into T1 values(0.5e2);
452 insert into T1 values(0.5e-002);
453 insert into T1 values(5e-002);
454 insert into T1 values(-5.0e-2);
455 insert into T1 values(-5.1e-2);
456 insert into T1 values(0.5e2);
457 insert into T1 values(0.5E+02);
458 insert into T1 values(5E+02);
459 insert into T1 values(5.0E+03);
460 select x*10 from T1 order by x*5;
462 } {-0.51 -0.5 0.05 0.5 5.0 500.0 500.0 500.0 5000.0 50000.0}
464 set v [catch {execsql {create bogus}} msg]
466 } {1 {near "bogus": syntax error}}
468 set v [catch {execsql {create}} msg]
470 } {1 {incomplete input}}
472 catchsql {SELECT 'abc' + #9}
473 } {1 {near "#9": syntax error}}
475 # The following test-case tests the linked list code used to manage
476 # sqlite3_vfs structures.
477 if {$::tcl_platform(platform)=="unix"
478 && [info command sqlite3async_initialize]!=""} {
479 ifcapable threadsafe {
481 sqlite3_crash_enable 1
482 sqlite3_crash_enable 0
484 sqlite3async_initialize "" 1
485 sqlite3async_shutdown
487 sqlite3_crash_enable 1
488 sqlite3async_initialize "" 1
489 sqlite3_crash_enable 0
490 sqlite3async_shutdown
492 sqlite3_crash_enable 1
493 sqlite3async_initialize "" 1
494 sqlite3async_shutdown
495 sqlite3_crash_enable 0
497 sqlite3async_initialize "" 1
498 sqlite3_crash_enable 1
499 sqlite3_crash_enable 0
500 sqlite3async_shutdown
502 sqlite3async_initialize "" 1
503 sqlite3_crash_enable 1
504 sqlite3async_shutdown
505 sqlite3_crash_enable 0
508 set rc [catch {sqlite3 db test.db -vfs crash} msg]
510 } {1 {no such vfs: crash}}
512 set rc [catch {sqlite3 db test.db -vfs async} msg]
514 } {1 {no such vfs: async}}
518 # Print the version number so that it can be picked up by releasetest.tcl.
520 puts [db one {SELECT 'VERSION: ' ||
521 sqlite_version() || ' ' ||
522 sqlite_source_id();}]
524 # Do deliberate failures if the TEST_FAILURE environment variable is set.
525 # This is done to verify that failure notifications are detected by the
526 # releasetest.tcl script, or possibly by other scripts involved in automatic
529 if {[info exists ::env(TEST_FAILURE)]} {
531 if {$::env(TEST_FAILURE)==0} {set res 234}
533 bad_behavior $::env(TEST_FAILURE)