blob: 2920d97d0dffe670cf3f3a0a7a02e78513849e9e [file] [log] [blame]
drhb19a2bc2001-09-16 00:13:26 +00001# 2001 September 15
drh960e8c62001-04-03 16:53:21 +00002#
drhb19a2bc2001-09-16 00:13:26 +00003# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
drh960e8c62001-04-03 16:53:21 +00005#
drhb19a2bc2001-09-16 00:13:26 +00006# 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.
drh960e8c62001-04-03 16:53:21 +00009#
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#
drhef4ac8f2004-06-19 00:16:31 +000018# $Id: tclsqlite.test,v 1.24 2004/06/19 00:16:31 drh Exp $
drh960e8c62001-04-03 16:53:21 +000019
20set testdir [file dirname $argv0]
21source $testdir/tester.tcl
22
23# Check the error messages generated by tclsqlite
24#
drhef4ac8f2004-06-19 00:16:31 +000025if {[sqlite3 -has-codec]} {
drh9eb9e262004-02-11 02:18:05 +000026 set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
drh22fbcb82004-02-01 01:22:50 +000027} else {
drhef4ac8f2004-06-19 00:16:31 +000028 set r "sqlite3 HANDLE FILENAME ?MODE?"
drh22fbcb82004-02-01 01:22:50 +000029}
drh960e8c62001-04-03 16:53:21 +000030do_test tcl-1.1 {
drhef4ac8f2004-06-19 00:16:31 +000031 set v [catch {sqlite3 bogus} msg]
drh960e8c62001-04-03 16:53:21 +000032 lappend v $msg
drh22fbcb82004-02-01 01:22:50 +000033} [list 1 "wrong # args: should be \"$r\""]
drh960e8c62001-04-03 16:53:21 +000034do_test tcl-1.2 {
35 set v [catch {db bogus} msg]
36 lappend v $msg
danielk1977d2b65b92004-06-10 10:51:47 +000037} {1 {bad option "bogus": must be authorizer, busy, changes, close, commit_hook, complete, errorcode, eval, function, last_insert_rowid, last_statement_changes, onecolumn, progress, rekey, timeout, trace, collate, or collation_needed}}
drh960e8c62001-04-03 16:53:21 +000038do_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}}
48do_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}}
56do_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 {}}
64do_test tcl-1.6 {
65 set v [catch {
66 db eval {SELECT * FROM t1} data {
67 expr x*
68 }
69 } msg]
drha297b5c2002-01-15 18:39:43 +000070 regsub {:.*$} $msg {} msg
drh960e8c62001-04-03 16:53:21 +000071 lappend v $msg
72} {1 {syntax error in expression "x*"}}
73
drhef4ac8f2004-06-19 00:16:31 +000074if {[sqlite3 -tcl-uses-utf]} {
drh6d4abfb2001-10-22 02:58:08 +000075 do_test tcl-2.1 {
76 execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
77 execsql "PRAGMA table_info(t\u0123x)"
drh78100cc2003-08-23 22:40:53 +000078 } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
drh6d4abfb2001-10-22 02:58:08 +000079 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
drh6d4abfb2001-10-22 02:58:08 +000086
drh5d9d7572003-08-19 14:31:01 +000087# Test the onecolumn method
88#
89do_test tcl-3.1 {
90 execsql {
91 INSERT INTO t1 SELECT a*2, b*2 FROM t1;
92 INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1;
93 INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1;
94 }
drh22fbcb82004-02-01 01:22:50 +000095 set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
96 lappend rc $msg
97} {0 10}
drh5d9d7572003-08-19 14:31:01 +000098do_test tcl-3.2 {
99 db onecolumn {SELECT * FROM t1 WHERE a<0}
100} {}
101do_test tcl-3.3 {
102 set rc [catch {db onecolumn} errmsg]
103 lappend rc $errmsg
104} {1 {wrong # args: should be "db onecolumn SQL"}}
105
drh6d4abfb2001-10-22 02:58:08 +0000106
drh960e8c62001-04-03 16:53:21 +0000107finish_test