Welcome Guest, Not a member yet? Register   Sign In
Off-by-one bug in nested transactions
#1

[eluser]Unknown[/eluser]
In DB_driver.php:

Code:
function trans_start($test_mode = FALSE)
{    
    if ( ! $this->trans_enabled)
    {
        return FALSE;
    }

    // When transactions are nested we only begin/commit/rollback the outermost ones
    if ($this->_trans_depth > 0)
    {
        $this->_trans_depth += 1;
        return;
    }
    
    $this->trans_begin($test_mode);
}

Since $this->_trans_depth is initialized to 0, it will never pass the > 0 test and be incremented. This means trans_begin() will always be called. It should be changed to:

Code:
$this->_trans_depth += 1;
if ($this->_trans_depth > 1)
{
    return;
}

Each of the *_driver.php files for the different databases need an edit to the trans_begin() function to change so the first transaction will be allowed to start.

From:
Code:
if ($this->_trans_depth > 0)
{
    return TRUE;
}
To:
Code:
if ($this->_trans_depth > 1)
{
    return TRUE;
}

I've attached a unified diff with these changes.

--EDIT--

There's a change in trans_complete() too, which I've put into the diff.


Messages In This Thread
Off-by-one bug in nested transactions - by El Forum - 09-21-2009, 11:33 PM
Off-by-one bug in nested transactions - by El Forum - 06-10-2011, 12:53 PM
Off-by-one bug in nested transactions - by El Forum - 06-11-2011, 01:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB