• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB transaction on non default DB group is not working

#1
[eluser]smilie[/eluser]
Hi all,

I have one 'challenge' with DB transactions.

Oke, I am loading DB group 'ns1':

Code:
$this->ns1 = $this->load->database('ns1',TRUE);

This one, when printed states that it is actually DB connection and:
[trans_enabled] => 1
[trans_strict] => 1
is in it as well, so far so good.

Then I have following in the model:
Code:
// Start transactions:
$this->ns1->trans_start();

// in loop, couple of times:
$this->ns1->update('records',array('ttl'=>$ttl),array('id'=>$val['id']));

// Once:
$this->ns1->update('domains',array('notified_serial'=>$serial,'blocked'=>'0','reden'=>NULL),array('id'=>$domainId['id']));

// Commit transaction and check it;
$this->ns1->trans_complete();
if($this->ns1->trans_status() === FALSE)
{
     return FALSE;
}
else
{
     return TRUE;
}

Problem is:

Query 1 (in the loop) is executed and committed (I see changes in DB);
Query 2 (executed once) fails (returns bool FALSE).
Model return FALSE, meaning:
if($this->ns1->trans_status() === FALSE)
is indeed FALSE.

However, my query 1 is not rolled back - changes remain in DB.

I would expect from DB transactions to roll changes of query 1 back in case query 2 fails.
But this does not happen Sad

Any idea's where am I going south with this one?

Thanks!
Cheers,
Smilie

#2
[eluser]porquero[/eluser]
What is your database engine?
If is mysql, is running in InnoDB?

Check this: http://ellislab.com/codeigniter/user-gui...tions.html

Quote:CodeIgniter's database abstraction allows you to use transactions with databases that support transaction-safe table types. In MySQL, you'll need to be running InnoDB or BDB table types rather than the more common MyISAM. Most other database platforms support transactions natively.

If you are not familiar with transactions we recommend you find a good online resource to learn about them for your particular database. The information below assumes you have a basic understanding of transactions.

#3
[eluser]smilie[/eluser]
[quote author="porquero" date="1330092899"]
What is your database engine?
[/quote]
MySQL

[quote author="porquero" date="1330092899"]
If is mysql, is running in InnoDB?
[/quote]
Yes, all tables are InnoDB;

[quote author="porquero" date="1330092899"]
Check this: http://ellislab.com/codeigniter/user-gui...tions.html
[/quote]

I read manual multiple times - but could not find any reference to why it should fail, nor about using different DB group Sad

Thanks for reply tho'

Cheers,
Aleks

#4
[eluser]Mauricio de Abreu Antunes[/eluser]
Where is your rollback? :-)
Is your strict mode enable?

#5
[eluser]Mauricio de Abreu Antunes[/eluser]
In this case, you don't need to use transactions.
Check your return update and just run next update if the first update is ok.
Bye!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.