Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2008, 02:45 AM
Junior Member
 
Join Date: Apr 2008
Posts: 5
Default Controlling Database Transactions not work on Truncate table

Hi, anyone able to help me with controlling database transaction over truncate table? The transaction not rollback when the insert fail. My code is as below:
$db->beginTransaction();
try {
if(!empty($system)){
$db->query("TRUNCATE TABLE systemmain");
}
$dataAfter = array ('name' => "Please Setup Company Information", 'keyId'=> "1");
$db->insert('systemmain', $dataAfter);
$db->commit();
}
catch (Exception $e) {
$db->rollBack();
$errorMsg[] = $e->getMessage();
}// end of catch exception
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-24-2008, 04:19 AM
Member
 
Join Date: Jul 2008
Posts: 60
Default

The MySQL docs (MySQL :: MySQL 5.0 Reference Manual :: 12.2.9 TRUNCATE Syntax) mention that "Truncate operations are not transaction-safe". Although it says that the truncate query should cause an error if in a transaction. This would still be my best guess at your problem.

Maybe you can use a "DELETE FROM systemmain WHERE 1" instead; it's not as performant though (especially on larger tables).
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-24-2008, 09:42 AM
Junior Member
 
Join Date: Apr 2008
Posts: 5
Default

Nice advice I try the DELETE FROM, hope it works
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

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



All times are GMT. The time now is 01:05 AM.