| | |
| | | // | Author: Paul Cooper <pgc@ucecom.com> | |
| | | // +----------------------------------------------------------------------+ |
| | | // |
| | | // $Id: pgsql.php 292715 2009-12-28 14:06:34Z quipo $ |
| | | // $Id: pgsql.php 295587 2010-02-28 17:16:38Z quipo $ |
| | | |
| | | /** |
| | | * MDB2 PostGreSQL driver |
| | |
| | | $this->destructor_registered = true; |
| | | register_shutdown_function('MDB2_closeOpenTransactions'); |
| | | } |
| | | $result =& $this->_doQuery('BEGIN', true); |
| | | $result = $this->_doQuery('BEGIN', true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | return $this->_doQuery($query, true); |
| | | } |
| | | |
| | | $result =& $this->_doQuery('COMMIT', true); |
| | | $result = $this->_doQuery('COMMIT', true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | } |
| | | |
| | | $query = 'ROLLBACK'; |
| | | $result =& $this->_doQuery($query, true); |
| | | $result = $this->_doQuery($query, true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | | } |
| | |
| | | * READ COMMITTED (prevents dirty reads) |
| | | * REPEATABLE READ (prevents nonrepeatable reads) |
| | | * SERIALIZABLE (prevents phantom reads) |
| | | * @param array some transaction options: |
| | | * 'wait' => 'WAIT' | 'NO WAIT' |
| | | * 'rw' => 'READ WRITE' | 'READ ONLY' |
| | | * |
| | | * @return mixed MDB2_OK on success, a MDB2 error on failure |
| | | * |
| | | * @access public |
| | | * @since 2.1.1 |
| | | */ |
| | | function setTransactionIsolation($isolation) |
| | | function setTransactionIsolation($isolation, $options = array()) |
| | | { |
| | | $this->debug('Setting transaction isolation level', __FUNCTION__, array('is_manip' => true)); |
| | | switch ($isolation) { |
| | |
| | | // }}} |
| | | // {{{ standaloneQuery() |
| | | |
| | | /** |
| | | /** |
| | | * execute a query as DBA |
| | | * |
| | | * @param string $query the SQL query |
| | |
| | | * @return mixed MDB2_OK on success, a MDB2 error on failure |
| | | * @access public |
| | | */ |
| | | function &standaloneQuery($query, $types = null, $is_manip = false) |
| | | function standaloneQuery($query, $types = null, $is_manip = false) |
| | | { |
| | | $user = $this->options['DBA_username']? $this->options['DBA_username'] : $this->dsn['username']; |
| | | $pass = $this->options['DBA_password']? $this->options['DBA_password'] : $this->dsn['password']; |
| | |
| | | $this->offset = $this->limit = 0; |
| | | $query = $this->_modifyQuery($query, $is_manip, $limit, $offset); |
| | | |
| | | $result =& $this->_doQuery($query, $is_manip, $connection, $this->database_name); |
| | | $result = $this->_doQuery($query, $is_manip, $connection, $this->database_name); |
| | | if (!PEAR::isError($result)) { |
| | | if ($is_manip) { |
| | | $result = $this->_affectedRows($connection, $result); |
| | |
| | | * @return result or error object |
| | | * @access protected |
| | | */ |
| | | function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null) |
| | | function _doQuery($query, $is_manip = false, $connection = null, $database_name = null) |
| | | { |
| | | $this->last_query = $query; |
| | | $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre')); |
| | |
| | | $function = $this->options['multi_query'] ? 'pg_send_query' : 'pg_query'; |
| | | $result = @$function($connection, $query); |
| | | if (!$result) { |
| | | $err =& $this->raiseError(null, null, null, |
| | | $err = $this->raiseError(null, null, null, |
| | | 'Could not execute statement', __FUNCTION__); |
| | | return $err; |
| | | } elseif ($this->options['multi_query']) { |
| | | if (!($result = @pg_get_result($connection))) { |
| | | $err =& $this->raiseError(null, null, null, |
| | | $err = $this->raiseError(null, null, null, |
| | | 'Could not get the first result from a multi query', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | * @access public |
| | | * @see bindParam, execute |
| | | */ |
| | | function &prepare($query, $types = null, $result_types = null, $lobs = array()) |
| | | function prepare($query, $types = null, $result_types = null, $lobs = array()) |
| | | { |
| | | if ($this->options['emulate_prepared']) { |
| | | $obj =& parent::prepare($query, $types, $result_types, $lobs); |
| | | return $obj; |
| | | return parent::prepare($query, $types, $result_types, $lobs); |
| | | } |
| | | $is_manip = ($result_types === MDB2_PREPARE_MANIP); |
| | | $offset = $this->offset; |
| | |
| | | $regexp = '/^.{'.($position+1).'}('.$this->options['bindname_format'].').*$/s'; |
| | | $param = preg_replace($regexp, '\\1', $query); |
| | | if ($param === '') { |
| | | $err =& $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | $err = $this->raiseError(MDB2_ERROR_SYNTAX, null, null, |
| | | 'named parameter name must match "bindname_format" option', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | if (false === $pgtypes) { |
| | | $result = @pg_prepare($connection, $statement_name, $query); |
| | | if (!$result) { |
| | | $err =& $this->raiseError(null, null, null, |
| | | $err = $this->raiseError(null, null, null, |
| | | 'Unable to create prepared statement handle', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | $types_string = ' ('.implode(', ', $pgtypes).') '; |
| | | } |
| | | $query = 'PREPARE '.$statement_name.$types_string.' AS '.$query; |
| | | $statement =& $this->_doQuery($query, true, $connection); |
| | | $statement = $this->_doQuery($query, true, $connection); |
| | | if (PEAR::isError($statement)) { |
| | | return $statement; |
| | | } |
| | |
| | | * @return int data array on success, a MDB2 error on failure |
| | | * @access public |
| | | */ |
| | | function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
| | | function fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
| | | { |
| | | if (null !== $rownum) { |
| | | $seek = $this->seek($rownum); |
| | |
| | | } |
| | | if (!$row) { |
| | | if (false === $this->result) { |
| | | $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | $err = $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | 'resultset has already been freed', __FUNCTION__); |
| | | return $err; |
| | | } |
| | | $null = null; |
| | | return $null; |
| | | return null; |
| | | } |
| | | $mode = $this->db->options['portability'] & MDB2_PORTABILITY_EMPTY_TO_NULL; |
| | | $rtrim = false; |
| | |
| | | * a MDB2 error on failure |
| | | * @access private |
| | | */ |
| | | function &_execute($result_class = true, $result_wrap_class = false) |
| | | function _execute($result_class = true, $result_wrap_class = false) |
| | | { |
| | | if (null === $this->statement) { |
| | | $result =& parent::_execute($result_class, $result_wrap_class); |
| | | return $result; |
| | | return parent::_execute($result_class, $result_wrap_class); |
| | | } |
| | | $this->db->last_query = $this->query; |
| | | $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values)); |
| | |
| | | if (!$query) { |
| | | $result = @pg_execute($connection, $this->statement, $parameters); |
| | | if (!$result) { |
| | | $err =& $this->db->raiseError(null, null, null, |
| | | $err = $this->db->raiseError(null, null, null, |
| | | 'Unable to execute statement', __FUNCTION__); |
| | | return $err; |
| | | } |
| | |
| | | return $affected_rows; |
| | | } |
| | | |
| | | $result =& $this->db->_wrapResult($result, $this->result_types, |
| | | $result = $this->db->_wrapResult($result, $this->result_types, |
| | | $result_class, $result_wrap_class, $this->limit, $this->offset); |
| | | $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'post', 'result' => $result)); |
| | | return $result; |