dbTalk Databases Forums  

ISQL and ERRORLEVELs for Syntax Errors

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss ISQL and ERRORLEVELs for Syntax Errors in the sybase.public.sqlanywhere.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Nathan Pralle
 
Posts: n/a

Default ISQL and ERRORLEVELs for Syntax Errors - 04-11-2006 , 10:24 AM






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

Reply With Quote
  #2  
Old   
Greg Fenton
 
Posts: n/a

Default Re: ISQL and ERRORLEVELs for Syntax Errors - 04-11-2006 , 11:16 AM






Nathan Pralle wrote:
Quote:
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/


Reply With Quote
  #3  
Old   
Nathan Pralle
 
Posts: n/a

Default Re: ISQL and ERRORLEVELs for Syntax Errors - 04-11-2006 , 11:24 AM



Quote:
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

Quote:
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


Reply With Quote
  #4  
Old   
Nathan Pralle
 
Posts: n/a

Default Re: ISQL and ERRORLEVELs for Syntax Errors - 04-11-2006 , 01:02 PM



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

Nathan Pralle wrote:
Quote:
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

Reply With Quote
  #5  
Old   
Pavel Karady
 
Posts: n/a

Default Re: ISQL and ERRORLEVELs for Syntax Errors - 04-12-2006 , 09:02 AM



"Nathan Pralle" <npralle (AT) BLAHcreativesolutionsunlimited (DOT) com> wrote in
message news:443bef34$1 (AT) forums-1-dub (DOT) ..
Quote:
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




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.