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: Michael Burstin <mikeb at concerto dot com>
Subject: DBI/DBD::Sybase error handling issues
Date: Apr 24 2002 2:15PM

I am once again running into some "interesting" error handling
sitations.  I have a set of scripts which are actually causing a
Sybase stacktrace, but in this, I discovered that I am not actually
catching the Sybase error in my DBI code.  I am in a situation where
$DBI::errstr is being set, however, $DBI::err is not!  I thought that
this was an impossible state to get into (I thought they were directly
tied together, errstr only getting set if err is set).

I am using DBI 1.14, DBD::Sybase .91, Solaris 8's compiled perl
version 5.005_03.  Sybase 12.5 64bit (DBD compiled against Sybase OC
12.0).

Sybase is returning a 5702 error to me (my code is causing a stack
trace), the Sybase write-up on this states to fix the error causing
this issue (which I agree), but I don't understand why I don't catch
this.

(I know the cause of these errors are someone tried to create a raw
device on a mounted UFS file system -- these scripts are being
developed to stage systems, not run on a system once live).

I do have a custom error handler, I do actually see output from my
error_handler stating that I have an error, but just don't catch it.
I am guessing I could add an eval, as I used in a previous issue, but
I don't see why I need it here.

I am attaching the portion of the code below, as well as the output
from a $DBI->trace(9) afterwords.

	  ====================begin code====================
  my $dbh =  DBI->connect("DBI:Sybase:server=$logonInfo->{SERVER}",
			  $logonInfo->{USER}, $logonInfo->{PASSWORD},
			  {PrintError => 0, RaiseError => 0 });

  $dbh->{syb_err_handler} = \&error_handler;

  
  #logs in this sql statement is not a good device, its supposed to
  #be a raw device, but is a mounted UFS file system!
  my $sqlString = "create database archive on   archive_data = '1000m'
     log on   logs = '500m'";

  my $sql = $dbh->prepare($sqlString);
  $sql->execute();

  #this is where I am expecting $DBI::err to be defined!!!
  if (defined($DBI::err)) {
    #alter database returns error 5005 if successful
    #create database returns error 1805 if successful
    if ( ($DBI::err == 1805) or ($DBI::err == 5005) ) {
      $dbh->{RaiseError} = 1;
      return 0;
    }
    _printlog('error', "$DBI::errstr\n" . __LINE__);
    die;
  }

sub error_handler {
  my($err, $sev, $state, $line, $server, $proc, $msg) = @_;

  if ($err) {
    _printlog('debug', "$err: $msg");

    #we have an error
    if (member(logger => $logger, operation => 'num',
	       search => $err, list => \@acceptableErrors)) {
      _printlog('debug', "Acceptable error");
      return 0;
    }
    _printlog('error', "Fatal error $err\n$msg");
    return 1;
  }
  return 0;
}

	  =====================end code=====================

	 ====================begin trace====================
    DBI::db=HASH(0x2bfcc4) trace level set to 9 in DBI 1.14-nothread
    -> prepare for DBD::Sybase::db (DBI::db=HASH(0x314008)~0x2bfcc4 'create database archive on   archive_data = '1000m'  log on   logs = '500m' ')
    dbih_setup_handle(DBI::st=HASH(0x1fabe0)=>DBI::st=HASH(0x315da0), DBD::Sybase::st, 313e70, Null!)
    dbih_make_com(DBI::db=HASH(0x2bfcc4), DBD::Sybase::st, 232)
    dbih_setup_attrib(DBI::st=HASH(0x315da0), Err, DBI::db=HASH(0x2bfcc4)) SCALAR(0x1208a8) (already defined)
    dbih_setup_attrib(DBI::st=HASH(0x315da0), State, DBI::db=HASH(0x2bfcc4)) SCALAR(0x1208f0) (already defined)
    dbih_setup_attrib(DBI::st=HASH(0x315da0), Errstr, DBI::db=HASH(0x2bfcc4)) SCALAR(0x1208cc) (already defined)
    dbih_setup_attrib(DBI::st=HASH(0x315da0), Handlers, DBI::db=HASH(0x2bfcc4)) ARRAY(0x2d1150) (already defined)
    dbih_setup_attrib(DBI::st=HASH(0x315da0), Debug, DBI::db=HASH(0x2bfcc4)) 9 (already defined)
    <- prepare= DBI::st=HASH(0x1fabe0) at Concerto/SybaseAdmin.pm line 1232.
    -> execute for DBD::Sybase::st (DBI::st=HASH(0x1fabe0)~0x315da0)
    syb_st_execute() -> ct_command() OK
    syb_st_execute() -> ct_send() OK
    st_next_result() -> ct_results(4047) == 1
    st_next_result() -> ct_results(4046) == 1
ct_execute() final retcode = -205
    st_next_result() -> lasterr = 0, lastsev = 0
    syb_st_execute() -> got CS_CMD_DONE: resetting ACTIVE, moreResults, dyn_execed
    <- execute= -1 at Concerto/SybaseAdmin.pm line 1233.
    -> $DBI::err (*) FETCH from lasth=DBI::st=HASH(0x315da0)
    <- err= undef
    -> STORE for DBD::Sybase::db (DBI::db=HASH(0x2bfcc4)~INNER 'RaiseError' 1)
    STORE DBI::db=HASH(0x2bfcc4) 'RaiseError' => 1
    <- STORE= 1 at Concerto/SybaseAdmin.pm line 1246.
    -> DESTROY for DBD::Sybase::st (DBI::st=HASH(0x315da0)~INNER)
    syb_st_destroy: called on 315750...
    syb_st_destroy(): freeing imp_sth->statement
    syb_st_destroy(): cmd dropped: 1
    <- DESTROY= undef at unknown location!
    -> DESTROY for DBD::Sybase::db (DBI::db=HASH(0x2bfcc4)~INNER)
    syb_db_disconnect() -> ct_close()
    <- DESTROY= undef at unknown location!
	 =====================end trace=====================

-- 
Michael Burstin
NPI Engineer
Concerto Software *
978-952-0842
mikeb@concerto.com
*Davox & Cellit Corporations are now doing business as Concerto Software