/ Check-in [e775ef00]
Login

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

Overview
Comment:In the CLI, code the "sqlite_parameters" name directly rather than using a macro, for clarity of presentation for users who are reading the code for the purpose of seeing how the CLI implements parameter binding.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: e775ef002dd33e6bcbeec8d4b6ad7f59749e35548c7a59c9fa3bcfdc5cc50730
User & Date: drh 2019-03-25 21:56:26
Context
2019-03-25
22:05
Fix an obsolete comment in the CLI. No code changes. check-in: fade103c user: drh tags: trunk
21:56
In the CLI, code the "sqlite_parameters" name directly rather than using a macro, for clarity of presentation for users who are reading the code for the purpose of seeing how the CLI implements parameter binding. check-in: e775ef00 user: drh tags: trunk
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
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

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