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: Re: deadlock detection in CTlib
Date: Feb 26 1998 3:55PM

balfouc@kben.co.uk wrote:
> 
> Michael
> 
> How would I do deadlock detection with Sybase::CTlib. I know how to use
> dbgetuser
> data in DBlib but appart from ct_diag which I do not think is implemented
> how would I
> do this? Could this be a feature to put in?

The way I would normally do it doesn't currently work in CTlib
because the handle attributes aren't accessible in the server
callback. They will be in the next release, though (no, I don't know
when 2.10 will be released).

The way I'd do it goes something like this (remember this does
NOT work at the moment with Sybase::CTlib):

Create the connection with an additional hash variable, where you store
the latest error, as well as the latest SQL that was sent to the server:

$dbh = new Sybase::CTlib user, pwd, server, undef, { ERROR=>0, SQL=>''};

Now when you submit a query you do something like

$sql = 'insert foo values(...)';
$dbh->{SQL} = $sql;
while(($ret = $dbh->ct_execute) != CS_SUCCEED && $dbh->{ERROR} == 1205)
{
	print "retrying\n";
}
if($ret != CS_SUCCEED) {
	die "this really broke!";
}
TRY_AGAIN:
while(($ret = $dbh->ct_results($restype)) == CS_SUCCEED) {
	etc...
}
if($ret == CS_FAIL && $dbh->{ERROR} = 1205) {
	goto TRY_AGAIN;
}

And in the server callback it take the error no and set $dbh->{ERROR}.

You can still do this if you only have one open connection to Sybase,
as you can ignore the connection handle that comes in as an argument to
the callback and set the ERROR hash element of a global handle variable
instead.

Michael
--
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@datamig.com    -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com