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