xref: /sqlite-3.40.0/test/tclsqlite.test (revision ef4ac8f9)
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*ef4ac8f9Sdrh# $Id: tclsqlite.test,v 1.24 2004/06/19 00:16:31 drh Exp $
19960e8c63Sdrh
20960e8c63Sdrhset testdir [file dirname $argv0]
21960e8c63Sdrhsource $testdir/tester.tcl
22960e8c63Sdrh
23960e8c63Sdrh# Check the error messages generated by tclsqlite
24960e8c63Sdrh#
25*ef4ac8f9Sdrhif {[sqlite3 -has-codec]} {
269eb9e26bSdrh  set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
2722fbcb8dSdrh} else {
28*ef4ac8f9Sdrh  set r "sqlite3 HANDLE FILENAME ?MODE?"
2922fbcb8dSdrh}
30960e8c63Sdrhdo_test tcl-1.1 {
31*ef4ac8f9Sdrh  set v [catch {sqlite3 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
37d2b65b9fSdanielk1977} {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}}
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
74*ef4ac8f9Sdrhif {[sqlite3 -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
866d4abfbeSdrh
875d9d7576Sdrh# Test the onecolumn method
885d9d7576Sdrh#
895d9d7576Sdrhdo_test tcl-3.1 {
905d9d7576Sdrh  execsql {
915d9d7576Sdrh    INSERT INTO t1 SELECT a*2, b*2 FROM t1;
925d9d7576Sdrh    INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1;
935d9d7576Sdrh    INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1;
945d9d7576Sdrh  }
9522fbcb8dSdrh  set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
9622fbcb8dSdrh  lappend rc $msg
9722fbcb8dSdrh} {0 10}
985d9d7576Sdrhdo_test tcl-3.2 {
995d9d7576Sdrh  db onecolumn {SELECT * FROM t1 WHERE a<0}
1005d9d7576Sdrh} {}
1015d9d7576Sdrhdo_test tcl-3.3 {
1025d9d7576Sdrh  set rc [catch {db onecolumn} errmsg]
1035d9d7576Sdrh  lappend rc $errmsg
1045d9d7576Sdrh} {1 {wrong # args: should be "db onecolumn SQL"}}
1055d9d7576Sdrh
1066d4abfbeSdrh
107960e8c63Sdrhfinish_test
108