diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 2 | ||||
-rw-r--r-- | src/vdbe.c | 1 | ||||
-rw-r--r-- | src/vdbeaux.c | 2 | ||||
-rw-r--r-- | src/vtab.c | 12 |
4 files changed, 12 insertions, 5 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 8419392cf..8e2727f6a 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -5627,7 +5627,7 @@ int sqlite3_create_module_v2( */ struct sqlite3_vtab { const sqlite3_module *pModule; /* The module for this virtual table */ - int nRef; /* NO LONGER USED */ + int nRef; /* Number of open cursors */ char *zErrMsg; /* Error message from sqlite3_mprintf() */ /* Virtual table implementations will typically add additional fields */ }; diff --git a/src/vdbe.c b/src/vdbe.c index bba6a90bf..82c313a2d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -6081,6 +6081,7 @@ case OP_VOpen: { pCur = allocateCursor(p, pOp->p1, 0, -1, 0); if( pCur ){ pCur->pVtabCursor = pVtabCursor; + pVtab->nRef++; }else{ db->mallocFailed = 1; pModule->xClose(pVtabCursor); diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 8397fbc10..bd00786eb 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -1782,6 +1782,8 @@ void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){ else if( pCx->pVtabCursor ){ sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; + assert( pVtabCursor->pVtab->nRef>0 ); + pVtabCursor->pVtab->nRef--; pModule->xClose(pVtabCursor); } #endif diff --git a/src/vtab.c b/src/vtab.c index 4631a7d0d..23f49bafc 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -780,11 +780,15 @@ int sqlite3VtabCallDestroy(sqlite3 *db, int iDb, const char *zTab){ pTab = sqlite3FindTable(db, zTab, db->aDb[iDb].zName); if( ALWAYS(pTab!=0 && pTab->pVTable!=0) ){ - VTable *p = vtabDisconnectAll(db, pTab); - - assert( rc==SQLITE_OK ); + VTable *p; + for(p=pTab->pVTable; p; p=p->pNext){ + assert( p->pVtab ); + if( p->pVtab->nRef>0 ){ + return SQLITE_LOCKED; + } + } + p = vtabDisconnectAll(db, pTab); rc = p->pMod->pModule->xDestroy(p->pVtab); - /* Remove the sqlite3_vtab* from the aVTrans[] array, if applicable */ if( rc==SQLITE_OK ){ assert( pTab->pVTable==p && p->pNext==0 ); |