home *** CD-ROM | disk | FTP | other *** search
- From: root@candle.uucp (Bruce Momjian)
- Newsgroups: comp.sources.misc
- Subject: v42i089: shql - Interactively read and execute SQL commands, Patch02
- Date: 8 May 1994 14:58:12 -0500
- Organization: a consultant's basement
- Sender: kent@sparky.sterling.com
- Approved: kent@sparky.sterling.com
- Message-ID: <2qjg8k$7lq@sparky.sterling.com>
- X-Md4-Signature: ca7ba9e71dc6550534653d3665397290
-
- Submitted-by: root@candle.uucp (Bruce Momjian)
- Posting-number: Volume 42, Issue 89
- Archive-name: shql/patch02
- Environment: SQL, UNIX
- Patch-To: shql: Volume 34, Issue 91
-
- Here is shql 1.2. It is supplied as a context diff to shql 1.1, which
- appeared in Volume 34 of comp.sources.misc in January of 1993.
-
- The new version fixes bugs with subselects, multi-table joins, and the
- -q option. See the CHANGES file for more info.
-
- SHQL is an interactive SQL database engine. Written as a Unix shell
- script, SHQL interprets SQL commands and manipulates flat files based on
- those commands. SHQL is limited in its understanding of SQL constructs.
- All this is outlined in the README file contained in the distribution.
- A demo file is also included to show some examples.
-
- This patch should be applied in a directory containing shql 1.1 source
- code.
- ---------------------------------------------------------------------------
- *** CHANGES.old Wed Mar 2 15:00:48 1994
- --- CHANGES Wed Mar 2 14:59:47 1994
- ***************
- *** 1,3 ****
- --- 1,11 ----
- + New to version 1.2
- + -----------------------------------
- + fixed bug where -q option causes first row to always print
- + fixed subselect bug on first row
- + fixed bug with subselect's with where clauses
- + fixed bug in multi-table joins
- +
- +
- New to version 1.1
- -----------------------------------
- Now runs under ksh as well as sh.
- *** README.old Wed Mar 2 15:00:56 1994
- --- README Wed Mar 2 14:59:51 1994
- ***************
- *** 1,4 ****
- ! S H Q L version 1.1
-
- Shql is a program that reads SQL commands interactively and
- executes those commands by creating and manipulating Unix files.
- --- 1,4 ----
- ! S H Q L version 1.2
-
- Shql is a program that reads SQL commands interactively and
- executes those commands by creating and manipulating Unix files.
- ***************
- *** 22,34 ****
- can be used by other programs by caputuring all lines that begin
- the pipe symbol.
-
- ! The program is patterned after Ingres' interactive sql terminal
- monitor program. Terminal monitor commands begin with either a
- ! forward or back-slash. Forward slashes may appear at the end of a
- ! commend line. Back-slashes are accepted for compatability. The /g
- ! is the 'go' command, /p is print, and /q is quit. Try 'help commands'
- ! for a full list. Because of this, if you need to put a slash as
- ! the second to last caracter on a line, you should add a space
- between the slash and the last character.
-
- To get started, invoke shql with a database name. Use the directory
- --- 22,34 ----
- can be used by other programs by caputuring all lines that begin
- the pipe symbol.
-
- ! The program is patterned after Ingres's interactive sql terminal
- monitor program. Terminal monitor commands begin with either a
- ! forward or backward-slash. Forward slashes may appear at the end of
- ! a commend line. Back-slashes are accepted for compatability. The /g
- ! is the 'go' command, /p is print, and /q is quit. Try 'help commands'
- ! for a full list. Because of this, if you need a slash as the
- ! second to last caracter on a line, you should add a space
- between the slash and the last character.
-
- To get started, invoke shql with a database name. Use the directory
- ***************
- *** 78,84 ****
- tables. This is used only for display purposes. Shql is
- case-sensitive, and expects SQL key words to be in lower case.
-
- ! Commands can be piped into shql, and the table data files are
- tab delimited, so awk scripts can be used to generate reports
- directly from the tables. To operate on non-shql data files,
- create a dummy table with the proper fields, then copy your file
- --- 78,84 ----
- tables. This is used only for display purposes. Shql is
- case-sensitive, and expects SQL key words to be in lower case.
-
- ! Commands can be piped into shql. The table data files are
- tab delimited, so awk scripts can be used to generate reports
- directly from the tables. To operate on non-shql data files,
- create a dummy table with the proper fields, then copy your file
- *** shql.old Wed Mar 2 15:01:05 1994
- --- shql Wed Mar 2 14:59:55 1994
- ***************
- *** 1,13 ****
- #!/bin/sh
- # use /bin/sh or /bin/ksh
- #
- ! # shql - version 1.1
- #
-
- # DEFINE THESE
- SHQL_ROOT="/u/shql" # system-wide database location
- EDITOR="${EDITOR:=/usr/bin/vi}" # default editor if EDITOR not defined
- ! SHELL="${SHELL:=/bin/sh}" # default editor if EDITOR not defined
-
- # Unix table file postfixes: @ is attrib, ~ is data, % is view
-
- --- 1,17 ----
- #!/bin/sh
- # use /bin/sh or /bin/ksh
- #
- ! # shql - version 1.2
- #
- + # by Bruce Momjian, root@candle.uucp (root%candle.uucp@bts.com)
- + #
- +
- + # $Id: shql,v 1.9 1994/02/15 20:04:45 root Exp root $
-
- # DEFINE THESE
- SHQL_ROOT="/u/shql" # system-wide database location
- EDITOR="${EDITOR:=/usr/bin/vi}" # default editor if EDITOR not defined
- ! SHELL="${SHELL:=/bin/sh}" # default editor if SHELL not defined
-
- # Unix table file postfixes: @ is attrib, ~ is data, % is view
-
- ***************
- *** 179,188 ****
- # lookup_field
- #**************************************************************************
- lookup_field(){
- ! if [ ! -f $TABLE% ]
- ! then RESULT="`grep -n \"^$1 \" $TABLE@`"
- ! else RESULT="`grep -n \"^$1 \" $TABLE@ | sed 1q`"
- ! fi
- if [ ! "$RESULT" ]
- then OUTFIELD="$1"
- return 1
- --- 183,189 ----
- # lookup_field
- #**************************************************************************
- lookup_field(){
- ! RESULT="`grep -n \"^$1 \" $TABLE@ | sed 1q`"
- if [ ! "$RESULT" ]
- then OUTFIELD="$1"
- return 1
- ***************
- *** 304,309 ****
- --- 305,311 ----
- COMP="=="
- LOGIC="||"
- [ "X$LAST" = "Xnot" ] && COMP="=" && LOGIC="&&"
- + [ "$#" -eq 0 ] && set "\"__()__\""
- for VALUE
- do
- [ "X$INWHERE" != "X" ] &&
- ***************
- *** 578,584 ****
- # select_
- #**************************************************************************
- select_(){
- ! [ "$DEBUG" = "Y" ] && set -x # uncomment for debugging
- UNION="Y"
- while [ "$UNION" != "" ]
- do
- --- 580,586 ----
- # select_
- #**************************************************************************
- select_(){
- ! [ "$DEBUG" = "Y" ] && set -x
- UNION="Y"
- while [ "$UNION" != "" ]
- do
- ***************
- *** 684,697 ****
- done
- shift 2
- WHERE=""
- SORT=""
- while [ $# -ne 0 ]
- do
- ! if [ "X$1" = "Xwhere" ]
- then
- where "$@"
- [ "$?" -ne 0 ] && return 1
- ! WHERE="$WHERE || NR == 1"
- shift
- elif [ "X$1" = "Xorder" ]
- then [ "X$2" != "Xby" ] &&
- --- 686,702 ----
- done
- shift 2
- WHERE=""
- + WHERE_USED=""
- SORT=""
- while [ $# -ne 0 ]
- do
- ! if [ "X$1" = "Xwhere" -a "$WHERE_USED" = "" ]
- then
- where "$@"
- [ "$?" -ne 0 ] && return 1
- ! [ "$QUIET" = "" -a "$SUBSELECT" = "" ] &&
- ! WHERE="$WHERE || NR == 1"
- ! WHERE_USED="Y"
- shift
- elif [ "X$1" = "Xorder" ]
- then [ "X$2" != "Xby" ] &&
- ***************
- *** 723,728 ****
- --- 728,734 ----
- elif [ "X$1" = "Xunion" ]
- then shift
- UNION="Y"
- + WHERE_USED=""
- break
- else shift
- fi
- ***************
- *** 758,765 ****
- END { printf \"( %1d rows)\\n\", (cnt - 1) \
- >\"/tmp/$$row\" }" - $TABLEFILE | eval "$DIST" \
- && if [ "$DISTINCT" = "" ]
- ! then cat /tmp/$$row
- ! else X=`expr \`cat /tmp/$$row|wc -l\` - 1`
- echo '('$X' rows)'
- fi
- fi
- --- 764,774 ----
- END { printf \"( %1d rows)\\n\", (cnt - 1) \
- >\"/tmp/$$row\" }" - $TABLEFILE | eval "$DIST" \
- && if [ "$DISTINCT" = "" ]
- ! then cat /tmp/$$row
- ! else if [ "$QUIET" = "" ]
- ! then X=`expr \`cat /tmp/$$row|wc -l\` - 1`
- ! else X=`expr \`cat /tmp/$$row|wc -l\``
- ! fi
- echo '('$X' rows)'
- fi
- fi
- ***************
- *** 846,849 ****
- *) echo "Missing or unrecognized command." 1>&2 ;;
- esac
- done
- -
- --- 855,857 ----
-
- --
- Bruce Momjian | 830 Blythe Avenue
- root%candle.uucp@bts.com | Drexel Hill, Pennsylvania 19026
- + If your life is a hard drive, | (215) 353-9879(w)
- + Christ can be your backup. | (215) 853-3000(h)
-
- exit 0 # Just in case...
-