Add the "exists" method to the TCL interface. (CVS 2813)

FossilOrigin-Name: 8a355d7aade5c7a95ab08aeedf1ee1857c121c33
This commit is contained in:
drh 2005-12-10 21:19:04 +00:00
parent e57c06fdf0
commit 97f2ebc192
4 changed files with 50 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C New\sbind\stests\s(check-ins\s(2797)\sand\s(2798))\sonly\swork\sright\son\sa\sUTF8\ndatabase.\s\sSo\smake\ssure\sthey\sare\sonly\srun\swhen\sthe\sdatabase\sis\sUTF8.\s(CVS\s2812)
D 2005-12-09T20:54:35
C Add\sthe\s"exists"\smethod\sto\sthe\sTCL\sinterface.\s(CVS\s2813)
D 2005-12-10T21:19:05
F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -71,7 +71,7 @@ F src/shell.c 4872acee1d2a826c73c914961e469e563204b7f9
F src/sqlite.h.in 8e648e1f386e4509f2f96c09ded7c07b0df0c9a2
F src/sqliteInt.h feb11bfe9bf79b4493319173c47739fe2bb7ffa4
F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
F src/tclsqlite.c 328060916c24d328cfab1622c9a0e7ad57c2da8c
F src/tclsqlite.c 6b34de66e8098c306bc3b96300143c23d4797769
F src/test1.c feae6cb2d70a1bc83d7084c590212989922b0f47
F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
F src/test3.c 7c97833e33496c2b69f4fe6b9882ac60a481da97
@ -221,7 +221,7 @@ F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
F test/sync.test 6e8b885cec5ccba2090e92c90f747a7142f53c88
F test/table.test ec0e6c2186bb8f6824f470caa118524dfd8fe057
F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
F test/tclsqlite.test 2da3e4b3a79b13c1511c9d0cd995e08f8362e782
F test/tclsqlite.test 07729a3b683407362bbd63c2a17b4c9ea8b0ec27
F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
F test/tester.tcl a06c798a653daefb5bce2c85fc3a7d06450a1875
F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
@ -327,7 +327,7 @@ F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P 590578bef88d0aa545f8138e8eec0db03c093861
R b11ea4449bdd8f6caa2595a115b86b1e
P 398037906956f0274ca35cbff6961f6df5149295
R 8e7c1e3ead7dacbb9408f99afbdcbea3
U drh
Z 9a38610602d3cdfe49544eea7c9cc80d
Z b05b2682bc485f2f8d89f673d48ca998

View File

@ -1 +1 @@
398037906956f0274ca35cbff6961f6df5149295
8a355d7aade5c7a95ab08aeedf1ee1857c121c33

View File

@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
** $Id: tclsqlite.c,v 1.135 2005/12/07 06:27:44 danielk1977 Exp $
** $Id: tclsqlite.c,v 1.136 2005/12/10 21:19:05 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@ -621,21 +621,22 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
"changes", "close", "collate",
"collation_needed", "commit_hook", "complete",
"copy", "errorcode", "eval",
"function", "last_insert_rowid", "nullvalue",
"onecolumn", "profile", "progress",
"rekey", "timeout", "total_changes",
"trace", "transaction", "version",
0
"exists", "function", "last_insert_rowid",
"nullvalue", "onecolumn", "profile",
"progress", "rekey", "timeout",
"total_changes", "trace", "transaction",
"version", 0
};
enum DB_enum {
DB_AUTHORIZER, DB_BUSY, DB_CACHE,
DB_CHANGES, DB_CLOSE, DB_COLLATE,
DB_COLLATION_NEEDED, DB_COMMIT_HOOK, DB_COMPLETE,
DB_COPY, DB_ERRORCODE, DB_EVAL,
DB_FUNCTION, DB_LAST_INSERT_ROWID,DB_NULLVALUE,
DB_ONECOLUMN, DB_PROFILE, DB_PROGRESS,
DB_REKEY, DB_TIMEOUT, DB_TOTAL_CHANGES,
DB_TRACE, DB_TRANSACTION, DB_VERSION
DB_EXISTS, DB_FUNCTION, DB_LAST_INSERT_ROWID,
DB_NULLVALUE, DB_ONECOLUMN, DB_PROFILE,
DB_PROGRESS, DB_REKEY, DB_TIMEOUT,
DB_TOTAL_CHANGES, DB_TRACE, DB_TRANSACTION,
DB_VERSION
};
/* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
@ -1136,7 +1137,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
** lindex [$db eval $sql] 0
*/
case DB_ONECOLUMN:
case DB_EVAL: {
case DB_EVAL:
case DB_EXISTS: {
char const *zSql; /* Next SQL statement to execute */
char const *zLeft; /* What is left after first stmt in zSql */
sqlite3_stmt *pStmt; /* Compiled SQL statment */
@ -1149,19 +1151,22 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
SqlPreparedStmt *pPreStmt; /* Pointer to a prepared statement */
int rc2;
if( choice==DB_ONECOLUMN ){
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
return TCL_ERROR;
}
pRet = 0;
}else{
if( choice==DB_EVAL ){
if( objc<3 || objc>5 ){
Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME? ?SCRIPT?");
return TCL_ERROR;
}
pRet = Tcl_NewObj();
Tcl_IncrRefCount(pRet);
}else{
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "SQL");
return TCL_ERROR;
}
pRet = 0;
if( choice==DB_EXISTS ){
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(0));
}
}
if( objc==3 ){
pArray = pScript = 0;
@ -1366,11 +1371,18 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
Tcl_ObjSetVar2(interp, pArray, apColName[i], pVal, 0);
}
}else if( choice==DB_ONECOLUMN ){
assert( pRet==0 );
if( pRet==0 ){
pRet = pVal;
Tcl_IncrRefCount(pRet);
}
rc = TCL_BREAK;
i = nCol;
}else if( choice==DB_EXISTS ){
assert( pRet==0 );
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(1));
rc = TCL_BREAK;
i = nCol;
}else{
Tcl_ListObjAppendElement(interp, pRet, pVal);
}

View File

@ -15,7 +15,7 @@
# 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.44 2005/08/29 23:00:05 drh Exp $
# $Id: tclsqlite.test,v 1.45 2005/12/10 21:19:06 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -34,7 +34,7 @@ do_test tcl-1.1 {
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, timeout, total_changes, trace, transaction, or version}}
} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, exists, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, timeout, total_changes, trace, transaction, or version}}
do_test tcl-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {INSERT INTO t1 VALUES(10,20)}
@ -435,4 +435,14 @@ do_test tcl-10.13 {
db eval {SELECT * FROM t4}
} {1 2 3 4 5 6 7}
do_test tcl-11.1 {
db exists {SELECT x,x*2,x+x FROM t4 WHERE x==4}
} {1}
do_test tcl-11.2 {
db exists {SELECT 0 FROM t4 WHERE x==4}
} {1}
do_test tcl-11.3 {
db exists {SELECT 1 FROM t4 WHERE x==8}
} {0}
finish_test