|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at peppler dot org>
Subject: CTLib Callback Msg; can this access the SQL statement being execu ted
Date: May 17 1999 1:17PM
Ruth Geever writes:
> Hello,
>
> I'm using Sybperl with Sybase Open Client 11.1.1;
> When an error occurs, I want to display the SQL statement that caused the
> error. However, I cannot access the SQL statement that caused the error in
> the callback subroutine.
Unfortunately there is no equivalent to dbstrcpy() in Client Library,
so there is no really easy way to do this.
There are a number of alternate ways to achieve this, however. The
most painless (and mostly transparent to your users) is to write a
module that inherits from Sybase::CTlib and that overloads
ct_execute(), storing the $sql in the $dbh before the execute.
Something like
package My::CTlib;
use Sybase::CTlib;
use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
require Exporter;
require AutoLoader;
@ISA = qw(Exporter AutoLoader Sybase::CTlib);
@EXPORT = @Sybase::CTlib::EXPORT;
$VERSION = '1.00';
sub new {
my ($package, $user, $pwd, $server, $app, $attr) = @_;
# Pre-allocate space for the SQL text in the $dbh struct.
if ($attr) {
$attr->{SQL} = '';
else {
$attr = {SQL => ''};
}
$package::SUPER->new($user, $pwd, $server, $app, $attr);
}
sub ct_execute {
my $dbh = shift;
my $sql = shift;
$dbh->{SQL} = $sql; # Store the $sql in the dbh...
$dbh::SUPER->ct_execute($sql); # call the real ct_execute;
}
1;
__END__
Place the above in a file in My/CTlib.pm.
Now in your program you do:
use My::CTlib;
ct_callback(CS_SERVERMSG_CB, \&msgCB);
$dbh = new My::CTlib $user, $pwd, $server;
$dbh->ct_execut("...");
etc...
sub msgCB
{
my $ctlib = shift;
my ($number, $severity, $origin, $layer, $server, $proc,
$msg, $osmsg) = @_;
my $q = new CGI;
print $q->header(),
$q->start_html(),
$q->h1('Sybase Error'),
'| Open Client Message: | | ',
'| Message Number: | LAYER = ',$layer,' ORIGIN =
',$origin,' | ',
' | SEVERITY = ',$severity,' NUMBER =
',$number,' | ',
'| Message String: | ',$msg,' | ';
print '| Operating System Error: | ',$osmsg,' | '
if defined($osmsg);
# Print out the SQL:
print '| SQL: | ', $ctlib->{SQL}, ' | ';
print ' ';
$q->end_html();
exit;
return CS_SUCCEED;
}
I hope this helps a little bit....
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@peppler.org -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
|