/ Check-in [b40a4edc]
Login

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

Overview
Comment:Provide a DBCONFIG to enable or disable virtual tables that match a LIKE pattern.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | disable-vtab
Files: files | file ages | folders
SHA3-256: b40a4edcebe5d027840bf515a06f5743e20e728f71badb151b88b1cdc4e32143
User & Date: drh 2019-04-04 20:21:25
Context
2019-04-04
22:05
Add the vtab enable/disable options to the sqlite3_db_config TCL command in the testfixture. Leaf check-in: c7052428 user: drh tags: disable-vtab
20:21
Provide a DBCONFIG to enable or disable virtual tables that match a LIKE pattern. check-in: b40a4edc user: drh tags: disable-vtab
19:21
Fix a typo in the documentation for sqlite3_value_frombind(). Also add a new hyperlink to that same documentation. No code changes. check-in: bf3cd936 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

   364    364       ** CREATE, then check to see if it is the name of an virtual table that
   365    365       ** can be an eponymous virtual table. */
   366    366       if( pParse->disableVtab==0 ){
   367    367         Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
   368    368         if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
   369    369           pMod = sqlite3PragmaVtabRegister(db, zName);
   370    370         }
   371         -      if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
          371  +      if( pMod
          372  +       && !pMod->bDisabled
          373  +       && sqlite3VtabEponymousTableInit(pParse, pMod)
          374  +      ){
   372    375           return pMod->pEpoTab;
   373    376         }
   374    377       }
   375    378   #endif
   376    379       if( flags & LOCATE_NOERR ) return 0;
   377    380       pParse->checkSchema = 1;
   378    381     }else if( IsVirtual(p) && pParse->disableVtab ){

Changes to src/main.c.

   824    824       }
   825    825       case SQLITE_DBCONFIG_LOOKASIDE: {
   826    826         void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
   827    827         int sz = va_arg(ap, int);       /* IMP: R-47871-25994 */
   828    828         int cnt = va_arg(ap, int);      /* IMP: R-04460-53386 */
   829    829         rc = setupLookaside(db, pBuf, sz, cnt);
   830    830         break;
          831  +    }
          832  +    case SQLITE_DBCONFIG_DISABLE_VTAB:
          833  +    case SQLITE_DBCONFIG_ENABLE_VTAB: {
          834  +      const char *zPattern = va_arg(ap, const char*);
          835  +      int bDisable = op==SQLITE_DBCONFIG_DISABLE_VTAB;
          836  +      HashElem *j;
          837  +      for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
          838  +        Module *pMod = (Module*)sqliteHashData(j);
          839  +        if( sqlite3_strlike(zPattern, pMod->zName, 0)==0 ){
          840  +          pMod->bDisabled = bDisable;
          841  +        }
          842  +      }
          843  +      rc = SQLITE_OK;
   831    844       }
   832    845       default: {
   833    846         static const struct {
   834    847           int op;      /* The opcode */
   835    848           u32 mask;    /* Mask of the bit in sqlite3.flags to set/clear */
   836    849         } aFlagOp[] = {
   837    850           { SQLITE_DBCONFIG_ENABLE_FKEY,           SQLITE_ForeignKeys    },

Changes to src/pragma.c.

  1252   1252   
  1253   1253   #ifndef SQLITE_OMIT_VIRTUALTABLE
  1254   1254     case PragTyp_MODULE_LIST: {
  1255   1255       HashElem *j;
  1256   1256       pParse->nMem = 1;
  1257   1257       for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
  1258   1258         Module *pMod = (Module*)sqliteHashData(j);
         1259  +      if( pMod->bDisabled ) continue;
  1259   1260         sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
  1260   1261       }
  1261   1262     }
  1262   1263     break;
  1263   1264   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  1264   1265   
  1265   1266     case PragTyp_PRAGMA_LIST: {

Changes to src/shell.c.in.

  6277   6277       }
  6278   6278     }else
  6279   6279   
  6280   6280     if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
  6281   6281       static const struct DbConfigChoices {
  6282   6282         const char *zName;
  6283   6283         int op;
         6284  +      int eArgType;
  6284   6285       } aDbConfig[] = {
  6285         -        { "enable_fkey",      SQLITE_DBCONFIG_ENABLE_FKEY            },
  6286         -        { "enable_trigger",   SQLITE_DBCONFIG_ENABLE_TRIGGER         },
  6287         -        { "fts3_tokenizer",   SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER  },
  6288         -        { "load_extension",   SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION  },
  6289         -        { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE       },
  6290         -        { "enable_qpsg",      SQLITE_DBCONFIG_ENABLE_QPSG            },
  6291         -        { "trigger_eqp",      SQLITE_DBCONFIG_TRIGGER_EQP            },
  6292         -        { "reset_database",   SQLITE_DBCONFIG_RESET_DATABASE         },
  6293         -        { "defensive",        SQLITE_DBCONFIG_DEFENSIVE              },
         6286  +        { "enable_fkey",      SQLITE_DBCONFIG_ENABLE_FKEY,            0 },
         6287  +        { "enable_trigger",   SQLITE_DBCONFIG_ENABLE_TRIGGER,         0 },
         6288  +        { "fts3_tokenizer",   SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,  0 },
         6289  +        { "load_extension",   SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,  0 },
         6290  +        { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,       0 },
         6291  +        { "enable_qpsg",      SQLITE_DBCONFIG_ENABLE_QPSG,            0 },
         6292  +        { "trigger_eqp",      SQLITE_DBCONFIG_TRIGGER_EQP,            0 },
         6293  +        { "reset_database",   SQLITE_DBCONFIG_RESET_DATABASE,         0 },
         6294  +        { "defensive",        SQLITE_DBCONFIG_DEFENSIVE,              0 },
         6295  +        { "enable_vtab",      SQLITE_DBCONFIG_ENABLE_VTAB,            1 },
         6296  +        { "disable_vtab",     SQLITE_DBCONFIG_DISABLE_VTAB,           1 },
  6294   6297       };
  6295   6298       int ii, v;
  6296   6299       open_db(p, 0);
  6297   6300       for(ii=0; ii<ArraySize(aDbConfig); ii++){
  6298   6301         if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
  6299   6302         if( nArg>=3 ){
  6300         -        sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
         6303  +        if( aDbConfig[ii].eArgType==0 ){
         6304  +          sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
         6305  +        }else{
         6306  +          sqlite3_db_config(p->db, aDbConfig[ii].op, azArg[2], 0);
         6307  +        }
  6301   6308         }
  6302         -      sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
  6303         -      utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
         6309  +      if( aDbConfig[ii].eArgType==0 ){
         6310  +        sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
         6311  +        utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
         6312  +      }else if( nArg<2 ){
         6313  +        utf8_printf(p->out, "%18s PATTERN\n", aDbConfig[ii].zName);
         6314  +      }
  6304   6315         if( nArg>1 ) break;
  6305   6316       }
  6306   6317       if( nArg>1 && ii==ArraySize(aDbConfig) ){
  6307   6318         utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
  6308   6319         utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
  6309         -    }   
         6320  +    }
  6310   6321     }else
  6311   6322   
  6312   6323     if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
  6313   6324       rc = shell_dbinfo_command(p, nArg, azArg);
  6314   6325     }else
  6315   6326   
  6316   6327     if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){

Changes to src/sqlite.h.in.

  2211   2211   ** the writable_schema, positive to enable writable_schema, or negative to
  2212   2212   ** leave the setting unchanged. The second parameter is a pointer to an
  2213   2213   ** integer into which is written 0 or 1 to indicate whether the writable_schema
  2214   2214   ** is enabled or disabled following this call.
  2215   2215   ** </dd>
  2216   2216   ** </dl>
  2217   2217   */
         2218  +#define SQLITE_DBCONFIG_MIN                    998 /* Smallest DBCONFIG */
         2219  +#define SQLITE_DBCONFIG_ENABLE_VTAB            998 /* const char* */
         2220  +#define SQLITE_DBCONFIG_DISABLE_VTAB           999 /* const char* */
  2218   2221   #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  2219   2222   #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  2220   2223   #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  2221   2224   #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
  2222   2225   #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  2223   2226   #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  2224   2227   #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */

Changes to src/sqliteInt.h.

  1802   1802   ** Each SQLite module (virtual table definition) is defined by an
  1803   1803   ** instance of the following structure, stored in the sqlite3.aModule
  1804   1804   ** hash table.
  1805   1805   */
  1806   1806   struct Module {
  1807   1807     const sqlite3_module *pModule;       /* Callback pointers */
  1808   1808     const char *zName;                   /* Name passed to create_module() */
         1809  +  u8 bDisabled;                        /* True if disabled */
  1809   1810     void *pAux;                          /* pAux passed to create_module() */
  1810   1811     void (*xDestroy)(void *);            /* Module destructor function */
  1811   1812     Table *pEpoTab;                      /* Eponymous table for this module */
  1812   1813   };
  1813   1814   
  1814   1815   /*
  1815   1816   ** information about each column of an SQL table is held in an instance

Changes to src/vtab.c.

   633    633       return SQLITE_OK;
   634    634     }
   635    635   
   636    636     /* Locate the required virtual table module */
   637    637     zMod = pTab->azModuleArg[0];
   638    638     pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
   639    639   
   640         -  if( !pMod ){
          640  +  if( !pMod || pMod->bDisabled ){
   641    641       const char *zModule = pTab->azModuleArg[0];
   642    642       sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
   643    643       rc = SQLITE_ERROR;
   644    644     }else{
   645    645       char *zErr = 0;
   646    646       rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
   647    647       if( rc!=SQLITE_OK ){