aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrdc <rdc@noemail.net>2004-02-25 22:51:06 +0000
committerrdc <rdc@noemail.net>2004-02-25 22:51:06 +0000
commitf146a77677c8455b0230ba3cc67902a52b3ba4fd (patch)
tree2def8f0ef7fd4554aeb0931fb5a4f562a1c5e1a9 /src
parent268380ca9ed4e5c1ac172f9650d6192bafd0346d (diff)
downloadsqlite-f146a77677c8455b0230ba3cc67902a52b3ba4fd.tar.gz
sqlite-f146a77677c8455b0230ba3cc67902a52b3ba4fd.zip
Add comments and prototype for experimental sqlite_last_statement_changes() API function. Also, allow function to be called from tcl. (CVS 1273)
FossilOrigin-Name: ca99920b0dbf773962b47766d690154fd1276513
Diffstat (limited to 'src')
-rw-r--r--src/func.c11
-rw-r--r--src/main.c8
-rw-r--r--src/sqlite.h.in28
-rw-r--r--src/tclsqlite.c44
4 files changed, 77 insertions, 14 deletions
diff --git a/src/func.c b/src/func.c
index fd581f8a1..e6613c5b1 100644
--- a/src/func.c
+++ b/src/func.c
@@ -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);
diff --git a/src/main.c b/src/main.c
index ea1e6df8b..c299c2c30 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;
}
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 32c3ba8ab..fa45d7d97 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -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.
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 2ef5bfa9e..4e3976478 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -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