RE: Ignoring Errors in DBACCESS
Posted in 1998
Fred Prose wrote:
>
> Is there a way to tell DBACCESS or ISQL to ignore errors in an SQL
script
> file? For example, don't stop if a DROP TABLE statement executes and
the
> table doesn't exist.
>
>
Fred,
For ISQL, the short answer is no. Any error will cause it to stop
processing. For DB-ACCESS, the opposite is true - the default behaviour
is to continue after error.
There is an undocumented environment variable DBACCNOIGN - if it is
defined, then DB-ACCESS will behave like ISQL, and stop on the first
error. This can be a handy feature, as it is switchable from within a
single script. I tend to think that it's better to separate the tasks
that you will allow to fail from the ones that must not ie:
#!/bin/ksh
# This SQL may fail, but thats OK.
set +e
undef DBACCNOIGN
dbaccess -e $DB << EOSQL DROP TABLE xx ; EOSQL
#These transactions must all complete successfully
set -e
DBACCNOIGN=1; export DBACCNOIGN
dbaccess -e $DB << EOSQL
BEGIN WORK;
-- etc
COMMIT WORK;
EOSQL
# Previous set -e will stop this script if anything above
failed, otherwise continue
# with more code
...
Hope that helps,
RET