sqlite/test/tclsqlite.test
drh ef4ac8f9df Change the name of the TCL command from "sqlite" to "sqlite3" so that both
SQLite version 2 and SQLite version 3 can be used by Tcl at the same time. (CVS 1626)

FossilOrigin-Name: d705d051bed2b92b6c3bbcc75fe5b056633b9c31
2004-06-19 00:16:31 +00:00

108 lines
2.9 KiB
Plaintext

# 2001 September 15
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for TCL interface to the
# SQLite library.
#
# Actually, all tests are based on the TCL interface, so the main
# interface is pretty well tested. This file contains some addition
# tests for fringe issues that the main test suite does not cover.
#
# $Id: tclsqlite.test,v 1.24 2004/06/19 00:16:31 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Check the error messages generated by tclsqlite
#
if {[sqlite3 -has-codec]} {
set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
} else {
set r "sqlite3 HANDLE FILENAME ?MODE?"
}
do_test tcl-1.1 {
set v [catch {sqlite3 bogus} msg]
lappend v $msg
} [list 1 "wrong # args: should be \"$r\""]
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
} {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}}
do_test tcl-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {INSERT INTO t1 VALUES(10,20)}
set v [catch {
db eval {SELECT * FROM t1} data {
error "The error message"
}
} msg]
lappend v $msg
} {1 {The error message}}
do_test tcl-1.4 {
set v [catch {
db eval {SELECT * FROM t2} data {
error "The error message"
}
} msg]
lappend v $msg
} {1 {no such table: t2}}
do_test tcl-1.5 {
set v [catch {
db eval {SELECT * FROM t1} data {
break
}
} msg]
lappend v $msg
} {0 {}}
do_test tcl-1.6 {
set v [catch {
db eval {SELECT * FROM t1} data {
expr x*
}
} msg]
regsub {:.*$} $msg {} msg
lappend v $msg
} {1 {syntax error in expression "x*"}}
if {[sqlite3 -tcl-uses-utf]} {
do_test tcl-2.1 {
execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
execsql "PRAGMA table_info(t\u0123x)"
} "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
do_test tcl-2.2 {
execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
db eval "SELECT * FROM t\u0123x" result break
set result(*)
} "a b\u1235"
}
# Test the onecolumn method
#
do_test tcl-3.1 {
execsql {
INSERT INTO t1 SELECT a*2, b*2 FROM t1;
INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1;
INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1;
}
set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg]
lappend rc $msg
} {0 10}
do_test tcl-3.2 {
db onecolumn {SELECT * FROM t1 WHERE a<0}
} {}
do_test tcl-3.3 {
set rc [catch {db onecolumn} errmsg]
lappend rc $errmsg
} {1 {wrong # args: should be "db onecolumn SQL"}}
finish_test