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 | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame^] | 18 | # $Id: tclsqlite.test,v 1.14 2003/08/19 14:31:02 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 | # |
| 25 | do_test tcl-1.1 { |
| 26 | set v [catch {sqlite bogus} msg] |
| 27 | lappend v $msg |
| 28 | } {1 {wrong # args: should be "sqlite HANDLE FILENAME ?MODE?"}} |
| 29 | do_test tcl-1.2 { |
| 30 | set v [catch {db bogus} msg] |
| 31 | lappend v $msg |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame^] | 32 | } {1 {bad option "bogus": must be authorizer, busy, changes, close, complete, errorcode, eval, function, last_insert_rowid, onecolumn, timeout, or trace}} |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 33 | do_test tcl-1.3 { |
| 34 | execsql {CREATE TABLE t1(a int, b int)} |
| 35 | execsql {INSERT INTO t1 VALUES(10,20)} |
| 36 | set v [catch { |
| 37 | db eval {SELECT * FROM t1} data { |
| 38 | error "The error message" |
| 39 | } |
| 40 | } msg] |
| 41 | lappend v $msg |
| 42 | } {1 {The error message}} |
| 43 | do_test tcl-1.4 { |
| 44 | set v [catch { |
| 45 | db eval {SELECT * FROM t2} data { |
| 46 | error "The error message" |
| 47 | } |
| 48 | } msg] |
| 49 | lappend v $msg |
| 50 | } {1 {no such table: t2}} |
| 51 | do_test tcl-1.5 { |
| 52 | set v [catch { |
| 53 | db eval {SELECT * FROM t1} data { |
| 54 | break |
| 55 | } |
| 56 | } msg] |
| 57 | lappend v $msg |
| 58 | } {0 {}} |
| 59 | do_test tcl-1.6 { |
| 60 | set v [catch { |
| 61 | db eval {SELECT * FROM t1} data { |
| 62 | expr x* |
| 63 | } |
| 64 | } msg] |
drh | a297b5c | 2002-01-15 18:39:43 +0000 | [diff] [blame] | 65 | regsub {:.*$} $msg {} msg |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 66 | lappend v $msg |
| 67 | } {1 {syntax error in expression "x*"}} |
| 68 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 69 | if {[sqlite -encoding]=="UTF-8" && [sqlite -tcl-uses-utf]} { |
| 70 | do_test tcl-2.1 { |
| 71 | execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)" |
| 72 | execsql "PRAGMA table_info(t\u0123x)" |
| 73 | } "0 a int 0 {} 1 b\u1235 float 0 {}" |
| 74 | do_test tcl-2.2 { |
| 75 | execsql "INSERT INTO t\u0123x VALUES(1,2.3)" |
| 76 | db eval "SELECT * FROM t\u0123x" result break |
| 77 | set result(*) |
| 78 | } "a b\u1235" |
| 79 | } |
| 80 | |
| 81 | if {[sqlite -encoding]=="iso8859" && [sqlite -tcl-uses-utf]} { |
| 82 | do_test tcl-2.1 { |
| 83 | execsql "CREATE TABLE t\251x(a int, b\306 float)" |
| 84 | execsql "PRAGMA table_info(t\251x)" |
| 85 | } "0 a int 0 {} 1 b\306 float 0 {}" |
| 86 | do_test tcl-2.2 { |
| 87 | execsql "INSERT INTO t\251x VALUES(1,2.3)" |
| 88 | db eval "SELECT * FROM t\251x" result break |
| 89 | set result(*) |
| 90 | } "a b\306" |
| 91 | } |
| 92 | |
drh | 5d9d757 | 2003-08-19 14:31:01 +0000 | [diff] [blame^] | 93 | # Test the onecolumn method |
| 94 | # |
| 95 | do_test tcl-3.1 { |
| 96 | execsql { |
| 97 | INSERT INTO t1 SELECT a*2, b*2 FROM t1; |
| 98 | INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1; |
| 99 | INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1; |
| 100 | } |
| 101 | db onecolumn {SELECT * FROM t1 ORDER BY a} |
| 102 | } {10} |
| 103 | do_test tcl-3.2 { |
| 104 | db onecolumn {SELECT * FROM t1 WHERE a<0} |
| 105 | } {} |
| 106 | do_test tcl-3.3 { |
| 107 | set rc [catch {db onecolumn} errmsg] |
| 108 | lappend rc $errmsg |
| 109 | } {1 {wrong # args: should be "db onecolumn SQL"}} |
| 110 | |
drh | 6d4abfb | 2001-10-22 02:58:08 +0000 | [diff] [blame] | 111 | |
drh | 960e8c6 | 2001-04-03 16:53:21 +0000 | [diff] [blame] | 112 | finish_test |