]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the "transaction" coommand to the TCL interface. Untested. (CVS 2572)
authordrh <drh@noemail.net>
Tue, 2 Aug 2005 12:21:08 +0000 (12:21 +0000)
committerdrh <drh@noemail.net>
Tue, 2 Aug 2005 12:21:08 +0000 (12:21 +0000)
FossilOrigin-Name: a5ce6c58c3bfc0e1c9953fe4ad4991ac56a4fb87

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

index a8bba663bd9d78158b2596ca53c86d46fb1e9976..2994e12038fa1451ae0edb4f1ff1e7710bd0ed0b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sproblems\scaused\sby\sover-agressive\soptimization\sof\sORDER\sBY\sin\sjoins.\nLots\smore\stesting\sneeded.\s(CVS\s2571)
-D 2005-07-29T19:43:58
+C Add\sthe\s"transaction"\scoommand\sto\sthe\sTCL\sinterface.\s\sUntested.\s(CVS\s2572)
+D 2005-08-02T12:21:09
 F Makefile.in 22ea9c0fe748f591712d8fe3c6d972c6c173a165
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -66,7 +66,7 @@ F src/shell.c 25b3217d7c64e6497225439d261a253a23efff26
 F src/sqlite.h.in 7ccf2f61de2a0dca515e73708e561362e6c3d1e3
 F src/sqliteInt.h 4cacefaca973cbf8e6a82910c704bf9b4a32fdf1
 F src/table.c 25b3ff2b39b7d87e8d4a5da0713d68dfc06cbee9
-F src/tclsqlite.c ef3276d0967cc0042bedcc1a7f09e0eb95cd3a8c
+F src/tclsqlite.c b24407b7363d6535e9ccf5e5bc8c68e3c879c340
 F src/test1.c 4268e81180a7f9b396a4cf2aa7f268d828cfdf74
 F src/test2.c 716c1809dba8e5be6093703e9cada99d627542dc
 F src/test3.c 683e1e3819152ffd35da2f201e507228921148d0
@@ -201,7 +201,7 @@ F test/subquery.test 0df3de0dbb65165b96ebe895550f1549d5439856
 F test/subselect.test 3f3f7a940dc3195c3139f4d530385cb54665d614
 F test/table.test e87fb2211b97c6a3a367fbc116e8572091b53160
 F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
-F test/tclsqlite.test faa15080060c39c9d6caa7e067c35e0ab3d4e793
+F test/tclsqlite.test 2679b0fa8397717c0a57609011a0727cb0c6510c
 F test/temptable.test c71eeffe8af807f76eafdc5a39824639a1e301df
 F test/tester.tcl 98ecdc5723b3b2be5a8a5c3a7f38fa53031466ee
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
@@ -289,7 +289,7 @@ F www/tclsqlite.tcl 425be741b8ae664f55cb1ef2371aab0a75109cf9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
-P cc7ae73ed01f0b89e31dd8de48b913bbd83887b8
-R f7ec03dd4f33cee2f3fa1b70964a7b5e
+P 1a4e526d46280970b43505a5c8a4090767c63043
+R 78b1c899f4b5fe928acfe9e6cfb5036e
 U drh
-Z d383af4bb27f70288e32f2b965c3944b
+Z 52f52fd4f5ae893bb4b1cf865ecc97b9
index 723a5bf124aa20eb87782f3ddd8ccb041d03447f..36f893842640e82468506dc78f40c621fa3fb54d 100644 (file)
@@ -1 +1 @@
-1a4e526d46280970b43505a5c8a4090767c63043
\ No newline at end of file
+a5ce6c58c3bfc0e1c9953fe4ad4991ac56a4fb87
\ No newline at end of file
index bc98e348df40962b34861e34c333a22b18b25cf7..f07d56009619ea9fb114329b3562ef2a39a63621 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.128 2005/07/23 02:17:03 drh Exp $
+** $Id: tclsqlite.c,v 1.129 2005/08/02 12:21:09 drh Exp $
 */
 #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
 
@@ -591,8 +591,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     "function",           "last_insert_rowid", "nullvalue",
     "onecolumn",          "progress",          "rekey",
     "timeout",            "total_changes",     "trace",
-    "version",
-    0                    
+    "transaction",        "version",           0
   };
   enum DB_enum {
     DB_AUTHORIZER,        DB_BUSY,             DB_CACHE,
@@ -602,7 +601,7 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     DB_FUNCTION,          DB_LAST_INSERT_ROWID,DB_NULLVALUE,
     DB_ONECOLUMN,         DB_PROGRESS,         DB_REKEY,
     DB_TIMEOUT,           DB_TOTAL_CHANGES,    DB_TRACE,
-    DB_VERSION
+    DB_TRANSACTION,       DB_VERSION,          
   };
   /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
 
@@ -1490,6 +1489,63 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     break;
   }
 
+  /*    $db transaction [-deferred|-immediate|-exclusive] SCRIPT
+  **
+  ** Start a new transaction (if we are not already in the midst of a
+  ** transaction) and execute the TCL script SCRIPT.  After SCRIPT
+  ** completes, either commit the transaction or roll it back if SCRIPT
+  ** throws an exception.  Or if no new transation was started, do nothing.
+  ** pass the exception on up the stack.
+  **
+  ** This command was inspired by Dave Thomas's talk on Ruby at the
+  ** 2005 O'Reilly Open Source Convention (OSCON).
+  */
+  case DB_TRANSACTION: {
+    int inTrans;
+    Tcl_Obj *pScript;
+    const char *zBegin = "BEGIN";
+    if( objc!=3 && objc!=4 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "[TYPE] SCRIPT");
+      return TCL_ERROR;
+    }
+    if( objc==3 ){
+      pScript = objv[2];
+    } else {
+      static const char *TTYPE_strs[] = {
+        "deferred",   "exclusive",  "immediate"
+      };
+      enum TTYPE_enum {
+        TTYPE_DEFERRED, TTYPE_EXCLUSIVE, TTYPE_IMMEDIATE
+      };
+      int ttype;
+      if( Tcl_GetIndexFromObj(interp, objv[2], TTYPE_strs, "transaction_type",
+                              0, &ttype) ){
+        return TCL_ERROR;
+      }
+      switch( (enum TTYPE_enum)ttype ){
+        case TTYPE_DEFERRED:    /* no-op */;                 break;
+        case TTYPE_EXCLUSIVE:   zBegin = "BEGIN EXCLUSIVE";  break;
+        case TTYPE_IMMEDIATE:   zBegin = "BEGIN IMMEDIATE";  break;
+      }
+      pScript = objv[3];
+    }
+    inTrans = !sqlite3_get_autocommit(pDb->db);
+    if( !inTrans ){
+      sqlite3_exec(pDb->db, zBegin, 0, 0, 0);
+    }
+    rc = Tcl_EvalObjEx(interp, pScript, 0);
+    if( !inTrans ){
+      const char *zEnd;
+      if( rc==TCL_ERROR ){
+        zEnd = "ROLLBACK";
+      } else {
+        zEnd = "COMMIT";
+      }
+      sqlite3_exec(pDb->db, zEnd, 0, 0, 0);
+    }
+    break;
+  }
+
   /*    $db copy conflict-algorithm table filename ?SEPARATOR? ?NULLINDICATOR?
   **
   ** Copy data into table from filename, optionally using SEPARATOR
index b41b6eec7714793b6392f46f535fb8ab5e9cd419..9f56e4639dce5804998d52db18ab6bb440545926 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.41 2005/06/26 17:55:34 drh Exp $
+# $Id: tclsqlite.test,v 1.42 2005/08/02 12:21:10 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, progress, rekey, timeout, total_changes, trace, or version}}
+} {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, 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)}