-C Make\sthe\scompile\swork\sunder\scygwin.\nTickets\s#327,\s#213,\s#316,\s#322,\s#349,\s#373,\sand\s#429.\s(CVS\s1075)
-D 2003-08-16T13:10:52
+C Add\sthe\s"onecolumn"\smethod\sto\sthe\sTCL\slanguage\sbindings.\s(CVS\s1076)
+D 2003-08-19T14:31:01
F Makefile.in 9ad23ed4ca97f9670c4496432e3fbd4b3760ebde
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
-F VERSION ab111ee5fce506ec6965461e6c89d8b9eb112e85
+F VERSION 97d209249f825001288ff942df07b48e1083af5c
F aclocal.m4 ff32919e75f42b2d4213fe3c6f79dd0fe47f7769
F config.guess 831db445a8ae31d1f773fce85e14c16c8677417d
F config.sub 975368989965310238930ecf8e7f06a23061dbb1
F src/sqlite.h.in dafa83571810b6932f089b589c783355ef7a54b5
F src/sqliteInt.h cdcfdb5dca98359e443e23384b822a53ebd610ac
F src/table.c 4301926464d88d2c2c7cd21c3360aa75bf068b95
-F src/tclsqlite.c d6860dcd56348b9521726280b72c412d2a33ae97
+F src/tclsqlite.c ec9e5b796bf9ec1483927e986828a205d4a7422a
F src/test1.c b12b585bfb4763df3262975ed8d3f4f274b5eaed
F src/test2.c 5014337d8576b731cce5b5a14bec4f0daf432700
F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
F test/tableapi.test 3c80421a889e1d106df16e5800fa787f0d2914a6
-F test/tclsqlite.test d9bdfc0afca9ee605c50ecb39e94ae4dea8c222b
+F test/tclsqlite.test 751b358b45843f7cab569e362f2db135612b8c59
F test/temptable.test c82bd6f800f10e8cf96921af6315e5f1c21e2692
F test/tester.tcl 2671536d3650c29e7c105219f277568b0884cb58
F test/trans.test 75e7a171b5d2d94ee56766459113e2ad0e5f809d
F www/quickstart.tcl 4e97bef825e6a4153c43afb9f97235fc4da278ab
F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
-F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
+F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
-P ef58f163b08d13f8e9b69459bd83e0bf9d5b404b
-R ce296030d9e4d30410759bccc85cc8c6
+P 7d8d3252df1e9f6bec5e105b6eca3313cb7e226a
+R d1a2b335d94bf870fe28343e60ff8361
U drh
-Z 56580904bed2b7015cd53a563fb3ab39
+Z 3a0f7413336c1c88c47d903a1a6bf2bc
-7d8d3252df1e9f6bec5e105b6eca3313cb7e226a
\ No newline at end of file
+c7b4c28fbc0bca5645af5750fd353f4eca400b40
\ No newline at end of file
*************************************************************************
** A TCL Interface to SQLite
**
-** $Id: tclsqlite.c,v 1.49 2003/06/06 19:00:42 drh Exp $
+** $Id: tclsqlite.c,v 1.50 2003/08/19 14:31:02 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
return 0;
}
+/*
+** This is a second alternative callback for database queries. A the
+** first column of the first row of the result is made the TCL result.
+*/
+static int DbEvalCallback3(
+ void *clientData, /* An instance of CallbackData */
+ int nCol, /* Number of columns in the result */
+ char ** azCol, /* Data for each column */
+ char ** azN /* Name for each column */
+){
+ Tcl_Interp *interp = (Tcl_Interp*)clientData;
+ Tcl_Obj *pElem;
+ if( azCol==0 ) return 1;
+ if( nCol==0 ) return 1;
+#ifdef UTF_TRANSLATION_NEEDED
+ {
+ Tcl_DString dCol;
+ Tcl_DStringInit(&dCol);
+ Tcl_ExternalToUtfDString(NULL, azCol[0], -1, &dCol);
+ pElem = Tcl_NewStringObj(Tcl_DStringValue(&dCol), -1);
+ Tcl_DStringFree(&dCol);
+ }
+#else
+ pElem = Tcl_NewStringObj(azCol[0], -1);
+#endif
+ Tcl_SetObjResult(interp, pElem);
+ return 1;
+}
+
/*
** Called when the command is deleted.
*/
"authorizer", "busy", "changes",
"close", "complete", "errorcode",
"eval", "function", "last_insert_rowid",
- "timeout", "trace", 0
+ "onecolumn", "timeout", "trace",
+ 0
};
enum DB_enum {
DB_AUTHORIZER, DB_BUSY, DB_CHANGES,
DB_CLOSE, DB_COMPLETE, DB_ERRORCODE,
DB_EVAL, DB_FUNCTION, DB_LAST_INSERT_ROWID,
- DB_TIMEOUT, DB_TRACE,
+ DB_ONECOLUMN, DB_TIMEOUT, DB_TRACE,
};
if( objc<2 ){
break;
}
+ /*
+ ** $db onecolumn SQL
+ **
+ ** Return a single column from a single row of the given SQL query.
+ */
+ case DB_ONECOLUMN: {
+ int rc;
+ char *zSql;
+ char *zErrMsg = 0;
+ if( objc!=3 ){
+ Tcl_WrongNumArgs(interp, 2, objv, "SQL");
+ return TCL_ERROR;
+ }
+ zSql = Tcl_GetStringFromObj(objv[2], 0);
+ rc = sqlite_exec(pDb->db, zSql, DbEvalCallback3, interp, &zErrMsg);
+ if( rc==SQLITE_ABORT ){
+ /* Do nothing. This is normal. */
+ }else if( zErrMsg ){
+ Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
+ free(zErrMsg);
+ rc = TCL_ERROR;
+ }else if( rc!=SQLITE_OK ){
+ Tcl_AppendResult(interp, sqlite_error_string(rc), 0);
+ rc = TCL_ERROR;
+ }
+ break;
+ }
+
/*
** $db timeout MILLESECONDS
**
# 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.13 2003/04/23 12:25:25 drh Exp $
+# $Id: tclsqlite.test,v 1.14 2003/08/19 14:31:02 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
do_test tcl-1.2 {
set v [catch {db bogus} msg]
lappend v $msg
-} {1 {bad option "bogus": must be authorizer, busy, changes, close, complete, errorcode, eval, function, last_insert_rowid, timeout, or trace}}
+} {1 {bad option "bogus": must be authorizer, busy, changes, close, complete, errorcode, eval, function, last_insert_rowid, onecolumn, timeout, or trace}}
do_test tcl-1.3 {
execsql {CREATE TABLE t1(a int, b int)}
execsql {INSERT INTO t1 VALUES(10,20)}
} "a b\306"
}
+# 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;
+ }
+ db onecolumn {SELECT * FROM t1 ORDER BY a}
+} {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"}}
+
finish_test
#
# Run this Tcl script to generate the tclsqlite.html file.
#
-set rcsid {$Id: tclsqlite.tcl,v 1.7 2002/04/12 10:09:00 drh Exp $}
+set rcsid {$Id: tclsqlite.tcl,v 1.8 2003/08/19 14:31:02 drh Exp $}
puts {<html>
<head>
<li> complete
<li> eval
<li> last_insert_rowid
+<li> onecolumn
<li> timeout
</ul>
</p>
<p>The "last_insert_rowid" method returns an integer which is the ROWID
of the most recently inserted database row.</p>
+<h2>The "onecolumn" method</h2>
+
+<p>The "onecolumn" method works like "eval" in that it evaluates the
+SQL query statement given as its argument. The difference is that
+"onecolumn" returns a single element which is the first column of the
+first row of the query result.</p>
+
+<p>This is a convenience method. It saves the user from having to
+do a "<tt>[lindex ... 0]</tt>" on the results of an "eval"
+in order to extract a single column result.</p>
+
<h2>The "changes" method</h2>
<p>The "changes" method returns an integer which is the number of rows