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 Peppler <mpeppler at peppler dot org>
Subject: RE: @@error
Date: Jun 17 2004 5:23PM

On Thu, 2004-06-17 at 19:02, Delegal, Darin wrote:
> Robert Huber writes:
> >How is the value of @@error obtained?
> If using DBLib:
> $dbh->dbretstatus
> If using CTLib, you need a standard results handling loop. You should get back a return type of CS_STATUS_RESULT.
> while($dbh->ct_results($restype) == CS_SUCCEED) {
> 	next unless $dbh->ct_fetchable($restype);
> 	if ($restype == CS_STATUS_RESULT) {

That's not quite the same thing as @@error - that's the return status
from a stored procedure.

@@error can be fetched via a normal select. However, the value of
@@error is also sent to the client's server callback (or the message
handler in DBlib).

For example:

sub srv_cb {
  my ($dbh, $errno, $sev, $state, $line, $srv, $proc, $msg) = @_;
  if($errno == 2601) {
      set some variable to note that a duplicate key error occured

ct_callback(CS_SERVERMSG_CB, \&srv_cb);
my $dbh = new Sybase::CTlib ...

This can be extended so that the last @@error value gets stored in the
database handle, for example (that's what Sybase::Simple does).

Michael Peppler                              Data Migrations, Inc.             
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short
or long term contract positions -