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