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 | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame^] | 18 | # $Id: tclsqlite.test,v 1.19 2004/02/11 02:18:07 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 | 9eb9e26 | 2004-02-11 02:18:05 +0000 | [diff] [blame^] | 25 | if {[sqlite -has-codec]} { |
| 26 | set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?" |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 27 | } else { |
| 28 | set r "sqlite HANDLE FILENAME ?MODE?" |
| 29 | } |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 30 | do_test tcl-1.1 { |
| 31 | set v [catch {sqlite bogus} msg] |
| 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 | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 37 | } {1 {bad option "bogus": must be authorizer, busy, changes, close, commit_hook, complete, errorcode, eval, function, last_insert_rowid, onecolumn, progress, rekey, timeout, 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*"}} |
| 73 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 74 | if {[sqlite -encoding]=="UTF-8" && [sqlite -tcl-uses-utf]} { |
| 75 | do_test tcl-2.1 { |
| 76 | execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)" |
| 77 | execsql "PRAGMA table_info(t\u0123x)" |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 78 | } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0" |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 79 | do_test tcl-2.2 { |
| 80 | execsql "INSERT INTO t\u0123x VALUES(1,2.3)" |
| 81 | db eval "SELECT * FROM t\u0123x" result break |
| 82 | set result(*) |
| 83 | } "a b\u1235" |
| 84 | } |
| 85 | |
| 86 | if {[sqlite -encoding]=="iso8859" && [sqlite -tcl-uses-utf]} { |
| 87 | do_test tcl-2.1 { |
| 88 | execsql "CREATE TABLE t\251x(a int, b\306 float)" |
| 89 | execsql "PRAGMA table_info(t\251x)" |
drh | 78100cc | 2003-08-23 22:40:53 +0000 | [diff] [blame] | 90 | } "0 a int 0 {} 0 1 b\306 float 0 {} 0" |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 91 | do_test tcl-2.2 { |
| 92 | execsql "INSERT INTO t\251x VALUES(1,2.3)" |
| 93 | db eval "SELECT * FROM t\251x" result break |
| 94 | set result(*) |
| 95 | } "a b\306" |
| 96 | } |
| 97 | |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame] | 98 | # Test the onecolumn method |
| 99 | # |
| 100 | do_test tcl-3.1 { |
| 101 | execsql { |
| 102 | INSERT INTO t1 SELECT a*2, b*2 FROM t1; |
| 103 | INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1; |
| 104 | INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1; |
| 105 | } |
drh | 22fbcb8 | 2004-02-01 01:22:50 +0000 | [diff] [blame] | 106 | set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg] |
| 107 | lappend rc $msg |
| 108 | } {0 10} |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame] | 109 | do_test tcl-3.2 { |
| 110 | db onecolumn {SELECT * FROM t1 WHERE a<0} |
| 111 | } {} |
| 112 | do_test tcl-3.3 { |
| 113 | set rc [catch {db onecolumn} errmsg] |
| 114 | lappend rc $errmsg |
| 115 | } {1 {wrong # args: should be "db onecolumn SQL"}} |
| 116 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 117 | |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 118 | finish_test |