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: ct_execute vs ct_sql
Date: Sep 23 1997 2:35PM

Java G wrote:
> 
> Hi,
> 
> What is the easiest way to check that a query went through ok if I'm
> only using the ct_sql() method in CTlib? or would using ct_callback()
> be appropriate? The idea is to encapsulate all database access in
> a lubrary, but we must have a robust exception handling technique.
> 
> The problem is that ct_execute() is asynchronous, and I need to know
> that things were ok before proceeding with the next operation...

No, ct_execute() is not asynchronous, at least not in the Sybase::CTlib
module. ct_execute() will block until the current operation completes,
and then ct_results() will tell you what result sets are coming back.

The current ct_sql() has a bug in that when a command fails on the
server ct_results() still returns CT_SUCCEED and CT_END_RESULTS when
it is done. It is the $res_type variable that gets set to
CS_CMD_FAIL when such a failure occurs, and this is what needs to be
monitored.

So a generic "execute SQL" sub would look something like:

sub execSQL {
    my $dbh = shift;
    my $sql = shift;

    my $ret = $dbh->ct_execute($sql);
    return $ret if($ret == CS_FAIL);

    my $res_type;
    my $fail = 0;
    while(($ret = $dbh->ct_results($res_type)) == CS_SUCCEED) {
        if($res_type == CS_CMD_FAIL) {
	    $fail = 1;
	}
	if($dbh->ct_fetchable) {
	    # shouldn't happen if this is an execute type routine...
	    while($dbh->ct_fetch()) {
		# throw away the rows!!!
	    }
	}
    }
    if($fail) {
	return CS_FAIL;
    } else {
      	return CS_SUCCEED;
    }
}

Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler