Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Dave Aiello" <dave_aiello at ctdata dot com>
Subject: Writing more robust message and error handlers
Date: Nov 10 2001 12:19AM

Thanks for the help with my previous question about transaction handling in 

I am in the process of trying to standardize 20 or 30 Perl scripts that use 
Sybase::DBlib.  These scripts were written by a team of programmers who were 
under deadline pressure, so there weren't many coding standards.  Many of these 
scripts are failing in testing because they do not handle Sybase messages and 
errors properly, although they all have handlers installed.  It's my job to 
write a single error handler and a single message handler, install it in a 
module, and make it work for all of the scripts.

I have read the script that comes with the Sybperl distribution.  
Many of our handlers look somewhat similar to the message_handler and 
error_handler subroutines in that program.  But, my requirements may be more 
complex, and I would like some help determining if I need to do more or 
something different.

For one thing, the handlers may be called while explicit transactions are 
pending.  If I get a Sybase error with a severity greater than 16, I am 
supposed to log the error information to a file, rollback the pending 
transaction(s), and exit the program.  However, I cannot depend upon blindly 
referencing a single well known database handle since the scripts do not have 
handles with the same names.

Do I need to explicitly rollback a transaction if I know my error is fatal?
If so, can I do it without knowing what database handle began it?
Should I do an INT_EXIT in this case?
Will INT_EXIT cause the Perl program to terminate?
If so, will it terminate with the equivalent of exit(1)?

In another related direction:

If the error handler is called and an INT_CANCEL is issued (as in the example), 
the Sybase Open Client DB-Library documentation says that the DB Library 
routine will return with failure.  Does this mean that I still can execute the 
alternative condition, for example the print statement in the following line of 
Perl code: (?)

$dbh->dbcmd("foo") || print "Foo didn't work!";


What is the first parameter to the message and error handlers, generally 
referred to as "$db"?
Is it the database handle where the error took place?
Can it be coerced into the handle?
Or, is there a function in DBlib that will give me that handle in case it is 
not dead and I need to do something with it in one of the handlers?

Any help that can be provided for any of these questions will be greatly 

Best regards,

Dave Aiello