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: Danilo Unite <danilo at acme dot nsc dot com>
Subject: Transactions
Date: Dec 11 1997 9:33PM

Hi,

I have just started using the Sybperl package and am still trying to get
familiar with all its functions. I would like to perform some updates,
inserts, and deletes within a transaction block. I am not clear on
exactly how this is done.

On first pass, this is the snippet of code that I tried:

    $dbh->ct_sql('begin transaction');
    foreach $query (@queries){
        $status = $dbh->ct_execute($query);
        while ($response = $dbh->ct_results($restype) == CS_SUCCEED){
            if($response == CS_FAIL || $response == CS_CANCELED){
                $dbh->ct_cancel(CS_CANCEL_ALL);
                $dbh->ct_sql('rollback transaction');
                $flag = 1;
                last;
            }
            else{
                next unless $dbh->ct_fetchable($restype);
                while(($data) = $dbh->ct_fetch){}
            }
        }
    }

    if(!$flag){
        $dbh->ct_sql('commit transaction');
    }

My question is, which return value do I check to determine whether the
sql command was successful. Do I check the return value from ct_execute,
the return value from ct_results, or the response type variable that is
passed to ct_results? Is this how I should perform a rollback(i.e.
checking the return status of either of these methods)? Any suggestions
would be greatly appreciated!

Sincerely,
Danilo Unite

--
*******************************************************************
Danilo Unite                             (408) 721-4047
Systems Development Engineer             danilo@acme.nsc.com
Intranet Technology Group
National Semiconductor Corporation

"The ability to quote is a serviceable substitute for wit."
- W. Somerset Maugham
*******************************************************************