1*4520Snw141292 2*4520Snw141292#pragma ident "%Z%%M% %I% %E% SMI" 3*4520Snw141292 4*4520Snw141292# 2001 September 15 5*4520Snw141292# 6*4520Snw141292# The author disclaims copyright to this source code. In place of 7*4520Snw141292# a legal notice, here is a blessing: 8*4520Snw141292# 9*4520Snw141292# May you do good and not evil. 10*4520Snw141292# May you find forgiveness for yourself and forgive others. 11*4520Snw141292# May you share freely, never taking more than you give. 12*4520Snw141292# 13*4520Snw141292#*********************************************************************** 14*4520Snw141292# This file implements regression tests for TCL interface to the 15*4520Snw141292# SQLite library. 16*4520Snw141292# 17*4520Snw141292# Actually, all tests are based on the TCL interface, so the main 18*4520Snw141292# interface is pretty well tested. This file contains some addition 19*4520Snw141292# tests for fringe issues that the main test suite does not cover. 20*4520Snw141292# 21*4520Snw141292# $Id: tclsqlite.test,v 1.20.2.1 2004/07/19 19:30:50 drh Exp $ 22*4520Snw141292 23*4520Snw141292set testdir [file dirname $argv0] 24*4520Snw141292source $testdir/tester.tcl 25*4520Snw141292 26*4520Snw141292# Check the error messages generated by tclsqlite 27*4520Snw141292# 28*4520Snw141292if {[sqlite -has-codec]} { 29*4520Snw141292 set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?" 30*4520Snw141292} else { 31*4520Snw141292 set r "sqlite HANDLE FILENAME ?MODE?" 32*4520Snw141292} 33*4520Snw141292do_test tcl-1.1 { 34*4520Snw141292 set v [catch {sqlite bogus} msg] 35*4520Snw141292 lappend v $msg 36*4520Snw141292} [list 1 "wrong # args: should be \"$r\""] 37*4520Snw141292do_test tcl-1.2 { 38*4520Snw141292 set v [catch {db bogus} msg] 39*4520Snw141292 lappend v $msg 40*4520Snw141292} {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}} 41*4520Snw141292do_test tcl-1.3 { 42*4520Snw141292 execsql {CREATE TABLE t1(a int, b int)} 43*4520Snw141292 execsql {INSERT INTO t1 VALUES(10,20)} 44*4520Snw141292 set v [catch { 45*4520Snw141292 db eval {SELECT * FROM t1} data { 46*4520Snw141292 error "The error message" 47*4520Snw141292 } 48*4520Snw141292 } msg] 49*4520Snw141292 lappend v $msg 50*4520Snw141292} {1 {The error message}} 51*4520Snw141292do_test tcl-1.4 { 52*4520Snw141292 set v [catch { 53*4520Snw141292 db eval {SELECT * FROM t2} data { 54*4520Snw141292 error "The error message" 55*4520Snw141292 } 56*4520Snw141292 } msg] 57*4520Snw141292 lappend v $msg 58*4520Snw141292} {1 {no such table: t2}} 59*4520Snw141292do_test tcl-1.5 { 60*4520Snw141292 set v [catch { 61*4520Snw141292 db eval {SELECT * FROM t1} data { 62*4520Snw141292 break 63*4520Snw141292 } 64*4520Snw141292 } msg] 65*4520Snw141292 lappend v $msg 66*4520Snw141292} {0 {}} 67*4520Snw141292do_test tcl-1.6 { 68*4520Snw141292 set v [catch { 69*4520Snw141292 db eval {SELECT * FROM t1} data { 70*4520Snw141292 expr x* 71*4520Snw141292 } 72*4520Snw141292 } msg] 73*4520Snw141292 regsub {:.*$} $msg {} msg 74*4520Snw141292 lappend v $msg 75*4520Snw141292} {1 {syntax error in expression "x*"}} 76*4520Snw141292 77*4520Snw141292if {[sqlite -encoding]=="UTF-8" && [sqlite -tcl-uses-utf]} { 78*4520Snw141292 catch {unset ::result} 79*4520Snw141292 do_test tcl-2.1 { 80*4520Snw141292 execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)" 81*4520Snw141292 execsql "PRAGMA table_info(t\u0123x)" 82*4520Snw141292 } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0" 83*4520Snw141292 do_test tcl-2.2 { 84*4520Snw141292 execsql "INSERT INTO t\u0123x VALUES(1,2.3)" 85*4520Snw141292 db eval "SELECT * FROM t\u0123x" result break 86*4520Snw141292 set result(*) 87*4520Snw141292 } "a b\u1235" 88*4520Snw141292} 89*4520Snw141292 90*4520Snw141292if {[sqlite -encoding]=="iso8859" && [sqlite -tcl-uses-utf]} { 91*4520Snw141292 do_test tcl-2.1 { 92*4520Snw141292 execsql "CREATE TABLE t\251x(a int, b\306 float)" 93*4520Snw141292 execsql "PRAGMA table_info(t\251x)" 94*4520Snw141292 } "0 a int 0 {} 0 1 b\306 float 0 {} 0" 95*4520Snw141292 do_test tcl-2.2 { 96*4520Snw141292 execsql "INSERT INTO t\251x VALUES(1,2.3)" 97*4520Snw141292 db eval "SELECT * FROM t\251x" result break 98*4520Snw141292 set result(*) 99*4520Snw141292 } "a b\306" 100*4520Snw141292} 101*4520Snw141292 102*4520Snw141292# Test the onecolumn method 103*4520Snw141292# 104*4520Snw141292do_test tcl-3.1 { 105*4520Snw141292 execsql { 106*4520Snw141292 INSERT INTO t1 SELECT a*2, b*2 FROM t1; 107*4520Snw141292 INSERT INTO t1 SELECT a*2+1, b*2+1 FROM t1; 108*4520Snw141292 INSERT INTO t1 SELECT a*2+3, b*2+3 FROM t1; 109*4520Snw141292 } 110*4520Snw141292 set rc [catch {db onecolumn {SELECT * FROM t1 ORDER BY a}} msg] 111*4520Snw141292 lappend rc $msg 112*4520Snw141292} {0 10} 113*4520Snw141292do_test tcl-3.2 { 114*4520Snw141292 db onecolumn {SELECT * FROM t1 WHERE a<0} 115*4520Snw141292} {} 116*4520Snw141292do_test tcl-3.3 { 117*4520Snw141292 set rc [catch {db onecolumn} errmsg] 118*4520Snw141292 lappend rc $errmsg 119*4520Snw141292} {1 {wrong # args: should be "db onecolumn SQL"}} 120*4520Snw141292 121*4520Snw141292 122*4520Snw141292finish_test 123