/ Check-in [4bdd040e]
Login

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

Overview
Comment:Mistake in help text. Spurious trailing whitespace removed. (CVS 532)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 4bdd040e4810565c91bcbb5f065580520c5e3c45
User & Date: persicom 2002-04-18 02:53:05
Context
2002-04-18
02:53
Updated to match new shell.c functionality. (CVS 533) check-in: ff67ad40 user: persicom tags: trunk
02:53
Mistake in help text. Spurious trailing whitespace removed. (CVS 532) check-in: 4bdd040e user: persicom tags: trunk
02:46
General: o Added global static chars mainPrompt and continuePrompt. o Moved Argv0 declaration to head of file. Needed in do_meta_command, previously found below that. o Added struct previous_mode_data to support new .explain toggle functionality. o Added nullvalue, explainPrev and outfile members to struct callback_data. o Added modeDescr array for number/text translation ofdisplay modes. o Modified zHelp to match new functionality.

callback(): o Added support for .nullvalue

do_meta_command(): o Output filename is now saved to callback struct. If using stdout, then the string "stdout" is saved. o Explain is now a toggle. When it is turned on, the current values of mode, header and colWidth are saved if not already in explain mode. When turned off, those values are restored. o Allow .mode plurals columns and lines and dot command plural .headers. o Added processing for new keywords .quit, .nullvalue, .show, .prompt.

main(): o Added -init as an option to override .sqliterc. o Added -nullvalue as a command line option. o Processes .sqliterc.

main_init(): o Genesis. Moved some initialization code here from inside main() so that it can be called initially by main and again if -init is specified.

one_input_line(): o Now takes prompts from settable values.

process_sqliterc(): o Genesis. Read .sqliterc from user's home directory and pass it to process_input(). File should contain meta commands for setups. (CVS 531) check-in: e751338c user: persicom tags: trunk

Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains code to implement the "sqlite" command line
    13     13   ** utility for accessing SQLite databases.
    14     14   **
    15         -** $Id: shell.c,v 1.51 2002/04/18 02:46:52 persicom Exp $
           15  +** $Id: shell.c,v 1.52 2002/04/18 02:53:05 persicom Exp $
    16     16   */
    17     17   #include <stdlib.h>
    18     18   #include <string.h>
    19     19   #include <stdio.h>
    20     20   #include "sqlite.h"
    21     21   #include <ctype.h>
    22     22   #include <pwd.h>
................................................................................
    27     27   #endif
    28     28   
    29     29   #if defined(HAVE_READLINE) && HAVE_READLINE==1
    30     30   # include <readline/readline.h>
    31     31   # include <readline/history.h>
    32     32   #else
    33     33   # define readline(p) getline(p,stdin)
    34         -# define add_history(X) 
           34  +# define add_history(X)
    35     35   #endif
    36     36   
    37     37   /*
    38     38   ** The following is the open SQLite database.  We make a pointer
    39     39   ** to this database a static variable so that it can be accessed
    40     40   ** by the SIGINT handler to interrupt database processing.
    41     41   */
................................................................................
   187    187   ** Return TRUE if the string supplied is a number of some kinds.
   188    188   */
   189    189   static int is_numeric(const char *z){
   190    190     int seen_digit = 0;
   191    191     if( *z=='-' || *z=='+' ){
   192    192       z++;
   193    193     }
   194         -  while( isdigit(*z) ){ 
          194  +  while( isdigit(*z) ){
   195    195       seen_digit = 1;
   196    196       z++;
   197    197     }
   198    198     if( seen_digit && *z=='.' ){
   199    199       z++;
   200    200       while( isdigit(*z) ){ z++; }
   201    201     }
................................................................................
   304    304             if( w<=0 ){
   305    305               w = strlen(azCol[i] ? azCol[i] : "");
   306    306               if( w<10 ) w = 10;
   307    307               n = strlen(azArg && azArg[i] ? azArg[i] : p->nullvalue);
   308    308               if( w<n ) w = n;
   309    309             }
   310    310             if( i<ArraySize(p->actualWidth) ){
   311         -            p->actualWidth[i] = w; 
          311  +            p->actualWidth[i] = w;
   312    312             }
   313    313             if( p->showHeader ){
   314    314               fprintf(p->out,"%-*.*s%s",w,w,azCol[i], i==nArg-1 ? "\n": "  ");
   315    315             }
   316    316           }
   317    317           if( p->showHeader ){
   318    318             for(i=0; i<nArg; i++){
................................................................................
   394    394             if( zSep[0] ) fprintf(p->out,"%s",zSep);
   395    395             output_quoted_string(p->out, azArg[i]);
   396    396           }
   397    397         }
   398    398         fprintf(p->out,");\n");
   399    399         break;
   400    400       }
   401         -  }      
          401  +  }
   402    402     return 0;
   403    403   }
   404    404   
   405    405   /*
   406    406   ** Set the destination table field of the callback_data structure to
   407    407   ** the name of the table given.  Escape any quote characters in the
   408    408   ** table name.
................................................................................
   452    452     fprintf(p->out, "%s;\n", azArg[2]);
   453    453     if( strcmp(azArg[1],"table")==0 ){
   454    454       struct callback_data d2;
   455    455       d2 = *p;
   456    456       d2.mode = MODE_Insert;
   457    457       d2.zDestTable = 0;
   458    458       set_table_name(&d2, azArg[0]);
   459         -    sqlite_exec_printf(p->db, 
          459  +    sqlite_exec_printf(p->db,
   460    460          "SELECT * FROM '%q'",
   461    461          callback, &d2, 0, azArg[0]
   462    462       );
   463    463       set_table_name(&d2, 0);
   464    464     }
   465    465     return 0;
   466    466   }
   467    467   
   468    468   /*
   469    469   ** Text of a help message
   470    470   */
   471         -static char zHelp[] = 
          471  +static char zHelp[] =
   472    472     ".dump ?TABLE? ...      Dump the database in an text format\n"
   473    473     ".echo ON|OFF           Turn command echo on or off\n"
   474    474     ".exit                  Exit this program\n"
   475    475     ".explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.\n"
   476    476     "                       \"off\" will revert to the output mode that was\n"
   477    477     "                       previously in effect\n"
   478    478     ".header(s) ON|OFF      Turn display of headers on or off\n"
................................................................................
   484    484     ".nullvalue STRING      Print STRING instead of nothing for NULL data\n"
   485    485     ".output FILENAME       Send output to FILENAME\n"
   486    486     ".output stdout         Send output to the screen\n"
   487    487     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
   488    488     "                       \"sqlite > \" and \"   ...> \"\n"
   489    489     "                       with the strings MAIN and CONTINUE\n"
   490    490     "                       CONTINUE is optional.\n"
   491         -  "                       Special characters are:\n"
   492    491     ".quit                  Exit this program\n"
   493    492     ".read FILENAME         Execute SQL in FILENAME\n"
   494    493     ".reindex ?TABLE?       Rebuild indices\n"
   495    494   /*  ".rename OLD NEW        Change the name of a table or index\n" */
   496    495     ".schema ?TABLE?        Show the CREATE statements\n"
   497    496     ".separator STRING      Change separator string for \"list\" mode\n"
   498    497     ".show                  Show the current values for the following:\n"
................................................................................
   553    552           "WHERE type!='meta' AND sql NOT NULL "
   554    553           "ORDER BY substr(type,2,1), name",
   555    554           dump_callback, p, &zErrMsg
   556    555         );
   557    556       }else{
   558    557         int i;
   559    558         for(i=1; i<nArg && zErrMsg==0; i++){
   560         -        sqlite_exec_printf(db, 
          559  +        sqlite_exec_printf(db,
   561    560             "SELECT name, type, sql FROM sqlite_master "
   562    561             "WHERE tbl_name LIKE '%q' AND type!='meta' AND sql NOT NULL "
   563    562             "ORDER BY substr(type,2,1), name",
   564    563             dump_callback, p, &zErrMsg, azArg[i]
   565    564           );
   566    565         }
   567    566       }
................................................................................
   580    579       for(j=0; z[j]; j++){
   581    580         if( isupper(z[j]) ) z[j] = tolower(z[j]);
   582    581       }
   583    582       if( strcmp(z,"on")==0 ){
   584    583         val = 1;
   585    584       }else if( strcmp(z,"yes")==0 ){
   586    585         val = 1;
   587         -    } 
          586  +    }
   588    587       p->echoOn = val;
   589    588     }else
   590    589   
   591    590     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
   592    591       sqlite_close(db);
   593    592       exit(0);
   594    593     }else
................................................................................
   644    643       for(j=0; z[j]; j++){
   645    644         if( isupper(z[j]) ) z[j] = tolower(z[j]);
   646    645       }
   647    646       if( strcmp(z,"on")==0 ){
   648    647         val = 1;
   649    648       }else if( strcmp(z,"yes")==0 ){
   650    649         val = 1;
   651         -    } 
          650  +    }
   652    651       p->showHeader = val;
   653    652     }else
   654    653   
   655    654     if( c=='h' && strncmp(azArg[0], "help", n)==0 ){
   656    655       fprintf(stderr,zHelp);
   657    656     }else
   658    657   
   659    658     if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
   660    659       struct callback_data data;
   661    660       char *zErrMsg = 0;
   662    661       memcpy(&data, p, sizeof(data));
   663    662       data.showHeader = 0;
   664    663       data.mode = MODE_List;
   665         -    sqlite_exec_printf(db, 
          664  +    sqlite_exec_printf(db,
   666    665         "SELECT name FROM sqlite_master "
   667    666         "WHERE type='index' AND tbl_name LIKE '%q' "
   668    667         "ORDER BY name",
   669    668         callback, &data, &zErrMsg, azArg[1]
   670    669       );
   671    670       if( zErrMsg ){
   672    671         fprintf(stderr,"Error: %s\n", zErrMsg);
................................................................................
   934    933         strcpy(&zSql[nSql++], "\n");
   935    934         strcpy(&zSql[nSql], zLine);
   936    935         nSql += len;
   937    936       }
   938    937       free(zLine);
   939    938       if( zSql && sqlite_complete(zSql) ){
   940    939         p->cnt = 0;
   941         -      if( sqlite_exec(db, zSql, callback, p, &zErrMsg)!=0 
          940  +      if( sqlite_exec(db, zSql, callback, p, &zErrMsg)!=0
   942    941              && zErrMsg!=0 ){
   943    942           if( in!=0 && !p->echoOn ) printf("%s\n",zSql);
   944    943           printf("SQL error: %s\n", zErrMsg);
   945    944           free(zErrMsg);
   946    945           zErrMsg = 0;
   947    946         }
   948    947         free(zSql);