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: "W dot Phillip Moore" <wpm at ms dot com>
Subject: Trapping errors from dblogin
Date: Mar 9 1998 4:11PM

If one has an message handler routine installed *before* calling
dblogin, then libsybdb will indeed call this handler when dblogin()
fails.

However, the usual means of reading the error string uses code like
the following (taken from the nsql_message_handler() routine):

      foreach $row ( split(/\n/,Sybase::DBlib::dbstrcpy($db)) ) {
          $DB_ERROR .= sprintf ("%5d", $lineno ++) . "> $row\n";
      }

However, calling dbstrcpy produces a fatal error if the login fails:

connection parameter is not a reference at /ms/dist/perl5/PROJ/syb/2.09/lib/perl5/Sybase/DBlib.pm line 478.

Line 478 is in fact the dbstrcpy line shown above.  In the debugger,
one can see that the error is in fact 'Login failed.':

connection parameter is not a reference at /ms/dist/perl5/PROJ/core/5.00404-n32/common/lib/perl5/perl5db.pl line 1134.
        Sybase::DBlib::nsql_message_handler(undef, 4002, 1, 14, 'Login failed.', 'NYPIBF15', undef, 1) called at /ms/dist/perl5/PROJ/core/5.00404-n32/common/lib/perl5/perl5db.pl line 1134

So, what is the right way to trap errors like this?  There seems to be 
a bit of a chicken/egg issue here.  You want to trap the error coming
back from libsybdb via the installed handler, but as currently coded,
it can't decode this if the login failed, since it tries to to read
information from the invalid Sybase login handle.

Should the dbstrcpy call be trapped in an eval, perhaps?  Should we
test $db to be sure we were passed a reference?  Seems to me the
simplest solution is the former.