Zend Framework

Zend_Db_Adapter_Oracle: Provide public method for setting execution mode

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.5
  • Fix Version/s: None
  • Component/s: Zend_Db_Adapter_Oracle
  • Labels:
    None

Description

The current Oracle adapter has a private method called _setExecuteMode($mode) for setting OCI execution mode.
It would be nice to have this method made public, so we can set a different "default" execution mode on the adapter instance.

This means that the following line within _connect() method should only be executed when no $execution_mode is set (and should be removed from the methods _commit() and _rollback():

$this->_setExecuteMode(OCI_COMMIT_ON_SUCCESS);

Activity

Hide
Gerton ten Ham added a comment -

Proposal (Changes for Zend_Db_Adapter_Oracle:

/**

  • @var integer
    */
    protected $_defaultExecuteMode = OCI_COMMIT_ON_SUCCESS;

/**

  • @param integer $mode
  • @throws Zend_Db_Adapter_Oracle_Exception
    */
    public function setDefaultExecuteMode($mode) { $this->_defaultExecuteMode = $mode; }
    /**
  • Creates a connection resource.
    *
  • @return void
  • @throws Zend_Db_Adapter_Oracle_Exception
    */
    protected function _connect()
    {
    if (is_resource($this->_connection)) { // connection already exists return; }

if (!extension_loaded('oci8')) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but the extension is not loaded'); }
// When not explicitly set, use default execution mode
if (!$this->_execute_mode) { $this->_setExecuteMode($this->_defaultExecuteMode); }

$connectionFuncName = ($this->_config['persistent'] == true) ? 'oci_pconnect' : 'oci_connect';

$this->_connection = @$connectionFuncName(
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$this->_config['charset']);

// check the connection
if (!$this->_connection) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error()); }
}

/**

  • Commit a transaction and return to default execution mode.
    *
  • @return void
  • @throws Zend_Db_Adapter_Oracle_Exception
    */
    protected function _commit()
    Unknown macro: { if (!oci_commit($this->_connection)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection)); }
    $this->_setExecuteMode($this->_defaultExecuteMode);
    }

    /**
    * Roll back a transaction and return to default execution mode.
    *
    * @return void
    * @throws Zend_Db_Adapter_Oracle_Exception
    */
    protected function _rollBack()
    {
    if (!oci_rollback($this->_connection)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection)); } }

    $this->_setExecuteMode($this->_defaultExecuteMode);
    }

Show
Gerton ten Ham added a comment - Proposal (Changes for Zend_Db_Adapter_Oracle: /**
  • @var integer */ protected $_defaultExecuteMode = OCI_COMMIT_ON_SUCCESS;
/**
  • @param integer $mode
  • @throws Zend_Db_Adapter_Oracle_Exception */ public function setDefaultExecuteMode($mode) { $this->_defaultExecuteMode = $mode; } /**
  • Creates a connection resource. *
  • @return void
  • @throws Zend_Db_Adapter_Oracle_Exception */ protected function _connect() { if (is_resource($this->_connection)) { // connection already exists return; }
if (!extension_loaded('oci8')) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception('The OCI8 extension is required for this adapter but the extension is not loaded'); } // When not explicitly set, use default execution mode if (!$this->_execute_mode) { $this->_setExecuteMode($this->_defaultExecuteMode); } $connectionFuncName = ($this->_config['persistent'] == true) ? 'oci_pconnect' : 'oci_connect'; $this->_connection = @$connectionFuncName( $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $this->_config['charset']); // check the connection if (!$this->_connection) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error()); } } /**
  • Commit a transaction and return to default execution mode. *
  • @return void
  • @throws Zend_Db_Adapter_Oracle_Exception */ protected function _commit()
    Unknown macro: { if (!oci_commit($this->_connection)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection)); } $this->_setExecuteMode($this->_defaultExecuteMode); } /** * Roll back a transaction and return to default execution mode. * * @return void * @throws Zend_Db_Adapter_Oracle_Exception */ protected function _rollBack() { if (!oci_rollback($this->_connection)) { /** * @see Zend_Db_Adapter_Oracle_Exception */ require_once 'Zend/Db/Adapter/Oracle/Exception.php'; throw new Zend_Db_Adapter_Oracle_Exception(oci_error($this->_connection)); } }
    $this->_setExecuteMode($this->_defaultExecuteMode); }

People

Vote (2)
Watch (1)

Dates

  • Created:
    Updated: