Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ISQL and ERRORLEVELs for Syntax Errors

96 views
Skip to first unread message

Nathan Pralle

unread,
Apr 11, 2006, 11:24:21 AM4/11/06
to
Greetings, all.

I already have a batch script that uses dbisql to apply a lot of
different script to a database, but I'm having issues trying to tell it
to stop when it hits a syntax or other DB error in one of the scripts.
dbisql doesn't seem to throw an ERRORLEVEL when it encounters a
syntax or other error, which is frustrating at best.

Ideas on how to handle this programatically?

Thanks,
Nathan

Greg Fenton

unread,
Apr 11, 2006, 12:16:36 PM4/11/06
to
Nathan Pralle wrote:
>
> Ideas on how to handle this programatically?
>

Please always post the version and build number of SQLAnywhere that you
are using (e.g. use the command "dbeng9 -v" for SQLAnywhere 9.x).

Can you give us a direct example of what kind of error you are trying to
have DBISQL catch?

greg.fenton
--
Greg Fenton
Consultant, Solution Services, iAnywhere Solutions
--------
Visit the iAnywhere Solutions Developer Community
Whitepapers, TechDocs, Downloads
http://www.ianywhere.com/developer/

Nathan Pralle

unread,
Apr 11, 2006, 12:24:25 PM4/11/06
to
> Please always post the version and build number of SQLAnywhere that you
> are using (e.g. use the command "dbeng9 -v" for SQLAnywhere 9.x).

My apologies, I'm usually better about that sort of thing.

ASA 9.0.2.3207

> Can you give us a direct example of what kind of error you are trying to
> have DBISQL catch?

Essentially, if SQLCODE<>0, I want dbisql to return something
(preferably an ERRORLEVEL) so my batch file knows that something didn't
go right.

That way when I run several dbisql calls in a row, the next one won't
execute if the first one dies.

IE:

dbisql -c "params here" -nogui -onerror continue -d1 READ "test.sql"
IF NOT %ERRORLEVEL% == 0 GOTO ERROR
dbisql -c "params here" -nogui -onerror continue -d1 READ "test2.sql"
IF NOT %ERRORLEVEL% == 0 GOTO ERROR
...

Etc,etc.

Right now, if it can't connect to the DB, or something like that, it
will raise an ERRORLEVEL. However, say inside "test.sql" I have
something like:

SELECT * FROM FOOBAR;

But there isn't any table named "FOOBAR" -- it won't set an ERRORLEVEL,
but there was still an error.

I want it to detect that there WAS an error so I can stop it. :)

Thanks,
Nathan

Nathan Pralle

unread,
Apr 11, 2006, 2:02:28 PM4/11/06
to
Nevermind; I have found the solution myself.

The key is to switch the "-onerror continue" to "-onerror exit", thus
making dbisql exit with ERRORLEVEL of 5 when an SQL error occurs.

Thanks anyway!

Nathan

Pavel Karady

unread,
Apr 12, 2006, 10:02:35 AM4/12/06
to
"Nathan Pralle" <npr...@BLAHcreativesolutionsunlimited.com> wrote in
message news:443bef34$1@forums-1-dub...

> Nevermind; I have found the solution myself.
>
> The key is to switch the "-onerror continue" to "-onerror exit", thus
> making dbisql exit with ERRORLEVEL of 5 when an SQL error occurs.

There even is a database option PUBLIC.on_error, which dbisql uses. Maybe
this won't help you but... it's good to know :)

Pavel


0 new messages