Re: SQL syntax checker
Posted in 1993
In article <27l6d1INNj5f@emory.mathcs.emory.edu>, das@trac3000.ueci.com (David Snyder) writes: } Is there any way I can check the syntax of an SQL statement without actually } executing it? Is there some un-documented option to isql that can do this? } Well this is my attempt at the above... give it a shot and let me know what you think. BTW, you can use "esql" or "c4gl" to compile this sucker. Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip #!/bin/sh # This is a shell archive (produced by shar 3.50) # To extract the files from this archive, save it to a file, remove # everything above the "!/bin/sh" line above, and type "sh file_name". # # Made 09/21/1993 22:10 EDT by dave@das13.snide.com # # Existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 269 -rw-r--r-- README # 578 -rw-r--r-- dbsyntax.1 # 1344 -rw-r--r-- dbsyntax.ec # 498 -rw-r--r-- dbvcs.h # 102 -rw-r--r-- makefile # # ============= README ============== if test -f 'README' -a X"$1" != X"-c"; then echo 'x - skipping README (File already exists)' else echo 'x - extracting README (Text)' sed 's/^X//' << 'SHAR_EOF' > 'README' && XDBINFO checks the syntax of SQL statements without actually executing them. XIf a file is not specified on the command line, stdin is used instead. X XBefore typing "make", edit the dbvcs.h file and provide your ESQL/C serial and Xversion numbers on the appropriate lines. SHAR_EOF chmod 0644 README || echo 'restore of README failed' Wc_c="`wc -c < 'README'`" test 269 -eq "$Wc_c" || echo 'README: original size 269, current size' "$Wc_c" fi # ============= dbsyntax.1 ============== if test -f 'dbsyntax.1' -a X"$1" != X"-c"; then echo 'x - skipping dbsyntax.1 (File already exists)' else echo 'x - extracting dbsyntax.1 (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dbsyntax.1' && X.\\" $Id: dbsyntax.1,v 1.1 1993/03/18 15:34:45 dave Exp $ X.\\" X.\\" Man page for dbsyntax. X.\\" X.TH DBSYNTAX 1 X.SH NAME Xdbsyntax \\- checks the syntax of SQL statements X.SH SYNOPSIS Xdbsyntax [files...] X.SH DESCRIPTION X.I Dbsyntax Xwill check the syntax of SQL statements. Errors are printed to stdout Xalong with the line that caused the error. X.SH NOTES X.I Dbsyntax Xmust be compiled with "c4gl" or "esql", however it can be run with just Xthe engine loaded. X.PP XIf a file name is not specified, then stdin is used X.SH SUPPORT XBug reports can be mailed to Dave Snyder <dave@snide.com> SHAR_EOF chmod 0644 dbsyntax.1 || echo 'restore of dbsyntax.1 failed' Wc_c="`wc -c < 'dbsyntax.1'`" test 578 -eq "$Wc_c" || echo 'dbsyntax.1: original size 578, current size' "$Wc_c" fi # ============= dbsyntax.ec ============== if test -f 'dbsyntax.ec' -a X"$1" != X"-c"; then echo 'x - skipping dbsyntax.ec (File already exists)' else echo 'x - extracting dbsyntax.ec (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dbsyntax.ec' && X/* X***************************************************** X* X* Copyright(c) 1993 by David A. Snyder. X* X* This document contains information that is X* the property of David A. Snyder. X* X* INFORMIX -- Informix Software Inc. X* X* Title: dbsyntax.ec X* X***************************************************** X*/ X X#include <stdio.h> X#include "dbvcs.h" X$include sqlca; X X/* ARGSUSED */ Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X char buf[4096]; X void perror(); X X /* Print copyright message */ X (void)fprintf(stderr, "\\n%-49.49s %29.29s\\n", "DBSYNTAX Sql Syntax Checking Utility", SQVERSNUMBER); X (void)fprintf(stderr, "%s\\n", SQCOPYRIGHT); X (void)fprintf(stderr, "%s\\n\\n", SQSERIAL); X X if (!*++argv) X process(argc, *argv, buf); X else X do { X if (!freopen(*argv, "r", stdin)) { X perror(*argv); X continue; X } X process(argc, *argv, buf); X } while (*++argv); X return(0); X} X X Xprocess(argc, argv, buf) Xint argc; Xchar *argv, *buf; X{ X $char *s; X X s = buf; X while ((*s = getchar()) != EOF) { X switch (*s++) { X case '{': X *s--; X while ((*s = getchar()) != '}') X ; X break; X case ';': X *s = '\\0'; X s = buf; X $prepare stmtid from $s; X if (sqlca.sqlcode == -201) { X if (*argv && argc > 2) X (void)printf("%s: ", argv); X (void)printf("%s\\nA syntax error has occured.\\n\\n", s); X } X break; X } X } X} X X SHAR_EOF chmod 0644 dbsyntax.ec || echo 'restore of dbsyntax.ec failed' Wc_c="`wc -c < 'dbsyntax.ec'`" test 1344 -eq "$Wc_c" || echo 'dbsyntax.ec: original size 1344, current size' "$Wc_c" fi # ============= dbvcs.h ============== if test -f 'dbvcs.h' -a X"$1" != X"-c"; then echo 'x - skipping dbvcs.h (File already exists)' else echo 'x - extracting dbvcs.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'dbvcs.h' && X/* X***************************************************** X* X* Copyright(c) 1993 by David A. Snyder. X* X* This document contains information that is X* the property of David A. Snyder. X* X* INFORMIX -- Informix Software Inc. X* X* Title: dbvcs.h X* X***************************************************** X*/ X X#define SQVERSNUMBER "INFORMIX-SQL Version 0.00.00X" X#define SQCOPYRIGHT "Copyright (C) 1981-1986 Informix Software, Inc." X#define SQSERIAL "Software Serial Number XXX#X000000" SHAR_EOF chmod 0644 dbvcs.h || echo 'restore of dbvcs.h failed' Wc_c="`wc -c < 'dbvcs.h'`" test 498 -eq "$Wc_c" || echo 'dbvcs.h: original size 498, current size' "$Wc_c" fi # ============= makefile ============== if test -f 'makefile' -a X"$1" != X"-c"; then echo 'x - skipping makefile (File already exists)' else echo 'x - extracting makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'makefile' && X# makefile X# This makes "dbsyntax" X Xdbsyntax: dbsyntax.ec dbvcs.h X esql -O dbsyntax.ec -o dbsyntax -s SHAR_EOF chmod 0644 makefile || echo 'restore of makefile failed' Wc_c="`wc -c < 'makefile'`" test 102 -eq "$Wc_c" || echo 'makefile: original size 102, current size' "$Wc_c" fi exit 0 Here --------- Snip Here --------- Snip Here --------- Snip Here --------- Snip DAS -- David Snyder @ Snide Computer Services - Folcroft, PA Current Release is db4glgen-3.15 UUCP: ..!uunet!das13!dave INTERNET: dave.snyder@snide.com