Welcome Guest, Not a member yet? Register   Sign In
Unable to check transaction status if a transaction fails
#3

(12-16-2015, 11:41 PM)skunkbad Wrote: Are you starting the transaction?

$this->db->trans_start();

Yes, I am using

PHP Code:
$this->db->trans_start(TRUE); // TRUE to enable test mode

// various inserts here

$this->db->query('SIGNAL SQLSTATE \'45000\' SET MESSAGE_TEXT = \'Custom error\''); // throw an error intentionally, for testing purposes!

$this->db->trans_complete();

if(
$this->db->trans_status() === FALSE// This is never reached, regardless of test mode or not, but it should be!
{
    
trigger_error("Commit failed"); // throw my own error, sadly never thrown :(
}
else
{
    return 
$object;


If you try this, even without test mode enabled, you will never reach the check for trans_status, because CI is intercepting the DB error right away, which is fine in a way.

I also tried using trans_begin, with the following check after the deliberate error:

PHP Code:
if($this->db->trans_status() === FALSE// putting a break point here, it never seems to hit it
{
    
$this->db->trans_rollback(); // break point here, never hit
    
trigger_error("Commit failed");
}
else
{
    
$this->db->commit();
    return 
true;


Although the transaction is never committed, I can't see how exactly it is being rolled back in this case (I have checked the DB and the data is not being inserted, as expected)

Sooo, it looks like checking for the trans_status is pointless in a production scenario, as any DB error is caught by CI/PHP anyway.

The only way it ever seems to check is when I set it to test_mode, then it always comes back as failed, which is ridiculous.

Test mode should not give a FALSE status, unless there is an error of course!
Reply


Messages In This Thread
RE: Unable to check transaction status if a transaction fails - by mr_pablo - 12-17-2015, 04:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB