/ Check-in [2c51644a]
Login

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

Overview
Comment:Add the ".eqp trigger" option to the ".eqp" command in the command-line shell. Implemented using the new SQLITE_DBCONFIG_TRIGGER_EQP control.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2c51644a12a638d89e4f7cc3fd561236ce424f2d4e1db31f1e8388f77add02b8
User & Date: drh 2017-12-21 21:02:27
Context
2017-12-21
21:41
Fix SQLITE_DBCONFIG_TRIGGER_EQP so that it works even if SQLITE_DEBUG is not defined. check-in: afbbfff7 user: drh tags: trunk
21:02
Add the ".eqp trigger" option to the ".eqp" command in the command-line shell. Implemented using the new SQLITE_DBCONFIG_TRIGGER_EQP control. check-in: 2c51644a user: drh tags: trunk
18:55
Add the ".expert" command to the shell tool's ".help" output. check-in: fc6193af user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

   873    873   #if defined(SQLITE_ENABLE_SESSION)
   874    874     int nSession;             /* Number of active sessions */
   875    875     OpenSession aSession[4];  /* Array of sessions.  [0] is in focus. */
   876    876   #endif
   877    877     ExpertInfo expert;        /* Valid if previous command was ".expert OPT..." */
   878    878   };
   879    879   
          880  +/* Allowed values for ShellState.autoEQP
          881  +*/
          882  +#define AUTOEQP_off      0
          883  +#define AUTOEQP_on       1
          884  +#define AUTOEQP_trigger  2
          885  +#define AUTOEQP_full     3
          886  +
   880    887   /*
   881    888   ** These are the allowed shellFlgs values
   882    889   */
   883    890   #define SHFLG_Pagecache      0x00000001 /* The --pagecache option is used */
   884    891   #define SHFLG_Lookaside      0x00000002 /* Lookaside memory is used */
   885    892   #define SHFLG_Backslash      0x00000004 /* The --backslash option is used */
   886    893   #define SHFLG_PreserveRowid  0x00000008 /* .dump preserves rowid values */
................................................................................
  2391   2398           utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
  2392   2399         }
  2393   2400   
  2394   2401         /* Show the EXPLAIN QUERY PLAN if .eqp is on */
  2395   2402         if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
  2396   2403           sqlite3_stmt *pExplain;
  2397   2404           char *zEQP;
         2405  +        int triggerEQP = 0;
  2398   2406           disable_debug_trace_modes();
         2407  +        sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
         2408  +        if( pArg->autoEQP>=AUTOEQP_trigger ){
         2409  +          sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 1, 0);
         2410  +        }
  2399   2411           zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
  2400   2412           rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
  2401   2413           if( rc==SQLITE_OK ){
  2402   2414             while( sqlite3_step(pExplain)==SQLITE_ROW ){
  2403   2415               raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
  2404   2416               raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
  2405   2417               raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
  2406   2418               utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
  2407   2419             }
  2408   2420           }
  2409   2421           sqlite3_finalize(pExplain);
  2410   2422           sqlite3_free(zEQP);
  2411         -        if( pArg->autoEQP>=2 ){
         2423  +        if( pArg->autoEQP>=AUTOEQP_full ){
  2412   2424             /* Also do an EXPLAIN for ".eqp full" mode */
  2413   2425             zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
  2414   2426             rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
  2415   2427             if( rc==SQLITE_OK ){
  2416   2428               pArg->cMode = MODE_Explain;
  2417   2429               explain_data_prepare(pArg, pExplain);
  2418   2430               exec_prepared_stmt(pArg, pExplain, xCallback);
  2419   2431               explain_data_delete(pArg);
  2420   2432             }
  2421   2433             sqlite3_finalize(pExplain);
  2422   2434             sqlite3_free(zEQP);
  2423   2435           }
         2436  +        sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0);
  2424   2437           restore_debug_trace_modes();
  2425   2438         }
  2426   2439   
  2427   2440         if( pArg ){
  2428   2441           pArg->cMode = pArg->mode;
  2429   2442           if( pArg->autoExplain
  2430   2443            && sqlite3_column_count(pStmt)==8
................................................................................
  4543   4556         rc = 1;
  4544   4557       }
  4545   4558     }else
  4546   4559   
  4547   4560     if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
  4548   4561       if( nArg==2 ){
  4549   4562         if( strcmp(azArg[1],"full")==0 ){
  4550         -        p->autoEQP = 2;
         4563  +        p->autoEQP = AUTOEQP_full;
         4564  +      }else if( strcmp(azArg[1],"trigger")==0 ){
         4565  +        p->autoEQP = AUTOEQP_trigger;
  4551   4566         }else{
  4552   4567           p->autoEQP = booleanValue(azArg[1]);
  4553   4568         }
  4554   4569       }else{
  4555         -      raw_printf(stderr, "Usage: .eqp on|off|full\n");
         4570  +      raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
  4556   4571         rc = 1;
  4557   4572       }
  4558   4573     }else
  4559   4574   
  4560   4575     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
  4561   4576       if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
  4562   4577       rc = 2;
................................................................................
  5901   5916       }
  5902   5917       x = system(zCmd);
  5903   5918       sqlite3_free(zCmd);
  5904   5919       if( x ) raw_printf(stderr, "System command returns %d\n", x);
  5905   5920     }else
  5906   5921   
  5907   5922     if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
  5908         -    static const char *azBool[] = { "off", "on", "full", "unk" };
         5923  +    static const char *azBool[] = { "off", "on", "trigger", "full"};
  5909   5924       int i;
  5910   5925       if( nArg!=1 ){
  5911   5926         raw_printf(stderr, "Usage: .show\n");
  5912   5927         rc = 1;
  5913   5928         goto meta_command_exit;
  5914   5929       }
  5915   5930       utf8_printf(p->out, "%12.12s: %s\n","echo",
................................................................................
  7053   7068       }else if( strcmp(z,"-header")==0 ){
  7054   7069         data.showHeader = 1;
  7055   7070       }else if( strcmp(z,"-noheader")==0 ){
  7056   7071         data.showHeader = 0;
  7057   7072       }else if( strcmp(z,"-echo")==0 ){
  7058   7073         ShellSetFlag(&data, SHFLG_Echo);
  7059   7074       }else if( strcmp(z,"-eqp")==0 ){
  7060         -      data.autoEQP = 1;
         7075  +      data.autoEQP = AUTOEQP_on;
  7061   7076       }else if( strcmp(z,"-eqpfull")==0 ){
  7062         -      data.autoEQP = 2;
         7077  +      data.autoEQP = AUTOEQP_full;
  7063   7078       }else if( strcmp(z,"-stats")==0 ){
  7064   7079         data.statsOn = 1;
  7065   7080       }else if( strcmp(z,"-scanstats")==0 ){
  7066   7081         data.scanstatsOn = 1;
  7067   7082       }else if( strcmp(z,"-backslash")==0 ){
  7068   7083         /* Undocumented command-line option: -backslash
  7069   7084         ** Causes C-style backslash escapes to be evaluated in SQL statements