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