home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume42 / shql / patch02 next >
Encoding:
Internet Message Format  |  1994-05-08  |  8.5 KB

  1. From: root@candle.uucp (Bruce Momjian)
  2. Newsgroups: comp.sources.misc
  3. Subject: v42i089:  shql - Interactively read and execute SQL commands, Patch02
  4. Date: 8 May 1994 14:58:12 -0500
  5. Organization: a consultant's basement
  6. Sender: kent@sparky.sterling.com
  7. Approved: kent@sparky.sterling.com
  8. Message-ID: <2qjg8k$7lq@sparky.sterling.com>
  9. X-Md4-Signature: ca7ba9e71dc6550534653d3665397290
  10.  
  11. Submitted-by: root@candle.uucp (Bruce Momjian)
  12. Posting-number: Volume 42, Issue 89
  13. Archive-name: shql/patch02
  14. Environment: SQL, UNIX
  15. Patch-To: shql: Volume 34, Issue 91
  16.  
  17. Here is shql 1.2.  It is supplied as a context diff to shql 1.1, which
  18. appeared in Volume 34 of comp.sources.misc in January of 1993.
  19.  
  20. The new version fixes bugs with subselects, multi-table joins, and the
  21. -q option.  See the CHANGES file for more info.
  22.  
  23. SHQL is an interactive SQL database engine.  Written as a Unix shell
  24. script, SHQL interprets SQL commands and manipulates flat files based on
  25. those commands.  SHQL is limited in its understanding of SQL constructs.
  26. All this is outlined in the README file contained in the distribution. 
  27. A demo file is also included to show some examples.
  28.  
  29. This patch should be applied in a directory containing shql 1.1 source
  30. code. 
  31. ---------------------------------------------------------------------------
  32. *** CHANGES.old    Wed Mar  2 15:00:48 1994
  33. --- CHANGES    Wed Mar  2 14:59:47 1994
  34. ***************
  35. *** 1,3 ****
  36. --- 1,11 ----
  37. + New to version 1.2
  38. + -----------------------------------
  39. + fixed bug where -q option causes first row to always print
  40. + fixed subselect bug on first row
  41. + fixed bug with subselect's with where clauses
  42. + fixed bug in multi-table joins
  43.   New to version 1.1
  44.   -----------------------------------
  45.   Now runs under ksh as well as sh.
  46. *** README.old    Wed Mar  2 15:00:56 1994
  47. --- README    Wed Mar  2 14:59:51 1994
  48. ***************
  49. *** 1,4 ****
  50. !                               S H Q L  version 1.1
  51.   
  52.       Shql is a program that reads SQL commands interactively and
  53.       executes those commands by creating and manipulating Unix files.
  54. --- 1,4 ----
  55. !                               S H Q L  version 1.2
  56.   
  57.       Shql is a program that reads SQL commands interactively and
  58.       executes those commands by creating and manipulating Unix files.
  59. ***************
  60. *** 22,34 ****
  61.       can be used by other programs by caputuring all lines that begin
  62.       the pipe symbol.
  63.   
  64. !       The program is patterned after Ingres' interactive sql terminal
  65.       monitor program.  Terminal monitor commands begin with either a
  66. !     forward or back-slash.  Forward slashes may appear at the end of a
  67. !     commend line. Back-slashes are accepted for compatability.  The /g
  68. !     is the 'go' command, /p is print, and /q is quit.  Try 'help commands' 
  69. !     for a full list.  Because of this, if you need to put a slash as
  70. !     the second to last caracter on a line, you should add a space
  71.       between the slash and the last character.
  72.       
  73.       To get started, invoke shql with a database name.  Use the directory 
  74. --- 22,34 ----
  75.       can be used by other programs by caputuring all lines that begin
  76.       the pipe symbol.
  77.   
  78. !       The program is patterned after Ingres's interactive sql terminal
  79.       monitor program.  Terminal monitor commands begin with either a
  80. !     forward or backward-slash.  Forward slashes may appear at the end of
  81. !     a commend line. Back-slashes are accepted for compatability.  The /g
  82. !     is the 'go' command, /p is print, and /q is quit.  Try 'help commands'
  83. !     for a full list.  Because of this, if you need a slash as the
  84. !     second to last caracter on a line, you should add a space
  85.       between the slash and the last character.
  86.       
  87.       To get started, invoke shql with a database name.  Use the directory 
  88. ***************
  89. *** 78,84 ****
  90.       tables.  This is used only for display purposes.  Shql is
  91.       case-sensitive, and expects SQL key words to be in lower case.
  92.       
  93. !     Commands can be piped into shql, and the table data files are
  94.       tab delimited, so awk scripts can be used to generate reports 
  95.       directly from the tables.  To operate on non-shql data files,
  96.       create a dummy table with the proper fields, then copy your file
  97. --- 78,84 ----
  98.       tables.  This is used only for display purposes.  Shql is
  99.       case-sensitive, and expects SQL key words to be in lower case.
  100.       
  101. !     Commands can be piped into shql.  The table data files are
  102.       tab delimited, so awk scripts can be used to generate reports 
  103.       directly from the tables.  To operate on non-shql data files,
  104.       create a dummy table with the proper fields, then copy your file
  105. *** shql.old    Wed Mar  2 15:01:05 1994
  106. --- shql    Wed Mar  2 14:59:55 1994
  107. ***************
  108. *** 1,13 ****
  109.   #!/bin/sh
  110.   # use /bin/sh or /bin/ksh
  111.   #
  112. ! # shql - version 1.1
  113.   #
  114.   
  115.   # DEFINE THESE
  116.   SHQL_ROOT="/u/shql"        # system-wide database location
  117.   EDITOR="${EDITOR:=/usr/bin/vi}" # default editor if EDITOR not defined
  118. ! SHELL="${SHELL:=/bin/sh}"     # default editor if EDITOR not defined
  119.   
  120.   # Unix table file postfixes:  @ is attrib, ~ is data, % is view
  121.   
  122. --- 1,17 ----
  123.   #!/bin/sh
  124.   # use /bin/sh or /bin/ksh
  125.   #
  126. ! # shql - version 1.2
  127.   #
  128. + # by Bruce Momjian, root@candle.uucp (root%candle.uucp@bts.com)
  129. + #
  130. + # $Id: shql,v 1.9 1994/02/15 20:04:45 root Exp root $
  131.   
  132.   # DEFINE THESE
  133.   SHQL_ROOT="/u/shql"        # system-wide database location
  134.   EDITOR="${EDITOR:=/usr/bin/vi}" # default editor if EDITOR not defined
  135. ! SHELL="${SHELL:=/bin/sh}"     # default editor if SHELL not defined
  136.   
  137.   # Unix table file postfixes:  @ is attrib, ~ is data, % is view
  138.   
  139. ***************
  140. *** 179,188 ****
  141.   # lookup_field
  142.   #**************************************************************************
  143.   lookup_field(){
  144. !     if [ ! -f $TABLE% ]
  145. !     then    RESULT="`grep -n \"^$1    \" $TABLE@`"
  146. !     else     RESULT="`grep -n \"^$1    \" $TABLE@ | sed 1q`"
  147. !     fi
  148.       if [ ! "$RESULT" ] 
  149.       then     OUTFIELD="$1"
  150.           return 1
  151. --- 183,189 ----
  152.   # lookup_field
  153.   #**************************************************************************
  154.   lookup_field(){
  155. !     RESULT="`grep -n \"^$1    \" $TABLE@ | sed 1q`"
  156.       if [ ! "$RESULT" ] 
  157.       then     OUTFIELD="$1"
  158.           return 1
  159. ***************
  160. *** 304,309 ****
  161. --- 305,311 ----
  162.                   COMP="=="
  163.                   LOGIC="||"
  164.                   [ "X$LAST" = "Xnot" ] && COMP="=" && LOGIC="&&"
  165. +                 [ "$#" -eq 0 ] && set "\"__()__\""
  166.                   for VALUE
  167.                   do
  168.                       [ "X$INWHERE" != "X" ] && 
  169. ***************
  170. *** 578,584 ****
  171.   # select_
  172.   #**************************************************************************
  173.   select_(){
  174. ! [ "$DEBUG" = "Y" ] && set -x           # uncomment for debugging
  175.       UNION="Y"
  176.       while [ "$UNION" != "" ]
  177.       do
  178. --- 580,586 ----
  179.   # select_
  180.   #**************************************************************************
  181.   select_(){
  182. ! [ "$DEBUG" = "Y" ] && set -x
  183.       UNION="Y"
  184.       while [ "$UNION" != "" ]
  185.       do
  186. ***************
  187. *** 684,697 ****
  188.           done
  189.           shift 2
  190.           WHERE=""
  191.           SORT=""
  192.           while [ $# -ne 0 ]
  193.           do    
  194. !             if [ "X$1" = "Xwhere" ]
  195.               then
  196.                   where "$@"
  197.                   [ "$?" -ne 0 ] && return 1 
  198. !                 WHERE="$WHERE || NR == 1"
  199.                   shift
  200.               elif [ "X$1" = "Xorder" ]
  201.               then     [ "X$2" != "Xby" ] && 
  202. --- 686,702 ----
  203.           done
  204.           shift 2
  205.           WHERE=""
  206. +         WHERE_USED=""
  207.           SORT=""
  208.           while [ $# -ne 0 ]
  209.           do    
  210. !             if [ "X$1" = "Xwhere" -a "$WHERE_USED" = "" ]
  211.               then
  212.                   where "$@"
  213.                   [ "$?" -ne 0 ] && return 1 
  214. !                 [ "$QUIET" = "" -a "$SUBSELECT" = "" ] && 
  215. !                         WHERE="$WHERE || NR == 1"
  216. !                 WHERE_USED="Y"
  217.                   shift
  218.               elif [ "X$1" = "Xorder" ]
  219.               then     [ "X$2" != "Xby" ] && 
  220. ***************
  221. *** 723,728 ****
  222. --- 728,734 ----
  223.               elif [ "X$1" = "Xunion" ]
  224.               then    shift
  225.                   UNION="Y"
  226. +                 WHERE_USED=""
  227.                   break
  228.               else    shift
  229.               fi
  230. ***************
  231. *** 758,765 ****
  232.               END    { printf \"( %1d rows)\\n\", (cnt - 1) \
  233.               >\"/tmp/$$row\" }" - $TABLEFILE | eval "$DIST" \
  234.                   && if [ "$DISTINCT" = "" ]
  235. !                 then    cat /tmp/$$row
  236. !                 else     X=`expr \`cat /tmp/$$row|wc -l\` - 1`
  237.                       echo '('$X' rows)' 
  238.                   fi
  239.           fi
  240. --- 764,774 ----
  241.               END    { printf \"( %1d rows)\\n\", (cnt - 1) \
  242.               >\"/tmp/$$row\" }" - $TABLEFILE | eval "$DIST" \
  243.                   && if [ "$DISTINCT" = "" ]
  244. !                    then    cat /tmp/$$row
  245. !                    else if [ "$QUIET" = "" ]
  246. !                     then    X=`expr \`cat /tmp/$$row|wc -l\` - 1`
  247. !                     else    X=`expr \`cat /tmp/$$row|wc -l\``
  248. !                     fi
  249.                       echo '('$X' rows)' 
  250.                   fi
  251.           fi
  252. ***************
  253. *** 846,849 ****
  254.           *)         echo "Missing or unrecognized command." 1>&2 ;;
  255.       esac
  256.   done
  257. --- 855,857 ----
  258.  
  259. -- 
  260. Bruce Momjian                          |  830 Blythe Avenue
  261. root%candle.uucp@bts.com               |  Drexel Hill, Pennsylvania 19026 
  262.   +  If your life is a hard drive,     |  (215) 353-9879(w) 
  263.   +  Christ can be your backup.        |  (215) 853-3000(h)
  264.  
  265. exit 0 # Just in case...
  266.