]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Convert the TCL interface to use sqlite3_open_v2 (CVS 4352)
authordrh <drh@noemail.net>
Fri, 31 Aug 2007 14:31:44 +0000 (14:31 +0000)
committerdrh <drh@noemail.net>
Fri, 31 Aug 2007 14:31:44 +0000 (14:31 +0000)
FossilOrigin-Name: 3434b7a9213f210498f43cb5094a0f3f5c25b957

manifest
manifest.uuid
src/tclsqlite.c
test/tclsqlite.test
test/tester.tcl

index 03f8e5357dd9214979d180d05b9ffb0244c65457..d850ce6df3f793dc96124209b1e313aaf1f3c436 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sproblem\sin\smalloc3.test\spreventing\sall.test\sfrom\scompleting.\sNo\scode\schanges.\s(CVS\s4351)
-D 2007-08-31T05:00:49
+C Convert\sthe\sTCL\sinterface\sto\suse\ssqlite3_open_v2\s(CVS\s4352)
+D 2007-08-31T14:31:45
 F Makefile.in bfcc303429a5d9dcd552d807ee016c77427418c3
 F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -135,7 +135,7 @@ F src/sqlite3ext.h 3e5368b64a28602ef8abf9cfb6c8c1643903f238
 F src/sqliteInt.h 5dbb7a934a88dfa9893e2627f4821b0464f5edc0
 F src/sqliteLimit.h 1bcbbdfa856f8b71b561abb31edb864b0eca1d12
 F src/table.c 1aeb9eab57b4235db86fe15a35dec76fb445a9c4
-F src/tclsqlite.c 5b801c7eeefe8c968325558e2a7977cf8a713d5f
+F src/tclsqlite.c 8db035768623779c97d0509eb88ecbb49c51abca
 F src/test1.c 8b20d1f05777ac480d3caf8d5f79ab7a543513fc
 F src/test2.c 4ab230fbdc0decfa7422f6a052b609ba54f4dfac
 F src/test3.c 199a440ba2b38b26251393b609451a3484a15907
@@ -418,9 +418,9 @@ F test/substr.test 9f26cfca74397b26ab217fb838c3d0549eb4bcf3
 F test/sync.test d05397b8f89f423dd6dba528692019ab036bc1c3
 F test/table.test dbdfd06aef054ad5aed8e57a782137d57d5c5528
 F test/tableapi.test 036575a98dcce7c92e9f39056839bbad8a715412
-F test/tclsqlite.test 593f3b30221e85786965d9e5670ae4f96b4e4159
+F test/tclsqlite.test 3addd6a88b8a756ec802ca8840587fa3d61bfcff
 F test/temptable.test c36f3e5a94507abb64f7ba23deeb4e1a8a8c3821
-F test/tester.tcl d6fd4e9eac69a7bc7791ca2f80c91945d1f6d1cc
+F test/tester.tcl 577c2eb71a6e308f8e4d6b283c6a0d2966ed2824
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
 F test/thread2.test 6d7b30102d600f51b4055ee3a5a19228799049fb
 F test/threadtest1.c 6029d9c5567db28e6dc908a0c63099c3ba6c383b
@@ -568,7 +568,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 1b39a714efbe1f4ccc8daf68a227a8c9b84a388f
-R 5354fced5254a75816d7576469879796
-U danielk1977
-Z ef735893af1f42e3e38cbeb5ea49fed9
+P ee9b3e5e38c52f5669009a08aec58678ccad0d87
+R b9ef3977fd4686cc6e05c610911a5a80
+U drh
+Z edb6e93aa3250c0879e9ae9ba46c5a0f
index 0430f1344d6da755fc911e0ea20f1a3bfc4f09fc..9454b4d1abfea429a7713a75e6f33dc818280a6a 100644 (file)
@@ -1 +1 @@
-ee9b3e5e38c52f5669009a08aec58678ccad0d87
\ No newline at end of file
+3434b7a9213f210498f43cb5094a0f3f5c25b957
\ No newline at end of file
index 52ffc88c62ed8ffffd878ab65a3439c27f9f0548..86cd06a9e91b40c6d880d517d5484e9c48d6f22d 100644 (file)
@@ -12,7 +12,7 @@
 ** A TCL Interface to SQLite.  Append this file to sqlite3.c and
 ** compile the whole thing to build a TCL-enabled version of SQLite.
 **
-** $Id: tclsqlite.c,v 1.199 2007/08/30 14:58:20 drh Exp $
+** $Id: tclsqlite.c,v 1.200 2007/08/31 14:31:45 drh Exp $
 */
 #include "tcl.h"
 #include <errno.h>
@@ -2255,7 +2255,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
 }
 
 /*
-**   sqlite3 DBNAME FILENAME ?MODE? ?-key KEY?
+**   sqlite3 DBNAME FILENAME ?-vfs VFSNAME? ?-key KEY? ?-readonly BOOLEAN?
+**                           ?-create BOOLEAN?
 **
 ** This is the main Tcl command.  When the "sqlite" Tcl command is
 ** invoked, this routine runs to process that command.
@@ -2265,25 +2266,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
 ** DBNAME that is used to control that connection.  The database
 ** connection is deleted when the DBNAME command is deleted.
 **
-** The second argument is the name of the directory that contains
-** the sqlite database that is to be accessed.
+** The second argument is the name of the database file.
 **
-** For testing purposes, we also support the following:
-**
-**  sqlite3 -encoding
-**
-**       Return the encoding used by LIKE and GLOB operators.  Choices
-**       are UTF-8 and iso8859.
-**
-**  sqlite3 -version
-**
-**       Return the version number of the SQLite library.
-**
-**  sqlite3 -tcl-uses-utf
-**
-**       Return "1" if compiled with a Tcl uses UTF-8.  Return "0" if
-**       not.  Used by tests to make sure the library was compiled 
-**       correctly.
 */
 static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   SqliteDb *p;
@@ -2291,7 +2275,10 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   int nKey = 0;
   const char *zArg;
   char *zErrMsg;
+  int i;
   const char *zFile;
+  const char *zVfs = 0;
+  int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
   Tcl_DString translatedFilename;
   if( objc==2 ){
     zArg = Tcl_GetStringFromObj(objv[1], 0);
@@ -2304,31 +2291,45 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
       Tcl_AppendResult(interp,"1",0);
 #else
       Tcl_AppendResult(interp,"0",0);
-#endif
-      return TCL_OK;
-    }
-    if( strcmp(zArg,"-tcl-uses-utf")==0 ){
-#ifdef TCL_UTF_MAX
-      Tcl_AppendResult(interp,"1",0);
-#else
-      Tcl_AppendResult(interp,"0",0);
 #endif
       return TCL_OK;
     }
   }
-  if( objc==5 || objc==6 ){
-    zArg = Tcl_GetStringFromObj(objv[objc-2], 0);
+  for(i=3; i+1<objc; i+=2){
+    zArg = Tcl_GetString(objv[i]);
     if( strcmp(zArg,"-key")==0 ){
-      pKey = Tcl_GetByteArrayFromObj(objv[objc-1], &nKey);
-      objc -= 2;
+      pKey = Tcl_GetByteArrayFromObj(objv[i+1], &nKey);
+    }else if( strcmp(zArg, "-vfs")==0 ){
+      i++;
+      zVfs = Tcl_GetString(objv[i]);
+    }else if( strcmp(zArg, "-readonly")==0 ){
+      int b;
+      if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
+      if( b ){
+        flags &= ~SQLITE_OPEN_READWRITE;
+        flags |= SQLITE_OPEN_READONLY;
+      }else{
+        flags &= ~SQLITE_OPEN_READONLY;
+        flags |= SQLITE_OPEN_READWRITE;
+      }
+    }else if( strcmp(zArg, "-create")==0 ){
+      int b;
+      if( Tcl_GetBooleanFromObj(interp, objv[i+1], &b) ) return TCL_ERROR;
+      if( b ){
+        flags |= SQLITE_OPEN_CREATE;
+      }else{
+        flags &= ~SQLITE_OPEN_CREATE;
+      }
+    }else{
+      Tcl_AppendResult(interp, "unknown option: ", zArg, (char*)0);
+      return TCL_ERROR;
     }
   }
-  if( objc!=3 && objc!=4 ){
+  if( objc<3 || (objc&1)!=1 ){
     Tcl_WrongNumArgs(interp, 1, objv, 
+      "HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
 #ifdef SQLITE_HAS_CODEC
-      "HANDLE FILENAME ?-key CODEC-KEY?"
-#else
-      "HANDLE FILENAME ?MODE?"
+      " ?-key CODECKEY?"
 #endif
     );
     return TCL_ERROR;
@@ -2342,7 +2343,7 @@ static int DbMain(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   memset(p, 0, sizeof(*p));
   zFile = Tcl_GetStringFromObj(objv[2], 0);
   zFile = Tcl_TranslateFileName(interp, zFile, &translatedFilename);
-  sqlite3_open(zFile, &p->db);
+  sqlite3_open_v2(zFile, &p->db, flags, zVfs);
   Tcl_DStringFree(&translatedFilename);
   if( SQLITE_OK!=sqlite3_errcode(p->db) ){
     zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(p->db));
@@ -2426,12 +2427,14 @@ EXTERN int Tclsqlite_SafeInit(Tcl_Interp *interp){ return TCL_OK; }
 #ifdef TCLSH
 /*****************************************************************************
 ** The code that follows is used to build standalone TCL interpreters
+** that are statically linked with SQLite.  
 */
 
 /*
 ** If the macro TCLSH is one, then put in code this for the
 ** "main" routine that will initialize Tcl and take input from
-** standard input.
+** standard input, or if a file is named on the command line
+** the TCL interpreter reads and evaluates that file.
 */
 #if TCLSH==1
 static char zMainloop[] =
index 30eccdd76f8aef00a72a18eedb686168635e60d0..158a0087d93c380874cfa21f6cd42fcca72d4b0e 100644 (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.59 2007/06/19 23:01:42 drh Exp $
+# $Id: tclsqlite.test,v 1.60 2007/08/31 14:31:45 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -25,7 +25,7 @@ source $testdir/tester.tcl
 if {[sqlite3 -has-codec]} {
   set r "sqlite_orig HANDLE FILENAME ?-key CODEC-KEY?"
 } else {
-  set r "sqlite3 HANDLE FILENAME ?MODE?"
+  set r "sqlite3 HANDLE FILENAME ?-vfs VFSNAME? ?-readonly BOOLEAN? ?-create BOOLEAN?"
 }
 do_test tcl-1.1 {
   set v [catch {sqlite3 bogus} msg]
@@ -140,22 +140,20 @@ do_test tcl-1.20 {
 } {1 {wrong # args: should be "db copy CONFLICT-ALGORITHM TABLE FILENAME ?SEPARATOR? ?NULLINDICATOR?"}}
 
 
-if {[sqlite3 -tcl-uses-utf]} {
-  catch {unset ::result}
-  do_test tcl-2.1 {
-    execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
-  } {}
-  ifcapable schema_pragmas {
-    do_test tcl-2.2 {
-      execsql "PRAGMA table_info(t\u0123x)"
-    } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
-  }
-  do_test tcl-2.3 {
-    execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
-    db eval "SELECT * FROM t\u0123x" result break
-    set result(*)
-  } "a b\u1235"
+catch {unset ::result}
+do_test tcl-2.1 {
+  execsql "CREATE TABLE t\u0123x(a int, b\u1235 float)"
+} {}
+ifcapable schema_pragmas {
+  do_test tcl-2.2 {
+    execsql "PRAGMA table_info(t\u0123x)"
+  } "0 a int 0 {} 0 1 b\u1235 float 0 {} 0"
 }
+do_test tcl-2.3 {
+  execsql "INSERT INTO t\u0123x VALUES(1,2.3)"
+  db eval "SELECT * FROM t\u0123x" result break
+  set result(*)
+} "a b\u1235"
 
 
 # Test the onecolumn method
index cc6acddb5fd0fe3133a176a851856d7853b95726..23c9900f14794eb77bee9bd288f33eedac655b99 100644 (file)
 # This file implements some common TCL routines used for regression
 # testing the SQLite library
 #
-# $Id: tester.tcl,v 1.88 2007/08/23 11:07:10 danielk1977 Exp $
-
-# Make sure tclsqlite3 was compiled correctly.  Abort now with an
-# error message if not.
-#
-if {[sqlite3 -tcl-uses-utf]} {
-  if {"\u1234"=="u1234"} {
-    puts stderr "***** BUILD PROBLEM *****"
-    puts stderr "$argv0 was linked against an older version"
-    puts stderr "of TCL that does not support Unicode, but uses a header"
-    puts stderr "file (\"tcl.h\") from a new TCL version that does support"
-    puts stderr "Unicode.  This combination causes internal errors."
-    puts stderr "Recompile using a TCL library and header file that match"
-    puts stderr "and try again.\n**************************"
-    exit 1
-  }
-} else {
-  if {"\u1234"!="u1234"} {
-    puts stderr "***** BUILD PROBLEM *****"
-    puts stderr "$argv0 was linked against an newer version"
-    puts stderr "of TCL that supports Unicode, but uses a header file"
-    puts stderr "(\"tcl.h\") from a old TCL version that does not support"
-    puts stderr "Unicode.  This combination causes internal errors."
-    puts stderr "Recompile using a TCL library and header file that match"
-    puts stderr "and try again.\n**************************"
-    exit 1
-  }
-}
+# $Id: tester.tcl,v 1.89 2007/08/31 14:31:45 drh Exp $
+
 
 set tcl_precision 15
 set sqlite_pending_byte 0x0010000