Conditional exit for SQL
Posted in 1997
Hi family,
I am writing a shell script to validate .unl files for dumbness like
internal duplication of primary key columns, as well as checking them
against P-Key values already in the target table. In order to keep
everything in a single file, I am using awk with the entire script
between the 'single quotes' and running with a "hereis"document. i.e.
dbaccess database - <<%%
... SQL code ...
%%
I have noticed that when I run a shell script this way, dbaccess
continues on the the %% marker even if there is an SQL error. I would
like it to stop on an error and exit dbaccess.
An even greater need: If I find replicate P-Keys using the "select
count(*).., which is not an error, I would like the script to stop as
well.
Effectively, what I want is for dbaccess to exit or abort based on a
non-zero count of some queries.
Does anyone know of a method (a kluge will do) to cause this? I just
tried an experiment - select (1/(col - col)) from a_table to trick it
into a zero-divide. No luck: it came up with (expression) and no rows
found.
I am experimenting with splitting up the SQL script into several
"hereis" documents and using shell to [test for zero length] but I would
rather do it neatly in SQL directly.
Thanks for ideas.
--
-- Jake (In pursuit of undomesticated semi-aquatic avians)
+---------------------------------------------------------------+
|Insofar as manifestations of functional deficiencies are agreed|
|by any and all concerned parties to be imperceivable, and are |
|so stipulated, it is incumbent upon said heretofore mentioned |
|parties to exercise the deferment of otherwise pertinent |
|maintenance procedures. |
+--------------------------------------- (www.hardyharhar.com) -+