drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 2 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 5 | # |
drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 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. |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this file is exercising the code in main.c. |
| 13 | # |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 14 | # $Id: main.test,v 1.10 2002/05/10 13:14:08 drh Exp $ |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 15 | |
| 16 | set testdir [file dirname $argv0] |
| 17 | source $testdir/tester.tcl |
| 18 | |
| 19 | # Tests of the sqlite_complete() function. |
| 20 | # |
| 21 | do_test main-1.1 { |
| 22 | db complete {This is a test} |
| 23 | } {0} |
| 24 | do_test main-1.2 { |
| 25 | db complete { |
| 26 | } |
| 27 | } {0} |
| 28 | do_test main-1.3 { |
| 29 | db complete { |
| 30 | -- a comment ; |
| 31 | } |
| 32 | } {0} |
| 33 | do_test main-1.4 { |
| 34 | db complete { |
| 35 | -- a comment ; |
| 36 | ; |
| 37 | } |
| 38 | } {1} |
drh | 8c82b35 | 2000-12-10 18:23:50 +0000 | [diff] [blame] | 39 | do_test main-1.5 { |
| 40 | db complete {DROP TABLE 'xyz;} |
| 41 | } {0} |
| 42 | do_test main-1.6 { |
| 43 | db complete {DROP TABLE 'xyz';} |
| 44 | } {1} |
| 45 | do_test main-1.7 { |
| 46 | db complete {DROP TABLE "xyz;} |
| 47 | } {0} |
| 48 | do_test main-1.8 { |
| 49 | db complete {DROP TABLE "xyz';} |
| 50 | } {0} |
| 51 | do_test main-1.9 { |
| 52 | db complete {DROP TABLE "xyz";} |
| 53 | } {1} |
| 54 | do_test main-1.10 { |
| 55 | db complete {DROP TABLE xyz; hi} |
| 56 | } {0} |
| 57 | do_test main-1.11 { |
| 58 | db complete {DROP TABLE xyz; } |
| 59 | } {1} |
| 60 | do_test main-1.12 { |
| 61 | db complete {DROP TABLE xyz; -- hi } |
| 62 | } {1} |
| 63 | do_test main-1.13 { |
| 64 | db complete {DROP TABLE xyz; -- hi |
| 65 | } |
| 66 | } {1} |
drh | c4a3c77 | 2001-04-04 11:48:57 +0000 | [diff] [blame] | 67 | do_test main-1.14 { |
| 68 | db complete {SELECT a-b FROM t1; } |
| 69 | } {1} |
| 70 | do_test main-1.15 { |
| 71 | db complete {SELECT a-b FROM t1 } |
| 72 | } {0} |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 73 | |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 74 | # Try to open a database with a corrupt database file. |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 75 | # |
| 76 | do_test main-2.0 { |
| 77 | catch {db close} |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 78 | file delete -force test.db |
| 79 | set fd [open test.db w] |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 80 | puts $fd hi! |
| 81 | close $fd |
drh | 3fc190c | 2001-09-14 03:24:23 +0000 | [diff] [blame] | 82 | set v [catch {sqlite db test.db} msg] |
drh | c22bd47 | 2002-05-10 13:14:07 +0000 | [diff] [blame] | 83 | if {$v} {lappend v $msg} {lappend v {}} |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 84 | } {0 {}} |
| 85 | |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 86 | # Here are some tests for tokenize.c. |
| 87 | # |
| 88 | do_test main-3.1 { |
| 89 | catch {db close} |
drh | 3494ffe | 2001-03-20 12:55:13 +0000 | [diff] [blame] | 90 | foreach f [glob -nocomplain testdb/*] {file delete -force $f} |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 91 | file delete -force testdb |
| 92 | sqlite db testdb |
| 93 | set v [catch {execsql {SELECT * from T1 where x!!5}} msg] |
| 94 | lappend v $msg |
| 95 | } {1 {unrecognized token: "!!"}} |
| 96 | do_test main-3.2 { |
| 97 | catch {db close} |
drh | 3494ffe | 2001-03-20 12:55:13 +0000 | [diff] [blame] | 98 | foreach f [glob -nocomplain testdb/*] {file delete -force $f} |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 99 | file delete -force testdb |
| 100 | sqlite db testdb |
drh | bf4133c | 2001-10-13 02:59:08 +0000 | [diff] [blame] | 101 | set v [catch {execsql {SELECT * from T1 where @x}} msg] |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 102 | lappend v $msg |
drh | bf4133c | 2001-10-13 02:59:08 +0000 | [diff] [blame] | 103 | } {1 {unrecognized token: "@"}} |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 104 | |
| 105 | do_test main-3.3 { |
| 106 | catch {db close} |
drh | 3494ffe | 2001-03-20 12:55:13 +0000 | [diff] [blame] | 107 | foreach f [glob -nocomplain testdb/*] {file delete -force $f} |
drh | c837e70 | 2000-06-08 16:26:24 +0000 | [diff] [blame] | 108 | file delete -force testdb |
| 109 | sqlite db testdb |
| 110 | execsql { |
| 111 | create table T1(X REAL); |
| 112 | insert into T1 values(.5); |
| 113 | insert into T1 values(0.5e2); |
| 114 | insert into T1 values(0.5e-002); |
| 115 | insert into T1 values(5e-002); |
| 116 | insert into T1 values(-5.0e-2); |
| 117 | insert into T1 values(-5.1e-2); |
| 118 | insert into T1 values(.5e2); |
| 119 | insert into T1 values(.5E+02); |
| 120 | insert into T1 values(5E+02); |
| 121 | insert into T1 values(5.E+03); |
| 122 | select x*10 from T1 order by x*5; |
| 123 | } |
| 124 | } {-0.51 -0.5 0.05 0.5 5 500 500 500 5000 50000} |
| 125 | do_test main-3.4 { |
| 126 | set v [catch {execsql {create bogus}} msg] |
| 127 | lappend v $msg |
| 128 | } {1 {near "bogus": syntax error}} |
| 129 | do_test main-3.5 { |
| 130 | set v [catch {execsql {create}} msg] |
| 131 | lappend v $msg |
| 132 | } {1 {near "create": syntax error}} |
| 133 | |
drh | cc85b41 | 2000-06-07 15:11:27 +0000 | [diff] [blame] | 134 | finish_test |