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 Peppler <mpeppler at MBAY dot NET>
Subject: CTlib extended error (CS_EXTRA_INF) (fwd)
Date: Nov 23 1998 7:26PM

Mike Lucente writes:
 > Second request -- did I miss a reply or was I not making sense?

Dunno - maybe it slipped by me...

 > 
 > I'm using the following callback routine (supplied with SybPerl):
 > 
 > sub srv_cb
 > {
 >     my($cmd, $number, $severity, $state, $line, $server, $proc, $msg) =

$cmd is actually the $dbh on which the error has occured, not the SQL
command that was sent to the server. DBlib allows you to easily get to 
the SQL command buffer, but this is not the case in CTlib.

You can get around this in various ways, one of them would be to write 
your own ct_execute().
 
 > The docs
 > suggest that I need only set CS_EXTRA_INF to CS_TRUE.

CS_EXRTA_INF refers to inline error processing for SQLCA structs and
friends. Sybase::CTlib is not built to handle that.

CS_HASEED is some extended info that can be retrieved for certain
types of errors (duplicat index insert errors, for example) where the
extra information will include the index that caused the error. Again
this does not seem to be what you are looking for.

If you need to have access to the SQL that was sent to the server you
can do a couple of things:

You can hack CTlib.xs and add a buffer to the ConInfo struct, copy the 
string passed in to ct_execute or ct_command and store it there, and
then add some functionality to retrieve it from the error handler.

You can write a small module that overloads ct_execute(), and use that 
in place of Sybase::CTlib. That module could be as simple as

package My::CTlib;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require AutoLoader;

use Carp;
use Sybase::CTlib;

@ISA = qw(Exporter AutoLoader Sybase::CTlib);
@EXPORT = @Sybase::CTlib::EXPORT;

sub new {
    my ($package, $user, $pwd, $server, $app, $attributes) = @_;

    $attributes->{SQL} = '';

    $package::SUPER->new($user, $pwd, $server, $app, $attributes);
}

sub ct_execute {
    my $self = shift;
    my $sql  = shift;

    $self->{SQL} = $sql;
    $self->SUPER::ct_execute($sql);
}

1;
__END__

Now in the error handler you should be able to refer to $cmd->{SQL} to 
get the SQL string.

Note that the above code was typed straight into the mail tool - there 
are probably some errors/typos but it should give you an idea...

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@mbay.net       -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com