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: michael dot peppler at bnpparibas dot com
Subject: Re: Error handling in Sybase::BCP
Date: Aug 14 2006 11:09AM


Sybase::BCP inherits from Sybase::DBlib. You should probably take a look at
the error handling in Sybase::DBlib, and in particular about how you write
an error message callback routine that will handle the client side or
server side errors.

Of particular interest will be the dbmsghandle() and dbserverhandle()
calls. See also the file that is included with your sybperl
distribution, as that file has some sample error handlers that you could
customize for your use.

That being said, the Try/Catch mechanism implemented by will
normally require the error to issue a die() call for the Catch to work
(using an eval {} block under the covers, I think). It's probably NOT a
good idea to issue the die() or croak() from within the error handler, so
you may be somewhat limited in getting Try/Catch to work without hacking
the Sybase::BCP source to die() if the bcpsendrow() fails.


Internet - 14/08/2006 11:42

Sent by:

To:    sybperl-l


Subject:    Error handling in Sybase::BCP


I've just discovered this list after hours of pulling my hair out!
I have written a perl script using sybase::bcp. All the script does is
input 8000+ lines of data to a database. In the database we have an
index that does not allow duplicate lines. If a duplicate line is
detected sybase:bcp throws a database error. I need to catch and process
this error.
I used the perl module to catch the error. It allows 'try',
'catch' syntax (I prefer it ;) )

Now the problem i'm having is that the errors thrown by the sysbase::bcp
module are not caught by try and catch. I cant even redirect the output
into a file, since (correct me if im wrong) the database errors are not
on the std out.

here's an example:

    my $bcp = new Sybase::BCP $USER, $PWD, $SERVER;
   $bcp->config(INPUT => "/data/$FILEOUT",
                OUTPUT => "$DATABASE.dbo.$FILE_TABLE",
                SEPARATOR => ',',
                ERRORS => "$ERRORLOCATION/$FILEOUT.err");
catch Error with
   #do general error processing
   #print error code
   #print error_msg

Please can some one point me to some docs that explains the exception
handling in SYBASE::BCP. Or better yet, some example code - code is
worth more than a thousand words :)
I need to know *how to catch errors* for the module. The above obviously
 does not work...any suggestions?

This message and any attachments (the "message") is
intended solely for the addressees and is confidential. 
If you receive this message in error, please delete it and 
immediately notify the sender. Any use not in accord with 
its purpose, any dissemination or disclosure, either whole 
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message. 
BNP PARIBAS (and its subsidiaries) shall (will) not 
therefore be liable for the message if modified. 


Ce message et toutes les pieces jointes (ci-apres le 
"message") sont etablis a l'intention exclusive de ses 
destinataires et sont confidentiels. Si vous recevez ce 
message par erreur, merci de le detruire et d'en avertir 
immediatement l'expediteur. Toute utilisation de ce 
message non conforme a sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf 
autorisation expresse. L'internet ne permettant pas 
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce 
message, dans l'hypothese ou il aurait ete modifie.