PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Jason Stajich <jason at chg dot mc dot duke dot edu>
Subject: Re: Trapping Sybase errors...
Date: Feb 9 2000 10:38PM

What Sybperl module are you using?

for DBI ( DBD::Sybase )
$dbh = DBI->connect($connectstr, $user,$pass, {
	RaiseError=>0});

if( ! $dbh->do($SQL) ) 
{
	# process error
	# look for duplicate key error code
	if( $dbh->err == 2601 ) {
#	  process specifics here to deal with the situation
#         where key already exists	
	}
}

in Sybase::CTlib
you can define callbacks for all messages
ct_callback(CS_CLIENTMSG_CB, \&msg_cb);
ct_callback(CS_SERVERMSG_CB, \&srv_cb);

And define functions srv_cb & msg_cb to process messages.

Look at Michael's SybTools module for a good example of this
type of code.

Depends on if you are interested in only duplicate key entry errors 
or all errors as to how you might want to handle this.

-Jason

Jason Stajich
Center for Human Genetics
Duke University Medical Center
jason@chg.mc.duke.edu



On Wed, 9 Feb 2000, Fuerte, Hector BGI SF wrote:

> Hi!
>  
> How do you trap this sql error in Perl:
>  
> Msg 2601, Level 14, State 3:
> Server 'SA_SBU', Line 1:
> Attempt to insert duplicate key row in object 't_web_xing_stats_hist' with
> unique index 'XPKt_web_xing_stats_hist'
> Command has been aborted.
> (0 rows affected)
>  
> thanks.
> Hector
>  
> 
>