/ Check-in [2b3511ec]
Login

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

Overview
Comment:Add pattern matching to the .table command (CVS 129)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:2b3511eca7e562ef2428cec2f7eeca1d26b6c1c8
User & Date: drh 2000-08-08 20:19:09
Context
2000-08-09
17:17
bug fix (CVS 130) check-in: e8882dac user: drh tags: trunk
2000-08-08
20:19
Add pattern matching to the .table command (CVS 129) check-in: 2b3511ec user: drh tags: trunk
2000-08-04
14:56
:-) (CVS 128) check-in: d53cccda user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

    20     20   **   drh@hwaci.com
    21     21   **   http://www.hwaci.com/drh/
    22     22   **
    23     23   *************************************************************************
    24     24   ** This file contains code to implement the "sqlite" command line
    25     25   ** utility for accessing SQLite databases.
    26     26   **
    27         -** $Id: shell.c,v 1.19 2000/08/02 13:47:42 drh Exp $
           27  +** $Id: shell.c,v 1.20 2000/08/08 20:19:09 drh Exp $
    28     28   */
    29     29   #include <stdlib.h>
    30     30   #include <string.h>
    31     31   #include <stdio.h>
    32     32   #include "sqlite.h"
    33     33   #include <unistd.h>
    34     34   #include <ctype.h>
................................................................................
   391    391     ".mode MODE             Set mode to one of \"line\", \"column\", "
   392    392                                         "\"list\", or \"html\"\n"
   393    393     ".mode insert TABLE     Generate SQL insert statements for TABLE\n"
   394    394     ".output FILENAME       Send output to FILENAME\n"
   395    395     ".output stdout         Send output to the screen\n"
   396    396     ".schema ?TABLE?        Show the CREATE statements\n"
   397    397     ".separator STRING      Change separator string for \"list\" mode\n"
   398         -  ".tables                List names all tables in the database\n"
          398  +  ".tables ?PATTERN?      List names of tables matching a pattern\n"
   399    399     ".timeout MS            Try opening locked tables for MS milliseconds\n"
   400    400     ".width NUM NUM ...     Set column widths for \"column\" mode\n"
   401    401   ;
   402    402   
   403    403   /*
   404    404   ** If an input line begins with "." then invoke this routine to
   405    405   ** process that line.
................................................................................
   570    570     if( c=='s' && strncmp(azArg[0], "separator", n)==0 && nArg==2 ){
   571    571       sprintf(p->separator, "%.*s", (int)ArraySize(p->separator)-1, azArg[1]);
   572    572     }else
   573    573   
   574    574     if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
   575    575       struct callback_data data;
   576    576       char *zErrMsg = 0;
   577         -    static char zSql[] = 
   578         -      "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
          577  +    char zSql[1000];
   579    578       memcpy(&data, p, sizeof(data));
   580    579       data.showHeader = 0;
   581    580       data.mode = MODE_List;
          581  +    if( nArg==1 ){
          582  +      sprintf(zSql,
          583  +        "SELECT name FROM sqlite_master "
          584  +        "WHERE type='table' "
          585  +        "ORDER BY name");
          586  +    }else{
          587  +      sprintf(zSql,
          588  +        "SELECT name FROM sqlite_master "
          589  +        "WHERE type='table' AND name LIKE '%%%.100s%%' "
          590  +        "ORDER BY name", azArg[1]);
          591  +    }
   582    592       sqlite_exec(db, zSql, callback, &data, &zErrMsg);
   583    593       if( zErrMsg ){
   584    594         fprintf(stderr,"Error: %s\n", zErrMsg);
   585    595         free(zErrMsg);
   586    596       }
   587    597     }else
   588    598   

Changes to src/shell.tcl.

     1      1   #!/usr/bin/wish
     2      2   #
     3      3   # A GUI shell for SQLite
     4      4   #
     5      5   
            6  +# The following code is slighly modified from the original.  See comments
            7  +# for the modifications...
     6      8   ############################################################################
     7      9   # A console widget for Tcl/Tk.  Invoke console:create with a window name,
     8     10   # a prompt string, and a title to get a new top-level window that allows 
     9     11   # the user to enter tcl commands.  This is mainly useful for testing and
    10     12   # debugging.
    11     13   #
    12     14   # Copyright (C) 1998, 1999 D. Richard Hipp
................................................................................
   273    275     $w insert end \n
   274    276     $w mark set out end
   275    277     if {$v(prior)==""} {
   276    278       set cmd $line
   277    279     } else {
   278    280       set cmd $v(prior)\n$line
   279    281     }
   280         -  if {[info complete $cmd]} {
   281         -    set rc [catch {uplevel #0 $cmd} res]
          282  +##### Original
          283  +# if {[info complete $cmd]} {    }
          284  +#   set rc [catch {uplevel #0 $cmd} res]
          285  +##### New
          286  +  global DB 
          287  +  if {[$DB complete $cmd]} {
          288  +    set CODE {}
          289  +    set rc [catch {$DB eval $cmd RESULT $CODE}]
          290  +##### End Of Changes
   282    291       if {![winfo exists $w]} return
   283    292       if {$rc} {
   284    293         $w insert end $res\n err
   285    294       } elseif {[string length $res]>0} {
   286    295         $w insert end $res\n ok
   287    296       }
   288    297       set v(prior) {}

Changes to www/changes.tcl.

    12     12   }
    13     13   
    14     14   
    15     15   proc chng {date desc} {
    16     16     puts "<DT><B>$date</B></DT>"
    17     17     puts "<DD><P><UL>$desc</UL></P></DD>"
    18     18   }
           19  +
           20  +chng {2000 Aug 8} {
           21  +<li>Added pattern matching to the ".table" command in the "sqlite"
           22  +command shell.</li>
           23  +}
    19     24   
    20     25   chng {2000 Aug 4} {
    21     26   <li>Documentation updates</li>
    22     27   <li>Added "busy" and "timeout" methods to the Tcl interface</li>
    23     28   }
    24     29   
    25     30   chng {2000 Aug 3} {

Changes to www/sqlite.tcl.

     1      1   #
     2      2   # Run this Tcl script to generate the sqlite.html file.
     3      3   #
     4         -set rcsid {$Id: sqlite.tcl,v 1.12 2000/08/04 13:49:03 drh Exp $}
            4  +set rcsid {$Id: sqlite.tcl,v 1.13 2000/08/08 20:19:09 drh Exp $}
     5      5   
     6      6   puts {<html>
     7      7   <head>
     8      8     <title>sqlite: A program of interacting with SQLite databases</title>
     9      9   </head>
    10     10   <body bgcolor=white>
    11     11   <h1 align=center>
................................................................................
   395    395   <blockquote><pre>
   396    396   SELECT sql FROM sqlite_master
   397    397   WHERE tbl_name LIKE '%s' AND type!='meta'
   398    398   ORDER BY type DESC, name
   399    399   </pre></blockquote>
   400    400   
   401    401   <p>The <b>%s</b> in the query above is replaced by the argument
   402         -to ".schema", of course.</p>
          402  +to ".schema", of course.  Notice that the argument to the ".schema"
          403  +command appears to the right of an SQL LIKE operator.  So you can
          404  +use wildcards in the name of the table.  For example, to get the
          405  +schema for all tables whose names contain the character string
          406  +"abc" you could enter:</p>}
          407  +
          408  +Code {
          409  +sqlite> (((.schema %abc%)))
          410  +}
          411  +
          412  +puts {
          413  +<p>
          414  +Along these same lines,
          415  +the ".table" command also accepts a pattern as its first argument.
          416  +If you give an argument to the .table command, a "%" is both
          417  +appended and prepended and a LIKE clause is added to the query.
          418  +This allows you to list only those tables that match a particular
          419  +pattern.</p>
   403    420   
   404    421   <h2>Converting An Entire Database To An ASCII Text File</h2>
   405    422   
   406    423   <p>Use the ".dump" command to convert the entire contents of a
   407    424   database into a single ASCII text file.  This file can be converted
   408    425   back into a database by piping it back into <b>sqlite</b>.</p>
   409    426