Welcome Guest, Not a member yet? Register   Sign In
Nested DB transactions
#8

[eluser]Unknown[/eluser]
trans_start() method from the DB_driver.php (CodeIgniter 1.7.1)
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);
    }

trans_complete() method from the DB_driver.php (CodeIgniter 1.7.1)
Code:
function trans_complete()
    {
        if ( ! $this->trans_enabled)
        {
            return FALSE;
        }
    
        // When transactions are nested we only begin/commit/rollback the outermost ones
        if ($this->_trans_depth > 1)
        {
            $this->_trans_depth -= 1;
            return TRUE;
        }
        
        // The query() function will set this flag to FALSE in the event that a query failed
        if ($this->_trans_status === FALSE)
        {
            $this->trans_rollback();

            // If we are NOT running in strict mode, we will reset
            // the _trans_status flag so that subsequent groups of transactions
            // will be permitted.
            if ($this->trans_strict === FALSE)
            {
                $this->_trans_status = TRUE;
            }

            log_message('debug', 'DB Transaction Failure');
            return FALSE;
        }

        $this->trans_commit();
        return TRUE;
    }

trans_complete() method from the DB_driver.php (CodeIgniter 1.7.1)

Following code is a part of trans_begin, trans_commit, trans_rollback from mysql_driver.php(same with other driver files) (CodeIgniter 1.7.1)
Code:
if ($this->_trans_depth > 0)
        {
            return TRUE;
        }

so... if you want to use mutiple transactions.
you should modify trans_start() method and trans_complete() method from DB_driver.php

it should be
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);
        $this->_trans_depth += 1;
    }

    function trans_complete()
    {
        if ( ! $this->trans_enabled)
        {
            return FALSE;
        }
    
        // When transactions are nested we only begin/commit/rollback the outermost ones
        if ($this->_trans_depth > 1)
        {
            $this->_trans_depth -= 1;
            return TRUE;
        }elseif($this->_trans_depth==1){
            $this->_trans_depth -= 1;
        }
        
        // The query() function will set this flag to FALSE in the event that a query failed
        if ($this->_trans_status === FALSE)
        {
            $this->trans_rollback();

            // If we are NOT running in strict mode, we will reset
            // the _trans_status flag so that subsequent groups of transactions
            // will be permitted.
            if ($this->trans_strict === FALSE)
            {
                $this->_trans_status = TRUE;
            }

            log_message('debug', 'DB Transaction Failure');
            return FALSE;
        }
        
        $this->trans_commit();
        return TRUE;
    }

and you can use it
Code:
$this->db->trans_start();

    $this->db->trans_start();
    ....
    $this->db->trans_complete();

    $this->db->trans_start();
    ....
    $this->db->trans_complete();

$this->db->trans_complete();


Messages In This Thread
Nested DB transactions - by El Forum - 01-08-2009, 05:00 AM
Nested DB transactions - by El Forum - 01-08-2009, 06:10 AM
Nested DB transactions - by El Forum - 01-08-2009, 08:21 AM
Nested DB transactions - by El Forum - 02-28-2009, 09:27 PM
Nested DB transactions - by El Forum - 02-28-2009, 09:41 PM
Nested DB transactions - by El Forum - 02-28-2009, 09:58 PM
Nested DB transactions - by El Forum - 03-03-2009, 04:39 AM
Nested DB transactions - by El Forum - 03-24-2009, 03:54 PM
Nested DB transactions - by El Forum - 03-25-2009, 08:13 PM
Nested DB transactions - by El Forum - 05-24-2009, 09:24 AM
Nested DB transactions - by El Forum - 10-23-2010, 06:42 AM
Nested DB transactions - by El Forum - 11-08-2012, 07:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB