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 > General > Database Concepts & Design > transactions and table sequences/ids

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-29-05, 09:59
mtjo mtjo is offline
Registered User
 
Join Date: Feb 2005
Posts: 14
transactions and table sequences/ids

I am working on a database abstraction app and now adding transaction support. When I set autocommit to false on say a mysql query or set the commit to default on a oracle db query, it works as expected and does not commit until I add a commit statement. However, in my script, I have it printing the num of rows, affected rows, etc., on each operation and it still increments the table index when I do not commit the transaction. Upon a subsequent transaction, it begins at the incremented index from the non-commited query. Is this the correct behavior for transactions/tables?
Reply With Quote
  #2 (permalink)  
Old 12-29-05, 10:09
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
I'm not sure what you mean by a "table index", but it sounds like you are talking about auto-incremented keys. In Oracle, these are implemented using a SEQUENCE, and a feature of sequences is that they are not part of the transaction: once the sequence has been incremented it stays incremented, even if the transaction rolls back.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 12-29-05, 10:19
mtjo mtjo is offline
Registered User
 
Join Date: Feb 2005
Posts: 14
Thanks Tony. Yes I did mean auto-incremented keys/sequences. Essentially, I am inserting a single value into the table w/o commiting. I print the results from a select query and the last field printed is the incremented value. Say I have 10 rows and I do 2 inserts w/o commiting. The key is incremented to 12 and upon subsequent inserts where I do commit, the auto-increment value begins at 13 instead of 11.
Reply With Quote
  #4 (permalink)  
Old 12-29-05, 11:17
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Yes, that is normal and correct behaviour!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 12-29-05, 11:19
mtjo mtjo is offline
Registered User
 
Join Date: Feb 2005
Posts: 14
Much obliged.
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