If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > why I cant rollback to savepoint?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-02-04, 17:52
rosbur rosbur is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
why I cant rollback to savepoint?

I run the following script in DB2 V8.1 under Linux.

CREATE TABLE tmp(
<table definition>
);
savepoint SPTMP on rollback retain cursors;
insert into tmp (select * from orders where o_id<10000);
select count(*) from tmp;
rollback to savepoint SPTMP;
select count(*) from tmp;

But get the following errors:

rollback to savepoint SPTMP
DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0880N SAVEPOINT "SPTMP" does not exist or is invalid in this context.
SQLSTATE=3B001

Apparently I have the savepoint defined. What have I done wrong?
Reply With Quote
  #2 (permalink)  
Old 11-02-04, 18:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Do you turn off autocommit when you run this script?
Reply With Quote
  #3 (permalink)  
Old 11-03-04, 05:57
rosbur rosbur is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
Thanks for your quick reply. But if I don't want to turn off autocommit, I just want to run the following piece of code in a transaction. What should I do?

savepoint SPTMP on rollback retain cursors;
insert into tmp (select * from orders where o_id<10000);
select count(*) from tmp;
rollback to savepoint SPTMP;

I tried wrapping those statements with BEGIN ATOMIC ... END but it doesnt work.
Reply With Quote
  #4 (permalink)  
Old 11-03-04, 10:11
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by rosbur
But if I don't want to turn off autocommit, I just want to run the following piece of code in a transaction. What should I do?
What you're saying essentially is "I want a transaction but I don't want a transaction." A COMMIT ends the current transaction. If you have autocommit turned on it issues a COMMIT after each statement. So, the answer is: if you want to run several statements in a single transaction, turn off autocommit.
Reply With Quote
  #5 (permalink)  
Old 11-03-04, 18:32
rosbur rosbur is offline
Registered User
 
Join Date: Oct 2004
Posts: 7
Maybe I migrated the wrong idea from oracle to DB2. In oracle I can have a bunch of statements executed as a single transaction if they are wrapped with BEGIN ... END clause, but the autocommit flag is still ON. That is I can have some statement autocommited but other running as a transaction.

--the following statements will be auto committed
<some statements>
--statements inside BEGIN..END run as a transaction
BEGIN
<statements>
END
I thought I can do that as well in DB2.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On