sqlite/test/tclsqlite.test
drh 1211de3709 Fix problems for 64-bit machines and when SQLITE_OMIT_AUTHORIZATION is defined. (CVS 1868)
FossilOrigin-Name: e3cad1ab6226089265b4d15c6fc67cc33a31425f
2004-07-26 12:24:22 +00:00

189 lines
5.1 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.28 2004/07/26 12:24:24 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, collate, collation_needed, commit_hook, complete, errorcode, eval, function, last_insert_rowid, onecolumn, progress, rekey, timeout, total_changes, or trace}}
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*"}}
do_test tcl-1.7 {
set v [catch {db} msg]
lappend v $msg
} {1 {wrong # args: should be "db SUBCOMMAND ..."}}
if {[catch {db auth {}}]==0} {
do_test tcl-1.8 {
set v [catch {db authorizer 1 2 3} msg]
lappend v $msg
} {1 {wrong # args: should be "db authorizer ?CALLBACK?"}}
}
do_test tcl-1.9 {
set v [catch {db busy 1 2 3} msg]
lappend v $msg
} {1 {wrong # args: should be "db busy CALLBACK"}}
do_test tcl-1.10 {
set v [catch {db progress 1} msg]
lappend v $msg
} {1 {wrong # args: should be "db progress N CALLBACK"}}
do_test tcl-1.11 {
set v [catch {db changes xyz} msg]
lappend v $msg
} {1 {wrong # args: should be "db changes "}}
do_test tcl-1.12 {
set v [catch {db commit_hook a b c} msg]
lappend v $msg
} {1 {wrong # args: should be "db commit_hook ?CALLBACK?"}}
do_test tcl-1.13 {
set v [catch {db complete} msg]
lappend v $msg
} {1 {wrong # args: should be "db complete SQL"}}
do_test tcl-1.14 {
set v [catch {db eval} msg]
lappend v $msg
} {1 {wrong # args: should be "db eval SQL ?ARRAY-NAME CODE?"}}
do_test tcl-1.15 {
set v [catch {db function} msg]
lappend v $msg
} {1 {wrong # args: should be "db function NAME SCRIPT"}}
do_test tcl-1.14 {
set v [catch {db last_insert_rowid xyz} msg]
lappend v $msg
} {1 {wrong # args: should be "db last_insert_rowid "}}
do_test tcl-1.15 {
set v [catch {db rekey} msg]
lappend v $msg
} {1 {wrong # args: should be "db rekey KEY"}}
do_test tcl-1.16 {
set v [catch {db timeout} msg]
lappend v $msg
} {1 {wrong # args: should be "db timeout MILLISECONDS"}}
do_test tcl-1.17 {
set v [catch {db collate} msg]
lappend v $msg
} {1 {wrong # args: should be "db collate NAME SCRIPT"}}
do_test tcl-1.18 {
set v [catch {db collation_needed} msg]
lappend v $msg
} {1 {wrong # args: should be "db collation_needed SCRIPT"}}
do_test tcl-1.19 {
set v [catch {db total_changes xyz} msg]
lappend v $msg
} {1 {wrong # args: should be "db total_changes "}}
if {[sqlite3 -tcl-uses-utf]} {
catch {unset ::result}
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"}}
do_test tcl-3.4 {
set rc [catch {db onecolumn {SELECT bogus}} errmsg]
lappend rc $errmsg
} {1 {no such column: bogus}}
# Turn the busy handler on and off
#
do_test tcl-4.1 {
proc busy_callback {cnt} {
break
}
db busy busy_callback
db busy
} {busy_callback}
do_test tcl-4.2 {
db busy {}
db busy
} {}
finish_test