]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In shell, changed ".tables" command to not add '%' to specified pattern. This is...
authorshane <shane@noemail.net>
Sat, 24 Oct 2009 02:00:07 +0000 (02:00 +0000)
committershane <shane@noemail.net>
Sat, 24 Oct 2009 02:00:07 +0000 (02:00 +0000)
with other commands that take a LIKE pattern (.dump, .schema, .indices).
Updated internal help to better describe LIKE pattern usage.
Fixed a few more inconsistencies in error messages. Ticket [6da68f691b].

FossilOrigin-Name: 7201244e67c197f16d6752cc0fa7232a9664381e

manifest
manifest.uuid
src/shell.c

index 47c0f930d5fd1ffeb66321bcc9ef990ab0d34844..da497a56de9e937ea24f1b5be3503f4b73e7b922 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C Check-in\s[19064d7cea]\sbroke\sthe\spTail\sreturn\son\ssqlite3_prepare16()\swhen\nthe\sSQL\scontained\ssurrogates.\sThis\scheck-in\srestores\scorrect\sfunction.\nPart\sof\sticket\s[3fe897352e].
-D 2009-10-24T01:55:15
+C In\sshell,\schanged\s".tables"\scommand\sto\snot\sadd\s'%'\sto\sspecified\spattern.\s\sThis\sis\sconsistent\nwith\sother\scommands\sthat\stake\sa\sLIKE\spattern\s(.dump,\s.schema,\s.indices).\nUpdated\sinternal\shelp\sto\sbetter\sdescribe\sLIKE\spattern\susage.\nFixed\sa\sfew\smore\sinconsistencies\sin\serror\smessages.\sTicket\s[6da68f691b].
+D 2009-10-24T02:00:07
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a77dfde96ad86aafd3f71651a4333a104debe86a
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -164,7 +161,7 @@ F src/random.c 676b9d7ac820fe81e6fb2394ac8c10cff7f38628
 F src/resolve.c 3ac31c7181fab03732125fdedf7c2091a5c07f1b
 F src/rowset.c c64dafba1f9fd876836c8db8682966b9d197eb1f
 F src/select.c cbe366a0ce114856e66f5daf0f848d7c48a88298
-F src/shell.c 19c86a22e32096a3bc6845b200a793fb9f2d0376
+F src/shell.c 0e43ac51c416d61e5491beeed14495b37941f9ab
 F src/sqlite.h.in 5853e42a4066a6c9c3bf6592a9d57d0012bfdb90
 F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
 F src/sqliteInt.h 3b00a3ce79e60c5a47c342b738c8b75013f3ec84
@@ -764,14 +761,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P 19064d7cea838e1a93fe63743ed247f440679e97
-R 44dc5ec300c49505c4d9505ed09a5846
-U drh
-Z 311a3a4efd8a48ee4d5b8ab3156cfc0d
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFK4l6HoxKgR168RlERAh4lAJ9MkpkD9AGChuh3laSqM4tt1RLMVwCdHia4
-0BLXlH3U8qi9GDIqnVIMoCM=
-=ltxy
------END PGP SIGNATURE-----
+P 65b1e3a4c31f6cb6fd3f600701658b0cdbee603f
+R 33ed6fc2ad95ec267314811e76645c50
+U shane
+Z 74660ae65b33d7b4cfbd712c9f8b941d
index d89d6b3c53025fbf82a6c99ac41fb139d2efb01b..9a63ba9e95f4230d9dcb7ca6f5a6be12b8b48648 100644 (file)
@@ -1 +1 @@
-65b1e3a4c31f6cb6fd3f600701658b0cdbee603f
\ No newline at end of file
+7201244e67c197f16d6752cc0fa7232a9664381e
\ No newline at end of file
index e4346edc8dd40aca5b5cf5bcf07349a9fd0a55c3..bd492394f1492e6a612884c4e2633450b4af9097 100644 (file)
@@ -1713,7 +1713,7 @@ static void set_table_name(struct callback_data *p, const char *zName){
   if( needQuote ) n += 2;
   z = p->zDestTable = malloc( n+1 );
   if( z==0 ){
-    fprintf(stderr,"Out of memory!\n");
+    fprintf(stderr,"Error: out of memory\n");
     exit(1);
   }
   n = 0;
@@ -1929,7 +1929,7 @@ static int shell_exec(
 
       rc2 = sqlite3_finalize(pStmt);
       /* if the last sqlite3_finalize() didn't complete successfully 
-      ** AND we don't have a save error from sqlite3_step ... */
+      ** AND we don't have a saved error from sqlite3_step ... */
       if( (SQLITE_OK != rc2) && (SQLITE_OK == rc) ){
         rc = rc2;
         if( pzErrMsg ){
@@ -2136,6 +2136,8 @@ static char zHelp[] =
   ".bail ON|OFF           Stop after hitting an error.  Default OFF\n"
   ".databases             List names and files of attached databases\n"
   ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
+  "                         If TABLE specified, only dump tables matching\n"
+  "                         LIKE pattern TABLE.\n"
   ".echo ON|OFF           Turn command echo on or off\n"
   ".exit                  Exit this program\n"
   ".explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.\n"
@@ -2150,7 +2152,9 @@ static char zHelp[] =
   ".header(s) ON|OFF      Turn display of headers on or off\n"
   ".help                  Show this message\n"
   ".import FILE TABLE     Import data from FILE into TABLE\n"
-  ".indices TABLE         Show names of all indices on TABLE\n"
+  ".indices ?TABLE?       Show names of all indices\n"
+  "                         If TABLE specified, only show indices for tables\n"
+  "                         matching LIKE pattern TABLE.\n"
 #ifdef SQLITE_ENABLE_IOTRACE
   ".iotrace FILE          Enable I/O diagnostic logging to FILE\n"
 #endif
@@ -2174,9 +2178,13 @@ static char zHelp[] =
   ".read FILENAME         Execute SQL in FILENAME\n"
   ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
   ".schema ?TABLE?        Show the CREATE statements\n"
+  "                         If TABLE specified, only show tables matching\n"
+  "                         LIKE pattern TABLE.\n"
   ".separator STRING      Change separator used by output mode and .import\n"
   ".show                  Show the current values for various settings\n"
-  ".tables ?PATTERN?      List names of tables matching a LIKE pattern\n"
+  ".tables ?TABLE?        List names of tables\n"
+  "                         If TABLE specified, only list tables matching\n"
+  "                         LIKE pattern TABLE.\n"
   ".timeout MS            Try opening locked tables for MS milliseconds\n"
   ".width NUM NUM ...     Set column widths for \"column\" mode\n"
 ;
@@ -2201,7 +2209,7 @@ static void open_db(struct callback_data *p){
           shellstaticFunc, 0, 0);
     }
     if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
-      fprintf(stderr,"Unable to open database \"%s\": %s\n", 
+      fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 
           p->zDbFilename, sqlite3_errmsg(db));
       exit(1);
     }
@@ -2600,28 +2608,43 @@ static int do_meta_command(char *zLine, struct callback_data *p){
     sqlite3_exec(p->db, zCommit, 0, 0, 0);
   }else
 
-  if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
+  if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
     struct callback_data data;
     char *zErrMsg = 0;
     open_db(p);
     memcpy(&data, p, sizeof(data));
     data.showHeader = 0;
     data.mode = MODE_List;
-    zShellStatic = azArg[1];
-    sqlite3_exec(p->db,
-      "SELECT name FROM sqlite_master "
-      "WHERE type='index' AND tbl_name LIKE shellstatic() "
-      "UNION ALL "
-      "SELECT name FROM sqlite_temp_master "
-      "WHERE type='index' AND tbl_name LIKE shellstatic() "
-      "ORDER BY 1",
-      callback, &data, &zErrMsg
-    );
-    zShellStatic = 0;
+    if( nArg==1 ){
+      rc = sqlite3_exec(p->db,
+        "SELECT name FROM sqlite_master "
+        "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
+        "UNION ALL "
+        "SELECT name FROM sqlite_temp_master "
+        "WHERE type='index' "
+        "ORDER BY 1",
+        callback, &data, &zErrMsg
+      );
+    }else{
+      zShellStatic = azArg[1];
+      rc = sqlite3_exec(p->db,
+        "SELECT name FROM sqlite_master "
+        "WHERE type='index' AND tbl_name LIKE shellstatic() "
+        "UNION ALL "
+        "SELECT name FROM sqlite_temp_master "
+        "WHERE type='index' AND tbl_name LIKE shellstatic() "
+        "ORDER BY 1",
+        callback, &data, &zErrMsg
+      );
+      zShellStatic = 0;
+    }
     if( zErrMsg ){
       fprintf(stderr,"Error: %s\n", zErrMsg);
       sqlite3_free(zErrMsg);
       rc = 1;
+    }else if( rc != SQLITE_OK ){
+      fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
+      rc = 1;
     }
   }else
 
@@ -2902,7 +2925,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){
     if( nArg==1 ){
       rc = sqlite3_get_table(p->db,
         "SELECT name FROM sqlite_master "
-        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'"
+        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
         "UNION ALL "
         "SELECT name FROM sqlite_temp_master "
         "WHERE type IN ('table','view') "
@@ -2913,10 +2936,10 @@ static int do_meta_command(char *zLine, struct callback_data *p){
       zShellStatic = azArg[1];
       rc = sqlite3_get_table(p->db,
         "SELECT name FROM sqlite_master "
-        "WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
+        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
         "UNION ALL "
         "SELECT name FROM sqlite_temp_master "
-        "WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
+        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
         "ORDER BY 1",
         &azResult, &nRow, 0, &zErrMsg
       );
@@ -3140,7 +3163,7 @@ static int process_input(struct callback_data *p, FILE *in){
     }
   }
   if( zSql ){
-    if( !_all_whitespace(zSql) ) fprintf(stderr, "Incomplete SQL: %s\n", zSql);
+    if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
     free(zSql);
   }
   free(zLine);
@@ -3230,15 +3253,15 @@ static int process_sqliterc(
     home_dir = find_home_dir();
     if( home_dir==0 ){
 #if !defined(__RTP__) && !defined(_WRS_KERNEL)
-      fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0);
+      fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
 #endif
       return 1;
     }
     nBuf = strlen30(home_dir) + 16;
     zBuf = malloc( nBuf );
     if( zBuf==0 ){
-      fprintf(stderr,"%s: out of memory!\n", Argv0);
-      exit(1);
+      fprintf(stderr,"%s: Error: out of memory\n",Argv0);
+      return 1;
     }
     sqlite3_snprintf(nBuf, zBuf,"%s/.sqliterc",home_dir);
     free(home_dir);
@@ -3247,7 +3270,7 @@ static int process_sqliterc(
   in = fopen(sqliterc,"rb");
   if( in ){
     if( stdin_is_interactive ){
-      printf("-- Loading resources from %s\n",sqliterc);
+      fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
     }
     rc = process_input(p,in);
     fclose(in);
@@ -3355,8 +3378,8 @@ int main(int argc, char **argv){
 
 #ifdef SQLITE_OMIT_MEMORYDB
   if( data.zDbFilename==0 ){
-    fprintf(stderr,"%s: no database filename specified\n", argv[0]);
-    exit(1);
+    fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
+    return 1;
   }
 #endif
 
@@ -3373,7 +3396,10 @@ int main(int argc, char **argv){
   ** is given on the command line, look for a file named ~/.sqliterc and
   ** try to process it.
   */
-  process_sqliterc(&data,zInitFile);
+  rc = process_sqliterc(&data,zInitFile);
+  if( rc>0 ){
+    return rc;
+  }
 
   /* Make a second pass through the command-line argument and set
   ** options.  This second pass is delayed until after the initialization
@@ -3422,7 +3448,7 @@ int main(int argc, char **argv){
     }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
       usage(1);
     }else{
-      fprintf(stderr,"%s: unknown option: %s\n", Argv0, z);
+      fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
       fprintf(stderr,"Use -help for a list of options.\n");
       return 1;
     }
@@ -3433,14 +3459,16 @@ int main(int argc, char **argv){
     */
     if( zFirstCmd[0]=='.' ){
       rc = do_meta_command(zFirstCmd, &data);
-      exit(rc);
+      return rc;
     }else{
-      int rc;
       open_db(&data);
       rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
-      if( rc!=0 && zErrMsg!=0 ){
-        fprintf(stderr,"SQL error: %s\n", zErrMsg);
-        exit(1);
+      if( zErrMsg!=0 ){
+        fprintf(stderr,"Error: %s\n", zErrMsg);
+        return rc!=0 ? rc : 1;
+      }else if( rc!=0 ){
+        fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
+        return rc;
       }
     }
   }else{
@@ -3480,7 +3508,8 @@ int main(int argc, char **argv){
   set_table_name(&data, 0);
   if( db ){
     if( sqlite3_close(db)!=SQLITE_OK ){
-      fprintf(stderr,"error closing database: %s\n", sqlite3_errmsg(db));
+      fprintf(stderr,"Error: cannot close database \"%s\"\n", sqlite3_errmsg(db));
+      rc++;
     }
   }
   return rc;