/ Check-in [24ef3844]
Login

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

Overview
Comment:Change the name of the parameter table in the CLI to "sqlite_parameters". Doing so involves adding SQLITE_DBCONFIG_WRITABLE_SCHEMA and allowing the creation of tables whose names begin with "sqlite_" and that are indexed while writable_schema is on.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 24ef3844692debc2db7b1d427f5dcf4050481a8c7f71c3b516766b819ecab587
User & Date: drh 2019-03-25 21:35:41
Context
2019-03-25
21:55
Remove a test from the index build logic which is no longer needed and is in fact unreachable. check-in: 9b20ee10 user: drh tags: trunk
21:35
Change the name of the parameter table in the CLI to "sqlite_parameters". Doing so involves adding SQLITE_DBCONFIG_WRITABLE_SCHEMA and allowing the creation of tables whose names begin with "sqlite_" and that are indexed while writable_schema is on. check-in: 24ef3844 user: drh tags: trunk
19:50
Earlier detection of corruption while added to the freelist. check-in: 8c80b004 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  3150   3150     }
  3151   3151     pDb = &db->aDb[iDb];
  3152   3152   
  3153   3153     assert( pTab!=0 );
  3154   3154     assert( pParse->nErr==0 );
  3155   3155     if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0 
  3156   3156          && db->init.busy==0
         3157  +       && pTblName!=0
  3157   3158   #if SQLITE_USER_AUTHENTICATION
  3158   3159          && sqlite3UserAuthTable(pTab->zName)==0
  3159   3160   #endif
  3160   3161   #ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
  3161   3162          && sqlite3StrICmp(&pTab->zName[7],"master")!=0
  3162   3163   #endif
  3163   3164          && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0

Changes to src/main.c.

   839    839           { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer  },
   840    840           { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension  },
   841    841           { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE,      SQLITE_NoCkptOnClose  },
   842    842           { SQLITE_DBCONFIG_ENABLE_QPSG,           SQLITE_EnableQPSG     },
   843    843           { SQLITE_DBCONFIG_TRIGGER_EQP,           SQLITE_TriggerEQP     },
   844    844           { SQLITE_DBCONFIG_RESET_DATABASE,        SQLITE_ResetDatabase  },
   845    845           { SQLITE_DBCONFIG_DEFENSIVE,             SQLITE_Defensive      },
          846  +        { SQLITE_DBCONFIG_WRITABLE_SCHEMA,       SQLITE_WriteSchema|
          847  +                                                 SQLITE_NoSchemaError  },
   846    848         };
   847    849         unsigned int i;
   848    850         rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
   849    851         for(i=0; i<ArraySize(aFlagOp); i++){
   850    852           if( aFlagOp[i].op==op ){
   851    853             int onoff = va_arg(ap, int);
   852    854             int *pRes = va_arg(ap, int*);

Changes to src/shell.c.in.

  2744   2744   #endif
  2745   2745   #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
  2746   2746     sqlite3WhereTrace = savedWhereTrace;
  2747   2747   #endif
  2748   2748   }
  2749   2749   
  2750   2750   /* Name of the TEMP table that holds bind parameter values */
  2751         -#define BIND_PARAM_TABLE "$Parameters"
         2751  +#define BIND_PARAM_TABLE "sqlite_parameters"
  2752   2752   
  2753   2753   /* Create the TEMP table used to store parameter bindings */
  2754   2754   static void bind_table_init(ShellState *p){
         2755  +  int wrSchema = 0;
         2756  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
         2757  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
  2755   2758     sqlite3_exec(p->db,
  2756         -    "CREATE TABLE IF NOT EXISTS temp.[" BIND_PARAM_TABLE "](\n"
         2759  +    "CREATE TABLE IF NOT EXISTS temp." BIND_PARAM_TABLE "(\n"
  2757   2760       "  key TEXT PRIMARY KEY,\n"
  2758   2761       "  value ANY\n"
  2759   2762       ") WITHOUT ROWID;",
  2760   2763       0, 0, 0);
         2764  +  sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
  2761   2765   }
  2762   2766   
  2763   2767   /*
  2764   2768   ** Bind parameters on a prepared statement.
  2765   2769   **
  2766   2770   ** Parameter bindings are taken from a TEMP table of the form:
  2767   2771   **
................................................................................
  2781   2785     nVar = sqlite3_bind_parameter_count(pStmt);
  2782   2786     if( nVar==0 ) return;  /* Nothing to do */
  2783   2787     if( sqlite3_table_column_metadata(pArg->db, "TEMP", BIND_PARAM_TABLE,
  2784   2788                                       "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
  2785   2789       return; /* Parameter table does not exist */
  2786   2790     }
  2787   2791     rc = sqlite3_prepare_v2(pArg->db,
  2788         -          "SELECT value FROM temp.\"" BIND_PARAM_TABLE "\""
         2792  +          "SELECT value FROM temp." BIND_PARAM_TABLE
  2789   2793             " WHERE key=?1", -1, &pQ, 0);
  2790   2794     if( rc || pQ==0 ) return;
  2791   2795     for(i=1; i<=nVar; i++){
  2792   2796       char zNum[30];
  2793   2797       const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
  2794   2798       if( zVar==0 ){
  2795   2799         sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
................................................................................
  7138   7142       open_db(p,0);
  7139   7143       if( nArg<=1 ) goto parameter_syntax_error;
  7140   7144   
  7141   7145       /* .parameter clear
  7142   7146       ** Clear all bind parameters by dropping the TEMP table that holds them.
  7143   7147       */
  7144   7148       if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
  7145         -      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.[" BIND_PARAM_TABLE "];",
         7149  +      int wrSchema = 0;
         7150  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
         7151  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
         7152  +      sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp." BIND_PARAM_TABLE ";",
  7146   7153                      0, 0, 0);
         7154  +      sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
  7147   7155       }else
  7148   7156   
  7149   7157       /* .parameter list
  7150   7158       ** List all bind parameters.
  7151   7159       */
  7152   7160       if( nArg==2 && strcmp(azArg[1],"list")==0 ){
  7153   7161         sqlite3_stmt *pStmt = 0;
  7154   7162         int rx;
  7155   7163         int len = 0;
  7156   7164         rx = sqlite3_prepare_v2(p->db,
  7157   7165                "SELECT max(length(key)) "
  7158         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7166  +             "FROM temp." BIND_PARAM_TABLE ";", -1, &pStmt, 0);
  7159   7167         if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
  7160   7168           len = sqlite3_column_int(pStmt, 0);
  7161   7169           if( len>40 ) len = 40;
  7162   7170         }
  7163   7171         sqlite3_finalize(pStmt);
  7164   7172         pStmt = 0;
  7165   7173         if( len ){
  7166   7174           rx = sqlite3_prepare_v2(p->db,
  7167   7175                "SELECT key, quote(value) "
  7168         -             "FROM temp.[" BIND_PARAM_TABLE "];", -1, &pStmt, 0);
         7176  +             "FROM temp." BIND_PARAM_TABLE ";", -1, &pStmt, 0);
  7169   7177           while( sqlite3_step(pStmt)==SQLITE_ROW ){
  7170   7178             utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
  7171   7179                         sqlite3_column_text(pStmt,1));
  7172   7180           }
  7173   7181           sqlite3_finalize(pStmt);
  7174   7182         }
  7175   7183       }else
................................................................................
  7192   7200         int rx;
  7193   7201         char *zSql;
  7194   7202         sqlite3_stmt *pStmt;
  7195   7203         const char *zKey = azArg[2];
  7196   7204         const char *zValue = azArg[3];
  7197   7205         bind_table_init(p);
  7198   7206         zSql = sqlite3_mprintf(
  7199         -                  "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7207  +                  "REPLACE INTO temp." BIND_PARAM_TABLE "(key,value)"
  7200   7208                     "VALUES(%Q,%s);", zKey, zValue);
  7201   7209         if( zSql==0 ) shell_out_of_memory();
  7202   7210         pStmt = 0;
  7203   7211         rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  7204   7212         sqlite3_free(zSql);
  7205   7213         if( rx!=SQLITE_OK ){
  7206   7214           sqlite3_finalize(pStmt);
  7207   7215           pStmt = 0;
  7208   7216           zSql = sqlite3_mprintf(
  7209         -                   "REPLACE INTO temp.[" BIND_PARAM_TABLE "](key,value)"
         7217  +                   "REPLACE INTO temp." BIND_PARAM_TABLE "(key,value)"
  7210   7218                      "VALUES(%Q,%Q);", zKey, zValue);
  7211   7219           if( zSql==0 ) shell_out_of_memory();
  7212   7220           rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
  7213   7221           sqlite3_free(zSql);
  7214   7222           if( rx!=SQLITE_OK ){
  7215   7223             utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
  7216   7224             sqlite3_finalize(pStmt);
................................................................................
  7224   7232   
  7225   7233       /* .parameter unset NAME
  7226   7234       ** Remove the NAME binding from the parameter binding table, if it
  7227   7235       ** exists.
  7228   7236       */
  7229   7237       if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
  7230   7238         char *zSql = sqlite3_mprintf(
  7231         -          "DELETE FROM temp.[" BIND_PARAM_TABLE "] WHERE key=%Q", azArg[2]);
         7239  +          "DELETE FROM temp." BIND_PARAM_TABLE " WHERE key=%Q", azArg[2]);
  7232   7240         if( zSql==0 ) shell_out_of_memory();
  7233   7241         sqlite3_exec(p->db, zSql, 0, 0, 0);
  7234   7242         sqlite3_free(zSql);
  7235   7243       }else
  7236   7244       /* If no command name matches, show a syntax error */
  7237   7245       parameter_syntax_error:
  7238   7246       showHelp(p->out, "parameter");

Changes to src/sqlite.h.in.

  2195   2195   ** features include but are not limited to the following:
  2196   2196   ** <ul>
  2197   2197   ** <li> The [PRAGMA writable_schema=ON] statement.
  2198   2198   ** <li> Writes to the [sqlite_dbpage] virtual table.
  2199   2199   ** <li> Direct writes to [shadow tables].
  2200   2200   ** </ul>
  2201   2201   ** </dd>
         2202  +**
         2203  +** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
         2204  +** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
         2205  +** "writable_schema" flag. This has the same effect and is logically equivalent
         2206  +** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
         2207  +** The first argument to this setting is an integer which is 0 to disable 
         2208  +** the writable_schema, positive to enable writable_schema, or negative to
         2209  +** leave the setting unchanged. The second parameter is a pointer to an
         2210  +** integer into which is written 0 or 1 to indicate whether the writable_schema
         2211  +** is enabled or disabled following this call.
         2212  +** </dd>
  2202   2213   ** </dl>
  2203   2214   */
  2204   2215   #define SQLITE_DBCONFIG_MAINDBNAME            1000 /* const char* */
  2205   2216   #define SQLITE_DBCONFIG_LOOKASIDE             1001 /* void* int int */
  2206   2217   #define SQLITE_DBCONFIG_ENABLE_FKEY           1002 /* int int* */
  2207   2218   #define SQLITE_DBCONFIG_ENABLE_TRIGGER        1003 /* int int* */
  2208   2219   #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
  2209   2220   #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
  2210   2221   #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE      1006 /* int int* */
  2211   2222   #define SQLITE_DBCONFIG_ENABLE_QPSG           1007 /* int int* */
  2212   2223   #define SQLITE_DBCONFIG_TRIGGER_EQP           1008 /* int int* */
  2213   2224   #define SQLITE_DBCONFIG_RESET_DATABASE        1009 /* int int* */
  2214   2225   #define SQLITE_DBCONFIG_DEFENSIVE             1010 /* int int* */
  2215         -#define SQLITE_DBCONFIG_MAX                   1010 /* Largest DBCONFIG */
         2226  +#define SQLITE_DBCONFIG_WRITABLE_SCHEMA       1011 /* int int* */
         2227  +#define SQLITE_DBCONFIG_MAX                   1011 /* Largest DBCONFIG */
  2216   2228   
  2217   2229   /*
  2218   2230   ** CAPI3REF: Enable Or Disable Extended Result Codes
  2219   2231   ** METHOD: sqlite3
  2220   2232   **
  2221   2233   ** ^The sqlite3_extended_result_codes() routine enables or disables the
  2222   2234   ** [extended result codes] feature of SQLite. ^The extended result