/ Check-in [f5ad1e1b]
Login

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

Overview
Comment:Updates to the command-line shell. Simplify the banner message. Add the ".save" command as an alias for ".backup". When starting with no arguments, include a banner message warning that the database is transient and in-memory and mention the ".open" command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f5ad1e1bf2828c5da70c1ff944d8212036142e6f
User & Date: drh 2014-02-11 16:22:18
Context
2014-02-11
16:24
Increase the version number to 3.8.4 check-in: 0a8bcbbd user: drh tags: trunk
16:22
Updates to the command-line shell. Simplify the banner message. Add the ".save" command as an alias for ".backup". When starting with no arguments, include a banner message warning that the database is transient and in-memory and mention the ".open" command. check-in: f5ad1e1b user: drh tags: trunk
14:37
Fixes to the "editline" support in the command-line shell. check-in: 7989ce5f user: drh tags: trunk
2014-02-10
19:59
Add the ".save" command as an alias for ".backup". Improvements to the way font changes are implemented on the in-memory database warning. Closed-Leaf check-in: fe284afe user: drh tags: memdb-warning
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  1582   1582     ".output FILENAME       Send output to FILENAME\n"
  1583   1583     ".output stdout         Send output to the screen\n"
  1584   1584     ".print STRING...       Print literal STRING\n"
  1585   1585     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  1586   1586     ".quit                  Exit this program\n"
  1587   1587     ".read FILENAME         Execute SQL in FILENAME\n"
  1588   1588     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
         1589  +  ".save FILE             Write in-memory database into FILE\n"
  1589   1590     ".schema ?TABLE?        Show the CREATE statements\n"
  1590   1591     "                         If TABLE specified, only show tables matching\n"
  1591   1592     "                         LIKE pattern TABLE.\n"
  1592   1593     ".separator STRING      Change separator used by output mode and .import\n"
  1593   1594     ".show                  Show the current values for various settings\n"
  1594   1595     ".stats ON|OFF          Turn stats on or off\n"
  1595   1596     ".tables ?TABLE?        List names of tables\n"
................................................................................
  2151   2152     }
  2152   2153   
  2153   2154     /* Process the input line.
  2154   2155     */
  2155   2156     if( nArg==0 ) return 0; /* no tokens, no error */
  2156   2157     n = strlen30(azArg[0]);
  2157   2158     c = azArg[0][0];
  2158         -  if( c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0 ){
         2159  +  if( (c=='b' && n>=3 && strncmp(azArg[0], "backup", n)==0)
         2160  +   || (c=='s' && n>=3 && strncmp(azArg[0], "save", n)==0)
         2161  +  ){
  2159   2162       const char *zDestFile = 0;
  2160   2163       const char *zDb = 0;
  2161   2164       sqlite3 *pDest;
  2162   2165       sqlite3_backup *pBackup;
  2163   2166       int j;
  2164   2167       for(j=1; j<nArg; j++){
  2165   2168         const char *z = azArg[j];
................................................................................
  3499   3502     sqlite3_config(SQLITE_CONFIG_URI, 1);
  3500   3503     sqlite3_config(SQLITE_CONFIG_LOG, shellLog, data);
  3501   3504     sqlite3_snprintf(sizeof(mainPrompt), mainPrompt,"sqlite> ");
  3502   3505     sqlite3_snprintf(sizeof(continuePrompt), continuePrompt,"   ...> ");
  3503   3506     sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
  3504   3507   }
  3505   3508   
         3509  +/*
         3510  +** Output text to the console in a font that attracts extra attention.
         3511  +*/
         3512  +#ifdef _WIN32
         3513  +static void printBold(const char *zText){
         3514  +  HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
         3515  +  CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
         3516  +  GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
         3517  +  SetConsoleTextAttribute(out,
         3518  +         FOREGROUND_RED|FOREGROUND_INTENSITY
         3519  +  );
         3520  +  printf("%s", zText);
         3521  +  SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes);
         3522  +}
         3523  +#else
         3524  +static void printBold(const char *zText){
         3525  +  printf("\033[1m%s\033[0m", zText);
         3526  +}
         3527  +#endif
         3528  +
  3506   3529   /*
  3507   3530   ** Get the argument to an --option.  Throw an error and die if no argument
  3508   3531   ** is available.
  3509   3532   */
  3510   3533   static char *cmdline_option_value(int argc, char **argv, int i){
  3511   3534     if( i==argc ){
  3512   3535       fprintf(stderr, "%s: Error: missing argument to %s\n",
................................................................................
  3519   3542   int main(int argc, char **argv){
  3520   3543     char *zErrMsg = 0;
  3521   3544     struct callback_data data;
  3522   3545     const char *zInitFile = 0;
  3523   3546     char *zFirstCmd = 0;
  3524   3547     int i;
  3525   3548     int rc = 0;
         3549  +  int warnInmemoryDb = 0;
  3526   3550   
  3527   3551     if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
  3528   3552       fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
  3529   3553               sqlite3_sourceid(), SQLITE_SOURCE_ID);
  3530   3554       exit(1);
  3531   3555     }
  3532   3556     Argv0 = argv[0];
................................................................................
  3613   3637           exit(1);
  3614   3638         }
  3615   3639       }
  3616   3640     }
  3617   3641     if( data.zDbFilename==0 ){
  3618   3642   #ifndef SQLITE_OMIT_MEMORYDB
  3619   3643       data.zDbFilename = ":memory:";
         3644  +    warnInmemoryDb = argc==1;
  3620   3645   #else
  3621   3646       fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
  3622   3647       return 1;
  3623   3648   #endif
  3624   3649     }
  3625   3650     data.out = stdout;
  3626   3651   
................................................................................
  3749   3774       */
  3750   3775       if( stdin_is_interactive ){
  3751   3776         char *zHome;
  3752   3777         char *zHistory = 0;
  3753   3778         int nHistory;
  3754   3779         printf(
  3755   3780           "SQLite version %s %.19s\n" /*extra-version-info*/
  3756         -        "Enter \".help\" for instructions\n"
  3757         -        "Enter SQL statements terminated with a \";\"\n",
         3781  +        "Enter \".help\" for usage hints.\n",
  3758   3782           sqlite3_libversion(), sqlite3_sourceid()
  3759   3783         );
         3784  +      if( warnInmemoryDb ){
         3785  +        printf("Connected to a ");
         3786  +        printBold("transient in-memory database.");
         3787  +        printf("\nUse \".open FILENAME\" to reopen on a "
         3788  +               "persistent database.\n");
         3789  +      }
  3760   3790         zHome = find_home_dir();
  3761   3791         if( zHome ){
  3762   3792           nHistory = strlen30(zHome) + 20;
  3763   3793           if( (zHistory = malloc(nHistory))!=0 ){
  3764   3794             sqlite3_snprintf(nHistory, zHistory,"%s/.sqlite_history", zHome);
  3765   3795           }
  3766   3796         }

Changes to test/shell1.test.

   101    101   
   102    102   # -interactive         force interactive I/O
   103    103   do_test shell1-1.7.1 {
   104    104     set res [catchcmd "-interactive test.db" ".quit"]
   105    105     set rc [lindex $res 0]
   106    106     list $rc \
   107    107          [regexp {SQLite version} $res] \
   108         -       [regexp {Enter SQL statements} $res]
          108  +       [regexp {Enter ".help" for usage hints} $res]
   109    109   } {0 1 1}
   110    110   
   111    111   # -batch               force batch I/O
   112    112   do_test shell1-1.8.1 {
   113    113     catchcmd "-batch test.db" "" 
   114    114   } {0 {}}
   115    115