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: Sybperl v2.07 for Solaris -- CTlib -- ct_sql
Date: Sep 18 1997 9:49PM

Ronald Page wrote:
> 
> Mike,
> 
> I am using your Sybperl library (which is really cool :-).  I have a
> question about ct_sql.   I am using ct_sql to INSERT a row and always
> get a return code of -205 whether it succeeds or fails. (using
> $db->{'RC'}).  Is this supposed to behave this way?  Am I doing
> something obviously wrong?  Should I be using ct_execute, etc. instead?

I think ct_sql() works fine. Only it does not return any failure code
when there's a failure on the server (ie syntax error, deadlock, etc.)

I've just recently discovered that ct_results() does not return CT_FAIL
in those cases. Rather, the $restype is set to CS_CMD_FAIL in that
case. The problem is that this value is lost because of the loop
on ct_results().

Here's a slightly modified version of ct_sql() which will put
CS_FAIL in $db->{RC} if the command fails on the server:

sub ct_sql
{
    my($db, $cmd, $sub, $flag) = @_;
    my(@res, @data, $rc);
    local($res_type);  # it's local so that it can be examined by &$sub
    my($count, $max);
    my $fail = 0;

    ($db->ct_execute($cmd) == &CS_SUCCEED) || return undef;

    $max = $db->{'MaxRows'};
    $res_type = 0;		# avoid 'unitialized variable' warnings...
    $flag = 0 unless $flag;

    while(($rc = $db->ct_results($res_type)) == &CS_SUCCEED) {
        $db->{'ROW_COUNT'} = $db->ct_res_info(&CS_ROW_COUNT)
            if $res_type == &CS_CMD_DONE;
	$fail = 1 if($res_type == &CS_CMD_FAIL;
	next unless $fetchable{$res_type};

        while (@data = $db->ct_fetch($flag)) {
	    last if($max && ++$count > $max);
            if (defined $sub) {
                &$sub(@data);
            } else {
		if($flag) {
		    push(@res, {@data});
		} else {
		    push(@res, [@data]);
		}
            }
        }
	$db->ct_cancel(&CS_CANCEL_CURRENT) if($max && $count > $max);
    }
    $db->{RC} = $fail ? &CS_FAIL : $rc;
    wantarray ? @res : \@res;  # return the result array
}


BTW - this routine should also use the ct_options() call to set rowcount
instead of doing the count itself...

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