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 > MySQL > Performing Atomic multi-operation transactions? [MySQL]

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-10-08, 14:04
Shaitan00 Shaitan00 is offline
Registered User
 
Join Date: Jan 2006
Posts: 13
Question Performing Atomic multi-operation transactions? [MySQL]

I need to find a way to ensure that 2 INSERT statements occur succesfully or none at all (atomic multi-operation transaction).
Specifically - I have a table called "transactions", when a user transfers funds I perform one INSERT for the withdrawl from the source account and one INSERT for the deposit to the target account. Obviously I need to ensure at 100% that either both operations work/are succesfull otherwise I want to ensure neither commit.

For example - what if the application crashes after running the first INSERT statement and never reaches the second - then we would have loss of funds (not permitted).

Is this somehow possible in MySQL?
I need these two operations (INSERT INTO source & INSERT INTO target) to be completly atomic (all or nothing).

Any help would be greatly appreciated...
Thanks,
Reply With Quote
  #2 (permalink)  
Old 08-10-08, 16:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
hmm, have you checked da manual?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-10-08, 18:03
Shaitan00 Shaitan00 is offline
Registered User
 
Join Date: Jan 2006
Posts: 13
Question Is a TRIGGER considered atomic with its associated action? [MySQL]

I was curious to know if a TRIGGER is considered to be atomic with its associated action...?
Meaning - if I perform an INSERT into one of my tables that has an associated TRIGGER AFTER INSERT ON, what happens if in the split second after the table INSERT something happens (pc dies, loose connection to db, etc...) and the TRIGGER does not get a chance to process? Will the INSERT still commit without the TRIGGER completing?

If so - is there a way to guard against this? I need these two operations (INSERT & TRIGGER) to be completly atomic (all or nothing).

Any help would be greatly appreciated...
Thanks,
Reply With Quote
  #4 (permalink)  
Old 08-10-08, 23:22
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
MySQL looks at many SQL operations differently depending on the MySQL storage engine currently in use. A given bit of code may (and often does) behave differently when it is executed against a different storage engine.

The default configuration of MySQL (as it is delivered when first installed) uses MyISAM, which does not support the concept of transactions at all, so there is no issue of ATOMIC or otherwise. If you read the MySQL manual COMMIT section, you'll find a single sentence that gives the key tidbit that you need:
Quote:
Originally Posted by MySQL Manual
If you are using a transaction-safe storage engine (such as InnoDB, BDB, or NDBCLUSTER), you can disable autocommit mode with the following statement:
Follow the link that r937 gave you, and read carefully. The information that you need is there. Read it carefully and interpret the manual very literally... The manual is almost always correct, especially when you think that it must be kidding!

-PatP
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