xref: /sqlite-3.40.0/test/tclsqlite.test (revision f146a776)
1b19a2bc6Sdrh# 2001 September 15
2960e8c63Sdrh#
3b19a2bc6Sdrh# The author disclaims copyright to this source code.  In place of
4b19a2bc6Sdrh# a legal notice, here is a blessing:
5960e8c63Sdrh#
6b19a2bc6Sdrh#    May you do good and not evil.
7b19a2bc6Sdrh#    May you find forgiveness for yourself and forgive others.
8b19a2bc6Sdrh#    May you share freely, never taking more than you give.
9960e8c63Sdrh#
10960e8c63Sdrh#***********************************************************************
11960e8c63Sdrh# This file implements regression tests for TCL interface to the
12960e8c63Sdrh# SQLite library.
13960e8c63Sdrh#
14960e8c63Sdrh# Actually, all tests are based on the TCL interface, so the main
15960e8c63Sdrh# interface is pretty well tested.  This file contains some addition
16960e8c63Sdrh# tests for fringe issues that the main test suite does not cover.
17960e8c63Sdrh#
18*f146a776Srdc# $Id: tclsqlite.test,v 1.20 2004/02/25 22:51:06 rdc Exp $
19960e8c63Sdrh
20960e8c63Sdrhset testdir [file dirname $argv0]
21960e8c63Sdrhsource $testdir/tester.tcl
22960e8c63Sdrh
23960e8c63Sdrh# Check the error messages generated by tclsqlite
24960e8c63Sdrh#
259eb9e26bSdrhif {[sqlite -has-codec]} {
269eb9e26bSdrh  set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
2722fbcb8dSdrh} else {
2822fbcb8dSdrh  set r "sqlite HANDLE FILENAME ?MODE?"
2922fbcb8dSdrh}
30960e8c63Sdrhdo_test tcl-1.1 {
31960e8c63Sdrh  set v [catch {sqlite bogus} msg]
32960e8c63Sdrh  lappend v $msg
3322fbcb8dSdrh} [list 1 "wrong # args: should be \"$r\""]
34960e8c63Sdrhdo_test tcl-1.2 {
35960e8c63Sdrh  set v [catch {db bogus} msg]
36960e8c63Sdrh  lappend v $msg
37*f146a776Srdc} {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, or trace}}
38960e8c63Sdrhdo_test tcl-1.3 {
39960e8c63Sdrh  execsql {CREATE TABLE t1(a int, b int)}
40960e8c63Sdrh  execsql {INSERT INTO t1 VALUES(10,20)}
41960e8c63Sdrh  set v [catch {
42960e8c63Sdrh    db eval {SELECT * FROM t1} data {
43960e8c63Sdrh      error "The error message"
44960e8c63Sdrh    }
45960e8c63Sdrh  } msg]
46960e8c63Sdrh  lappend v $msg
47960e8c63Sdrh} {1 {The error message}}
48960e8c63Sdrhdo_test tcl-1.4 {
49960e8c63Sdrh  set v [catch {
50960e8c63Sdrh    db eval {SELECT * FROM t2} data {
51960e8c63Sdrh      error "The error message"
52960e8c63Sdrh    }
53960e8c63Sdrh  } msg]
54960e8c63Sdrh  lappend v $msg
55960e8c63Sdrh} {1 {no such table: t2}}
56960e8c63Sdrhdo_test tcl-1.5 {
57960e8c63Sdrh  set v [catch {
58960e8c63Sdrh    db eval {SELECT * FROM t1} data {
59960e8c63Sdrh      break
60960e8c63Sdrh    }
61960e8c63Sdrh  } msg]
62960e8c63Sdrh  lappend v $msg
63960e8c63Sdrh} {0 {}}
64960e8c63Sdrhdo_test tcl-1.6 {
65960e8c63Sdrh  set v [catch {
66960e8c63Sdrh    db eval {SELECT * FROM t1} data {
67960e8c63Sdrh      expr x*
68960e8c63Sdrh    }
69960e8c63Sdrh  } msg]
70a297b5c3Sdrh  regsub {:.*$} $msg {} msg
71960e8c63Sdrh  lappend v $msg
72960e8c63Sdrh} {1 {syntax error in expression "x*"}}
73960e8c63Sdrh
746d4abfbeSdrhif {[sqlite -encoding]=="UTF-8" && [sqlite -tcl-uses-utf]} {
756d4abfbeSdrh  do_test tcl-2.1 {
766d4abfbeSdrh    execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
776d4abfbeSdrh    execsql "PRAGMA table_info(t\u0123x)"
7878100cc9Sdrh  } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
796d4abfbeSdrh  do_test tcl-2.2 {
806d4abfbeSdrh    execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
816d4abfbeSdrh    db eval "SELECT * FROM t\u0123x" result break
826d4abfbeSdrh    set result(*)
836d4abfbeSdrh  } "a b\u1235"
846d4abfbeSdrh}
856d4abfbeSdrh
866d4abfbeSdrhif {[sqlite -encoding]=="iso8859" && [sqlite -tcl-uses-utf]} {
876d4abfbeSdrh  do_test tcl-2.1 {
886d4abfbeSdrh    execsql "CREATE TABLE t\251x(a int, b\306 float)"
896d4abfbeSdrh    execsql "PRAGMA table_info(t\251x)"
9078100cc9Sdrh  } "0 a int 0 {} 0 1 b\306 float 0 {} 0"
916d4abfbeSdrh  do_test tcl-2.2 {
926d4abfbeSdrh    execsql "INSERT INTO t\251x VALUES(1,2.3)"
936d4abfbeSdrh    db eval "SELECT * FROM t\251x" result break
946d4abfbeSdrh    set result(*)
956d4abfbeSdrh  } "a b\306"
966d4abfbeSdrh}
976d4abfbeSdrh
985d9d7576Sdrh# Test the onecolumn method
995d9d7576Sdrh#
1005d9d7576Sdrhdo_test tcl-3.1 {
1015d9d7576Sdrh  execsql {
1025d9d7576Sdrh    INSERT INTO t1 SELECT a*2, b*2 FROM t1;
1035d9d7576Sdrh    INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1;
1045d9d7576Sdrh    INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1;
1055d9d7576Sdrh  }
10622fbcb8dSdrh  set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
10722fbcb8dSdrh  lappend rc $msg
10822fbcb8dSdrh} {0 10}
1095d9d7576Sdrhdo_test tcl-3.2 {
1105d9d7576Sdrh  db onecolumn {SELECT * FROM t1 WHERE a<0}
1115d9d7576Sdrh} {}
1125d9d7576Sdrhdo_test tcl-3.3 {
1135d9d7576Sdrh  set rc [catch {db onecolumn} errmsg]
1145d9d7576Sdrh  lappend rc $errmsg
1155d9d7576Sdrh} {1 {wrong # args: should be "db onecolumn SQL"}}
1165d9d7576Sdrh
1176d4abfbeSdrh
118960e8c63Sdrhfinish_test
119