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