diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/insert.c | 4 | ||||
-rw-r--r-- | src/sqlite.h.in | 4 | ||||
-rw-r--r-- | src/test8.c | 15 | ||||
-rw-r--r-- | src/test_schema.c | 3 | ||||
-rw-r--r-- | src/vdbe.c | 19 |
5 files changed, 34 insertions, 11 deletions
diff --git a/src/insert.c b/src/insert.c index e36417767..efefb2aae 100644 --- a/src/insert.c +++ b/src/insert.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.167 2006/06/15 07:29:01 danielk1977 Exp $ +** $Id: insert.c,v 1.168 2006/06/16 06:17:47 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -632,7 +632,7 @@ void sqlite3Insert( */ #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pTab) ){ - sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+2, + sqlite3VdbeOp3(v, OP_VUpdate, 1, pTab->nCol+2, (const char*)pTab->pVtab, P3_VTAB); }else #endif diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 68f3a568b..f210bfa42 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.177 2006/06/15 04:28:13 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.178 2006/06/16 06:17:47 danielk1977 Exp $ */ #ifndef _SQLITE3_H_ #define _SQLITE3_H_ @@ -1552,7 +1552,7 @@ struct sqlite3_module { int (*xNext)(sqlite3_vtab_cursor*); int (*xColumn)(sqlite3_vtab_cursor*, sqlite3_context*, int); int (*xRowid)(sqlite3_vtab_cursor*, sqlite_int64 *pRowid); - int (*xUpdate)(sqlite3_vtab *pVTab, int, sqlite3_value **apData); + int (*xUpdate)(sqlite3_vtab *, int, sqlite3_value **, sqlite_int64 *); int (*xBegin)(sqlite3_vtab *pVTab); int (*xSync)(sqlite3_vtab *pVTab); int (*xCommit)(sqlite3_vtab *pVTab); diff --git a/src/test8.c b/src/test8.c index 847ae20f5..563d2799d 100644 --- a/src/test8.c +++ b/src/test8.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test8.c,v 1.23 2006/06/15 15:38:42 danielk1977 Exp $ +** $Id: test8.c,v 1.24 2006/06/16 06:17:47 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -512,7 +512,12 @@ static void string_concat(char **pzStr, char *zAppend, int doFree){ ** NULL INTEGER (nCol args) INSERT (incl. rowid value) ** */ -int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ +int echoUpdate( + sqlite3_vtab *tab, + int nData, + sqlite3_value **apData, + sqlite_int64 *pRowid +){ echo_vtab *pVtab = (echo_vtab *)tab; sqlite3 *db = pVtab->db; int rc = SQLITE_OK; @@ -557,7 +562,7 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ int ii; char *zInsert = 0; char *zValues = 0; - + zInsert = sqlite3_mprintf("INSERT OR REPLACE INTO %Q (", pVtab->zTableName); if( sqlite3_value_type(apData[1])==SQLITE_INTEGER ){ bindArgOne = 1; @@ -602,6 +607,10 @@ int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){ rc = sqlite3_finalize(pStmt); } + if( pRowid && rc==SQLITE_OK ){ + *pRowid = sqlite3_last_insert_rowid(db); + } + return rc; } diff --git a/src/test_schema.c b/src/test_schema.c index e5da4f4d4..9d8a6b1d5 100644 --- a/src/test_schema.c +++ b/src/test_schema.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test_schema.c,v 1.2 2006/06/15 16:26:45 danielk1977 Exp $ +** $Id: test_schema.c,v 1.3 2006/06/16 06:17:47 danielk1977 Exp $ */ /* The code in this file defines a sqlite3 module that provides @@ -301,6 +301,7 @@ static int register_schema_module( Tcl_WrongNumArgs(interp, 1, objv, "DB"); return TCL_ERROR; } + if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR; #ifndef SQLITE_OMIT_VIRTUALTABLE sqlite3_create_module(db, "schema", &schemaModule, 0); #endif diff --git a/src/vdbe.c b/src/vdbe.c index 035dc9487..044133474 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.561 2006/06/15 07:29:01 danielk1977 Exp $ +** $Id: vdbe.c,v 1.562 2006/06/16 06:17:47 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -3269,6 +3269,10 @@ case OP_NewRowid: { ** then rowid is stored for subsequent return by the ** sqlite3_last_insert_rowid() function (otherwise it's unmodified). ** +** Parameter P3 may point to a string containing the table-name, or +** may be NULL. If it is not NULL, then the update-hook +** (sqlite3.xUpdateCallback) is invoked following a successful insert. +** ** This instruction only works on tables. The equivalent instruction ** for indices is OP_IdxInsert. */ @@ -4773,7 +4777,7 @@ case OP_VNoChange: { #ifndef SQLITE_OMIT_VIRTUALTABLE -/* Opcode: VUpdate * P2 P3 +/* Opcode: VUpdate P1 P2 P3 ** ** P3 is a pointer to a virtual table object, an sqlite3_vtab structure. ** This opcode invokes the corresponding xUpdate method. P2 values @@ -4795,6 +4799,10 @@ case OP_VNoChange: { ** ** If P2==1 then no insert is performed. argv[0] is the rowid of ** a row to delete. +** +** P1 is a boolean flag. If it is set to true and the xUpdate call +** is successful, then the value returned by sqlite3_last_insert_rowid() +** is set to the value of the rowid for the row just inserted. */ case OP_VUpdate: { /* no-push */ sqlite3_vtab *pVtab = (sqlite3_vtab *)(pOp->p3); @@ -4806,14 +4814,19 @@ case OP_VUpdate: { /* no-push */ rc = SQLITE_ERROR; }else{ int i; + sqlite_int64 rowid; Mem **apArg = p->apArg; Mem *pX = &pTos[1-nArg]; for(i = 0; i<nArg; i++, pX++){ apArg[i] = pX->flags ? storeTypeInfo(pX,0), pX : 0; } if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse; - rc = pModule->xUpdate(pVtab, nArg, apArg); + rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse; + if( pOp->p1 && rc==SQLITE_OK ){ + assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); + db->lastRowid = rowid; + } } popStack(&pTos, nArg); break; |