Source for file oci8.php
Documentation is available at oci8.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB is a merge of PEAR DB and Metabases that provides a unified DB |
// | API as well as database abstraction for PHP applications. |
// | This LICENSE is in the BSD license style. |
// | Redistribution and use in source and binary forms, with or without |
// | modification, are permitted provided that the following conditions |
// | Redistributions of source code must retain the above copyright |
// | notice, this list of conditions and the following disclaimer. |
// | Redistributions in binary form must reproduce the above copyright |
// | notice, this list of conditions and the following disclaimer in the |
// | documentation and/or other materials provided with the distribution. |
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken, |
// | Lukas Smith nor the names of his contributors may be used to endorse |
// | or promote products derived from this software without specific prior|
// | written permission. |
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
// | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
// | Author: Lukas Smith <smith@backendmedia.com> |
// +----------------------------------------------------------------------+
// $Id: oci8.php,v 1.21.4.24 2004/03/31 16:02:40 lsmith Exp $
require_once('MDB/Common.php');
* - when fetching in associative mode all keys are uppercased which is not the
* intenteded behavior. Due to BC issues this will not be changed in MDB 1.x
* - createDatabase and dropDatabase are not supported
* - Text fields with unspecified length limit are created as VARCHAR with an
* optional limit that may not exceed 4000 characters.
* - date fields are emulated with date fields with time set to 00:00:00.
time fields are emulated with date fields with the day set to 0001-01-01.
* - The numRows method is emulated by fetching all the rows into memory.
* Avoid using it if for queries with large result sets.
* - Oracle does not provide direct support for returning result sets restricted
to a given range. Such support is emulated in the MDB oci8 driver.
* - Storing data in large object fields has to be done in two phases: first the
fields are initialized using a INSERT or UPDATE query that sets the fields
to an empty value, then the data values are uploaded to the large objects
returned by reference from the executed queries.
* Besides the fact that only INSERT and UPDATE queries are supported to
upload large object data values, only UPDATE queries that affect only one
row will set the large object fields correctly.
* - The driver alterTable method does not implement table or column renaming.
* @author Lukas Smith <smith@backendmedia.com>
$this->dbsyntax = 'oci8';
$this->supported['Sequences'] = 1;
$this->supported['Indexes'] = 1;
$this->supported['SummaryFunctions'] = 1;
$this->supported['OrderByText'] = 1;
$this->supported['CurrId'] = 1;
$this->supported["AffectedRows"]= 1;
$this->supported['Transactions'] = 1;
$this->supported['SelectRowRanges'] = 1;
$this->supported['LOBs'] = 1;
$this->supported['Replace'] = 1;
$this->supported['SubSelects'] = 1;
$this->options['DBAUser'] = FALSE;
$this->options['DBAPassword'] = FALSE;
$this->errorcode_map = array (
* Get the native error code of the last error (if any) that
* occured on the current connection.
* @return int native oci8 error code
$error = @OCIError ($statement);
* This method is used to communicate an error and invoke error
* callbacks etc. Basically a wrapper for MDB::raiseError
* that checks for native error msgs.
* @param integer $errno error code
* @param string $message userinfo message
* @return object a PEAR error object
NULL , NULL , $message, $error['message']));
$error = @OCIError ($errno);
NULL , NULL , $message, $error['message']));
* Define whether database changes done on the database be automatically
* committed. This function may also implicitly start or end a transaction.
* @param boolean $auto_commit flag that indicates whether the database
* changes should be committed right after
* executing every query statement. If this
* argument is 0 a transaction implicitly
* started. Otherwise, if a transaction is
* in progress it is ended by committing any
* database changes that were pending.
* @return mixed MDB_OK on success, a MDB error on failure
$this->debug('AutoCommit: '. ($auto_commit ? 'On' : 'Off'));
if ($this->auto_commit == $auto_commit) {
$this->auto_commit = $auto_commit;
$this->in_transaction = !$auto_commit;
* Commit the database changes done during a transaction that is in
* progress. This function may only be called when auto-committing is
* disabled, otherwise it will fail. Therefore, a new transaction is
* implicitly started after committing the pending changes.
* @return mixed MDB_OK on success, a MDB error on failure
$this->debug('Commit Transaction');
if (!isset ($this->supported['Transactions'])) {
'Commit transactions: transactions are not in use'));
if ($this->auto_commit) {
'Commit transactions: transaction changes are being auto commited'));
'Commit transactions: Could not commit pending transaction: '." $message. Error: ". $error['code']. ' ('. $error['message']. ')'));
* Cancel any database changes done during a transaction that is in
* progress. This function may only be called when auto-committing is
* disabled, otherwise it will fail. Therefore, a new transaction is
* implicitly started after canceling the pending changes.
* @return mixed MDB_OK on success, a MDB error on failure
$this->debug('Rollback Transaction');
if ($this->auto_commit) {
'Rollback transactions: transactions can not be rolled back when changes are auto commited'));
'Rollback transaction: Could not rollback pending transaction'));
* Connect to the database
* @return TRUE on success, MDB_Error on failure
function connect($user = NULL , $password = NULL , $persistent = NULL )
$password = $this->password;
if($persistent === NULL ) {
$persistent = $this->getOption('persistent');
if (isset ($this->host)) {
'Connect: it was not specified a valid Oracle Service IDentifier (SID)'));
&& $this->opened_persistent == $persistent)
if(!PEAR ::loadExtension ($this->phptype)) {
NULL , NULL , 'extension '. $this->phptype. ' is not compiled into PHP',
if (isset ($this->options['HOME'])) {
putenv('ORACLE_HOME='. $this->options['HOME']);
$function = ($persistent ? 'OCIPLogon' : 'OCINLogon');
'Connect: Oracle OCI API support is not available in this PHP configuration'));
if (!($this->connection = @$function($user, $password, $sid))) {
'Connect: Could not connect to Oracle server'));
if (MDB::isError($doquery = $this->_doQuery ("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"))) {
if (MDB::isError($doquery = $this->_doQuery ("ALTER SESSION SET NLS_NUMERIC_CHARACTERS='. '"))) {
$this->opened_persistent = $persistent;
* all the RDBMS specific things needed close a DB connection
$this->affected_rows = -1;
* all the RDBMS specific things needed close a DB connection
function _doQuery ($query, $first = 0 , $limit = 0 , $prepared_query = 0 )
for(reset($this->clobs[$prepared_query]), $clob = 0;
$clob < count($this->clobs[$prepared_query]);
$clob++ , next($this->clobs[$prepared_query]))
$position = key($this->clobs[$prepared_query]);
if (gettype($descriptors[$position] = @OCINewDescriptor ($this->connection, OCI_D_LOB )) != 'object') {
'Do query: Could not create descriptor for clob parameter');
$columns.= ($lobs == 0 ? ' RETURNING ' : ','). $this->prepared_queries[$prepared_query-1 ]['Fields'][$position-1 ];
$variables.= ($lobs == 0 ? ' INTO ' : ','). ':clob'. $position;
for(reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++ , next($this->blobs[$prepared_query])) {
$position = key($this->blobs[$prepared_query]);
if (gettype($descriptors[$position] = @OCINewDescriptor ($this->connection, OCI_D_LOB )) != 'object') {
'Do query: Could not create descriptor for blob parameter');
$columns.= ($lobs == 0 ? ' RETURNING ' : ','). $this->prepared_queries[$prepared_query-1 ]['Fields'][$position-1 ];
$variables.= ($lobs == 0 ? ' INTO ' : ','). ':blob'. $position;
$query.= $columns. $variables;
if (($statement = @OCIParse ($this->connection, $query))) {
for(reset($this->clobs[$prepared_query]), $clob = 0; $clob < count($this->clobs[$prepared_query]); $clob++ , next($this->clobs[$prepared_query])) {
$position = key($this->clobs[$prepared_query]);
if (!@OCIBindByName ($statement, ':clob'. $position, $descriptors[$position], -1 , OCI_B_CLOB )) {
'Do query: Could not bind clob upload descriptor');
for(reset($this->blobs[$prepared_query]), $blob = 0;
$blob < count($this->blobs[$prepared_query]);
$blob++ , next($this->blobs[$prepared_query]))
$position = key($this->blobs[$prepared_query]);
if (!@OCIBindByName ($statement, ':blob'. $position, $descriptors[$position], -1 , OCI_B_BLOB )) {
'Do query: Could not bind blob upload descriptor');
if (($result = @OCIExecute ($statement, ($lobs == 0 && $this->auto_commit) ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT ))) {
for(reset($this->clobs[$prepared_query]), $clob = 0;
$clob < count($this->clobs[$prepared_query]);
$clob++ , next($this->clobs[$prepared_query]))
$position = key($this->clobs[$prepared_query]);
$clob_stream = $this->prepared_queries[$prepared_query-1 ]['Values'][$position-1 ];
for($value = ''; !$this->endOfLOB ($clob_stream); ) {
if ($this->readLOB ($clob_stream, $data, $this->getOption('lob_buffer_length')) < 0 ) {
if (!MDB::isError($success) && !$descriptors[$position]->save ($value)) {
'Do query: Could not upload clob data');
for(reset($this->blobs[$prepared_query]), $blob = 0; $blob < count($this->blobs[$prepared_query]); $blob++ , next($this->blobs[$prepared_query])) {
$position = key($this->blobs[$prepared_query]);
$blob_stream = $this->prepared_queries[$prepared_query-1 ]['Values'][$position-1 ];
for($value = ''; !$this->endOfLOB ($blob_stream); ) {
if ($this->readLOB ($blob_stream, $data, $this->getOption('lob_buffer_length')) < 0 ) {
if (!MDB::isError($success) && !$descriptors[$position]->save ($value)) {
'Do query: Could not upload blob data');
if ($this->auto_commit) {
'Do query: '. $success->getUserinfo (). ' and then could not rollback LOB updating transaction');
'Do query: Could not commit pending LOB updating transaction');
switch (@OCIStatementType ($statement)) {
$result_value = intval($statement);
$this->limits[$result_value] = array ($first, $limit, 0 );
$this->affected_rows = @OCIRowCount ($statement);
@OCIFreeCursor ($statement);
return($this->oci8RaiseError($statement, 'Do query: Could not execute query'));
return($this->oci8RaiseError(NULL , 'Do query: Could not parse query'));
for(reset($descriptors), $descriptor = 0;
$descriptor < count($descriptors);
$descriptor++ , next($descriptors))
@OCIFreeDesc ($descriptors[key($descriptors)]);
* Send a query to the database and return any results
* @param string $query the SQL query
* @param array $types array that contains the types of the columns in
* @return mixed a result handle or MDB_OK on success, a MDB error on failure
function query($query, $types = NULL )
$this->debug(" Query: $query" );
$this->last_query = $query;
$first = $this->first_selected_row;
$limit = $this->selected_row_limit;
$this->first_selected_row = $this->selected_row_limit = 0;
if(!MDB::isError($result = $this->_doQuery ($query, $first, $limit))) {
// {{{ _executePreparedQuery()
* Execute a prepared query statement.
* @param int $prepared_query argument is a handle that was returned by
* the function prepareQuery()
* @param string $query query to be executed
* @param array $types array that contains the types of the columns in
* @return mixed a result handle or MDB_OK on success, a MDB error on failure
function _executePreparedQuery ($prepared_query, $query)
$first = $this->first_selected_row;
$limit = $this->selected_row_limit;
$this->first_selected_row = $this->selected_row_limit = 0;
return($this->_doQuery ($query, $first, $limit, $prepared_query));
// {{{ _skipLimitOffset()
* Skip the first row of a result set.
* @param resource $result
* @return mixed a result handle or MDB_OK on success, a MDB error on failure
function _skipLimitOffset ($result)
$result_value = intval($result);
$first = $this->limits[$result_value][0 ];
for(; $this->limits[$result_value][2 ] < $first; $this->limits[$result_value][2 ]++ ) {
if (!@OCIFetch ($result)) {
$this->limits[$result_value][2 ] = $first;
'Skip first rows: could not skip a query result row'));
* Retrieve the names of columns returned by the DBMS in a query result.
* @param resource $result result identifier
* @return mixed an associative array variable
* that will hold the names of columns.The
* indexes of the array are the column names
* mapped to lower case and the values are the
* respective numbers of the columns starting
* from 0. Some DBMS may not return any
* columns when the result set does not
$result_value = intval($result);
'Get column names: it was specified an inexisting result set'));
if (!isset ($this->columns[$result_value])) {
$this->columns[$result_value] = array ();
$columns = @OCINumCols ($result);
for($column = 0; $column < $columns; $column++ ) {
$field_name = @OCIColumnName ($result, $column + 1 );
if ($this->options['optimize'] == 'portability') {
$this->columns[$result_value][$field_name] = $column;
return($this->columns[$result_value]);
* Count the number of columns returned by the DBMS in a query result.
* @param resource $result result identifier
* @return mixed integer value with the number of columns, a MDB error
$result_value = intval($result);
'Number of columns: it was specified an inexisting result set'));
return(@OCINumCols ($result));
* check if the end of the result set has been reached
* @param resource $result result identifier
* @return mixed TRUE or FALSE on sucess, a MDB error on failure
$result_value = intval($result);
'End of result: attempted to check the end of an unknown result'));
if (isset ($this->results[$result_value]) && end($this->results[$result_value]) === FALSE ) {
if (isset ($this->limits[$result_value])) {
if (MDB::isError($this->_skipLimitOffset ($result))
if (@OCIFetchInto ($result, $this->row_buffer[$result_value], OCI_RETURN_NULLS )) {
* fetch a lob value from a result set
* @param int $lob handle to a lob created by the createLob() function
* @return mixed MDB_OK on success, a MDB error on failure
function _retrieveLob ($lob)
if (!isset ($this->lobs[$lob])) {
'Retrieve LOB: it was not specified a valid lob'));
if (!isset ($this->lobs[$lob]['Value'])) {
$result = $this->lobs[$lob]['Result'];
$row = $this->lobs[$lob]['Row'];
$field = $this->lobs[$lob]['Field'];
$lob_object = $this->fetch($result, $row, $field);
if (gettype($lob_object) != 'object') {
'Retrieve LOB: attemped to retrieve LOB from non existing or NULL column'));
$this->lobs[$lob]['Value'] = $lob_object->load ();
* fetch value from a result set
* @param resource $result result identifier
* @param int $rownum number of the row where the data can be found
* @param int $colnum field number where the data can be found
* @return mixed string on success, a MDB error on failure
function fetch($result, $rownum, $colnum)
$row = $this->fetchInto($result, $fetchmode, $rownum);
* fetch a clob value from a result set
* @param resource $result result identifier
* @param int $row number of the row where the data can be found
* @param int $field field number where the data can be found
* @return mixed content of the specified data cell, a MDB error on failure,
return($this->fetchLOB ($result, $row, $field));
* fetch a blob value from a result set
* @param resource $result result identifier
* @param int $row number of the row where the data can be found
* @param int $field field number where the data can be found
* @return mixed content of the specified data cell, a MDB error on failure
return($this->fetchLOB ($result, $row, $field));
* Determine whether the value of a query result located in given row and
* @param resource $result result identifier
* @param int $rownum number of the row where the data can be found
* @param int $field field number where the data can be found
* @return mixed TRUE or FALSE on success, a MDB error on failure
$value = $this->fetch($result, $rownum, $field);
* convert a value to a RDBMS indepdenant MDB type
* @param mixed $value value to be converted
* @param int $type constant that specifies which type to convert to
* @return mixed converted value
return($this->_baseConvertResult ($value, $type));
* returns the number of rows in a result object
* @param ressource $result a valid result ressouce pointer
* @return mixed MDB_Error or the number of rows
$result_value = intval($result);
'Number of rows: attemped to obtain the number of rows contained in an unknown query result'));
if (isset ($this->limits[$result_value])) {
if (MDB::isError($skipfirstrow = $this->_skipLimitOffset ($result))) {
while ((!isset ($this->limits[$result_value])
&& @OCIFetchInto ($result, $buffer, OCI_RETURN_NULLS )
* Free the internal resources associated with $result.
* @param $result result identifier
* @return bool TRUE on success, FALSE if $result is invalid
$result_value = intval($result);
'Free result: attemped to free an unknown query result'));
if(isset ($this->limits[$result_value])) {
unset ($this->limits[$result_value]);
if(isset ($this->results[$result_value])) {
unset ($this->results[$result_value]);
if(isset ($this->columns[$result_value])) {
unset ($this->columns[$result_value]);
if(isset ($this->result_types[$result_value])) {
unset ($this->result_types[$result_value]);
return(@OCIFreeCursor ($result));
// {{{ getTypeDeclaration()
* Obtain DBMS specific native datatype as a string
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* @return string with the correct RDBMS native type
switch ($field['type']) {
return('VARCHAR ('. (isset ($field['length'])
? $field['length'] : (isset ($this->options['DefaultTextFieldLength'])
? $this->options['DefaultTextFieldLength'] : 4000 )). ')');
return('NUMBER(*,'. $this->decimal_places. ')');
// {{{ getIntegerDeclaration()
* Obtain DBMS specific SQL code portion needed to declare an integer type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Id
* of supported field properties are as follows:
* Boolean flag that indicates whether the field should be
* declared as unsigned integer if possible.
* Integer value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
if (isset ($field['unsigned']))
$this->warning = " unsigned integer field \"$name\" is being declared as signed integer";
. (isset ($field['default']) ? ' DEFAULT '. $field['default'] : '')
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getTextDeclaration()
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Integer value that determines the maximum length of the text
* field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
* Text value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '. $this->getTextValue($field['default']) : '')
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getClobDeclaration()
* Obtain DBMS specific SQL code portion needed to declare an character
* large object type field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
return(" $name CLOB". (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getBlobDeclaration()
* Obtain DBMS specific SQL code portion needed to declare an binary large
* object type field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Integer value that determines the maximum length of the large
* object field. If this argument is missing the field should be
* declared to have the longest length allowed by the DBMS.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
return(" $name BLOB". (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getBooleanDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a boolean type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Boolean value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getDateDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a date type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Date value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getTimestampDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a timestamp
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Timestamp value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getTimeDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a time
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Time value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getFloatDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a float type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Float value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
// {{{ getDecimalDeclaration()
* Obtain DBMS specific SQL code portion needed to declare a decimal type
* field to be used in statements like CREATE TABLE.
* @param string $name name the field to be declared.
* @param string $field associative array with the name of the properties
* of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows:
* Decimal value to be used as default for this field.
* Boolean flag that indicates whether this field is constrained
* @return string DBMS specific SQL code portion that should be used to
* declare the specified field.
. (isset ($field['default']) ? ' DEFAULT '
. (isset ($field['notnull']) ? ' NOT NULL' : ''));
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param resource $prepared_query query handle from prepare()
* @return string text string that represents the given argument value in
* a DBMS specific format.
* free a character large object
* @param resource $prepared_query query handle from prepare()
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param resource $prepared_query query handle from prepare()
* @return string text string that represents the given argument value in
* a DBMS specific format.
* free a binary large object
* @param resource $prepared_query query handle from prepare()
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string $value text string value that is intended to be converted.
* @return string text string that represents the given argument value in
* a DBMS specific format.
return(($value === NULL ) ? 'NULL' : " TO_DATE('$value','YYYY-MM-DD')" );
// {{{ getTimestampValue()
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string $value text string value that is intended to be converted.
* @return string text string that represents the given argument value in
* a DBMS specific format.
return(($value === NULL ) ? 'NULL' : " TO_DATE('$value','YYYY-MM-DD HH24:MI:SS')" );
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string $value text string value that is intended to be converted.
* @return string text string that represents the given argument value in
* a DBMS specific format.
return(($value === NULL ) ? 'NULL' : " TO_DATE('0001-01-01 $value','YYYY-MM-DD HH24:MI:SS')" );
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string $value text string value that is intended to be converted.
* @return string text string that represents the given argument value in
* a DBMS specific format.
return(($value === NULL ) ? 'NULL' : (float) $value);
* Convert a text value into a DBMS specific format that is suitable to
* compose query statements.
* @param string $value text string value that is intended to be converted.
* @return string text string that represents the given argument value in
* a DBMS specific format.
return(($value === NULL ) ? 'NULL' : $value);
* returns the next free id of a sequence
* @param string $seq_name name of the sequence
* @param boolean $ondemand when TRUE the seqence is
* automatic created, if it
* @return mixed MDB_Error or id
function nextId($seq_name, $ondemand = TRUE )
$result = $this->_doQuery (" SELECT $sequence_name.nextval FROM DUAL" );
return $this->nextId($seq_name, false );
* returns the current id of a sequence
* @param string $seq_name name of the sequence
* @return mixed MDB_Error or id
$result = $this->_doQuery (" SELECT $sequence_name.currval FROM DUAL" );
'currId: unable to select from ' . $seq_name) );
'currId: could not find value in sequence table'));
* Fetch a row and return data in an array.
* @param resource $result result identifier
* @param int $fetchmode how the array data should be indexed
* @param int $rownum the row number to fetch
* @return mixed data array or NULL on success, a MDB error on failure
function fetchInto($result, $fetchmode = MDB_FETCHMODE_DEFAULT , $rownum = NULL )
$result_value = intval($result);
'fetchInto: attemped to fetch on an unknown query result'));
$fetchmode = $this->fetchmode;
if (!isset ($this->results[$result_value][$rownum])
if (isset ($this->limits[$result_value])) {
if ($rownum > $this->limits[$result_value][1 ]) {
// are all previous rows fetched so that we can set the end
// of the result set and not have any "holes" in between?
|| (isset ($this->results[$result_value])
$this->results[$result_value][$rownum] = FALSE;
if($this->options['autofree']) {
if (MDB::isError($this->_skipLimitOffset ($result))) {
$this->results[$result_value] = array (FALSE );
if($this->options['autofree']) {
if (!isset ($this->results[$result_value][$rownum])
&& @OCIFetchInto ($result, $buffer, OCI_RETURN_NULLS )
// end of result set reached
if (isset ($this->results[$result_value][$rownum])
&& $this->results[$result_value][$rownum]
$row = $this->results[$result_value][$rownum];
if($this->options['autofree']) {
foreach($column_names as $name => $i) {
$column_names[$name] = $row[$i];
if (isset ($this->result_types[$result_value])) {
* Move the internal oracle result pointer to the next available result
* Currently not supported
* @param $result a oracle valid result resource
* @return TRUE if a result is available otherwise return FALSE
* returns meta data about the result set
* @param resource $result result identifier
* @param mixed $mode depends on implementation
* @return array an nested array, or a MDB error
* depending on $mode, metadata returns the following values:
* - mode is FALSE (default):
* [0]['table'] table name
* [0]['len'] field length
* [0]['nullable'] field can be NULL (boolean)
* [0]['format'] field precision if NUMBER
* [0]['default'] field default value
* - mode is MDB_TABLEINFO_ORDER
* ['num_fields'] number of fields
* [0]['table'] table name
* [0]['len'] field length
* [0]['nullable'] field can be NULL (boolean)
* [0]['format'] field precision if NUMBER
* [0]['default'] field default value
* ['order'][field name] index of field named 'field name'
* The last one is used, if you have a field name, but no index.
* Test: if (isset($result['order']['myfield'])) { ...
* - mode is MDB_TABLEINFO_ORDERTABLE
* the same as above. but additionally
* ['ordertable'][table name][field name] index of field
* this is, because if you have fields from different
* tables with the same field name * they override each
* other with MDB_TABLEINFO_ORDER
* you can combine DB_TABLEINFO_ORDER and
* MDB_TABLEINFO_ORDERTABLE with MDB_TABLEINFO_ORDER |
* MDB_TABLEINFO_ORDERTABLE * or with MDB_TABLEINFO_FULL
// if $result is a string, we collect info for a table only
$q_fields = " select column_name, data_type, data_length, data_precision,
nullable, data_default from user_tab_columns
where table_name='$result' order by column_id";
if (!$stmt = @OCIParse ($this->connection, $q_fields)) {
if (!@OCIExecute ($stmt, OCI_DEFAULT )) {
} while (@OCIFetch ($stmt)) {
$res[$count]['name'] = strtolower(@OCIResult ($stmt, 1 ));
$res[$count]['type'] = strtolower(@OCIResult ($stmt, 2 ));
$res[$count]['len'] = @OCIResult ($stmt, 3 );
$res[$count]['format'] = @OCIResult ($stmt, 4 );
$res[$count]['nullable'] = (@OCIResult ($stmt, 5 ) == 'Y') ? TRUE : FALSE;
$res[$count]['default'] = @OCIResult ($stmt, 6 );
$res['order'][$res[$count]['name']] = $count;
$res['ordertable'][$res[$count]['table']][$res[$count]['name']] = $count;
$res['num_fields'] = $count;
@OCIFreeStatement ($stmt);
} else { // else we want information about a resultset
#if ($result === $this->last_stmt) {
$count = @OCINumCols ($result);
for ($i = 0; $i < $count; $i++ ) {
$res[$i]['name'] = strtolower(@OCIColumnName ($result, $i + 1 ));
$res[$i]['type'] = strtolower(@OCIColumnType ($result, $i + 1 ));
$res[$i]['len'] = @OCIColumnSize ($result, $i + 1 );
$q_fields = "SELECT table_name, data_precision, nullable, data_default from user_tab_columns WHERE column_name='". $res[$i]['name']. "'";
if (!$stmt = @OCIParse ($this->connection, $q_fields)) {
if (!@OCIExecute ($stmt, OCI_DEFAULT )) {
$res[$i]['table'] = strtolower(@OCIResult ($stmt, 1 ));
$res[$i]['format'] = @OCIResult ($stmt, 2 );
$res[$i]['nullable'] = (@OCIResult ($stmt, 3 ) == 'Y') ? TRUE : FALSE;
$res[$i]['default'] = @OCIResult ($stmt, 4 );
@OCIFreeStatement ($stmt);
$res['order'][$res[$i]['name']] = $i;
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
$res['num_fields'] = $count;
# return($this->raiseError(MDB_ERROR_NOT_CAPABLE));
Documentation generated on Mon, 11 Mar 2019 10:15:29 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|