xref: /sqlite-3.40.0/test/tclsqlite.test (revision ef5ecb41)
1# 2001 September 15
2#
3# The author disclaims copyright to this source code.  In place of
4# a legal notice, here is a blessing:
5#
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.
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#
18# $Id: tclsqlite.test,v 1.23 2004/06/10 10:51:53 danielk1977 Exp $
19
20set testdir [file dirname $argv0]
21source $testdir/tester.tcl
22
23# Check the error messages generated by tclsqlite
24#
25if {[sqlite -has-codec]} {
26  set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
27} else {
28  set r "sqlite HANDLE FILENAME ?MODE?"
29}
30do_test tcl-1.1 {
31  set v [catch {sqlite bogus} msg]
32  lappend v $msg
33} [list 1 "wrong # args: should be \"$r\""]
34do_test tcl-1.2 {
35  set v [catch {db bogus} msg]
36  lappend v $msg
37} {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}}
38do_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]
70  regsub {:.*$} $msg {} msg
71  lappend v $msg
72} {1 {syntax error in expression "x*"}}
73
74if {[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)"
78  } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
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
87# 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  }
95  set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
96  lappend rc $msg
97} {0 10}
98do_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
106
107finish_test
108