/ Check-in [6b77d61a]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the ability to disable future calls to virtual table methods by invoking sqlite3_create_module() with a NULL sqlite3_module pointer.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | disable-vtab
Files: files | file ages | folders
SHA1: 6b77d61adbc52a9d28ad522aa101c2c193942d18
User & Date: drh 2013-06-11 22:41:12
Context
2013-06-12
02:53
Another attempt at disabling virtual tables. This one leaks memory. Closed-Leaf check-in: 399e2828 user: drh tags: disable-vtab
2013-06-11
22:41
Add the ability to disable future calls to virtual table methods by invoking sqlite3_create_module() with a NULL sqlite3_module pointer. check-in: 6b77d61a user: drh tags: disable-vtab
14:22
Add the SQLITE_FTS3_MAX_EXPR_DEPTH compile time option. check-in: 24fc9d44 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vtab.c.

    22     22   ** are invoked only from within xCreate and xConnect methods.
    23     23   */
    24     24   struct VtabCtx {
    25     25     VTable *pVTable;    /* The virtual table being constructed */
    26     26     Table *pTab;        /* The Table object to which the virtual table belongs */
    27     27   };
    28     28   
           29  +/*
           30  +** A place-holder virtual table method that always fails.
           31  +*/
           32  +static int errorMethod(void){ return SQLITE_ERROR; }
           33  +
           34  +/*
           35  +** A dummy virtual table implementation in which every method fails.
           36  +*/
           37  +static const sqlite3_module errorModule = {
           38  +  /* iVersion      */ 2,
           39  +  /* xCreate       */ (int(*)(sqlite3*,void*,int,const char*const*,
           40  +                              sqlite3_vtab**,char**))errorMethod,
           41  +  /* xConnect      */ (int(*)(sqlite3*,void*,int,const char*const*,
           42  +                              sqlite3_vtab**,char**))errorMethod,
           43  +  /* xBestIndex    */ (int(*)(sqlite3_vtab*, sqlite3_index_info*))errorMethod,
           44  +  /* xDisconnect   */ (int(*)(sqlite3_vtab*))errorMethod,
           45  +  /* xDestroy      */ (int(*)(sqlite3_vtab*))errorMethod,
           46  +  /* xOpen         */ (int(*)(sqlite3_vtab*,sqlite3_vtab_cursor**))errorMethod,
           47  +  /* xClose        */ (int(*)(sqlite3_vtab_cursor*))errorMethod,
           48  +  /* xFilter       */ (int(*)(sqlite3_vtab_cursor*,int,const char*,int,
           49  +                              sqlite3_value**))errorMethod,
           50  +  /* xNext         */ (int(*)(sqlite3_vtab_cursor*))errorMethod,
           51  +  /* xEof          */ (int(*)(sqlite3_vtab_cursor*))errorMethod,
           52  +  /* xColumn       */ (int(*)(sqlite3_vtab_cursor*,sqlite3_context*,int))
           53  +                                                                   errorMethod,
           54  +  /* xRowid        */ (int(*)(sqlite3_vtab_cursor*,sqlite3_int64*))errorMethod,
           55  +  /* xUpdate       */ (int(*)(sqlite3_vtab*,int,sqlite3_value**,
           56  +                              sqlite3_int64*))errorMethod,
           57  +  /* xBegin        */ (int(*)(sqlite3_vtab*))errorMethod,
           58  +  /* xSync         */ (int(*)(sqlite3_vtab*))errorMethod,
           59  +  /* xCommit       */ (int(*)(sqlite3_vtab*))errorMethod,
           60  +  /* xRollback     */ (int(*)(sqlite3_vtab*))errorMethod,
           61  +  /* xFindFunction */ (int(*)(sqlite3_vtab*,int,const char*,
           62  +                             void(**)(sqlite3_context*,int,sqlite3_value**),
           63  +                             void**))errorMethod,
           64  +  /* xRename       */ (int(*)(sqlite3_vtab*,const char*))errorMethod,
           65  +  /* xSavepoint    */ (int(*)(sqlite3_vtab*,int))errorMethod,
           66  +  /* xRelease      */ (int(*)(sqlite3_vtab*,int))errorMethod,
           67  +  /* xRollbackTo   */ (int(*)(sqlite3_vtab*,int))errorMethod
           68  +};
           69  +
    29     70   /*
    30     71   ** The actual function that does the work of creating a new module.
    31     72   ** This function implements the sqlite3_create_module() and
    32     73   ** sqlite3_create_module_v2() interfaces.
    33     74   */
    34     75   static int createModule(
    35     76     sqlite3 *db,                    /* Database in which module is registered */
................................................................................
    36     77     const char *zName,              /* Name assigned to this module */
    37     78     const sqlite3_module *pModule,  /* The definition of the module */
    38     79     void *pAux,                     /* Context pointer for xCreate/xConnect */
    39     80     void (*xDestroy)(void *)        /* Module destructor function */
    40     81   ){
    41     82     int rc = SQLITE_OK;
    42     83     int nName;
           84  +  Module *pMod;
    43     85   
    44     86     sqlite3_mutex_enter(db->mutex);
    45     87     nName = sqlite3Strlen30(zName);
    46         -  if( sqlite3HashFind(&db->aModule, zName, nName) ){
    47         -    rc = SQLITE_MISUSE_BKPT;
           88  +  if( (pMod = sqlite3HashFind(&db->aModule, zName, nName))!=0 ){
           89  +    if( pModule!=0 ){
           90  +      rc = SQLITE_MISUSE_BKPT;
           91  +    }else{
           92  +      pMod->pModule = &errorModule;
           93  +    }
    48     94     }else{
    49         -    Module *pMod;
    50     95       pMod = (Module *)sqlite3DbMallocRaw(db, sizeof(Module) + nName + 1);
    51     96       if( pMod ){
    52     97         Module *pDel;
    53     98         char *zCopy = (char *)(&pMod[1]);
    54     99         memcpy(zCopy, zName, nName+1);
    55    100         pMod->zName = zCopy;
    56    101         pMod->pModule = pModule;