mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-06 15:49:35 +03:00
Allow virtual tables to be used in shared-cache mode. (CVS 6928)
FossilOrigin-Name: 5d9e767a05e381235e064061043e30cc03a11a07
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
*************************************************************************
|
||||
** Internal interface definitions for SQLite.
|
||||
**
|
||||
** @(#) $Id: sqliteInt.h,v 1.893 2009/07/13 15:52:38 drh Exp $
|
||||
** @(#) $Id: sqliteInt.h,v 1.894 2009/07/24 17:58:53 danielk1977 Exp $
|
||||
*/
|
||||
#ifndef _SQLITEINT_H_
|
||||
#define _SQLITEINT_H_
|
||||
@@ -613,6 +613,7 @@ typedef struct TriggerStack TriggerStack;
|
||||
typedef struct TriggerStep TriggerStep;
|
||||
typedef struct Trigger Trigger;
|
||||
typedef struct UnpackedRecord UnpackedRecord;
|
||||
typedef struct VTable VTable;
|
||||
typedef struct Walker Walker;
|
||||
typedef struct WherePlan WherePlan;
|
||||
typedef struct WhereInfo WhereInfo;
|
||||
@@ -839,8 +840,9 @@ struct sqlite3 {
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
Hash aModule; /* populated by sqlite3_create_module() */
|
||||
Table *pVTab; /* vtab with active Connect/Create method */
|
||||
sqlite3_vtab **aVTrans; /* Virtual tables with open transactions */
|
||||
VTable **aVTrans; /* Virtual tables with open transactions */
|
||||
int nVTrans; /* Allocated size of aVTrans */
|
||||
VTable *pDisconnect; /* Disconnect these in next sqlite3_prepare() */
|
||||
#endif
|
||||
FuncDefHash aFunc; /* Hash table of connection functions */
|
||||
Hash aCollSeq; /* All collating sequences */
|
||||
@@ -905,7 +907,6 @@ struct sqlite3 {
|
||||
#define SQLITE_LoadExtension 0x00020000 /* Enable load_extension */
|
||||
|
||||
#define SQLITE_RecoveryMode 0x00040000 /* Ignore schema errors */
|
||||
#define SQLITE_SharedCache 0x00080000 /* Cache sharing is enabled */
|
||||
#define SQLITE_ReverseOrder 0x00100000 /* Reverse unordered SELECTs */
|
||||
|
||||
/*
|
||||
@@ -1114,6 +1115,56 @@ struct CollSeq {
|
||||
#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
|
||||
#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
|
||||
|
||||
/*
|
||||
** An object of this type is created for each virtual table present in
|
||||
** the database schema.
|
||||
**
|
||||
** If the database schema is shared, then there is one instance of this
|
||||
** structure for each database connection (sqlite3*) that uses the shared
|
||||
** schema. This is because each database connection requires its own unique
|
||||
** instance of the sqlite3_vtab* handle used to access the virtual table
|
||||
** implementation. sqlite3_vtab* handles can not be shared between
|
||||
** database connections, even when the rest of the in-memory database
|
||||
** schema is shared, as the implementation often stores the database
|
||||
** connection handle passed to it via the xConnect() or xCreate() method
|
||||
** during initialization internally. This database connection handle may
|
||||
** then used by the virtual table implementation to access real tables
|
||||
** within the database. So that they appear as part of the callers
|
||||
** transaction, these accesses need to be made via the same database
|
||||
** connection as that used to execute SQL operations on the virtual table.
|
||||
**
|
||||
** All VTable objects that correspond to a single table in a shared
|
||||
** database schema are initially stored in a linked-list pointed to by
|
||||
** the Table.pVTable member variable of the corresponding Table object.
|
||||
** When an sqlite3_prepare() operation is required to access the virtual
|
||||
** table, it searches the list for the VTable that corresponds to the
|
||||
** database connection doing the preparing so as to use the correct
|
||||
** sqlite3_vtab* handle in the compiled query.
|
||||
**
|
||||
** When an in-memory Table object is deleted (for example when the
|
||||
** schema is being reloaded for some reason), the VTable objects are not
|
||||
** deleted and the sqlite3_vtab* handles are not xDisconnect()ed
|
||||
** immediately. Instead, they are moved from the Table.pVTable list to
|
||||
** another linked list headed by the sqlite3.pDisconnect member of the
|
||||
** corresponding sqlite3 structure. They are then deleted/xDisconnected
|
||||
** next time a statement is prepared using said sqlite3*. This is done
|
||||
** to avoid deadlock issues involving multiple sqlite3.mutex mutexes.
|
||||
** Refer to comments above function sqlite3VtabUnlockList() for an
|
||||
** explanation as to why it is safe to add an entry to an sqlite3.pDisconnect
|
||||
** list without holding the corresponding sqlite3.mutex mutex.
|
||||
**
|
||||
** The memory for objects of this type is always allocated by
|
||||
** sqlite3DbMalloc(), using the connection handle stored in VTable.db as
|
||||
** the first argument.
|
||||
*/
|
||||
struct VTable {
|
||||
sqlite3 *db; /* Database connection associated with this table */
|
||||
Module *pMod; /* Pointer to module implementation */
|
||||
sqlite3_vtab *pVtab; /* Pointer to vtab instance */
|
||||
int nRef; /* Number of pointers to this structure */
|
||||
VTable *pNext; /* Next in linked list (see above) */
|
||||
};
|
||||
|
||||
/*
|
||||
** Each SQL table is represented in memory by an instance of the
|
||||
** following structure.
|
||||
@@ -1165,8 +1216,7 @@ struct Table {
|
||||
int addColOffset; /* Offset in CREATE TABLE stmt to add a new column */
|
||||
#endif
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
Module *pMod; /* Pointer to the implementation of the module */
|
||||
sqlite3_vtab *pVtab; /* Pointer to the module instance */
|
||||
VTable *pVTable; /* List of VTable objects. */
|
||||
int nModuleArg; /* Number of arguments to the module */
|
||||
char **azModuleArg; /* Text of all module args. [0] is module name */
|
||||
#endif
|
||||
@@ -2812,21 +2862,25 @@ void sqlite3AutoLoadExtensions(sqlite3*);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_OMIT_VIRTUALTABLE
|
||||
# define sqlite3VtabClear(X)
|
||||
# define sqlite3VtabClear(Y)
|
||||
# define sqlite3VtabSync(X,Y) SQLITE_OK
|
||||
# define sqlite3VtabRollback(X)
|
||||
# define sqlite3VtabCommit(X)
|
||||
# define sqlite3VtabInSync(db) 0
|
||||
# define sqlite3VtabLock(X)
|
||||
# define sqlite3VtabUnlock(X)
|
||||
# define sqlite3VtabUnlockList(X)
|
||||
#else
|
||||
void sqlite3VtabClear(Table*);
|
||||
int sqlite3VtabSync(sqlite3 *db, char **);
|
||||
int sqlite3VtabRollback(sqlite3 *db);
|
||||
int sqlite3VtabCommit(sqlite3 *db);
|
||||
void sqlite3VtabLock(VTable *);
|
||||
void sqlite3VtabUnlock(VTable *);
|
||||
void sqlite3VtabUnlockList(sqlite3*);
|
||||
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
|
||||
#endif
|
||||
void sqlite3VtabMakeWritable(Parse*,Table*);
|
||||
void sqlite3VtabLock(sqlite3_vtab*);
|
||||
void sqlite3VtabUnlock(sqlite3*, sqlite3_vtab*);
|
||||
void sqlite3VtabBeginParse(Parse*, Token*, Token*, Token*);
|
||||
void sqlite3VtabFinishParse(Parse*, Token*);
|
||||
void sqlite3VtabArgInit(Parse*);
|
||||
@@ -2834,7 +2888,7 @@ void sqlite3VtabArgExtend(Parse*, Token*);
|
||||
int sqlite3VtabCallCreate(sqlite3*, int, const char *, char **);
|
||||
int sqlite3VtabCallConnect(Parse*, Table*);
|
||||
int sqlite3VtabCallDestroy(sqlite3*, int, const char *);
|
||||
int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
|
||||
int sqlite3VtabBegin(sqlite3 *, VTable *);
|
||||
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
|
||||
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
|
||||
int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
|
||||
@@ -2842,6 +2896,7 @@ int sqlite3Reprepare(Vdbe*);
|
||||
void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
|
||||
CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
|
||||
int sqlite3TempInMemory(const sqlite3*);
|
||||
VTable *sqlite3GetVTable(sqlite3*, Table*);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user