/ Check-in [931421a2]
Login

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

Overview
Comment:Fix the shell so that it can be built with SQLITE_OMIT_VIRTUALTABLE.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 931421a22507a5e1edb46e19cb5b3958ec3904807836ab5bcc7a90f37f476e6a
User & Date: dan 2018-01-09 15:25:55
Context
2018-01-09
15:28
Updates to the README.md file for the ext/misc directory. No code changes. check-in: 6b3f4349 user: drh tags: trunk
15:25
Fix the shell so that it can be built with SQLITE_OMIT_VIRTUALTABLE. check-in: 931421a2 user: dan tags: trunk
14:30
Do not attempt to build the code in ext/expert/sqlite3expert.c if SQLITE_OMIT_VIRTUALTABLE is defined. check-in: ba967ad2 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.in.

  2396   2396         do{
  2397   2397           rc = sqlite3_step(pStmt);
  2398   2398         } while( rc == SQLITE_ROW );
  2399   2399       }
  2400   2400     }
  2401   2401   }
  2402   2402   
         2403  +#ifndef SQLITE_OMIT_VIRTUALTABLE
  2403   2404   /*
  2404   2405   ** This function is called to process SQL if the previous shell command
  2405   2406   ** was ".expert". It passes the SQL in the second argument directly to
  2406   2407   ** the sqlite3expert object.
  2407   2408   **
  2408   2409   ** If successful, SQLITE_OK is returned. Otherwise, an SQLite error
  2409   2410   ** code. In this case, (*pzErr) may be set to point to a buffer containing
................................................................................
  2468   2469       }
  2469   2470     }
  2470   2471     sqlite3_expert_destroy(p);
  2471   2472     pState->expert.pExpert = 0;
  2472   2473     return rc;
  2473   2474   }
  2474   2475   
         2476  +/*
         2477  +** Implementation of ".expert" dot command.
         2478  +*/
         2479  +static int expertDotCommand(
         2480  +  ShellState *pState,             /* Current shell tool state */
         2481  +  char **azArg,                   /* Array of arguments passed to dot command */
         2482  +  int nArg                        /* Number of entries in azArg[] */
         2483  +){
         2484  +  int rc = SQLITE_OK;
         2485  +  char *zErr = 0;
         2486  +  int i;
         2487  +  int iSample = 0;
         2488  +
         2489  +  assert( pState->expert.pExpert==0 );
         2490  +  memset(&pState->expert, 0, sizeof(ExpertInfo));
         2491  +
         2492  +  for(i=1; rc==SQLITE_OK && i<nArg; i++){
         2493  +    char *z = azArg[i];
         2494  +    int n;
         2495  +    if( z[0]=='-' && z[1]=='-' ) z++;
         2496  +    n = strlen30(z);
         2497  +    if( n>=2 && 0==strncmp(z, "-verbose", n) ){
         2498  +      pState->expert.bVerbose = 1;
         2499  +    }
         2500  +    else if( n>=2 && 0==strncmp(z, "-sample", n) ){
         2501  +      if( i==(nArg-1) ){
         2502  +        raw_printf(stderr, "option requires an argument: %s\n", z);
         2503  +        rc = SQLITE_ERROR;
         2504  +      }else{
         2505  +        iSample = (int)integerValue(azArg[++i]);
         2506  +        if( iSample<0 || iSample>100 ){
         2507  +          raw_printf(stderr, "value out of range: %s\n", azArg[i]);
         2508  +          rc = SQLITE_ERROR;
         2509  +        }
         2510  +      }
         2511  +    }
         2512  +    else{
         2513  +      raw_printf(stderr, "unknown option: %s\n", z);
         2514  +      rc = SQLITE_ERROR;
         2515  +    }
         2516  +  }
         2517  +
         2518  +  if( rc==SQLITE_OK ){
         2519  +    pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
         2520  +    if( pState->expert.pExpert==0 ){
         2521  +      raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
         2522  +      rc = SQLITE_ERROR;
         2523  +    }else{
         2524  +      sqlite3_expert_config(
         2525  +          pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
         2526  +      );
         2527  +    }
         2528  +  }
         2529  +
         2530  +  return rc;
         2531  +}
         2532  +#endif /* ifndef SQLITE_OMIT_VIRTUALTABLE */
  2475   2533   
  2476   2534   /*
  2477   2535   ** Execute a statement or set of statements.  Print
  2478   2536   ** any result rows/columns depending on the current mode
  2479   2537   ** set via the supplied callback.
  2480   2538   **
  2481   2539   ** This is very similar to SQLite's built-in sqlite3_exec()
................................................................................
  2495   2553     int rc2;
  2496   2554     const char *zLeftover;          /* Tail of unprocessed SQL */
  2497   2555   
  2498   2556     if( pzErrMsg ){
  2499   2557       *pzErrMsg = NULL;
  2500   2558     }
  2501   2559   
         2560  +#ifndef SQLITE_OMIT_VIRTUALTABLE
  2502   2561     if( pArg->expert.pExpert ){
  2503   2562       rc = expertHandleSQL(pArg, zSql, pzErrMsg);
  2504   2563       return expertFinish(pArg, (rc!=SQLITE_OK), pzErrMsg);
  2505   2564     }
         2565  +#endif
  2506   2566   
  2507   2567     while( zSql[0] && (SQLITE_OK == rc) ){
  2508   2568       static const char *zStmtSql;
  2509   2569       rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
  2510   2570       if( SQLITE_OK != rc ){
  2511   2571         if( pzErrMsg ){
  2512   2572           *pzErrMsg = save_err_msg(db);
................................................................................
  5102   5162   
  5103   5163     return rc;
  5104   5164   }
  5105   5165   /* End of the ".archive" or ".ar" command logic
  5106   5166   **********************************************************************************/
  5107   5167   #endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB) */
  5108   5168   
  5109         -/*
  5110         -** Implementation of ".expert" dot command.
  5111         -*/
  5112         -static int expertDotCommand(
  5113         -  ShellState *pState,             /* Current shell tool state */
  5114         -  char **azArg,                   /* Array of arguments passed to dot command */
  5115         -  int nArg                        /* Number of entries in azArg[] */
  5116         -){
  5117         -  int rc = SQLITE_OK;
  5118         -  char *zErr = 0;
  5119         -  int i;
  5120         -  int iSample = 0;
  5121         -
  5122         -  assert( pState->expert.pExpert==0 );
  5123         -  memset(&pState->expert, 0, sizeof(ExpertInfo));
  5124         -
  5125         -  for(i=1; rc==SQLITE_OK && i<nArg; i++){
  5126         -    char *z = azArg[i];
  5127         -    int n;
  5128         -    if( z[0]=='-' && z[1]=='-' ) z++;
  5129         -    n = strlen30(z);
  5130         -    if( n>=2 && 0==strncmp(z, "-verbose", n) ){
  5131         -      pState->expert.bVerbose = 1;
  5132         -    }
  5133         -    else if( n>=2 && 0==strncmp(z, "-sample", n) ){
  5134         -      if( i==(nArg-1) ){
  5135         -        raw_printf(stderr, "option requires an argument: %s\n", z);
  5136         -        rc = SQLITE_ERROR;
  5137         -      }else{
  5138         -        iSample = (int)integerValue(azArg[++i]);
  5139         -        if( iSample<0 || iSample>100 ){
  5140         -          raw_printf(stderr, "value out of range: %s\n", azArg[i]);
  5141         -          rc = SQLITE_ERROR;
  5142         -        }
  5143         -      }
  5144         -    }
  5145         -    else{
  5146         -      raw_printf(stderr, "unknown option: %s\n", z);
  5147         -      rc = SQLITE_ERROR;
  5148         -    }
  5149         -  }
  5150         -
  5151         -  if( rc==SQLITE_OK ){
  5152         -    pState->expert.pExpert = sqlite3_expert_new(pState->db, &zErr);
  5153         -    if( pState->expert.pExpert==0 ){
  5154         -      raw_printf(stderr, "sqlite3_expert_new: %s\n", zErr);
  5155         -      rc = SQLITE_ERROR;
  5156         -    }else{
  5157         -      sqlite3_expert_config(
  5158         -          pState->expert.pExpert, EXPERT_CONFIG_SAMPLE, iSample
  5159         -      );
  5160         -    }
  5161         -  }
  5162         -
  5163         -  return rc;
  5164         -}
  5165         -
  5166   5169   
  5167   5170   /*
  5168   5171   ** If an input line begins with "." then invoke this routine to
  5169   5172   ** process that line.
  5170   5173   **
  5171   5174   ** Return 1 on error, 2 to exit, and 0 otherwise.
  5172   5175   */
................................................................................
  5173   5176   static int do_meta_command(char *zLine, ShellState *p){
  5174   5177     int h = 1;
  5175   5178     int nArg = 0;
  5176   5179     int n, c;
  5177   5180     int rc = 0;
  5178   5181     char *azArg[50];
  5179   5182   
         5183  +#ifndef SQLITE_OMIT_VIRTUALTABLE
  5180   5184     if( p->expert.pExpert ){
  5181   5185       expertFinish(p, 1, 0);
  5182   5186     }
         5187  +#endif
  5183   5188   
  5184   5189     /* Parse the input line into tokens.
  5185   5190     */
  5186   5191     while( zLine[h] && nArg<ArraySize(azArg) ){
  5187   5192       while( IsSpace(zLine[h]) ){ h++; }
  5188   5193       if( zLine[h]==0 ) break;
  5189   5194       if( zLine[h]=='\'' || zLine[h]=='"' ){
................................................................................
  5540   5545         p->autoExplain = 0;
  5541   5546       }else if( val==99 ){
  5542   5547         if( p->mode==MODE_Explain ) p->mode = p->normalMode;
  5543   5548         p->autoExplain = 1;
  5544   5549       }
  5545   5550     }else
  5546   5551   
         5552  +#ifndef SQLITE_OMIT_VIRTUALTABLE
  5547   5553     if( c=='e' && strncmp(azArg[0], "expert", n)==0 ){
  5548   5554       open_db(p, 0);
  5549   5555       expertDotCommand(p, azArg, nArg);
  5550   5556     }else
         5557  +#endif
  5551   5558   
  5552   5559     if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
  5553   5560       ShellState data;
  5554   5561       char *zErrMsg = 0;
  5555   5562       int doStats = 0;
  5556   5563       memcpy(&data, p, sizeof(data));
  5557   5564       data.showHeader = 0;