|
|
sybperl-l Archive
Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: How to find out when you're killed because of a deadlock?
Date: Apr 9 1998 11:43PM
Marc Merlin writes:
> On Thu, Apr 09, 1998 at 09:35:23AM -0400, David C Worenklein wrote:
> >
> > The answer is in the Sybase manuals, if you know where to look.
>
> I am the RTFM kind of guy, but I'm not the Sybase DBA, so I don't have the
> said manuals :-) (I did ask the DBA though, but he didn't know).
The Sybase manuals are online at http://sybooks.sybase.com.
Of course this isn't really a DBA type question, but rather an
application programmers issue...
> > Create your Sybase handle thus:
> >
> > my $db = new Sybase::DBlib($USER, $PWD, $SERVER, $APPNAME, {DEADLOCK => 0});
> >
> > Use this message handler:
> >
> > sub SybMsgHandler {
> > my ($db, $message, $state, $severity, $text, $server, $procedure, $line) = @_;
>
> Cool, good to know. Maybe it would be a good thing to add this to the manual
> page, there is no mention of that command anywhere...
>
> And Michael Peppler added:
> > Whether dbsqlexec() returns FAIL for a problem or not depends on the
> > query. If there is only one result set, dbsqlexec() will *normally*
>
> Yes, I always launch queries one at a time.
>
> > return FAIL, but you should always check the return code from
> > dbresults() too (which will return FAIL if the query failed for any
> > reason and dbsqlexec() returned SUCCEED).
>
> I understand now that the Sybperl documentation is meant for those who know
> Sybase well, or at least its C API (I suppose that Sybperl is something very
> similar).
Yes - as the Sybase docs are on line, it feels a little unnecessary to
repeat all of the details of how to use the Sybase calls. I can
understand that it would be nice, but time is always lacking for this
sort of thing...
> However, it would maybe be a good idea to provide a safe snipplet of code in
> the man page, that people can re-use.
>
> Something along of the lines of:
>
> $db->dbcmd($query);
> ($db->dbsqlexec == &SUCCEED) or die "Problem with the following query: \"$query\": $!";
> # During a deadlock, dbsqlexec can unfortunately return SUCCEED, so we also
> # need to make sure that dbresults is different from FAIL
> ($db->dbresults != FAIL) or die "The following query failed:
\"$query\": $!";
Actually you should code your queries like this:
if($dbh->dbsqlexec != SUCCEED) {
return "argggg";
}
while(($ret = $dbh->dbresults) != NO_MORE_RESULTS) {
if ($ret == FAIL) {
something bad happened - here you'd add the deadlock detection
code
}
here you should check if there were any rows returned and process
them
}
Michael
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@datamig.com -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
|