]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Obj-ify tclsqlite (CVS 146)
authordrh <drh@noemail.net>
Thu, 21 Sep 2000 13:01:35 +0000 (13:01 +0000)
committerdrh <drh@noemail.net>
Thu, 21 Sep 2000 13:01:35 +0000 (13:01 +0000)
FossilOrigin-Name: 85a4254ef0998fac06ddc285decd79345968fee1

Makefile.in
configure
configure.in
manifest
manifest.uuid
src/tclsqlite.c
test/tester.tcl
www/changes.tcl

index cf1d86ff4590c418b4a1d30739758c128e09d1d0..4e45100e546595a95d0480e67ff36e625be34fb2 100644 (file)
@@ -49,7 +49,7 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
 #
 LIBOBJ = build.o dbbe.o delete.o expr.o insert.o \
          main.o parse.o select.o tokenize.o update.o \
-         util.o vdbe.o where.o
+         util.o vdbe.o where.o tclsqlite.o
 
 # All of the source code files.
 #
@@ -157,6 +157,9 @@ select.o:   $(TOP)/src/select.c $(HDR)
 update.o:      $(TOP)/src/update.c $(HDR)
        $(TCC) $(GDBM_FLAGS) -c $(TOP)/src/update.c
 
+tclsqlite.o:   $(TOP)/src/tclsqlite.c $(HDR)
+       $(TCC) $(GDBM_FLAGS) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
+
 gdbmdump:      $(TOP)/tool/gdbmdump.c
        $(TCC) $(GDBM_FLAGS) -o gdbmdump $(TOP)/tool/gdbmdump.c $(LIBGDBM)
 
index f191be8d28f208aa0aeee1b95d6cdaf1eb918d8d..ec9364f834b84050238b15c56fd1dfe10e3705bf 100755 (executable)
--- a/configure
+++ b/configure
@@ -525,7 +525,7 @@ fi
 
 
 # The following RCS revision string applies to configure.in
-# $Revision: 1.6 $
+# $Revision: 1.7 $
 
 #########
 # Make sure we are not building in a subdirectory of the source tree.
@@ -1374,6 +1374,9 @@ fi
     fi
   done
 fi
+if test "$found" = "no"; then
+  TARGET_TCL_INC="-DNO_TCL=1"
+fi
 
 
 ##########
@@ -1387,14 +1390,14 @@ else
   LIBS=""
   
 echo $ac_n "checking for library containing gdbm_open""... $ac_c" 1>&6
-echo "configure:1391: checking for library containing gdbm_open" >&5
+echo "configure:1394: checking for library containing gdbm_open" >&5
 if eval "test \"`echo '$''{'ac_cv_search_gdbm_open'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_func_search_save_LIBS="$LIBS"
 ac_cv_search_gdbm_open="no"
 cat > conftest.$ac_ext <<EOF
-#line 1398 "configure"
+#line 1401 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1405,7 +1408,7 @@ int main() {
 gdbm_open()
 ; return 0; }
 EOF
-if { (eval echo configure:1409: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1412: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_gdbm_open="none required"
 else
@@ -1416,7 +1419,7 @@ rm -f conftest*
 test "$ac_cv_search_gdbm_open" = "no" && for i in gdbm; do
 LIBS="-l$i  $ac_func_search_save_LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1420 "configure"
+#line 1423 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1427,7 +1430,7 @@ int main() {
 gdbm_open()
 ; return 0; }
 EOF
-if { (eval echo configure:1431: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1434: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_gdbm_open="-l$i"
 break
@@ -1455,7 +1458,7 @@ fi
 # Figure out where to get the GDBM header files.
 #
 echo $ac_n "checking GDBM header files""... $ac_c" 1>&6
-echo "configure:1459: checking GDBM header files" >&5
+echo "configure:1462: checking GDBM header files" >&5
 found=no
 if test "$config_TARGET_GDBM_INC" != ""; then
   TARGET_GDBM_INC=$config_TARGET_GDBM_INC
@@ -1467,17 +1470,17 @@ else
   echo "$ac_t""not specified: still searching..." 1>&6
   ac_safe=`echo "gdbm.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for gdbm.h""... $ac_c" 1>&6
-echo "configure:1471: checking for gdbm.h" >&5
+echo "configure:1474: checking for gdbm.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1476 "configure"
+#line 1479 "configure"
 #include "confdefs.h"
 #include <gdbm.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1481: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1484: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1504,7 +1507,7 @@ if test "$found" = "no"; then
     
 ac_safe=`echo "$dir/include/gdbm.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $dir/include/gdbm.h""... $ac_c" 1>&6
-echo "configure:1508: checking for $dir/include/gdbm.h" >&5
+echo "configure:1511: checking for $dir/include/gdbm.h" >&5
 if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1545,14 +1548,14 @@ else
   LIBS=""
   
 echo $ac_n "checking for library containing readline""... $ac_c" 1>&6
-echo "configure:1549: checking for library containing readline" >&5
+echo "configure:1552: checking for library containing readline" >&5
 if eval "test \"`echo '$''{'ac_cv_search_readline'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_func_search_save_LIBS="$LIBS"
 ac_cv_search_readline="no"
 cat > conftest.$ac_ext <<EOF
-#line 1556 "configure"
+#line 1559 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1563,7 +1566,7 @@ int main() {
 readline()
 ; return 0; }
 EOF
-if { (eval echo configure:1567: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1570: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_readline="none required"
 else
@@ -1574,7 +1577,7 @@ rm -f conftest*
 test "$ac_cv_search_readline" = "no" && for i in readline; do
 LIBS="-l$i  $ac_func_search_save_LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1578 "configure"
+#line 1581 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1585,7 +1588,7 @@ int main() {
 readline()
 ; return 0; }
 EOF
-if { (eval echo configure:1589: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1592: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_readline="-l$i"
 break
@@ -1613,7 +1616,7 @@ fi
 # Figure out where to get the READLINE header files.
 #
 echo $ac_n "checking readline header files""... $ac_c" 1>&6
-echo "configure:1617: checking readline header files" >&5
+echo "configure:1620: checking readline header files" >&5
 found=no
 if test "$config_TARGET_READLINE_INC" != ""; then
   TARGET_READLINE_INC=$config_TARGET_READLINE_INC
@@ -1625,17 +1628,17 @@ else
   echo "$ac_t""not specified: still searching..." 1>&6
   ac_safe=`echo "readline.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for readline.h""... $ac_c" 1>&6
-echo "configure:1629: checking for readline.h" >&5
+echo "configure:1632: checking for readline.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1634 "configure"
+#line 1637 "configure"
 #include "confdefs.h"
 #include <readline.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1639: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1642: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1662,7 +1665,7 @@ if test "$found" = "no"; then
     
 ac_safe=`echo "$dir/include/readline.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $dir/include/readline.h""... $ac_c" 1>&6
-echo "configure:1666: checking for $dir/include/readline.h" >&5
+echo "configure:1669: checking for $dir/include/readline.h" >&5
 if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1691,7 +1694,7 @@ fi
     
 ac_safe=`echo "$dir/include/readline/readline.h" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $dir/include/readline/readline.h""... $ac_c" 1>&6
-echo "configure:1695: checking for $dir/include/readline/readline.h" >&5
+echo "configure:1698: checking for $dir/include/readline/readline.h" >&5
 if eval "test \"`echo '$''{'ac_cv_file_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1735,12 +1738,12 @@ fi
 # Figure out whether or not we have a "usleep()" function.
 #
 echo $ac_n "checking for usleep""... $ac_c" 1>&6
-echo "configure:1739: checking for usleep" >&5
+echo "configure:1742: checking for usleep" >&5
 if eval "test \"`echo '$''{'ac_cv_func_usleep'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1744 "configure"
+#line 1747 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char usleep(); below.  */
@@ -1763,7 +1766,7 @@ usleep();
 
 ; return 0; }
 EOF
-if { (eval echo configure:1767: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1770: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_usleep=yes"
 else
index 606558347fe55919fc55c601c7a8ff5beb9102f9..50bc4bc52745a35c40d0254907a928297c21f95a 100644 (file)
@@ -151,7 +151,7 @@ AC_INIT(src/sqlite.h.in)
 dnl Put the RCS revision string after AC_INIT so that it will also
 dnl show in in configure.
 # The following RCS revision string applies to configure.in
-# $Revision: 1.6 $
+# $Revision: 1.7 $
 
 #########
 # Make sure we are not building in a subdirectory of the source tree.
@@ -416,6 +416,9 @@ if test "$found" = "no"; then
     fi
   done
 fi
+if test "$found" = "no"; then
+  TARGET_TCL_INC="-DNO_TCL=1"
+fi
 AC_SUBST(TARGET_TCL_INC)
 
 ##########
index cf4dc1eb245e5ba296a02fc1416b84d76c24f66a..a0b6a253a03929771fc0432104fce7346f64b101 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,11 +1,11 @@
-C Version\s1.0.5\s(CVS\s495)
-D 2000-09-14T01:25:00
+C Obj-ify\stclsqlite\s(CVS\s146)
+D 2000-09-21T13:01:36
 F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
-F Makefile.in 036bce328b963f48dbaadbec8cc4144a1fd9e50a
+F Makefile.in e699d55492bcfe06ab93e2d3f86da4705d45692c
 F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
 F VERSION 4edef6ec60a55c61b01fc0abebbf5a2f67c4f0e7
-F configure 078a370347baf9375baa8053857ca1e6bc84afa7 x
-F configure.in 381aeb4564f1562b7b2a115f5e99035c561a7fea
+F configure bc917320fcc6d8a1a5154737304763acb5f7f68c x
+F configure.in ae915ce37ff010e8aac34b90b9136d4a32659bdb
 F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
 F src/build.c 4d90e9e94750ca80249fc7958c617021d8bb7a50
 F src/dbbe.c 226daaf8c095ceb4aff48cad188dad90643f9867
@@ -20,7 +20,7 @@ F src/shell.c f1ef4268c679e4a9faedc7b0bbf8045d062d1f9c
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in d341439fc1432c7d7014bcff5f7b6e914571232c
 F src/sqliteInt.h b65fdecac7281aafb4c9ff3e79ea1b5546478385
-F src/tclsqlite.c 89dc4ba2b521f3e919d6d7aaa4cc1c2aba8e16f3
+F src/tclsqlite.c a08428125ba2429b71764d5365653771ded4a2b8
 F src/tokenize.c 097bec5843d4a0fb4509e036fee93bac080c5e73
 F src/update.c 51b9ef7434b15e31096155da920302e9db0d27fc
 F src/util.c 782f87af3c48c898631a2d5b7074437c899f6f13
@@ -47,7 +47,7 @@ F test/select5.test e2b9d51d88cbd6c307c2c05b0ef55fe7ba811ac2
 F test/sort.test d582086c4bb7df3fbf50aa72e69d7e235e9f8e31
 F test/subselect.test bf8b251a92fb091973c1c469ce499dc9648a41d5
 F test/table.test 620cd72a6c29da3b9153d15c9e94abbbb282373b
-F test/tester.tcl 95b286791e6256bb6db0165f9342c70fff549a62
+F test/tester.tcl ad57d7e8114b0691eb5e943b9dabbd68119b8e2c
 F test/update.test 62f6ce99ff31756aab0ca832ff6d34c5a87b6250
 F test/vacuum.test 8becf5cfeb897108b35cdd996793e7f1df2f28fd
 F test/where.test bbab5a308055fb6087dc23d600b4ad2b72797397
@@ -62,7 +62,7 @@ F www/arch.fig 4e26e9dca3c49724fc8f554c695ddea9f2413156
 F www/arch.png c4d908b79065a72e7dcf19317f36d1324c550e87
 F www/arch.tcl 4f6a9afecc099a27bba17b4f8cc9561abc15dc40
 F www/c_interface.tcl 1b79e404a0dd46f44cd453a44b01df568c9586d1
-F www/changes.tcl 8ac23210e8cef43b77041f01b439a6ff3d1554fc
+F www/changes.tcl 5f047e9e0154cf1b800e626e635c4334420ddb9b
 F www/crosscompile.tcl 19734ce7f18b16ff2ed8479412abf8aca56e1dcc
 F www/fileformat.tcl cfb7fba80b7275555281ba2f256c00734bcdd1c9
 F www/index.tcl 2f5cc070b8fa8c3fc2f71bba4e6b7877d528fbde
@@ -71,7 +71,7 @@ F www/mingw.tcl fc5f4ba9d336b6e8c97347cc6496d6162461ef60
 F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
 F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
 F www/vdbe.tcl bcbfc33bcdd0ebad95eab31286adb9e1bc289520
-P ea0e32828f5643eeb00b216a287d14f4826ddf2d
-R d838e77add09f4d92cf328c578007f7b
+P 84839d8764ecdfac4d8c56618d9c107c8bbf65ab
+R c08eefda2a9f502c4bc4de062c9d0908
 U drh
-Z de8fe72d201ddf752c7db67bb8650632
+Z 23e467b7f382bfed639e5b43f4e92064
index 801b1d81c8577aaab404f93b0901d8bb3c0a7c96..96878291777153621c245c5e557d427006dc6ed5 100644 (file)
@@ -1 +1 @@
-84839d8764ecdfac4d8c56618d9c107c8bbf65ab
\ No newline at end of file
+85a4254ef0998fac06ddc285decd79345968fee1
\ No newline at end of file
index 11221a76938a6d0ea4f8ddd05943fb4cf742005d..b4bdd889381df843d86b3b0f764a3196d8f1809d 100644 (file)
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.8 2000/08/17 09:50:00 drh Exp $
+** $Id: tclsqlite.c,v 1.9 2000/09/21 13:01:37 drh Exp $
 */
+#ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
+
 #include "sqlite.h"
 #include <tcl.h>
 #include <stdlib.h>
@@ -38,7 +40,7 @@ typedef struct SqliteDb SqliteDb;
 struct SqliteDb {
   sqlite *db;           /* The "real" database structure */
   Tcl_Interp *interp;   /* The interpreter used for this database */
-  char *zBusy;          /* The name of the busy callback routine */
+  char *zBusy;          /* The busy callback routine */
 };
 
 /*
@@ -49,7 +51,7 @@ typedef struct CallbackData CallbackData;
 struct CallbackData {
   Tcl_Interp *interp;       /* The TCL interpreter */
   char *zArray;             /* The array into which data is written */
-  char *zCode;              /* The code to execute for each row */
+  Tcl_Obj *pCode;           /* The code to execute for each row */
   int once;                 /* Set only for the first invocation of callback */
 };
 
@@ -84,10 +86,36 @@ static int DbEvalCallback(
     }
   }
   cbData->once = 0;
-  rc = Tcl_Eval(cbData->interp, cbData->zCode);
+  rc = Tcl_EvalObj(cbData->interp, cbData->pCode);
   return rc;
 }
 
+/*
+** This is an alternative callback for database queries.  Instead
+** of invoking a TCL script to handle the result, this callback just
+** appends each column of the result to a list.  After the query
+** is complete, the list is returned.
+*/
+static int DbEvalCallback2(
+  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_Obj *pList = (Tcl_Obj*)clientData;
+  int i;
+  for(i=0; i<nCol; i++){
+    Tcl_Obj *pElem;
+    if( azCol[i] && *azCol[i] ){
+      pElem = Tcl_NewStringObj(azCol[i], -1);
+    }else{
+      pElem = Tcl_NewObj();
+    }
+    Tcl_ListObjAppendElement(0, pList, pElem);
+  }
+  return 0;
+}
+
 /*
 ** Called when the command is deleted.
 */
@@ -139,58 +167,70 @@ static int DbBusyHandler(void *cd, const char *zTable, int nTries){
 ** and calls that connection "db1".  The second command causes this
 ** subroutine to be invoked.
 */
-static int DbCmd(void *cd, Tcl_Interp *interp, int argc, char **argv){
-  char *z;
-  int n, c;
+static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   SqliteDb *pDb = (SqliteDb*)cd;
-  if( argc<2 ){
-    Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
-        " SUBCOMMAND ...\"", 0);
+  int choice;
+  static char *DB_optStrs[] = {
+     "busy",   "close",  "complete",  "eval",  "timeout"
+  };
+  enum DB_opts {
+     DB_BUSY,  DB_CLOSE, DB_COMPLETE, DB_EVAL, DB_TIMEOUT
+  };
+
+  if( objc<2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
+    return TCL_ERROR;
+  }
+  if( Tcl_GetIndexFromObj(interp, objv[1], DB_optStrs, "option", 0, &choice) ){
     return TCL_ERROR;
   }
-  z = argv[1];
-  n = strlen(z);
-  c = z[0];
+
+  switch( (enum DB_opts)choice ){
 
   /*    $db busy ?CALLBACK?
   **
   ** Invoke the given callback if an SQL statement attempts to open
   ** a locked database file.
   */
-  if( c=='b' && strncmp(z,"busy",n)==0 ){
-    if( argc>3 ){
-      Tcl_AppendResult(interp,"wrong # args: should be \"",
-         argv[0], " busy ?CALLBACK?", 0);
+  case DB_BUSY: {
+    if( objc>3 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "CALLBACK");
       return TCL_ERROR;
-    }else if( argc==2 ){
+    }else if( objc==2 ){
       if( pDb->zBusy ){
         Tcl_AppendResult(interp, pDb->zBusy, 0);
       }
     }else{
+      char *zBusy;
+      int len;
       if( pDb->zBusy ){
         Tcl_Free(pDb->zBusy);
-        pDb->zBusy = 0;
       }
-      if( argv[2][0] ){
-        pDb->zBusy = Tcl_Alloc( strlen(argv[2]) + 1 );
-        if( pDb->zBusy ){
-          strcpy(pDb->zBusy, argv[2]);
-        }
+      zBusy = Tcl_GetStringFromObj(objv[2], &len);
+      if( zBusy && len>0 ){
+        pDb->zBusy = Tcl_Alloc( len + 1 );
+        strcpy(pDb->zBusy, zBusy);
+      }else{
+        pDb->zBusy = 0;
       }
       if( pDb->zBusy ){
         pDb->interp = interp;
         sqlite_busy_handler(pDb->db, DbBusyHandler, pDb);
+      }else{
+        sqlite_busy_handler(pDb->db, 0, 0);
       }
     }
-  }else
+    break;
+  }
 
   /*    $db close
   **
   ** Shutdown the database
   */
-  if( c=='c' && n>=2 && strncmp(z,"close",n)==0 ){
-    Tcl_DeleteCommand(interp, argv[0]);
-  }else
+  case DB_CLOSE: {
+    Tcl_DeleteCommand(interp, Tcl_GetStringFromObj(objv[0], 0));
+    break;
+  }
 
   /*    $db complete SQL
   **
@@ -198,16 +238,18 @@ static int DbCmd(void *cd, Tcl_Interp *interp, int argc, char **argv){
   ** additional lines of input are needed.  This is similar to the
   ** built-in "info complete" command of Tcl.
   */
-  if( c=='c' && n>=2 && strncmp(z,"complete",n)==0 ){
-    char *zRes;
-    if( argc!=3 ){
-      Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
-          " complete SQL\"", 0);
+  case DB_COMPLETE: {
+    Tcl_Obj *pResult;
+    int isComplete;
+    if( objc!=3 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "SQL");
       return TCL_ERROR;
     }
-    zRes = sqlite_complete(argv[2]) ? "1" : "0";
-    Tcl_SetResult(interp, zRes, TCL_VOLATILE);
-  }else
+    isComplete = sqlite_complete( Tcl_GetStringFromObj(objv[2], 0) );
+    pResult = Tcl_GetObjResult(interp);
+    Tcl_SetBooleanObj(pResult, isComplete);
+    break;
+  }
    
   /*
   **    $db eval $sql ?array {  ...code... }?
@@ -218,57 +260,59 @@ static int DbCmd(void *cd, Tcl_Interp *interp, int argc, char **argv){
   ** If "array" is an empty string, then the values are placed in variables
   ** that have the same name as the fields extracted by the query.
   */
-  if( c=='e' && strncmp(z,"eval",n)==0 ){
+  case DB_EVAL: {
     CallbackData cbData;
     char *zErrMsg;
+    char *zSql;
     int rc;
 
-    if( argc!=5 && argc!=3 ){
-      Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
-         " eval SQL ?ARRAY-NAME CODE?", 0);
+    if( objc!=5 && objc!=3 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "SQL ?ARRAY-NAME CODE?");
       return TCL_ERROR;
     }
     pDb->interp = interp;
-    if( argc==5 ){
+    zSql = Tcl_GetStringFromObj(objv[2], 0);
+    Tcl_IncrRefCount(objv[2]);
+    if( objc==5 ){
       cbData.interp = interp;
       cbData.once = 1;
-      cbData.zArray = argv[3];
-      cbData.zCode = argv[4];
+      cbData.zArray = Tcl_GetStringFromObj(objv[3], 0);
+      cbData.pCode = objv[4];
       zErrMsg = 0;
-      rc = sqlite_exec(pDb->db, argv[2], DbEvalCallback, &cbData, &zErrMsg);
+      Tcl_IncrRefCount(objv[3]);
+      Tcl_IncrRefCount(objv[4]);
+      rc = sqlite_exec(pDb->db, zSql, DbEvalCallback, &cbData, &zErrMsg);
+      Tcl_DecrRefCount(objv[4]);
+      Tcl_DecrRefCount(objv[3]);
     }else{
-      rc = sqlite_exec(pDb->db, argv[2], 0, 0, &zErrMsg);
+      Tcl_Obj *pList = Tcl_NewObj();
+      rc = sqlite_exec(pDb->db, zSql, DbEvalCallback2, pList, &zErrMsg);
+      Tcl_SetObjResult(interp, pList);
     }
     if( zErrMsg ){
       Tcl_SetResult(interp, zErrMsg, TCL_VOLATILE);
       free(zErrMsg);
     }
+    Tcl_DecrRefCount(objv[2]);
     return rc;
-  }else
+  }
 
   /*
   **     $db timeout MILLESECONDS
   **
   ** Delay for the number of milliseconds specified when a file is locked.
   */
-  if( c=='t' && strncmp(z,"timeout",n)==0 ){
+  case DB_TIMEOUT: {
     int ms;
-    if( argc!=3 ){
-      Tcl_AppendResult(interp,"wrong # args: should be \"", argv[0],
-          " timeout MILLISECONDS", 0);
+    if( objc!=3 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "MILLISECONDS");
       return TCL_ERROR;
     }
-    if( Tcl_GetInt(interp, argv[2], &ms) ) return TCL_ERROR;
+    if( Tcl_GetIntFromObj(interp, objv[2], &ms) ) return TCL_ERROR;
     sqlite_busy_timeout(pDb->db, ms);
-  }else
-
-  /* The default
-  */
-  {
-    Tcl_AppendResult(interp,"unknown subcommand \"", z, 
-        "\" - should be one of: close complete eval", 0);
-    return TCL_ERROR;
+    break;
   }
+  } /* End of the SWITCH statement */
   return TCL_OK;
 }
 
@@ -314,7 +358,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int argc, char **argv){
     free(zErrMsg);
     return TCL_ERROR;
   }
-  Tcl_CreateCommand(interp, argv[1], DbCmd, (char*)p, DbDeleteCmd);
+  Tcl_CreateObjCommand(interp, argv[1], DbObjCmd, (char*)p, DbDeleteCmd);
   return TCL_OK;
 }
 
@@ -397,3 +441,5 @@ int TCLSH_MAIN(int argc, char **argv){
   return 0;
 }
 #endif /* TCLSH */
+
+#endif /* !defined(NO_TCL) */
index cf132bf6daf7af8cca72cb94fe653aebd3408a90..390368d80f66d01ddc920a7cc6bf55e45d9571b9 100644 (file)
@@ -23,7 +23,7 @@
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.5 2000/06/08 13:36:41 drh Exp $
+# $Id: tester.tcl,v 1.6 2000/09/21 13:01:37 drh Exp $
 
 # Create a test database
 #
@@ -82,13 +82,7 @@ proc finish_test {} {
 # A procedure to execute SQL
 #
 proc execsql {sql} {
-  set result {}
-  db eval $sql data {
-    foreach f $data(*) {
-      lappend result $data($f)
-    }
-  }
-  return $result
+  return [db eval $sql]
 }
 
 # Another procedure to execute SQL.  This one includes the field
index c2401201a1f774093c493d946b5a2bdeb049ba4b..9ff6bc6e77feb27723317fcc03ea53a05d512fb0 100644 (file)
@@ -17,6 +17,13 @@ proc chng {date desc} {
   puts "<DD><P><UL>$desc</UL></P></DD>"
 }
 
+chng {2000 Sep 21 (Not Released)} {
+<li>Change the tclsqlite "eval" method to return a list of results if
+    no callback script is specified.</li>
+<li>Change tclsqlite.c to use the Tcl_Obj interface</li>
+<li>Add tclsqlite.c to the libsqlite.a library</li>
+}
+
 chng {2000 Sep 13 (Version 1.0.5)} {
 <li>Changed the print format for floating point values from "%g" to "%.15g".
     </li>