/ Check-in [7201244e]
Login

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

Overview
Comment:In shell, changed ".tables" command to not add '%' to specified pattern. This is consistent 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].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7201244e67c197f16d6752cc0fa7232a9664381e
User & Date: shane 2009-10-24 02:00:07
References
2009-10-24
02:00 Fixed ticket [6da68f69]: tables says you provide a like pattern but it adds % in code plus 3 other changes artifact: ac365444 user: shane
Context
2009-10-24
02:06
In shell, modified to not print informational messages during startup while in "batch mode". Ticket [2cb66577f6]. check-in: e3898e25 user: shane tags: trunk
02:00
In shell, changed ".tables" command to not add '%' to specified pattern. This is consistent 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]. check-in: 7201244e user: shane tags: trunk
01:55
Check-in [19064d7cea] broke the pTail return on sqlite3_prepare16() when the SQL contained surrogates. This check-in restores correct function. Part of ticket [3fe897352e]. check-in: 65b1e3a4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

  1709   1709         needQuote = 1;
  1710   1710         if( zName[i]=='\'' ) n++;
  1711   1711       }
  1712   1712     }
  1713   1713     if( needQuote ) n += 2;
  1714   1714     z = p->zDestTable = malloc( n+1 );
  1715   1715     if( z==0 ){
  1716         -    fprintf(stderr,"Out of memory!\n");
         1716  +    fprintf(stderr,"Error: out of memory\n");
  1717   1717       exit(1);
  1718   1718     }
  1719   1719     n = 0;
  1720   1720     if( needQuote ) z[n++] = '\'';
  1721   1721     for(i=0; zName[i]; i++){
  1722   1722       z[n++] = zName[i];
  1723   1723       if( zName[i]=='\'' ) z[n++] = '\'';
................................................................................
  1925   1925           }
  1926   1926         }else{
  1927   1927           rc = SQLITE_OK;
  1928   1928         }
  1929   1929   
  1930   1930         rc2 = sqlite3_finalize(pStmt);
  1931   1931         /* if the last sqlite3_finalize() didn't complete successfully 
  1932         -      ** AND we don't have a save error from sqlite3_step ... */
         1932  +      ** AND we don't have a saved error from sqlite3_step ... */
  1933   1933         if( (SQLITE_OK != rc2) && (SQLITE_OK == rc) ){
  1934   1934           rc = rc2;
  1935   1935           if( pzErrMsg ){
  1936   1936             *pzErrMsg = save_err_msg(db);
  1937   1937           }
  1938   1938         }
  1939   1939   
................................................................................
  2132   2132   ** Text of a help message
  2133   2133   */
  2134   2134   static char zHelp[] =
  2135   2135     ".backup ?DB? FILE      Backup DB (default \"main\") to FILE\n"
  2136   2136     ".bail ON|OFF           Stop after hitting an error.  Default OFF\n"
  2137   2137     ".databases             List names and files of attached databases\n"
  2138   2138     ".dump ?TABLE? ...      Dump the database in an SQL text format\n"
         2139  +  "                         If TABLE specified, only dump tables matching\n"
         2140  +  "                         LIKE pattern TABLE.\n"
  2139   2141     ".echo ON|OFF           Turn command echo on or off\n"
  2140   2142     ".exit                  Exit this program\n"
  2141   2143     ".explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.\n"
  2142   2144   #if !defined(SQLITE_OMIT_VIRTUALTABLE) && !defined(SQLITE_OMIT_SUBQUERY)
  2143   2145     ".genfkey ?OPTIONS?     Options are:\n"
  2144   2146     "                         --no-drop: Do not drop old fkey triggers.\n"
  2145   2147     "                         --ignore-errors: Ignore tables with fkey errors\n"
................................................................................
  2146   2148     "                         --exec: Execute generated SQL immediately\n"
  2147   2149     "                       See file tool/genfkey.README in the source \n"
  2148   2150     "                       distribution for further information.\n"
  2149   2151   #endif
  2150   2152     ".header(s) ON|OFF      Turn display of headers on or off\n"
  2151   2153     ".help                  Show this message\n"
  2152   2154     ".import FILE TABLE     Import data from FILE into TABLE\n"
  2153         -  ".indices TABLE         Show names of all indices on TABLE\n"
         2155  +  ".indices ?TABLE?       Show names of all indices\n"
         2156  +  "                         If TABLE specified, only show indices for tables\n"
         2157  +  "                         matching LIKE pattern TABLE.\n"
  2154   2158   #ifdef SQLITE_ENABLE_IOTRACE
  2155   2159     ".iotrace FILE          Enable I/O diagnostic logging to FILE\n"
  2156   2160   #endif
  2157   2161   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  2158   2162     ".load FILE ?ENTRY?     Load an extension library\n"
  2159   2163   #endif
  2160   2164     ".mode MODE ?TABLE?     Set output mode where MODE is one of:\n"
................................................................................
  2170   2174     ".output FILENAME       Send output to FILENAME\n"
  2171   2175     ".output stdout         Send output to the screen\n"
  2172   2176     ".prompt MAIN CONTINUE  Replace the standard prompts\n"
  2173   2177     ".quit                  Exit this program\n"
  2174   2178     ".read FILENAME         Execute SQL in FILENAME\n"
  2175   2179     ".restore ?DB? FILE     Restore content of DB (default \"main\") from FILE\n"
  2176   2180     ".schema ?TABLE?        Show the CREATE statements\n"
         2181  +  "                         If TABLE specified, only show tables matching\n"
         2182  +  "                         LIKE pattern TABLE.\n"
  2177   2183     ".separator STRING      Change separator used by output mode and .import\n"
  2178   2184     ".show                  Show the current values for various settings\n"
  2179         -  ".tables ?PATTERN?      List names of tables matching a LIKE pattern\n"
         2185  +  ".tables ?TABLE?        List names of tables\n"
         2186  +  "                         If TABLE specified, only list tables matching\n"
         2187  +  "                         LIKE pattern TABLE.\n"
  2180   2188     ".timeout MS            Try opening locked tables for MS milliseconds\n"
  2181   2189     ".width NUM NUM ...     Set column widths for \"column\" mode\n"
  2182   2190   ;
  2183   2191   
  2184   2192   static char zTimerHelp[] =
  2185   2193     ".timer ON|OFF          Turn the CPU timer measurement on or off\n"
  2186   2194   ;
................................................................................
  2197   2205       sqlite3_open(p->zDbFilename, &p->db);
  2198   2206       db = p->db;
  2199   2207       if( db && sqlite3_errcode(db)==SQLITE_OK ){
  2200   2208         sqlite3_create_function(db, "shellstatic", 0, SQLITE_UTF8, 0,
  2201   2209             shellstaticFunc, 0, 0);
  2202   2210       }
  2203   2211       if( db==0 || SQLITE_OK!=sqlite3_errcode(db) ){
  2204         -      fprintf(stderr,"Unable to open database \"%s\": %s\n", 
         2212  +      fprintf(stderr,"Error: unable to open database \"%s\": %s\n", 
  2205   2213             p->zDbFilename, sqlite3_errmsg(db));
  2206   2214         exit(1);
  2207   2215       }
  2208   2216   #ifndef SQLITE_OMIT_LOAD_EXTENSION
  2209   2217       sqlite3_enable_load_extension(p->db, 1);
  2210   2218   #endif
  2211   2219     }
................................................................................
  2596   2604       } /* end while */
  2597   2605       free(azCol);
  2598   2606       fclose(in);
  2599   2607       sqlite3_finalize(pStmt);
  2600   2608       sqlite3_exec(p->db, zCommit, 0, 0, 0);
  2601   2609     }else
  2602   2610   
  2603         -  if( c=='i' && strncmp(azArg[0], "indices", n)==0 && nArg>1 ){
         2611  +  if( c=='i' && strncmp(azArg[0], "indices", n)==0 ){
  2604   2612       struct callback_data data;
  2605   2613       char *zErrMsg = 0;
  2606   2614       open_db(p);
  2607   2615       memcpy(&data, p, sizeof(data));
  2608   2616       data.showHeader = 0;
  2609   2617       data.mode = MODE_List;
  2610         -    zShellStatic = azArg[1];
  2611         -    sqlite3_exec(p->db,
  2612         -      "SELECT name FROM sqlite_master "
  2613         -      "WHERE type='index' AND tbl_name LIKE shellstatic() "
  2614         -      "UNION ALL "
  2615         -      "SELECT name FROM sqlite_temp_master "
  2616         -      "WHERE type='index' AND tbl_name LIKE shellstatic() "
  2617         -      "ORDER BY 1",
  2618         -      callback, &data, &zErrMsg
  2619         -    );
  2620         -    zShellStatic = 0;
         2618  +    if( nArg==1 ){
         2619  +      rc = sqlite3_exec(p->db,
         2620  +        "SELECT name FROM sqlite_master "
         2621  +        "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
         2622  +        "UNION ALL "
         2623  +        "SELECT name FROM sqlite_temp_master "
         2624  +        "WHERE type='index' "
         2625  +        "ORDER BY 1",
         2626  +        callback, &data, &zErrMsg
         2627  +      );
         2628  +    }else{
         2629  +      zShellStatic = azArg[1];
         2630  +      rc = sqlite3_exec(p->db,
         2631  +        "SELECT name FROM sqlite_master "
         2632  +        "WHERE type='index' AND tbl_name LIKE shellstatic() "
         2633  +        "UNION ALL "
         2634  +        "SELECT name FROM sqlite_temp_master "
         2635  +        "WHERE type='index' AND tbl_name LIKE shellstatic() "
         2636  +        "ORDER BY 1",
         2637  +        callback, &data, &zErrMsg
         2638  +      );
         2639  +      zShellStatic = 0;
         2640  +    }
  2621   2641       if( zErrMsg ){
  2622   2642         fprintf(stderr,"Error: %s\n", zErrMsg);
  2623   2643         sqlite3_free(zErrMsg);
  2624   2644         rc = 1;
         2645  +    }else if( rc != SQLITE_OK ){
         2646  +      fprintf(stderr,"Error: querying sqlite_master and sqlite_temp_master\n");
         2647  +      rc = 1;
  2625   2648       }
  2626   2649     }else
  2627   2650   
  2628   2651   #ifdef SQLITE_ENABLE_IOTRACE
  2629   2652     if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
  2630   2653       extern void (*sqlite3IoTrace)(const char*, ...);
  2631   2654       if( iotrace && iotrace!=stdout ) fclose(iotrace);
................................................................................
  2898   2921       char **azResult;
  2899   2922       int nRow;
  2900   2923       char *zErrMsg;
  2901   2924       open_db(p);
  2902   2925       if( nArg==1 ){
  2903   2926         rc = sqlite3_get_table(p->db,
  2904   2927           "SELECT name FROM sqlite_master "
  2905         -        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'"
         2928  +        "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%' "
  2906   2929           "UNION ALL "
  2907   2930           "SELECT name FROM sqlite_temp_master "
  2908   2931           "WHERE type IN ('table','view') "
  2909   2932           "ORDER BY 1",
  2910   2933           &azResult, &nRow, 0, &zErrMsg
  2911   2934         );
  2912   2935       }else{
  2913   2936         zShellStatic = azArg[1];
  2914   2937         rc = sqlite3_get_table(p->db,
  2915   2938           "SELECT name FROM sqlite_master "
  2916         -        "WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
         2939  +        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
  2917   2940           "UNION ALL "
  2918   2941           "SELECT name FROM sqlite_temp_master "
  2919         -        "WHERE type IN ('table','view') AND name LIKE '%'||shellstatic()||'%' "
         2942  +        "WHERE type IN ('table','view') AND name LIKE shellstatic() "
  2920   2943           "ORDER BY 1",
  2921   2944           &azResult, &nRow, 0, &zErrMsg
  2922   2945         );
  2923   2946         zShellStatic = 0;
  2924   2947       }
  2925   2948       if( zErrMsg ){
  2926   2949         fprintf(stderr,"Error: %s\n", zErrMsg);
................................................................................
  3136   3159         }
  3137   3160         free(zSql);
  3138   3161         zSql = 0;
  3139   3162         nSql = 0;
  3140   3163       }
  3141   3164     }
  3142   3165     if( zSql ){
  3143         -    if( !_all_whitespace(zSql) ) fprintf(stderr, "Incomplete SQL: %s\n", zSql);
         3166  +    if( !_all_whitespace(zSql) ) fprintf(stderr, "Error: incomplete SQL: %s\n", zSql);
  3144   3167       free(zSql);
  3145   3168     }
  3146   3169     free(zLine);
  3147   3170     return errCnt;
  3148   3171   }
  3149   3172   
  3150   3173   /*
................................................................................
  3226   3249     int nBuf;
  3227   3250     int rc = 0;
  3228   3251   
  3229   3252     if (sqliterc == NULL) {
  3230   3253       home_dir = find_home_dir();
  3231   3254       if( home_dir==0 ){
  3232   3255   #if !defined(__RTP__) && !defined(_WRS_KERNEL)
  3233         -      fprintf(stderr,"%s: cannot locate your home directory!\n", Argv0);
         3256  +      fprintf(stderr,"%s: Error: cannot locate your home directory\n", Argv0);
  3234   3257   #endif
  3235   3258         return 1;
  3236   3259       }
  3237   3260       nBuf = strlen30(home_dir) + 16;
  3238   3261       zBuf = malloc( nBuf );
  3239   3262       if( zBuf==0 ){
  3240         -      fprintf(stderr,"%s: out of memory!\n", Argv0);
  3241         -      exit(1);
         3263  +      fprintf(stderr,"%s: Error: out of memory\n",Argv0);
         3264  +      return 1;
  3242   3265       }
  3243   3266       sqlite3_snprintf(nBuf, zBuf,"%s/.sqliterc",home_dir);
  3244   3267       free(home_dir);
  3245   3268       sqliterc = (const char*)zBuf;
  3246   3269     }
  3247   3270     in = fopen(sqliterc,"rb");
  3248   3271     if( in ){
  3249   3272       if( stdin_is_interactive ){
  3250         -      printf("-- Loading resources from %s\n",sqliterc);
         3273  +      fprintf(stderr,"-- Loading resources from %s\n",sqliterc);
  3251   3274       }
  3252   3275       rc = process_input(p,in);
  3253   3276       fclose(in);
  3254   3277     }
  3255   3278     free(zBuf);
  3256   3279     return rc;
  3257   3280   }
................................................................................
  3351   3374     if( i<argc ){
  3352   3375       zFirstCmd = argv[i++];
  3353   3376     }
  3354   3377     data.out = stdout;
  3355   3378   
  3356   3379   #ifdef SQLITE_OMIT_MEMORYDB
  3357   3380     if( data.zDbFilename==0 ){
  3358         -    fprintf(stderr,"%s: no database filename specified\n", argv[0]);
  3359         -    exit(1);
         3381  +    fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
         3382  +    return 1;
  3360   3383     }
  3361   3384   #endif
  3362   3385   
  3363   3386     /* Go ahead and open the database file if it already exists.  If the
  3364   3387     ** file does not exist, delay opening it.  This prevents empty database
  3365   3388     ** files from being created if a user mistypes the database name argument
  3366   3389     ** to the sqlite command-line tool.
................................................................................
  3369   3392       open_db(&data);
  3370   3393     }
  3371   3394   
  3372   3395     /* Process the initialization file if there is one.  If no -init option
  3373   3396     ** is given on the command line, look for a file named ~/.sqliterc and
  3374   3397     ** try to process it.
  3375   3398     */
  3376         -  process_sqliterc(&data,zInitFile);
         3399  +  rc = process_sqliterc(&data,zInitFile);
         3400  +  if( rc>0 ){
         3401  +    return rc;
         3402  +  }
  3377   3403   
  3378   3404     /* Make a second pass through the command-line argument and set
  3379   3405     ** options.  This second pass is delayed until after the initialization
  3380   3406     ** file is processed so that the command-line arguments will override
  3381   3407     ** settings in the initialization file.
  3382   3408     */
  3383   3409     for(i=1; i<argc && argv[i][0]=='-'; i++){
................................................................................
  3418   3444       }else if( strcmp(z,"-interactive")==0 ){
  3419   3445         stdin_is_interactive = 1;
  3420   3446       }else if( strcmp(z,"-batch")==0 ){
  3421   3447         stdin_is_interactive = 0;
  3422   3448       }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){
  3423   3449         usage(1);
  3424   3450       }else{
  3425         -      fprintf(stderr,"%s: unknown option: %s\n", Argv0, z);
         3451  +      fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z);
  3426   3452         fprintf(stderr,"Use -help for a list of options.\n");
  3427   3453         return 1;
  3428   3454       }
  3429   3455     }
  3430   3456   
  3431   3457     if( zFirstCmd ){
  3432   3458       /* Run just the command that follows the database name
  3433   3459       */
  3434   3460       if( zFirstCmd[0]=='.' ){
  3435   3461         rc = do_meta_command(zFirstCmd, &data);
  3436         -      exit(rc);
         3462  +      return rc;
  3437   3463       }else{
  3438         -      int rc;
  3439   3464         open_db(&data);
  3440   3465         rc = shell_exec(data.db, zFirstCmd, shell_callback, &data, &zErrMsg);
  3441         -      if( rc!=0 && zErrMsg!=0 ){
  3442         -        fprintf(stderr,"SQL error: %s\n", zErrMsg);
  3443         -        exit(1);
         3466  +      if( zErrMsg!=0 ){
         3467  +        fprintf(stderr,"Error: %s\n", zErrMsg);
         3468  +        return rc!=0 ? rc : 1;
         3469  +      }else if( rc!=0 ){
         3470  +        fprintf(stderr,"Error: unable to process SQL \"%s\"\n", zFirstCmd);
         3471  +        return rc;
  3444   3472         }
  3445   3473       }
  3446   3474     }else{
  3447   3475       /* Run commands received from standard input
  3448   3476       */
  3449   3477       if( stdin_is_interactive ){
  3450   3478         char *zHome;
................................................................................
  3476   3504       }else{
  3477   3505         rc = process_input(&data, stdin);
  3478   3506       }
  3479   3507     }
  3480   3508     set_table_name(&data, 0);
  3481   3509     if( db ){
  3482   3510       if( sqlite3_close(db)!=SQLITE_OK ){
  3483         -      fprintf(stderr,"error closing database: %s\n", sqlite3_errmsg(db));
         3511  +      fprintf(stderr,"Error: cannot close database \"%s\"\n", sqlite3_errmsg(db));
         3512  +      rc++;
  3484   3513       }
  3485   3514     }
  3486   3515     return rc;
  3487   3516   }