/ Changes On Branch disable-vtab
Login

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

Changes In Branch disable-vtab Excluding Merge-Ins

This is equivalent to a diff from bf3cd9364f to c70524280f

2019-04-04
22:05
Add the vtab enable/disable options to the sqlite3_db_config TCL command in the testfixture. (Leaf check-in: c70524280f user: drh tags: disable-vtab)
20:55
Add further test cases to improve VDBE branch coverage. (check-in: 51a95e52fc user: dan tags: trunk)
20:21
Provide a DBCONFIG to enable or disable virtual tables that match a LIKE pattern. (check-in: b40a4edceb 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: bf3cd9364f user: drh tags: trunk)
18:20
Minor fixes to requirements marks. (check-in: 02ebc60b9b user: drh tags: trunk)

Changes to src/build.c.

364
365
366
367
368
369
370


371

372
373
374
375
376
377
378
    ** CREATE, then check to see if it is the name of an virtual table that
    ** can be an eponymous virtual table. */
    if( pParse->disableVtab==0 ){
      Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName);
      if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
        pMod = sqlite3PragmaVtabRegister(db, zName);
      }


      if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){

        return pMod->pEpoTab;
      }
    }
#endif
    if( flags & LOCATE_NOERR ) return 0;
    pParse->checkSchema = 1;
  }else if( IsVirtual(p) && pParse->disableVtab ){







>
>
|
>







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

Changes to src/main.c.

824
825
826
827
828
829
830













831
832
833
834
835
836
837
    }
    case SQLITE_DBCONFIG_LOOKASIDE: {
      void *pBuf = va_arg(ap, void*); /* IMP: R-26835-10964 */
      int sz = va_arg(ap, int);       /* IMP: R-47871-25994 */
      int cnt = va_arg(ap, int);      /* IMP: R-04460-53386 */
      rc = setupLookaside(db, pBuf, sz, cnt);
      break;













    }
    default: {
      static const struct {
        int op;      /* The opcode */
        u32 mask;    /* Mask of the bit in sqlite3.flags to set/clear */
      } aFlagOp[] = {
        { SQLITE_DBCONFIG_ENABLE_FKEY,           SQLITE_ForeignKeys    },







>
>
>
>
>
>
>
>
>
>
>
>
>







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

Changes to src/pragma.c.

1252
1253
1254
1255
1256
1257
1258

1259
1260
1261
1262
1263
1264
1265

#ifndef SQLITE_OMIT_VIRTUALTABLE
  case PragTyp_MODULE_LIST: {
    HashElem *j;
    pParse->nMem = 1;
    for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
      Module *pMod = (Module*)sqliteHashData(j);

      sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
    }
  }
  break;
#endif /* SQLITE_OMIT_VIRTUALTABLE */

  case PragTyp_PRAGMA_LIST: {







>







1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266

#ifndef SQLITE_OMIT_VIRTUALTABLE
  case PragTyp_MODULE_LIST: {
    HashElem *j;
    pParse->nMem = 1;
    for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
      Module *pMod = (Module*)sqliteHashData(j);
      if( pMod->bDisabled ) continue;
      sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
    }
  }
  break;
#endif /* SQLITE_OMIT_VIRTUALTABLE */

  case PragTyp_PRAGMA_LIST: {

Changes to src/shell.c.in.

6277
6278
6279
6280
6281
6282
6283

6284
6285
6286
6287
6288
6289
6290
6291
6292
6293


6294
6295
6296
6297
6298
6299

6300


6301


6302
6303



6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
    }
  }else

  if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
    static const struct DbConfigChoices {
      const char *zName;
      int op;

    } aDbConfig[] = {
        { "enable_fkey",      SQLITE_DBCONFIG_ENABLE_FKEY            },
        { "enable_trigger",   SQLITE_DBCONFIG_ENABLE_TRIGGER         },
        { "fts3_tokenizer",   SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER  },
        { "load_extension",   SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION  },
        { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE       },
        { "enable_qpsg",      SQLITE_DBCONFIG_ENABLE_QPSG            },
        { "trigger_eqp",      SQLITE_DBCONFIG_TRIGGER_EQP            },
        { "reset_database",   SQLITE_DBCONFIG_RESET_DATABASE         },
        { "defensive",        SQLITE_DBCONFIG_DEFENSIVE              },


    };
    int ii, v;
    open_db(p, 0);
    for(ii=0; ii<ArraySize(aDbConfig); ii++){
      if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
      if( nArg>=3 ){

        sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);


      }


      sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
      utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");



      if( nArg>1 ) break;
    }
    if( nArg>1 && ii==ArraySize(aDbConfig) ){
      utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
      utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
    }   
  }else

  if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
    rc = shell_dbinfo_command(p, nArg, azArg);
  }else

  if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){







>

|
|
|
|
|
|
|
|
|
>
>






>
|
>
>
|
>
>
|
|
>
>
>





|







6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
    }
  }else

  if( c=='d' && n>=3 && strncmp(azArg[0], "dbconfig", n)==0 ){
    static const struct DbConfigChoices {
      const char *zName;
      int op;
      int eArgType;
    } aDbConfig[] = {
        { "enable_fkey",      SQLITE_DBCONFIG_ENABLE_FKEY,            0 },
        { "enable_trigger",   SQLITE_DBCONFIG_ENABLE_TRIGGER,         0 },
        { "fts3_tokenizer",   SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,  0 },
        { "load_extension",   SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,  0 },
        { "no_ckpt_on_close", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,       0 },
        { "enable_qpsg",      SQLITE_DBCONFIG_ENABLE_QPSG,            0 },
        { "trigger_eqp",      SQLITE_DBCONFIG_TRIGGER_EQP,            0 },
        { "reset_database",   SQLITE_DBCONFIG_RESET_DATABASE,         0 },
        { "defensive",        SQLITE_DBCONFIG_DEFENSIVE,              0 },
        { "enable_vtab",      SQLITE_DBCONFIG_ENABLE_VTAB,            1 },
        { "disable_vtab",     SQLITE_DBCONFIG_DISABLE_VTAB,           1 },
    };
    int ii, v;
    open_db(p, 0);
    for(ii=0; ii<ArraySize(aDbConfig); ii++){
      if( nArg>1 && strcmp(azArg[1], aDbConfig[ii].zName)!=0 ) continue;
      if( nArg>=3 ){
        if( aDbConfig[ii].eArgType==0 ){
          sqlite3_db_config(p->db, aDbConfig[ii].op, booleanValue(azArg[2]), 0);
        }else{
          sqlite3_db_config(p->db, aDbConfig[ii].op, azArg[2], 0);
        }
      }
      if( aDbConfig[ii].eArgType==0 ){
        sqlite3_db_config(p->db, aDbConfig[ii].op, -1, &v);
        utf8_printf(p->out, "%18s %s\n", aDbConfig[ii].zName, v ? "on" : "off");
      }else if( nArg<2 ){
        utf8_printf(p->out, "%18s PATTERN\n", aDbConfig[ii].zName);
      }
      if( nArg>1 ) break;
    }
    if( nArg>1 && ii==ArraySize(aDbConfig) ){
      utf8_printf(stderr, "Error: unknown dbconfig \"%s\"\n", azArg[1]);
      utf8_printf(stderr, "Enter \".dbconfig\" with no arguments for a list\n");
    }
  }else

  if( c=='d' && n>=3 && strncmp(azArg[0], "dbinfo", n)==0 ){
    rc = shell_dbinfo_command(p, nArg, azArg);
  }else

  if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){

Changes to src/sqlite.h.in.

2211
2212
2213
2214
2215
2216
2217



2218
2219
2220
2221
2222
2223
2224
** the writable_schema, positive to enable writable_schema, or negative to
** leave the setting unchanged. The second parameter is a pointer to an
** integer into which is written 0 or 1 to indicate whether the writable_schema
** is enabled or disabled following this call.
** </dd>
** </dl>
*/



#define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
#define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
#define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */







>
>
>







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

Changes to src/sqliteInt.h.

1802
1803
1804
1805
1806
1807
1808

1809
1810
1811
1812
1813
1814
1815
** Each SQLite module (virtual table definition) is defined by an
** instance of the following structure, stored in the sqlite3.aModule
** hash table.
*/
struct Module {
  const sqlite3_module *pModule;       /* Callback pointers */
  const char *zName;                   /* Name passed to create_module() */

  void *pAux;                          /* pAux passed to create_module() */
  void (*xDestroy)(void *);            /* Module destructor function */
  Table *pEpoTab;                      /* Eponymous table for this module */
};

/*
** information about each column of an SQL table is held in an instance







>







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

/*
** information about each column of an SQL table is held in an instance

Changes to src/test1.c.

7579
7580
7581
7582
7583
7584
7585

7586
7587
7588
7589
7590
7591
7592
7593
7594
7595



7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610


7611
7612
7613
7614
7615
7616
7617
7618

7619
7620
7621



7622
7623
7624
7625
7626
7627
7628
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  static const struct {
    const char *zName;
    int eVal;

  } aSetting[] = {
    { "FKEY",            SQLITE_DBCONFIG_ENABLE_FKEY },
    { "TRIGGER",         SQLITE_DBCONFIG_ENABLE_TRIGGER },
    { "FTS3_TOKENIZER",  SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER },
    { "LOAD_EXTENSION",  SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION },
    { "NO_CKPT_ON_CLOSE",SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE },
    { "QPSG",            SQLITE_DBCONFIG_ENABLE_QPSG },
    { "TRIGGER_EQP",     SQLITE_DBCONFIG_TRIGGER_EQP },
    { "RESET_DB",        SQLITE_DBCONFIG_RESET_DATABASE },
    { "DEFENSIVE",       SQLITE_DBCONFIG_DEFENSIVE },



  };
  int i;
  int v;
  const char *zSetting;
  sqlite3 *db;

  if( objc!=4 ){
    Tcl_WrongNumArgs(interp, 1, objv, "DB SETTING VALUE");
    return TCL_ERROR;
  }
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  zSetting = Tcl_GetString(objv[2]);
  if( sqlite3_strglob("SQLITE_*", zSetting)==0 ) zSetting += 7;
  if( sqlite3_strglob("DBCONFIG_*", zSetting)==0 ) zSetting += 9;
  if( sqlite3_strglob("ENABLE_*", zSetting)==0 ) zSetting += 7;


  for(i=0; i<ArraySize(aSetting); i++){
    if( strcmp(zSetting, aSetting[i].zName)==0 ) break;
  }
  if( i>=ArraySize(aSetting) ){
    Tcl_SetObjResult(interp,
      Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
    return TCL_ERROR;
  }

  if( Tcl_GetIntFromObj(interp, objv[3], &v) ) return TCL_ERROR;
  sqlite3_db_config(db, aSetting[i].eVal, v, &v);
  Tcl_SetObjResult(interp, Tcl_NewIntObj(v));



  return TCL_OK;
}

/*
** Change the name of the main database schema from "main" to "icecube".
*/
static int SQLITE_TCLAPI test_dbconfig_maindbname_icecube(







>

|
|
|
|
|
|
|
|
|
>
>
>














|
>
>








>
|
|
|
>
>
>







7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
  Tcl_Interp *interp,
  int objc,
  Tcl_Obj *CONST objv[]
){
  static const struct {
    const char *zName;
    int eVal;
    int eArgType;
  } aSetting[] = {
    { "FKEY",            SQLITE_DBCONFIG_ENABLE_FKEY,            0 },
    { "TRIGGER",         SQLITE_DBCONFIG_ENABLE_TRIGGER,         0 },
    { "FTS3_TOKENIZER",  SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER,  0 },
    { "LOAD_EXTENSION",  SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION,  0 },
    { "NO_CKPT_ON_CLOSE",SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,       0 },
    { "QPSG",            SQLITE_DBCONFIG_ENABLE_QPSG,            0 },
    { "TRIGGER_EQP",     SQLITE_DBCONFIG_TRIGGER_EQP,            0 },
    { "RESET_DB",        SQLITE_DBCONFIG_RESET_DATABASE,         0 },
    { "DEFENSIVE",       SQLITE_DBCONFIG_DEFENSIVE,              0 },
    { "WRITABLE_SCHEMA", SQLITE_DBCONFIG_WRITABLE_SCHEMA,        0 },
    { "ENABLE_VTAB",     SQLITE_DBCONFIG_ENABLE_VTAB,            1 },
    { "DISABLE_VTAB",    SQLITE_DBCONFIG_DISABLE_VTAB,           1 },
  };
  int i;
  int v;
  const char *zSetting;
  sqlite3 *db;

  if( objc!=4 ){
    Tcl_WrongNumArgs(interp, 1, objv, "DB SETTING VALUE");
    return TCL_ERROR;
  }
  if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
  zSetting = Tcl_GetString(objv[2]);
  if( sqlite3_strglob("SQLITE_*", zSetting)==0 ) zSetting += 7;
  if( sqlite3_strglob("DBCONFIG_*", zSetting)==0 ) zSetting += 9;
  if( sqlite3_strglob("ENABLE_*", zSetting)==0 && zSetting[7]!='V' ){
    zSetting += 7;
  }
  for(i=0; i<ArraySize(aSetting); i++){
    if( strcmp(zSetting, aSetting[i].zName)==0 ) break;
  }
  if( i>=ArraySize(aSetting) ){
    Tcl_SetObjResult(interp,
      Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
    return TCL_ERROR;
  }
  if( aSetting[i].eArgType==0 ){
    if( Tcl_GetIntFromObj(interp, objv[3], &v) ) return TCL_ERROR;
    sqlite3_db_config(db, aSetting[i].eVal, v, &v);
    Tcl_SetObjResult(interp, Tcl_NewIntObj(v));
  }else if( aSetting[i].eArgType==1 ){
    sqlite3_db_config(db, aSetting[i].eVal, Tcl_GetString(objv[3]));
  }
  return TCL_OK;
}

/*
** Change the name of the main database schema from "main" to "icecube".
*/
static int SQLITE_TCLAPI test_dbconfig_maindbname_icecube(

Changes to src/vtab.c.

633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
    return SQLITE_OK;
  }

  /* Locate the required virtual table module */
  zMod = pTab->azModuleArg[0];
  pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);

  if( !pMod ){
    const char *zModule = pTab->azModuleArg[0];
    sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
    rc = SQLITE_ERROR;
  }else{
    char *zErr = 0;
    rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
    if( rc!=SQLITE_OK ){







|







633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
    return SQLITE_OK;
  }

  /* Locate the required virtual table module */
  zMod = pTab->azModuleArg[0];
  pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);

  if( !pMod || pMod->bDisabled ){
    const char *zModule = pTab->azModuleArg[0];
    sqlite3ErrorMsg(pParse, "no such module: %s", zModule);
    rc = SQLITE_ERROR;
  }else{
    char *zErr = 0;
    rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
    if( rc!=SQLITE_OK ){