| | |
| | | * @package DB |
| | | * @author James L. Pine <jlp@valinux.com> |
| | | * @author Daniel Convissor <danielc@php.net> |
| | | * @copyright 1997-2005 The PHP Group |
| | | * @copyright 1997-2007 The PHP Group |
| | | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| | | * @version CVS: $Id$ |
| | | * @link http://pear.php.net/package/DB |
| | |
| | | * @package DB |
| | | * @author James L. Pine <jlp@valinux.com> |
| | | * @author Daniel Convissor <danielc@php.net> |
| | | * @copyright 1997-2005 The PHP Group |
| | | * @copyright 1997-2007 The PHP Group |
| | | * @license http://www.php.net/license/3_0.txt PHP License 3.0 |
| | | * @version Release: @package_version@ |
| | | * @version Release: 1.7.13 |
| | | * @link http://pear.php.net/package/DB |
| | | */ |
| | | class DB_oci8 extends DB_common |
| | |
| | | * @var array |
| | | */ |
| | | var $errorcode_map = array( |
| | | 1 => DB_ERROR_CONSTRAINT, |
| | | 900 => DB_ERROR_SYNTAX, |
| | | 904 => DB_ERROR_NOSUCHFIELD, |
| | | 913 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | 921 => DB_ERROR_SYNTAX, |
| | | 923 => DB_ERROR_SYNTAX, |
| | | 942 => DB_ERROR_NOSUCHTABLE, |
| | | 955 => DB_ERROR_ALREADY_EXISTS, |
| | | 1400 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1401 => DB_ERROR_INVALID, |
| | | 1407 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1418 => DB_ERROR_NOT_FOUND, |
| | | 1476 => DB_ERROR_DIVZERO, |
| | | 1722 => DB_ERROR_INVALID_NUMBER, |
| | | 2289 => DB_ERROR_NOSUCHTABLE, |
| | | 2291 => DB_ERROR_CONSTRAINT, |
| | | 2292 => DB_ERROR_CONSTRAINT, |
| | | 2449 => DB_ERROR_CONSTRAINT, |
| | | 1 => DB_ERROR_CONSTRAINT, |
| | | 900 => DB_ERROR_SYNTAX, |
| | | 904 => DB_ERROR_NOSUCHFIELD, |
| | | 913 => DB_ERROR_VALUE_COUNT_ON_ROW, |
| | | 921 => DB_ERROR_SYNTAX, |
| | | 923 => DB_ERROR_SYNTAX, |
| | | 942 => DB_ERROR_NOSUCHTABLE, |
| | | 955 => DB_ERROR_ALREADY_EXISTS, |
| | | 1400 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1401 => DB_ERROR_INVALID, |
| | | 1407 => DB_ERROR_CONSTRAINT_NOT_NULL, |
| | | 1418 => DB_ERROR_NOT_FOUND, |
| | | 1476 => DB_ERROR_DIVZERO, |
| | | 1722 => DB_ERROR_INVALID_NUMBER, |
| | | 2289 => DB_ERROR_NOSUCHTABLE, |
| | | 2291 => DB_ERROR_CONSTRAINT, |
| | | 2292 => DB_ERROR_CONSTRAINT, |
| | | 2449 => DB_ERROR_CONSTRAINT, |
| | | 12899 => DB_ERROR_INVALID, |
| | | ); |
| | | |
| | | /** |
| | |
| | | * @access private |
| | | */ |
| | | var $manip_query = array(); |
| | | |
| | | /** |
| | | * Store of prepared SQL queries. |
| | | * @var array |
| | | * @access private |
| | | */ |
| | | var $_prepared_queries = array(); |
| | | |
| | | |
| | | // }}} |
| | |
| | | $this->dbsyntax = $dsn['dbsyntax']; |
| | | } |
| | | |
| | | // Backwards compatibility with DB < 1.7.0 |
| | | if (empty($dsn['database']) && !empty($dsn['hostspec'])) { |
| | | $db = $dsn['hostspec']; |
| | | } else { |
| | | $db = $dsn['database']; |
| | | } |
| | | |
| | | if (function_exists('oci_connect')) { |
| | | if (isset($dsn['new_link']) |
| | | && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) |
| | |
| | | $connect_function = $persistent ? 'oci_pconnect' |
| | | : 'oci_connect'; |
| | | } |
| | | |
| | | // Backwards compatibility with DB < 1.7.0 |
| | | if (empty($dsn['database']) && !empty($dsn['hostspec'])) { |
| | | $db = $dsn['hostspec']; |
| | | } else { |
| | | $db = $dsn['database']; |
| | | if (isset($this->dsn['port']) && $this->dsn['port']) { |
| | | $db = '//'.$db.':'.$this->dsn['port']; |
| | | } |
| | | |
| | | $char = empty($dsn['charset']) ? null : $dsn['charset']; |
| | |
| | | } |
| | | } else { |
| | | $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; |
| | | if ($dsn['hostspec']) { |
| | | if ($db) { |
| | | $this->connection = @$connect_function($dsn['username'], |
| | | $dsn['password'], |
| | | $dsn['hostspec']); |
| | | $db); |
| | | } elseif ($dsn['username'] || $dsn['password']) { |
| | | $this->connection = @$connect_function($dsn['username'], |
| | | $dsn['password']); |
| | |
| | | return $this->oci8RaiseError($result); |
| | | } |
| | | $this->last_stmt = $result; |
| | | if (DB::isManip($query)) { |
| | | if ($this->_checkManip($query)) { |
| | | return DB_OK; |
| | | } else { |
| | | @ocisetprefetch($result, $this->options['result_buffering']); |
| | |
| | | */ |
| | | function freeResult($result) |
| | | { |
| | | return @OCIFreeStatement($result); |
| | | return is_resource($result) ? OCIFreeStatement($result) : false; |
| | | } |
| | | |
| | | /** |
| | |
| | | $save_query = $this->last_query; |
| | | $save_stmt = $this->last_stmt; |
| | | |
| | | if (count($this->_data)) { |
| | | $smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')'); |
| | | $count = $this->execute($smt, $this->_data); |
| | | } else { |
| | | $count =& $this->query($countquery); |
| | | } |
| | | $count = $this->query($countquery); |
| | | |
| | | // Restore the last query and statement. |
| | | $this->last_query = $save_query; |
| | | $this->last_stmt = $save_stmt; |
| | | |
| | | if (DB::isError($count) || |
| | | DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED))) |
| | | { |
| | | $this->last_query = $save_query; |
| | | $this->last_stmt = $save_stmt; |
| | | return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
| | | } |
| | | |
| | | return $row[0]; |
| | | } |
| | | return $this->raiseError(DB_ERROR_NOT_CAPABLE); |
| | |
| | | } |
| | | $this->prepare_types[(int)$stmt] = $types; |
| | | $this->manip_query[(int)$stmt] = DB::isManip($query); |
| | | $this->_prepared_queries[(int)$stmt] = $newquery; |
| | | return $stmt; |
| | | } |
| | | |
| | |
| | | { |
| | | $data = (array)$data; |
| | | $this->last_parameters = $data; |
| | | $this->last_query = $this->_prepared_queries[(int)$stmt]; |
| | | $this->_data = $data; |
| | | |
| | | $types =& $this->prepare_types[(int)$stmt]; |
| | | $types = $this->prepare_types[(int)$stmt]; |
| | | if (count($types) != count($data)) { |
| | | $tmp =& $this->raiseError(DB_ERROR_MISMATCH); |
| | | $tmp = $this->raiseError(DB_ERROR_MISMATCH); |
| | | return $tmp; |
| | | } |
| | | |
| | |
| | | } elseif ($types[$i] == DB_PARAM_OPAQUE) { |
| | | $fp = @fopen($data[$key], 'rb'); |
| | | if (!$fp) { |
| | | $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION); |
| | | return $tmp; |
| | | } |
| | | $data[$key] = fread($fp, filesize($data[$key])); |
| | | fclose($fp); |
| | | } elseif ($types[$i] == DB_PARAM_SCALAR) { |
| | | // Floats have to be converted to a locale-neutral |
| | | // representation. |
| | | if (is_float($data[$key])) { |
| | | $data[$key] = $this->quoteFloat($data[$key]); |
| | | } |
| | | } |
| | | if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) { |
| | | $tmp = $this->oci8RaiseError($stmt); |
| | | return $tmp; |
| | | } |
| | | $this->last_query = str_replace(':bind'.$i, $this->quoteSmart($data[$key]), $this->last_query); |
| | | $i++; |
| | | } |
| | | if ($this->autocommit) { |
| | |
| | | return $tmp; |
| | | } |
| | | $this->last_stmt = $stmt; |
| | | if ($this->manip_query[(int)$stmt]) { |
| | | if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { |
| | | $this->_last_query_manip = true; |
| | | $this->_next_query_manip = false; |
| | | $tmp = DB_OK; |
| | | } else { |
| | | $this->_last_query_manip = false; |
| | | @ocisetprefetch($stmt, $this->options['result_buffering']); |
| | | $tmp =& new DB_result($this, $stmt); |
| | | $tmp = new DB_result($this, $stmt); |
| | | } |
| | | return $tmp; |
| | | } |
| | |
| | | if (count($params)) { |
| | | $result = $this->prepare("SELECT * FROM ($query) " |
| | | . 'WHERE NULL = NULL'); |
| | | $tmp =& $this->execute($result, $params); |
| | | $tmp = $this->execute($result, $params); |
| | | } else { |
| | | $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL"; |
| | | |
| | |
| | | $repeat = 0; |
| | | do { |
| | | $this->expectError(DB_ERROR_NOSUCHTABLE); |
| | | $result =& $this->query("SELECT ${seqname}.nextval FROM dual"); |
| | | $result = $this->query("SELECT ${seqname}.nextval FROM dual"); |
| | | $this->popExpect(); |
| | | if ($ondemand && DB::isError($result) && |
| | | $result->getCode() == DB_ERROR_NOSUCHTABLE) { |
| | |
| | | if (!@OCIExecute($stmt, OCI_DEFAULT)) { |
| | | return $this->oci8RaiseError($stmt); |
| | | } |
| | | |
| | | |
| | | $i = 0; |
| | | while (@OCIFetch($stmt)) { |
| | | $res[$i] = array( |
| | |
| | | return 'SELECT table_name FROM user_tables'; |
| | | case 'synonyms': |
| | | return 'SELECT synonym_name FROM user_synonyms'; |
| | | case 'views': |
| | | return 'SELECT view_name FROM user_views'; |
| | | default: |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | // }}} |
| | | // {{{ quoteFloat() |
| | | |
| | | /** |
| | | * Formats a float value for use within a query in a locale-independent |
| | | * manner. |
| | | * |
| | | * @param float the float value to be quoted. |
| | | * @return string the quoted string. |
| | | * @see DB_common::quoteSmart() |
| | | * @since Method available since release 1.7.8. |
| | | */ |
| | | function quoteFloat($float) { |
| | | return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); |
| | | } |
| | | |
| | | // }}} |
| | | |
| | | } |
| | | |