Add tests (and fixes) for the virtual table transaction interface. (CVS 3265)

FossilOrigin-Name: 8a5b121f2f26bebe3f1164bc2f504d29b74400f4
This commit is contained in:
danielk1977
2006-06-17 09:39:55 +00:00
parent 4273deaec1
commit c69cdfd4ec
8 changed files with 267 additions and 21 deletions
+1 -2
View 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.179 2006/06/16 08:01:04 danielk1977 Exp $
** @(#) $Id: sqlite.h.in,v 1.180 2006/06/17 09:39:56 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -1558,7 +1558,6 @@ struct sqlite3_module {
int (*xSync)(sqlite3_vtab *pVTab);
int (*xCommit)(sqlite3_vtab *pVTab);
int (*xRollback)(sqlite3_vtab *pVTab);
int (*xIsInTrans)(sqlite3_vtab *pVTab);
};
/*
+57 -3
View File
@@ -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.24 2006/06/16 06:17:47 danielk1977 Exp $
** $Id: test8.c,v 1.25 2006/06/17 09:39:56 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -24,6 +24,14 @@
typedef struct echo_vtab echo_vtab;
typedef struct echo_cursor echo_cursor;
/*
** The test module defined in this file uses two global Tcl variables to
** commicate with test-scripts:
**
** $::echo_module
** $::echo_module_sync_fail
*/
/*
** An echo virtual-table object.
**
@@ -32,7 +40,8 @@ typedef struct echo_cursor echo_cursor;
** (implicit or otherwise). In other words, if SQLite can optimize
** a query like "SELECT * FROM real_table WHERE col = ?".
**
** Member variable contains copies of the column names of the real table.
** Member variable aCol[] contains copies of the column names of the real
** table.
*/
struct echo_vtab {
sqlite3_vtab base;
@@ -614,6 +623,47 @@ int echoUpdate(
return rc;
}
/*
** xBegin, xSync, xCommit and xRollback callbacks for echo module
** virtual tables. Do nothing other than add the name of the callback
** to the $::echo_module Tcl variable.
*/
static int echoTransactionCall(sqlite3_vtab *tab, const char *zCall){
char *z;
echo_vtab *pVtab = (echo_vtab *)tab;
z = sqlite3_mprintf("echo(%s)", pVtab->zTableName);
appendToEchoModule(pVtab->interp, zCall);
appendToEchoModule(pVtab->interp, z);
sqlite3_free(z);
return SQLITE_OK;
}
static int echoBegin(sqlite3_vtab *tab){
return echoTransactionCall(tab, "xBegin");
}
static int echoSync(sqlite3_vtab *tab){
echo_vtab *pVtab = (echo_vtab *)tab;
Tcl_Interp *interp = pVtab->interp;
const char *zVal;
echoTransactionCall(tab, "xSync");
/* Check if the $::echo_module_sync_fail variable is defined. If it is,
** and it is set to the name of the real table underlying this virtual
** echo module table, then cause this xSync operation to fail.
*/
zVal = Tcl_GetVar(interp, "echo_module_sync_fail", TCL_GLOBAL_ONLY);
if( zVal && 0==strcmp(zVal, pVtab->zTableName) ){
return -1;
}
return SQLITE_OK;
}
static int echoCommit(sqlite3_vtab *tab){
return echoTransactionCall(tab, "xCommit");
}
static int echoRollback(sqlite3_vtab *tab){
return echoTransactionCall(tab, "xRollback");
}
/*
** A virtual table module that merely echos method calls into TCL
** variables.
@@ -632,7 +682,11 @@ static sqlite3_module echoModule = {
echoNext, /* xNext - advance a cursor */
echoColumn, /* xColumn - read data */
echoRowid, /* xRowid - read data */
echoUpdate /* xUpdate - write data */
echoUpdate, /* xUpdate - write data */
echoBegin, /* xBegin - begin transaction */
echoSync, /* xSync - sync transaction */
echoCommit, /* xCommit - commit transaction */
echoRollback /* xRollback - rollback transaction */
};
/*
+2 -1
View File
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.129 2006/06/17 06:31:19 danielk1977 Exp $
** $Id: update.c,v 1.130 2006/06/17 09:39:56 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -611,6 +611,7 @@ static void updateVirtualTable(
for(i=0; i<pTab->nCol; i++){
sqlite3VdbeAddOp(v, OP_Column, ephemTab, i+1+(pRowid!=0));
}
pParse->pVirtualLock = pTab;
sqlite3VdbeOp3(v, OP_VUpdate, 0, pTab->nCol+2,
(const char*)pTab->pVtab, P3_VTAB);
sqlite3VdbeAddOp(v, OP_Next, ephemTab, addr);
+2 -2
View File
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to help implement virtual tables.
**
** $Id: vtab.c,v 1.16 2006/06/17 03:27:23 danielk1977 Exp $
** $Id: vtab.c,v 1.17 2006/06/17 09:39:56 danielk1977 Exp $
*/
#ifndef SQLITE_OMIT_VIRTUALTABLE
#include "sqliteInt.h"
@@ -447,7 +447,7 @@ static int callFinaliser(sqlite3 *db, int offset, int doDelete){
for(i=0; rc==SQLITE_OK && i<db->nVTrans && db->aVTrans[i]; i++){
sqlite3_vtab *pVtab = db->aVTrans[i];
int (*x)(sqlite3_vtab *);
x = (int (*)(sqlite3_vtab *))((char *)pVtab->pModule + offset);
x = *(int (**)(sqlite3_vtab *))((char *)pVtab->pModule + offset);
if( x ){
rc = x(pVtab);
}