]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add comments and prototype for experimental sqlite_last_statement_changes() API funct...
authorrdc <rdc@noemail.net>
Wed, 25 Feb 2004 22:51:06 +0000 (22:51 +0000)
committerrdc <rdc@noemail.net>
Wed, 25 Feb 2004 22:51:06 +0000 (22:51 +0000)
FossilOrigin-Name: ca99920b0dbf773962b47766d690154fd1276513

manifest
manifest.uuid
src/func.c
src/main.c
src/sqlite.h.in
src/tclsqlite.c
test/tclsqlite.test

index 205eb0c57789d61bca1e219b3082f137f5df4bae..9203c45a41b3acb1b22150a01dc006506386950b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Min()\sand\smax()\sfunctions\shonor\sthe\sdistinction\sbetween\sTEXT\sand\sNUMERIC\ndata.\s\sTicket\s#623.\s\stypeof()\sis\snow\sa\suser\sfunction.\s\sSome\stests\sare\nnow\sfailing\sdue\sto\sticket\s#521.\s(CVS\s1272)
-D 2004-02-25T13:47:31
+C Add\scomments\sand\sprototype\sfor\sexperimental\ssqlite_last_statement_changes()\sAPI\sfunction.\sAlso,\sallow\sfunction\sto\sbe\scalled\sfrom\stcl.\s(CVS\s1273)
+D 2004-02-25T22:51:06
 F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -33,11 +33,11 @@ F src/date.c 3025642cee50d5c41aef4a22cbc41aa7e543c922
 F src/delete.c 82001c74882319f94dab5f6b92a27311b31092ae
 F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
 F src/expr.c 95ea5d47d11b5085aaeeb77d60b17c2cba13383a
-F src/func.c 424256b469717367f3939725a36a6f3c3d7b5f60
+F src/func.c 34fead7a33e82095f6412d3fafd379d47864b3be
 F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
 F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
 F src/insert.c c0485ee2d1b99322894e2d1e0b576fd05ed75616
-F src/main.c af984c8dbfe769fb88fb0ac70e5f813e50800c1b
+F src/main.c 2956e9332241ff9e62c25f370d0615a9981e6d8f
 F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
 F src/os.c f5fc4954725b2fcd852979f2746085fe8ca27710
 F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24
@@ -49,10 +49,10 @@ F src/printf.c f201a5a316afc474d29d51e07501536e8998194d
 F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
 F src/select.c a8b0f9bfe92001d2399d33832bd6ec57ba492ae7
 F src/shell.c b19e750ffcccf49b626f4b6fefe89c1dbae47e82
-F src/sqlite.h.in 8a83091fbbbd73d30a9743310ed0089e3f1fda0f
+F src/sqlite.h.in 01a7009223517d151da9780b0bb7b748777015dd
 F src/sqliteInt.h 235ce244b62bb26cc9ab394fb7a0724dd4e65c83
 F src/table.c d845cb101b5afc1f7fea083c99e3d2fa7998d895
-F src/tclsqlite.c b84dafe3a8532ff534c36e96bd38880e4b9cedf3
+F src/tclsqlite.c 819d92d305756c4ea57de023c387d2fa8a256aff
 F src/test1.c 9aa62b89d420e6763b5e7ae89a47f6cf87370477
 F src/test2.c 75819b0f2c63c6a0fd6995445881f2eb94036996
 F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
@@ -132,7 +132,7 @@ F test/sort.test ba07b107c16070208e6aab3cadea66ba079d85ba
 F test/subselect.test f0fea8cf9f386d416d64d152e3c65f9116d0f50f
 F test/table.test 371a1fc1c470982b2f68f9732f903a5d96f949c4
 F test/tableapi.test e0c4cce61e58343caa84dab33fa6823cb35fe1e1
-F test/tclsqlite.test 602c73172b46c47221d4e699beaf6684eb120d48
+F test/tclsqlite.test a684fc191b81e6cded8a81263663d5a130fbb013
 F test/temptable.test a770ba6308d7f7332fce985086b8e06bed6430c2
 F test/tester.tcl 2f1d43df1311c9dc06acaa7a82e87bfea85dea5f
 F test/thread1.test 53f050d5be6932d9430df7756edd379366508ff6
@@ -189,7 +189,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 9c9f4a867a4ea708847cbb0839b7279eb33ecd7c
-R 5415532acf52c246928d5fc32e241eec
-U drh
-Z 719381690dd478a52c92cb1074f23dac
+P adbe31adf1ad0ca723203ca3d7dc480324c60d43
+R 3c9515cca68a5695cd3226713e65c42d
+U rdc
+Z e0bb7fa0c538643c4a09a58dfdcb0be7
index 2f6ee2c2c90d10f24190634a7f37bb0eef24554d..1b88329ee2814ea41896c867b2ee6e76d9dfb188 100644 (file)
@@ -1 +1 @@
-adbe31adf1ad0ca723203ca3d7dc480324c60d43
\ No newline at end of file
+ca99920b0dbf773962b47766d690154fd1276513
\ No newline at end of file
index fd581f8a168ec04b141b384302305ecc23c8e3d1..e6613c5b1d4dd77552660628e31188ca755fc824 100644 (file)
@@ -16,7 +16,7 @@
 ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
 ** All other code has file scope.
 **
-** $Id: func.c,v 1.42 2004/02/25 13:47:32 drh Exp $
+** $Id: func.c,v 1.43 2004/02/25 22:51:06 rdc Exp $
 */
 #include <ctype.h>
 #include <math.h>
@@ -210,10 +210,19 @@ static void last_insert_rowid(sqlite_func *context, int arg, const char **argv){
   sqlite_set_result_int(context, sqlite_last_insert_rowid(db));
 }
 
+/*
+** Implementation of the change_count() SQL function.  The return
+** value is the same as the sqlite_changes() API function.
+*/
 static void change_count(sqlite_func *context, int arg, const char **argv){
   sqlite *db = sqlite_user_data(context);
   sqlite_set_result_int(context, sqlite_changes(db));
 }
+
+/*
+** Implementation of the last_statement_change_count() SQL function.  The
+** return value is the same as the sqlite_last_statement_changes() API function.
+*/
 static void last_statement_change_count(sqlite_func *context, int arg,
                                         const char **argv){
   sqlite *db = sqlite_user_data(context);
index ea1e6df8b7d403a5708e0c7a3c7dc90cf8600655..c299c2c30ba1bf77bb85873167d083c6c1496f64 100644 (file)
@@ -14,7 +14,7 @@
 ** other files are for internal use by SQLite and should not be
 ** accessed by users of the library.
 **
-** $Id: main.c,v 1.160 2004/02/25 13:47:32 drh Exp $
+** $Id: main.c,v 1.161 2004/02/25 22:51:06 rdc Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -545,6 +545,12 @@ int sqlite_changes(sqlite *db){
   return db->nChange;
 }
 
+/*
+** Return the number of changes produced by the last INSERT, UPDATE, or
+** DELETE statement to complete execution. The count does not include
+** changes due to SQL statements executed in trigger programs that were
+** triggered by that statement
+*/
 int sqlite_last_statement_changes(sqlite *db){
   return db->lsChange;
 }
index 32c3ba8ab89b31d416cf483984818d25b488e341..fa45d7d9790347282d7eca08340a52235005d01c 100644 (file)
@@ -12,7 +12,7 @@
 ** This header file defines the interface that the SQLite library
 ** presents to client programs.
 **
-** @(#) $Id: sqlite.h.in,v 1.58 2004/02/25 13:47:33 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.59 2004/02/25 22:51:06 rdc Exp $
 */
 #ifndef _SQLITE_H_
 #define _SQLITE_H_
@@ -204,6 +204,32 @@ int sqlite_last_insert_rowid(sqlite*);
 */
 int sqlite_changes(sqlite*);
 
+/*
+** This function returns the number of database rows that were changed
+** by the last INSERT, UPDATE, or DELETE statment executed by sqlite_exec(),
+** or by the last VM to run to completion. The change count is not updated
+** by SQL statements other than INSERT, UPDATE or DELETE.
+**
+** Changes are counted, even if they are later undone by a ROLLBACK or
+** ABORT. Changes associated with trigger programs that execute as a
+** result of the INSERT, UPDATE, or DELETE statement are not counted.
+**
+** If a callback invokes sqlite_exec() recursively, then the changes
+** in the inner, recursive call are counted together with the changes
+** in the outer call.
+**
+** SQLite implements the command "DELETE FROM table" without a WHERE clause
+** by dropping and recreating the table.  (This is much faster than going
+** through and deleting individual elements form the table.)  Because of
+** this optimization, the change count for "DELETE FROM table" will be
+** zero regardless of the number of elements that were originally in the
+** table. To get an accurate count of the number of rows deleted, use
+** "DELETE FROM table WHERE 1" instead.
+**
+******* THIS IS AN EXPERIMENTAL API AND IS SUBJECT TO CHANGE ******
+*/
+int sqlite_last_statement_changes(sqlite*);
+
 /* If the parameter to this routine is one of the return value constants
 ** defined above, then this routine returns a constant text string which
 ** descripts (in English) the meaning of the return value.
index 2ef5bfa9edab04a4da992e8b9fe426f9cec18ab4..4e3976478a4ec4497561af7216ad26cdd1da3313 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.58 2004/02/12 20:49:36 drh Exp $
+** $Id: tclsqlite.c,v 1.59 2004/02/25 22:51:06 rdc Exp $
 */
 #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
 
@@ -488,19 +488,21 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
   int choice;
   int rc = TCL_OK;
   static const char *DB_strs[] = {
-    "authorizer",         "busy",              "changes",
-    "close",              "commit_hook",       "complete",
-    "errorcode",          "eval",              "function",
-    "last_insert_rowid",  "onecolumn",         "progress",
-    "rekey",              "timeout",           "trace",
+    "authorizer",         "busy",                   "changes",
+    "close",              "commit_hook",            "complete",
+    "errorcode",          "eval",                   "function",
+    "last_insert_rowid",  "last_statement_changes", "onecolumn",
+    "progress",           "rekey",                  "timeout",
+    "trace",
     0                    
   };
   enum DB_enum {
-    DB_AUTHORIZER,        DB_BUSY,             DB_CHANGES,
-    DB_CLOSE,             DB_COMMIT_HOOK,      DB_COMPLETE,
-    DB_ERRORCODE,         DB_EVAL,             DB_FUNCTION,
-    DB_LAST_INSERT_ROWID, DB_ONECOLUMN,        DB_PROGRESS,
-    DB_REKEY,             DB_TIMEOUT,          DB_TRACE,
+    DB_AUTHORIZER,        DB_BUSY,                   DB_CHANGES,
+    DB_CLOSE,             DB_COMMIT_HOOK,            DB_COMPLETE,
+    DB_ERRORCODE,         DB_EVAL,                   DB_FUNCTION,
+    DB_LAST_INSERT_ROWID, DB_LAST_STATEMENT_CHANGES, DB_ONECOLUMN,        
+    DB_PROGRESS,          DB_REKEY,                  DB_TIMEOUT,
+    DB_TRACE
   };
 
   if( objc<2 ){
@@ -660,6 +662,26 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     break;
   }
 
+  /*
+  **     $db last_statement_changes
+  **
+  ** Return the number of rows that were modified, inserted, or deleted by
+  ** the last statment to complete execution (excluding changes due to
+  ** triggers)
+  */
+  case DB_LAST_STATEMENT_CHANGES: {
+    Tcl_Obj *pResult;
+    int lsChange;
+    if( objc!=2 ){
+      Tcl_WrongNumArgs(interp, 2, objv, "");
+      return TCL_ERROR;
+    }
+    lsChange = sqlite_last_statement_changes(pDb->db);
+    pResult = Tcl_GetObjResult(interp);
+    Tcl_SetIntObj(pResult, lsChange);
+    break;
+  }
+
   /*    $db close
   **
   ** Shutdown the database
index fcbd25ab21d45647ac1249e1a69c617f0789fa53..ecaf2a921f2048d9b829fc1d0fcfc257b90fbdd9 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.19 2004/02/11 02:18:07 drh Exp $
+# $Id: tclsqlite.test,v 1.20 2004/02/25 22:51:06 rdc 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, changes, close, commit_hook, complete, errorcode, eval, function, last_insert_rowid, onecolumn, progress, rekey, timeout, or trace}}
+} {1 {bad option "bogus": must be authorizer, busy, changes, close, commit_hook, complete, errorcode, eval, function, last_insert_rowid, last_statement_changes, onecolumn, progress, rekey, timeout, or trace}}
 do_test tcl-1.3 {
   execsql {CREATE TABLE t1(a int, b int)}
   execsql {INSERT INTO t1 VALUES(10,20)}