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 > Question on COMMIT inside child procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-09-09, 21:35
raizel raizel is offline
Registered User
 
Join Date: Dec 2009
Posts: 5
Question Question on COMMIT inside child procedure

Hi to all.

I hope someone can help me find asnwers for this.

Scenario: I have one stored procedure which then calls multiple stored procedures. These children stored procedures have insert update and delete statements. Is it possible to issue a 'COMMIT;' statement "inside" these children stored procedures? I have no testing environment at the moment that's why I cannot test if its allowed. My first design was to issue the commit inside the parent stored procedure every after child procedure is done. But I found out that I need it inside child procedures.

Thanks a lot!
Reply With Quote
  #2 (permalink)  
Old 12-10-09, 08:20
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Yes you can do that. If each child SP is atomic, then that is what you want to do.

Andy
Reply With Quote
  #3 (permalink)  
Old 12-10-09, 08:41
rahul_s80 rahul_s80 is offline
Registered User
 
Join Date: Jul 2006
Location: Pune , India
Posts: 433
two things to remember:
1. cursor will be closed if not with hold because of commit.
2. You cannot issue commit within a begin atomic statement
__________________
Rahul Singh
Certified DB2 9 DBA / Application Developer
Reply With Quote
  #4 (permalink)  
Old 12-10-09, 10:27
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Another remark: if a nested procedure commits, it actually commits at the transactional scope of the DB2 client. Calling a stored procedure does not open a nested transaction or autonomous transaction. The only thing you can do is to set a savepoint and rollback to that savepoint within a procedure (but not COMMIT).
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #5 (permalink)  
Old 12-10-09, 17:41
raizel raizel is offline
Registered User
 
Join Date: Dec 2009
Posts: 5
Thanks for all the replies =).

Here is a simple Pseudo code:

Parent Procedure:
Code:
Procedure 1()

	declare global session table here;

	for each stored procedure

		call procedureChildX()	;
	
		do something here;

		commit;

	end for;	

	open cursor for global session table here;

end procedure 1
Child Procedure:
Code:
procedureChildX()


	for each selected rows from tableA
		
		insert to TableB
		
		commit;

	end for;

	insert something to global session table here;

end procedureChildX
I'm just wondering if there will be problem here I must address. I still have no testing environment at the moment.

Thanks a lot!
Reply With Quote
  #6 (permalink)  
Old 12-11-09, 11:26
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
As I said, each COMMIT statement (regardless where it occurs) commits the transaction initiated by the DB2 client. Whether those semantics are acceptable for your client application is something you have to determine. Other than that, you can do this...
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 12-12-09, 05:16
raizel raizel is offline
Registered User
 
Join Date: Dec 2009
Posts: 5
Quote:
Originally Posted by stolze View Post
As I said, each COMMIT statement (regardless where it occurs) commits the transaction initiated by the DB2 client. Whether those semantics are acceptable for your client application is something you have to determine. Other than that, you can do this...
That clarified my question. Thank you so much!
Reply With Quote
Reply

Tags
commit, db2, procedure, stored procedures

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