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: Gregory Sawyer <gsawyer at gage dot com>
Subject: Re: BEGIN, COMMIT, ROLLBACK
Date: Oct 15 1997 5:39PM

I think your problem is in sub test_ins.  You have to execute dbresults once  
for each command in the buffer.  You send two commands in the main line,  
then an additional command in test_ins, then dbsqlexec, then dbresults.  You  
have to execute dbresults once for each command in the buffer, or execute a  
dbcancel.  You can test the result of dbresults by looking at the return code  
for NO_MORE_RESULTS.  You can also test for errors by looking at the return  
status from dbsqlexec and dbresults.  See also the Sybase Open Client Library  
manual for details on how these two interact when there are multiple  
commands and commands that don't return a result set to the client.

--Gregory



Begin forwarded message:

X-Listname: SybPerl Discussion List 
Warnings-To: <>
Sender: owner-sybperl-l@trln.lib.unc.edu
From: 
Reply-To: SYBPERL-L@trln.lib.unc.edu
Date: Wed, 15 Oct 97 10:41:05 -0400
Subject: BEGIN, COMMIT, ROLLBACK
To: SYBPERL-L@trln.lib.unc.edu

     What I am trying to do is set up a $dbh with a BEGIN TRANSACTION
     statement, do a series of inserts, updates, etc and if there is an
     error, roll them all back else commit them (pretty much database 101).

     Anyway, in Sybperl I am a little stuck as to how to implement this.
     The $dbh will be passed through a series of subs as outlined below.
     My big issue is how do I perform my &get_last_err procedure to get
     any errors returned from that connection ($dbh).  The way my code is
     now I get the following error:

     Sybase error: Attempt to initiate a new SQL Server operation with
     results pending.

     I would open up a new $dbh, but then I wouldn't have the error
     information would I?

     Thanks in advance and if I am overlooking something really obvious I
     apologize.

     Regards,

     Sal

     *********************************************************************

     

     $dbh->dbcmd("BEGIN TRANSACTION\n");

     $dbh->dbcmd("INSERT INTO Foo (MyID, Name, Number)
                  VALUES (1, 'bar', 34)\n");

     &test_ins ($dbh);

     #################################################################
     # Subroutines...
     #################################################################

     sub test_ins {

         my $dbh = @_[0];

         $dbh->dbcmd("INSERT INTO Foo (MyID, Name, Number)
                      VALUES (2, 'foo', 'bad value')\n");

         $dbh->dbsqlexec; $dbh->dbresults;

         if (&get_last_err ($dbh)) {

        $dbh->dbcmd("ROLLBACK TRANSACTION")

         } else {

        $dbh->dbcmd("COMMIT TRANSACTION")

         }

         $dbh->dbsqlexec; $dbh->dbresults;

     }

     sub get_last_err {

         my $dbh = @_[0];

         $dbh->dbcmd("SELECT \@\@error\n");

         $dbh->dbsqlexec; $dbh->dbresults;

         return $dbh->dbnextrow(1);

     }