drh | b19a2bc | 2001-09-16 00:13:26 +0000 | [diff] [blame] | 1 | # 2001 September 15 |
drh | 960e8c6 | 2001-04-03 16:53:21 +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 | 960e8c6 | 2001-04-03 16:53:21 +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 | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 9 | # |
| 10 | #*********************************************************************** |
| 11 | # This file implements regression tests for TCL interface to the |
| 12 | # SQLite library. |
| 13 | # |
| 14 | # Actually, all tests are based on the TCL interface, so the main |
| 15 | # interface is pretty well tested. This file contains some addition |
| 16 | # tests for fringe issues that the main test suite does not cover. |
| 17 | # |
drh | 0f14e2e | 2004-06-29 12:39:08 +0000 | [diff] [blame^] | 18 | # $Id: tclsqlite.test,v 1.26 2004/06/29 12:39:08 drh Exp $ |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 19 | |
| 20 | set testdir [file dirname $argv0] |
| 21 | source $testdir/tester.tcl |
| 22 | |
| 23 | # Check the error messages generated by tclsqlite |
| 24 | # |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 25 | if {[sqlite3 -has-codec]} { |
drh | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame] | 26 | set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?" |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 27 | } else { |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 28 | set r "sqlite3 HANDLE FILENAME ?MODE?" |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 29 | } |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 30 | do_test tcl-1.1 { |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 31 | set v [catch {sqlite3 bogus} msg] |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 32 | lappend v $msg |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 33 | } [list 1 "wrong # args: should be \"$r\""] |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 34 | do_test tcl-1.2 { |
| 35 | set v [catch {db bogus} msg] |
| 36 | lappend v $msg |
drh | 0f14e2e | 2004-06-29 12:39:08 +0000 | [diff] [blame^] | 37 | } {1 {bad option "bogus": must be authorizer, busy, changes, close, collate, collation_needed, commit_hook, complete, errorcode, eval, function, last_insert_rowid, onecolumn, progress, rekey, timeout, total_changes, or trace}} |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 38 | do_test tcl-1.3 { |
| 39 | execsql {CREATE TABLE t1(a int, b int)} |
| 40 | execsql {INSERT INTO t1 VALUES(10,20)} |
| 41 | set v [catch { |
| 42 | db eval {SELECT * FROM t1} data { |
| 43 | error "The error message" |
| 44 | } |
| 45 | } msg] |
| 46 | lappend v $msg |
| 47 | } {1 {The error message}} |
| 48 | do_test tcl-1.4 { |
| 49 | set v [catch { |
| 50 | db eval {SELECT * FROM t2} data { |
| 51 | error "The error message" |
| 52 | } |
| 53 | } msg] |
| 54 | lappend v $msg |
| 55 | } {1 {no such table: t2}} |
| 56 | do_test tcl-1.5 { |
| 57 | set v [catch { |
| 58 | db eval {SELECT * FROM t1} data { |
| 59 | break |
| 60 | } |
| 61 | } msg] |
| 62 | lappend v $msg |
| 63 | } {0 {}} |
| 64 | do_test tcl-1.6 { |
| 65 | set v [catch { |
| 66 | db eval {SELECT * FROM t1} data { |
| 67 | expr x* |
| 68 | } |
| 69 | } msg] |
drh | a297b5c | 2002-01-15 18:39:43 +0000 | [diff] [blame] | 70 | regsub {:.*$} $msg {} msg |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 71 | lappend v $msg |
| 72 | } {1 {syntax error in expression "x*"}} |
drh | 0f14e2e | 2004-06-29 12:39:08 +0000 | [diff] [blame^] | 73 | do_test tcl-1.7 { |
| 74 | set v [catch {db} msg] |
| 75 | lappend v $msg |
| 76 | } {1 {wrong # args: should be "db SUBCOMMAND ..."}} |
| 77 | do_test tcl-1.8 { |
| 78 | set v [catch {db authorizer 1 2 3} msg] |
| 79 | lappend v $msg |
| 80 | } {1 {wrong # args: should be "db authorizer ?CALLBACK?"}} |
| 81 | do_test tcl-1.9 { |
| 82 | set v [catch {db busy 1 2 3} msg] |
| 83 | lappend v $msg |
| 84 | } {1 {wrong # args: should be "db busy CALLBACK"}} |
| 85 | do_test tcl-1.10 { |
| 86 | set v [catch {db progress 1} msg] |
| 87 | lappend v $msg |
| 88 | } {1 {wrong # args: should be "db progress N CALLBACK"}} |
| 89 | do_test tcl-1.11 { |
| 90 | set v [catch {db changes xyz} msg] |
| 91 | lappend v $msg |
| 92 | } {1 {wrong # args: should be "db changes "}} |
| 93 | do_test tcl-1.12 { |
| 94 | set v [catch {db commit_hook a b c} msg] |
| 95 | lappend v $msg |
| 96 | } {1 {wrong # args: should be "db commit_hook ?CALLBACK?"}} |
| 97 | do_test tcl-1.13 { |
| 98 | set v [catch {db complete} msg] |
| 99 | lappend v $msg |
| 100 | } {1 {wrong # args: should be "db complete SQL"}} |
| 101 | do_test tcl-1.14 { |
| 102 | set v [catch {db eval} msg] |
| 103 | lappend v $msg |
| 104 | } {1 {wrong # args: should be "db eval SQL ?ARRAY-NAME CODE?"}} |
| 105 | do_test tcl-1.15 { |
| 106 | set v [catch {db function} msg] |
| 107 | lappend v $msg |
| 108 | } {1 {wrong # args: should be "db function NAME SCRIPT"}} |
| 109 | do_test tcl-1.14 { |
| 110 | set v [catch {db last_insert_rowid xyz} msg] |
| 111 | lappend v $msg |
| 112 | } {1 {wrong # args: should be "db last_insert_rowid "}} |
| 113 | do_test tcl-1.15 { |
| 114 | set v [catch {db rekey} msg] |
| 115 | lappend v $msg |
| 116 | } {1 {wrong # args: should be "db rekey KEY"}} |
| 117 | do_test tcl-1.16 { |
| 118 | set v [catch {db timeout} msg] |
| 119 | lappend v $msg |
| 120 | } {1 {wrong # args: should be "db timeout MILLISECONDS"}} |
| 121 | do_test tcl-1.17 { |
| 122 | set v [catch {db collate} msg] |
| 123 | lappend v $msg |
| 124 | } {1 {wrong # args: should be "db collate NAME SCRIPT"}} |
| 125 | do_test tcl-1.18 { |
| 126 | set v [catch {db collation_needed} msg] |
| 127 | lappend v $msg |
| 128 | } {1 {wrong # args: should be "db collation_needed SCRIPT"}} |
| 129 | do_test tcl-1.19 { |
| 130 | set v [catch {db total_changes xyz} msg] |
| 131 | lappend v $msg |
| 132 | } {1 {wrong # args: should be "db total_changes "}} |
| 133 | |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 134 | |
drh | ef4ac8f | 2004-06-19 00:16:31 +0000 | [diff] [blame] | 135 | if {[sqlite3 -tcl-uses-utf]} { |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 136 | do_test tcl-2.1 { |
| 137 | execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)" |
| 138 | execsql "PRAGMA table_info(t\u0123x)" |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 139 | } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0" |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 140 | do_test tcl-2.2 { |
| 141 | execsql "INSERT INTO t\u0123x VALUES(1,2.3)" |
| 142 | db eval "SELECT * FROM t\u0123x" result break |
| 143 | set result(*) |
| 144 | } "a b\u1235" |
| 145 | } |
| 146 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 147 | |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame] | 148 | # Test the onecolumn method |
| 149 | # |
| 150 | do_test tcl-3.1 { |
| 151 | execsql { |
| 152 | INSERT INTO t1 SELECT a*2, b*2 FROM t1; |
| 153 | INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1; |
| 154 | INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1; |
| 155 | } |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 156 | set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg] |
| 157 | lappend rc $msg |
| 158 | } {0 10} |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame] | 159 | do_test tcl-3.2 { |
| 160 | db onecolumn {SELECT * FROM t1 WHERE a<0} |
| 161 | } {} |
| 162 | do_test tcl-3.3 { |
| 163 | set rc [catch {db onecolumn} errmsg] |
| 164 | lappend rc $errmsg |
| 165 | } {1 {wrong # args: should be "db onecolumn SQL"}} |
drh | 0f14e2e | 2004-06-29 12:39:08 +0000 | [diff] [blame^] | 166 | do_test tcl-3.4 { |
| 167 | set rc [catch {db onecolumn {SELECT bogus}} errmsg] |
| 168 | lappend rc $errmsg |
| 169 | } {1 {no such column: bogus}} |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame] | 170 | |
drh | 0f14e2e | 2004-06-29 12:39:08 +0000 | [diff] [blame^] | 171 | # Turn the busy handler on and off |
| 172 | # |
| 173 | do_test tcl-4.1 { |
| 174 | proc busy_callback {cnt} { |
| 175 | break |
| 176 | } |
| 177 | db busy busy_callback |
| 178 | db busy |
| 179 | } {busy_callback} |
| 180 | do_test tcl-4.2 { |
| 181 | db busy {} |
| 182 | db busy |
| 183 | } {} |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 184 | |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 185 | finish_test |