/**
* Obtain the DB_common class so it can be extended from
*/
-require_once 'DB/common.php';
+//require_once 'DB/common.php';
+require_once 'common.php';
/**
* The methods PEAR DB uses to interact with PHP's oci8 extension
* The DB driver type (mysql, oci8, odbc, etc.)
* @var string
*/
- var $phptype = 'oci8';
+ public $phptype = 'oci8';
/**
* The database syntax variant to be used (db2, access, etc.), if any
* @var string
*/
- var $dbsyntax = 'oci8';
+ public $dbsyntax = 'oci8';
/**
* The capabilities of this DB implementation
*
* @var array
*/
- var $features = array(
- 'limit' => 'alter',
- 'new_link' => '5.0.0',
- 'numrows' => 'subquery',
- 'pconnect' => true,
- 'prepare' => true,
- 'ssl' => false,
- 'transactions' => true,
+ public $features = array(
+ 'limit' => 'alter',
+ 'new_link' => '5.0.0',
+ 'numrows' => 'subquery',
+ 'pconnect' => true,
+ 'prepare' => true,
+ 'ssl' => false,
+ 'transactions' => true,
);
/**
* A mapping of native error codes to DB error codes
* @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,
+ public $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,
12899 => DB_ERROR_INVALID,
);
* The raw database connection created by PHP
* @var resource
*/
- var $connection;
+ public $connection;
/**
* The DSN information for connecting to a database
* @var array
*/
- var $dsn = array();
+ public $dsn = array();
/**
* @var bool
* @access private
*/
- var $autocommit = true;
+ public $autocommit = true;
/**
* Stores the $data passed to execute() in the oci8 driver
* @var array
* @access private
*/
- var $_data = array();
+ public $_data = array();
/**
* The result or statement handle from the most recently executed query
* @var resource
*/
- var $last_stmt;
+ public $last_stmt;
/**
* Is the given prepared statement a data manipulation query?
* @var array
* @access private
*/
- var $manip_query = array();
+ public $manip_query = array();
/**
* Store of prepared SQL queries.
* @var array
* @access private
*/
- var $_prepared_queries = array();
+ public $_prepared_queries = array();
// }}}
*
* @return void
*/
- function __construct()
+ public function __construct()
{
parent::__construct();
}
* not portable to other DBMS's.
* Available since PEAR DB 1.7.0.
*
- * @param array $dsn the data source name
- * @param bool $persistent should the connection be persistent?
+ * @param array $dsn the data source name
+ * @param bool $persistent should the connection be persistent?
*
- * @return int DB_OK on success. A DB_Error object on failure.
+ * @return int|object
*/
- function connect($dsn, $persistent = false)
+ public function connect($dsn, $persistent = false)
{
if (!PEAR::loadExtension('oci8')) {
return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
if (function_exists('oci_connect')) {
if (isset($dsn['new_link'])
- && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true))
- {
+ && ($dsn['new_link'] == 'true' || $dsn['new_link'] === true)) {
$connect_function = 'oci_new_connect';
} else {
$connect_function = $persistent ? 'oci_pconnect'
- : 'oci_connect';
+ : 'oci_connect';
}
if (isset($this->dsn['port']) && $this->dsn['port']) {
- $db = '//'.$db.':'.$this->dsn['port'];
+ $db = '//' . $db . ':' . $this->dsn['port'];
}
$char = empty($dsn['charset']) ? null : $dsn['charset'];
- $this->connection = @$connect_function($dsn['username'],
- $dsn['password'],
- $db,
- $char);
+ $this->connection = @$connect_function(
+ $dsn['username'],
+ $dsn['password'],
+ $db,
+ $char
+ );
$error = OCIError();
if (!empty($error) && $error['code'] == 12541) {
// Couldn't find TNS listener. Try direct connection.
- $this->connection = @$connect_function($dsn['username'],
- $dsn['password'],
- null,
- $char);
+ $this->connection = @$connect_function(
+ $dsn['username'],
+ $dsn['password'],
+ null,
+ $char
+ );
}
} else {
$connect_function = $persistent ? 'OCIPLogon' : 'OCILogon';
if ($db) {
- $this->connection = @$connect_function($dsn['username'],
- $dsn['password'],
- $db);
+ $this->connection = @$connect_function(
+ $dsn['username'],
+ $dsn['password'],
+ $db
+ );
} elseif ($dsn['username'] || $dsn['password']) {
- $this->connection = @$connect_function($dsn['username'],
- $dsn['password']);
+ $this->connection = @$connect_function(
+ $dsn['username'],
+ $dsn['password']
+ );
}
}
if (!$this->connection) {
$error = OCIError();
$error = (is_array($error)) ? $error['message'] : null;
- return $this->raiseError(DB_ERROR_CONNECT_FAILED,
- null, null, null,
- $error);
+ return $this->raiseError(
+ DB_ERROR_CONNECT_FAILED,
+ null,
+ null,
+ null,
+ $error
+ );
}
return DB_OK;
}
*
* @return bool TRUE on success, FALSE on failure
*/
- function disconnect()
+ public function disconnect()
{
if (function_exists('oci_close')) {
$ret = @oci_close($this->connection);
* + the DB_OK constant for other successful queries
* + a DB_Error object on failure
*/
- function simpleQuery($query)
+ public function simpleQuery($query)
{
$this->_data = array();
$this->last_parameters = array();
return $this->oci8RaiseError();
}
if ($this->autocommit) {
- $success = @OCIExecute($result,OCI_COMMIT_ON_SUCCESS);
+ $success = @OCIExecute($result, OCI_COMMIT_ON_SUCCESS);
} else {
- $success = @OCIExecute($result,OCI_DEFAULT);
+ $success = @OCIExecute($result, OCI_DEFAULT);
}
if (!$success) {
return $this->oci8RaiseError($result);
// }}}
// {{{ nextResult()
+ /**
+ * Changes a query string for various DBMS specific reasons
+ *
+ * "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle.
+ *
+ * @param string $query the query string to modify
+ *
+ * @return string the modified query string
+ *
+ * @access protected
+ */
+ public function modifyQuery($query)
+ {
+ if (preg_match('/^\s*SELECT/i', $query) &&
+ !preg_match('/\sFROM\s/i', $query)) {
+ $query .= ' FROM dual';
+ }
+ return $query;
+ }
+
+ // }}}
+ // {{{ fetchInto()
+
+ /**
+ * Produces a DB_Error object regarding the current problem
+ *
+ * @param int $errno if the error is being manually raised pass a
+ * DB_ERROR* constant here. If this isn't passed
+ * the error information gathered from the DBMS.
+ *
+ * @return object the DB_Error object
+ *
+ * @see DB_common::raiseError(),
+ * DB_oci8::errorNative(), DB_oci8::errorCode()
+ */
+ public function oci8RaiseError($errno = null)
+ {
+ if ($errno === null) {
+ $error = @OCIError($this->connection);
+ return $this->raiseError(
+ $this->errorCode($error['code']),
+ null,
+ null,
+ null,
+ $error['message']
+ );
+ } elseif (is_resource($errno)) {
+ $error = @OCIError($errno);
+ return $this->raiseError(
+ $this->errorCode($error['code']),
+ null,
+ null,
+ null,
+ $error['message']
+ );
+ }
+ return $this->raiseError($this->errorCode($errno));
+ }
+
+ // }}}
+ // {{{ freeResult()
+
/**
* Move the internal oracle result pointer to the next available result
*
*
* @return true if a result is available otherwise return false
*/
- function nextResult($result)
+ public function nextResult($result)
{
return false;
}
- // }}}
- // {{{ fetchInto()
-
/**
* Places a row from the result set into the given array
*
* DB_result::fetchInto() instead. It can't be declared "protected"
* because DB_result is a separate object.
*
- * @param resource $result the query result resource
- * @param array $arr the referenced array to put the data in
- * @param int $fetchmode how the resulting array should be indexed
- * @param int $rownum the row number to fetch (0 = first row)
+ * @param resource $result the query result resource
+ * @param array $arr the referenced array to put the data in
+ * @param int $fetchmode how the resulting array should be indexed
+ * @param int $rownum the row number to fetch (0 = first row)
*
* @return mixed DB_OK on success, NULL when the end of a result set is
* reached or on failure
*
* @see DB_result::fetchInto()
*/
- function fetchInto($result, &$arr, $fetchmode, $rownum = null)
+ public function fetchInto($result, &$arr, $fetchmode, $rownum = null)
{
if ($rownum !== null) {
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
if ($fetchmode & DB_FETCHMODE_ASSOC) {
- $moredata = @OCIFetchInto($result,$arr,OCI_ASSOC+OCI_RETURN_NULLS+OCI_RETURN_LOBS);
+ $moredata = @OCIFetchInto($result, $arr, OCI_ASSOC + OCI_RETURN_NULLS + OCI_RETURN_LOBS);
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE &&
- $moredata)
- {
+ $moredata) {
$arr = array_change_key_case($arr, CASE_LOWER);
}
} else {
- $moredata = OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
+ $moredata = OCIFetchInto($result, $arr, OCI_RETURN_NULLS + OCI_RETURN_LOBS);
}
if (!$moredata) {
return null;
}
// }}}
- // {{{ freeResult()
+ // {{{ numRows()
/**
* Deletes the result set and frees the memory occupied by the result set
* DB_result::free() instead. It can't be declared "protected"
* because DB_result is a separate object.
*
- * @param resource $result PHP's query result resource
+ * @param resource $result PHP's query result resource
*
* @return bool TRUE on success, FALSE if $result is invalid
*
* @see DB_result::free()
*/
- function freeResult($result)
+ public function freeResult($result)
{
return is_resource($result) ? OCIFreeStatement($result) : false;
}
+ // }}}
+ // {{{ numCols()
+
/**
* Frees the internal resources associated with a prepared query
*
- * @param resource $stmt the prepared statement's resource
- * @param bool $free_resource should the PHP resource be freed too?
+ * @param resource $stmt the prepared statement's resource
+ * @param bool $free_resource should the PHP resource be freed too?
* Use false if you need to get data
* from the result set later.
*
*
* @see DB_oci8::prepare()
*/
- function freePrepared($stmt, $free_resource = true)
+ public function freePrepared($stmt, $free_resource = true)
{
if (!is_resource($stmt)) {
return false;
}
// }}}
- // {{{ numRows()
+ // {{{ prepare()
/**
* Gets the number of rows in a result set
* DB_result::numRows() instead. It can't be declared "protected"
* because DB_result is a separate object.
*
- * @param resource $result PHP's query result resource
+ * @param resource $result PHP's query result resource
*
- * @return int the number of rows. A DB_Error object on failure.
+ * @return int|object
*
* @see DB_result::numRows(), DB_common::setOption()
*/
- function numRows($result)
+ public function numRows($result)
{
// emulate numRows for Oracle. yuck.
if ($this->options['portability'] & DB_PORTABILITY_NUMROWS &&
- $result === $this->last_stmt)
- {
- $countquery = 'SELECT COUNT(*) FROM ('.$this->last_query.')';
+ $result === $this->last_stmt) {
+ $countquery = 'SELECT COUNT(*) FROM (' . $this->last_query . ')';
$save_query = $this->last_query;
$save_stmt = $this->last_stmt;
// 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)))
- {
+ DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED))) {
return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
}
// }}}
- // {{{ numCols()
+ // {{{ execute()
/**
* Gets the number of columns in a result set
* DB_result::numCols() instead. It can't be declared "protected"
* because DB_result is a separate object.
*
- * @param resource $result PHP's query result resource
+ * @param resource $result PHP's query result resource
*
- * @return int the number of columns. A DB_Error object on failure.
+ * @return int|object
*
* @see DB_result::numCols()
*/
- function numCols($result)
+ public function numCols($result)
{
$cols = @OCINumCols($result);
if (!$cols) {
}
// }}}
- // {{{ prepare()
+ // {{{ autoCommit()
+
+ /**
+ * Enables or disables automatic commits
+ *
+ * @param bool $onoff true turns it on, false turns it off
+ *
+ * @return int DB_OK on success. A DB_Error object if the driver
+ * doesn't support auto-committing transactions.
+ */
+ public function autoCommit($onoff = false)
+ {
+ $this->autocommit = (bool)$onoff;;
+ return DB_OK;
+ }
+
+ // }}}
+ // {{{ commit()
+
+ /**
+ * Commits the current transaction
+ *
+ * @return int|object
+ */
+ public function commit()
+ {
+ $result = @OCICommit($this->connection);
+ if (!$result) {
+ return $this->oci8RaiseError();
+ }
+ return DB_OK;
+ }
+
+ // }}}
+ // {{{ rollback()
+
+ /**
+ * Reverts the current transaction
+ *
+ * @return int|object
+ */
+ public function rollback()
+ {
+ $result = @OCIRollback($this->connection);
+ if (!$result) {
+ return $this->oci8RaiseError();
+ }
+ return DB_OK;
+ }
+
+ // }}}
+ // {{{ affectedRows()
+
+ /**
+ * Determines the number of rows affected by a data maniuplation query
+ *
+ * 0 is returned for queries that don't manipulate data.
+ *
+ * @return int|object
+ */
+ public function affectedRows()
+ {
+ if ($this->last_stmt === false) {
+ return $this->oci8RaiseError();
+ }
+ $result = @OCIRowCount($this->last_stmt);
+ if ($result === false) {
+ return $this->oci8RaiseError($this->last_stmt);
+ }
+ return $result;
+ }
+
+ // }}}
+ // {{{ modifyQuery()
+
+ /**
+ * Adds LIMIT clauses to a query string according to current DBMS standards
+ *
+ * @param string $query the query to modify
+ * @param int $from the row to start to fetching (0 = the first row)
+ * @param int $count the numbers of rows to fetch
+ * @param mixed $params array, string or numeric data to be used in
+ * execution of the statement. Quantity of items
+ * passed must match quantity of placeholders in
+ * query: meaning 1 placeholder for non-array
+ * parameters or 1 placeholder per array element.
+ *
+ * @return string the query string with LIMIT clauses added
+ *
+ * @access protected
+ */
+ public function modifyLimitQuery($query, $from, $count, $params = array())
+ {
+ // Let Oracle return the name of the columns instead of
+ // coding a "home" SQL parser
+
+ if (count($params)) {
+ $result = $this->prepare("SELECT * FROM ($query) "
+ . 'WHERE NULL = NULL');
+ $tmp = $this->execute($result, $params);
+ } else {
+ $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
+
+ if (!$result = @OCIParse($this->connection, $q_fields)) {
+ $this->last_query = $q_fields;
+ return $this->oci8RaiseError();
+ }
+ if (!@OCIExecute($result, OCI_DEFAULT)) {
+ $this->last_query = $q_fields;
+ return $this->oci8RaiseError($result);
+ }
+ }
+
+ $ncols = OCINumCols($result);
+ $cols = array();
+ for ($i = 1; $i <= $ncols; $i++) {
+ $cols[] = '"' . OCIColumnName($result, $i) . '"';
+ }
+ $fields = implode(', ', $cols);
+ // XXX Test that (tip by John Lim)
+ //if (preg_match('/^\s*SELECT\s+/is', $query, $match)) {
+ // // Introduce the FIRST_ROWS Oracle query optimizer
+ // $query = substr($query, strlen($match[0]), strlen($query));
+ // $query = "SELECT /* +FIRST_ROWS */ " . $query;
+ //}
+
+ // Construct the query
+ // more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2
+ // Perhaps this could be optimized with the use of Unions
+ $query = "SELECT $fields FROM" .
+ " (SELECT rownum as linenum, $fields FROM" .
+ " ($query)" .
+ ' WHERE rownum <= ' . ($from + $count) .
+ ') WHERE linenum >= ' . ++$from;
+ return $query;
+ }
+
+ // }}}
+ // {{{ modifyLimitQuery()
/**
* Prepares a query for multiple execution with execute().
* "UPDATE foo SET col=? WHERE col='over \& under'"
* </code>
*
- * @param string $query the query to be prepared
+ * @param string $query the query to be prepared
*
* @return mixed DB statement resource on success. DB_Error on failure.
*
* @see DB_oci8::execute()
*/
- function prepare($query)
+ public function prepare($query)
{
- $tokens = preg_split('/((?<!\\\)[&?!])/', $query, -1,
- PREG_SPLIT_DELIM_CAPTURE);
- $binds = count($tokens) - 1;
- $token = 0;
- $types = array();
+ $tokens = preg_split(
+ '/((?<!\\\)[&?!])/',
+ $query,
+ -1,
+ PREG_SPLIT_DELIM_CAPTURE
+ );
+ $binds = count($tokens) - 1;
+ $token = 0;
+ $types = array();
$newquery = '';
foreach ($tokens as $key => $val) {
}
// }}}
- // {{{ execute()
+ // {{{ nextId()
/**
* Executes a DB statement prepared with prepare().
* ocisetprefetch(), see the "result_buffering" option in setOptions().
* This option was added in Release 1.7.0.
*
- * @param resource $stmt a DB statement resource returned from prepare()
- * @param mixed $data array, string or numeric data to be used in
+ * @param resource $stmt a DB statement resource returned from prepare()
+ * @param mixed $data array, string or numeric data to be used in
* execution of the statement. Quantity of items
* passed must match quantity of placeholders in
* query: meaning 1 for non-array items or the
*
* @see DB_oci8::prepare()
*/
- function &execute($stmt, $data = array())
+ public function &execute($stmt, $data = array())
{
$data = (array)$data;
$this->last_parameters = $data;
$tmp = $this->oci8RaiseError($stmt);
return $tmp;
}
- $this->last_query = preg_replace("/:bind$i(?!\d)/",
- $this->quoteSmart($data[$key]), $this->last_query, 1);
+ $this->last_query = preg_replace(
+ "/:bind$i(?!\d)/",
+ $this->quoteSmart($data[$key]),
+ $this->last_query,
+ 1
+ );
$i++;
}
if ($this->autocommit) {
return $tmp;
}
- // }}}
- // {{{ autoCommit()
-
- /**
- * Enables or disables automatic commits
- *
- * @param bool $onoff true turns it on, false turns it off
- *
- * @return int DB_OK on success. A DB_Error object if the driver
- * doesn't support auto-committing transactions.
- */
- function autoCommit($onoff = false)
- {
- $this->autocommit = (bool)$onoff;;
- return DB_OK;
- }
-
- // }}}
- // {{{ commit()
-
- /**
- * Commits the current transaction
- *
- * @return int DB_OK on success. A DB_Error object on failure.
- */
- function commit()
- {
- $result = @OCICommit($this->connection);
- if (!$result) {
- return $this->oci8RaiseError();
- }
- return DB_OK;
- }
-
- // }}}
- // {{{ rollback()
-
- /**
- * Reverts the current transaction
- *
- * @return int DB_OK on success. A DB_Error object on failure.
- */
- function rollback()
- {
- $result = @OCIRollback($this->connection);
- if (!$result) {
- return $this->oci8RaiseError();
- }
- return DB_OK;
- }
-
- // }}}
- // {{{ affectedRows()
-
- /**
- * Determines the number of rows affected by a data maniuplation query
- *
- * 0 is returned for queries that don't manipulate data.
- *
- * @return int the number of rows. A DB_Error object on failure.
- */
- function affectedRows()
- {
- if ($this->last_stmt === false) {
- return $this->oci8RaiseError();
- }
- $result = @OCIRowCount($this->last_stmt);
- if ($result === false) {
- return $this->oci8RaiseError($this->last_stmt);
- }
- return $result;
- }
-
- // }}}
- // {{{ modifyQuery()
-
/**
- * Changes a query string for various DBMS specific reasons
- *
- * "SELECT 2+2" must be "SELECT 2+2 FROM dual" in Oracle.
- *
- * @param string $query the query string to modify
- *
- * @return string the modified query string
- *
- * @access protected
- */
- function modifyQuery($query)
- {
- if (preg_match('/^\s*SELECT/i', $query) &&
- !preg_match('/\sFROM\s/i', $query)) {
- $query .= ' FROM dual';
- }
- return $query;
- }
-
- // }}}
- // {{{ modifyLimitQuery()
-
- /**
- * Adds LIMIT clauses to a query string according to current DBMS standards
- *
- * @param string $query the query to modify
- * @param int $from the row to start to fetching (0 = the first row)
- * @param int $count the numbers of rows to fetch
- * @param mixed $params array, string or numeric data to be used in
- * execution of the statement. Quantity of items
- * passed must match quantity of placeholders in
- * query: meaning 1 placeholder for non-array
- * parameters or 1 placeholder per array element.
- *
- * @return string the query string with LIMIT clauses added
+ * Formats a float value for use within a query in a locale-independent
+ * manner.
*
- * @access protected
+ * @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 modifyLimitQuery($query, $from, $count, $params = array())
+ public function quoteFloat($float)
{
- // Let Oracle return the name of the columns instead of
- // coding a "home" SQL parser
-
- if (count($params)) {
- $result = $this->prepare("SELECT * FROM ($query) "
- . 'WHERE NULL = NULL');
- $tmp = $this->execute($result, $params);
- } else {
- $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL";
-
- if (!$result = @OCIParse($this->connection, $q_fields)) {
- $this->last_query = $q_fields;
- return $this->oci8RaiseError();
- }
- if (!@OCIExecute($result, OCI_DEFAULT)) {
- $this->last_query = $q_fields;
- return $this->oci8RaiseError($result);
- }
- }
-
- $ncols = OCINumCols($result);
- $cols = array();
- for ( $i = 1; $i <= $ncols; $i++ ) {
- $cols[] = '"' . OCIColumnName($result, $i) . '"';
- }
- $fields = implode(', ', $cols);
- // XXX Test that (tip by John Lim)
- //if (preg_match('/^\s*SELECT\s+/is', $query, $match)) {
- // // Introduce the FIRST_ROWS Oracle query optimizer
- // $query = substr($query, strlen($match[0]), strlen($query));
- // $query = "SELECT /* +FIRST_ROWS */ " . $query;
- //}
-
- // Construct the query
- // more at: http://marc.theaimsgroup.com/?l=php-db&m=99831958101212&w=2
- // Perhaps this could be optimized with the use of Unions
- $query = "SELECT $fields FROM".
- " (SELECT rownum as linenum, $fields FROM".
- " ($query)".
- ' WHERE rownum <= '. ($from + $count) .
- ') WHERE linenum >= ' . ++$from;
- return $query;
+ return $this->escapeSimple(str_replace(',', '.', strval(floatval($float))));
}
// }}}
- // {{{ nextId()
+ // {{{ dropSequence()
/**
* Returns the next free id in a sequence
*
- * @param string $seq_name name of the sequence
- * @param boolean $ondemand when true, the seqence is automatically
+ * @param string $seq_name name of the sequence
+ * @param boolean $ondemand when true, the seqence is automatically
* created if it does not exist
*
- * @return int the next id number in the sequence.
+ * @return int|object
* A DB_Error object on failure.
*
* @see DB_common::nextID(), DB_common::getSequenceName(),
* DB_oci8::createSequence(), DB_oci8::dropSequence()
*/
- function nextId($seq_name, $ondemand = true)
+ public function nextId($seq_name, $ondemand = true)
{
$seqname = $this->getSequenceName($seq_name);
$repeat = 0;
return $arr[0];
}
+ // }}}
+ // {{{ oci8RaiseError()
+
/**
* Creates a new sequence
*
- * @param string $seq_name name of the new sequence
+ * @param string $seq_name name of the new sequence
*
* @return int DB_OK on success. A DB_Error object on failure.
*
* @see DB_common::createSequence(), DB_common::getSequenceName(),
* DB_oci8::nextID(), DB_oci8::dropSequence()
*/
- function createSequence($seq_name)
+ public function createSequence($seq_name)
{
return $this->query('CREATE SEQUENCE '
- . $this->getSequenceName($seq_name));
+ . $this->getSequenceName($seq_name));
}
// }}}
- // {{{ dropSequence()
+ // {{{ errorNative()
/**
* Deletes a sequence
*
- * @param string $seq_name name of the sequence to be deleted
+ * @param string $seq_name name of the sequence to be deleted
*
* @return int DB_OK on success. A DB_Error object on failure.
*
* @see DB_common::dropSequence(), DB_common::getSequenceName(),
* DB_oci8::nextID(), DB_oci8::createSequence()
*/
- function dropSequence($seq_name)
+ public function dropSequence($seq_name)
{
return $this->query('DROP SEQUENCE '
- . $this->getSequenceName($seq_name));
+ . $this->getSequenceName($seq_name));
}
// }}}
- // {{{ oci8RaiseError()
-
- /**
- * Produces a DB_Error object regarding the current problem
- *
- * @param int $errno if the error is being manually raised pass a
- * DB_ERROR* constant here. If this isn't passed
- * the error information gathered from the DBMS.
- *
- * @return object the DB_Error object
- *
- * @see DB_common::raiseError(),
- * DB_oci8::errorNative(), DB_oci8::errorCode()
- */
- function oci8RaiseError($errno = null)
- {
- if ($errno === null) {
- $error = @OCIError($this->connection);
- return $this->raiseError($this->errorCode($error['code']),
- null, null, null, $error['message']);
- } elseif (is_resource($errno)) {
- $error = @OCIError($errno);
- return $this->raiseError($this->errorCode($error['code']),
- null, null, null, $error['message']);
- }
- return $this->raiseError($this->errorCode($errno));
- }
-
- // }}}
- // {{{ errorNative()
+ // {{{ tableInfo()
/**
* Gets the DBMS' native error code produced by the last query
* @return int the DBMS' error code. FALSE if the code could not be
* determined
*/
- function errorNative()
+ public function errorNative()
{
if (is_resource($this->last_stmt)) {
$error = @OCIError($this->last_stmt);
}
// }}}
- // {{{ tableInfo()
+ // {{{ getSpecialQuery()
/**
* Returns information about a table or a result set
*
* NOTE: flags won't contain index information.
*
- * @param object|string $result DB_result object from a query or a
+ * @param object|string $result DB_result object from a query or a
* string containing the name of a table.
* While this also accepts a query result
* resource identifier, this behavior is
* deprecated.
- * @param int $mode a valid tableInfo mode
+ * @param int $mode a valid tableInfo mode
*
- * @return array an associative array with the information requested.
+ * @return array|object
* A DB_Error object on failure.
*
* @see DB_common::tableInfo()
*/
- function tableInfo($result, $mode = null)
+ public function tableInfo($result, $mode = null)
{
if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {
$case_func = 'strtolower';
*/
$result = strtoupper($result);
$q_fields = 'SELECT column_name, data_type, data_length, '
- . 'nullable '
- . 'FROM user_tab_columns '
- . "WHERE table_name='$result' ORDER BY column_id";
+ . 'nullable '
+ . 'FROM user_tab_columns '
+ . "WHERE table_name='$result' ORDER BY column_id";
$this->last_query = $q_fields;
if (!@OCIExecute($stmt, OCI_DEFAULT)) {
return $this->oci8RaiseError($stmt);
}
-
+
$i = 0;
while (@OCIFetch($stmt)) {
$res[$i] = array(
'table' => $case_func($result),
- 'name' => $case_func(@OCIResult($stmt, 1)),
- 'type' => @OCIResult($stmt, 2),
- 'len' => @OCIResult($stmt, 3),
+ 'name' => $case_func(@OCIResult($stmt, 1)),
+ 'type' => @OCIResult($stmt, 2),
+ 'len' => @OCIResult($stmt, 3),
'flags' => (@OCIResult($stmt, 4) == 'N') ? 'not_null' : '',
);
if ($mode & DB_TABLEINFO_ORDER) {
$res['num_fields'] = $i;
}
@OCIFreeStatement($stmt);
-
} else {
if (isset($result->result)) {
/*
for ($i = 0; $i < $count; $i++) {
$res[$i] = array(
'table' => '',
- 'name' => $case_func(@OCIColumnName($result, $i+1)),
- 'type' => @OCIColumnType($result, $i+1),
- 'len' => @OCIColumnSize($result, $i+1),
+ 'name' => $case_func(@OCIColumnName($result, $i + 1)),
+ 'type' => @OCIColumnType($result, $i + 1),
+ 'len' => @OCIColumnSize($result, $i + 1),
'flags' => '',
);
if ($mode & DB_TABLEINFO_ORDER) {
}
// }}}
- // {{{ getSpecialQuery()
+ // {{{ quoteFloat()
/**
* Obtains the query string needed for listing a given type of objects
*
- * @param string $type the kind of objects you want to retrieve
+ * @param string $type the kind of objects you want to retrieve
*
* @return string the SQL query string or null if the driver doesn't
* support the object type requested
* @access protected
* @see DB_common::getListOf()
*/
- function getSpecialQuery($type)
+ public function getSpecialQuery($type)
{
switch ($type) {
case 'tables':
}
// }}}
- // {{{ 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))));
- }
-
- // }}}
-
}
/*
* c-basic-offset: 4
* End:
*/
-
-?>