Source for file ibase.php
Documentation is available at ibase.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: Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
// $Id: ibase.php,v 1.9.4.29 2004/03/31 20:00:55 quipo Exp $
require_once 'MDB/Common.php';
* MDB FireBird/InterBase driver
* - when fetching in associative mode all keys are lowercased.
* - Currently, the driver relies on the Interbase server to use SQL dialect 3
* that was introduced with Interbase 6. Some versions of Interbase server,
* like the Super Server, do not seem to work by default with dialect 3.
* This may lead to errors when trying to create tables using Interbase SQL
* data types that are only available when using this dialect version.
* - Interbase does not support per field index sorting support. Indexes are
* either ascending, descending or both even when they are defined from more
* than one field. Currently Metabase Interbase driver uses the index sorting
* type given by the first field of the index for which it is specified the
* - The numRows method is emulated by fetching all the rows into memory.
* Avoid using it if for queries with large result sets.
* - Interbase does not provide direct support for returning result sets
restrictedto a given range. Such support is emulated in the MDB ibase driver.
* - Current Interbase versions do not support altering table field DEFAULT
* values and NOT NULL constraint. Text fields' length may only be raised in
* increments defined by Interbase, so the Metabase Interbase does not support
* altering text field length yet.
* - createDatabase and dropDatabase are not supported
* - MDB creates Interbase blobs before executing a prepared queries to insert
* or update large object fields. If such queries fail to execute, MDB
* Interbase driver class is not able to reclaim the database space allocated
* for the large object values because there is currently no PHP function to do so.
* @author Lorenzo Alberton <l.alberton@quipo.it>
$this->phptype = 'ibase';
$this->dbsyntax = 'ibase';
$this->supported['Sequences'] = 1;
$this->supported['Indexes'] = 1;
$this->supported['SummaryFunctions'] = 1;
$this->supported['OrderByText'] = 1;
$this->supported['Transactions'] = 1;
$this->supported['CurrId'] = 0;
$this->supported['AffectedRows'] = 0;
$this->supported['SelectRowRanges'] = 1;
$this->supported['LOBs'] = 1;
$this->supported['Replace'] = 1;
$this->supported['SubSelects'] = 1;
$this->options['DatabasePath'] = '';
$this->options['DatabaseExtension'] = '.gdb';
$this->options['DBAUser'] = FALSE;
$this->options['DBAPassword'] = FALSE;
$this->errorcode_map = array (
* Map native error codes to DB's portable ones. Requires that
* the DB implementation's constructor fills in the $errorcode_map
* @param $nativecode the native error code, as returned by the backend
* database extension (string or integer)
* @return int a portable MDB error code, or FALSE if this DB
* implementation has no mapping for the given error code.
// memo for the interbase php module hackers: we need something similar
// to mysql_errno() to retrieve error codes instead of this ugly hack
if (preg_match('/^([^0-9\-]+)([0-9\-]+)\s+(.*)$/', $errormsg, $match)) {
if (isset ($this->errorcode_map[$errno])) {
return($this->errorcode_map[$errno]);
if (empty ($error_regexps)) {
'/arithmetic exception, numeric overflow, or string truncation/' => MDB_ERROR_DIVZERO,
foreach ($error_regexps as $regexp => $code) {
// Fall back to MDB_ERROR if there was no mapping.
* 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
* Get the native error code of the last error (if any) that
* occured on the current connection.
* @return int native ibase error code
* 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 ($this->auto_commit) {
'Commit: transaction changes are being auto commited'));
* 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 can not be rolled back when changes are auto commited'));
//return ibase_rollback($this->connection);
'Rollback: Could not rollback a pending transaction: '. @ibase_errmsg ()));
'Rollback: Could not start a new transaction: '. @ibase_errmsg ()));
if (isset ($this->options['DatabasePath'])) {
$this->database_path = $this->options['DatabasePath'];
if (isset ($this->options['DatabaseExtension'])) {
$this->database_extension = $this->options['DatabaseExtension'];
//$this->database_path = (isset($this->options['DatabasePath']) ? $this->options['DatabasePath'] : '');
//$this->database_extension = (isset($this->options['DatabaseExtension']) ? $this->options['DatabaseExtension'] : '.gdb');
//$database_path = (isset($this->options['DatabasePath']) ? $this->options['DatabasePath'] : '');
//$database_extension = (isset($this->options['DatabaseExtension']) ? $this->options['DatabaseExtension'] : '.gdb');
return $this->database_path. $database_name. $this->database_extension;
* Does the grunt work of connecting to the database
* @return mixed connection resource on success, MDB_Error on failure
function _doConnect ($database_name, $persistent)
$function = ($persistent ? 'ibase_pconnect' : 'ibase_connect');
'doConnect: FireBird/InterBase support is not available in this PHP configuration'));
($this->host . ':' . $database_name) :
$params[] = !empty ($this->user) ? $this->user : NULL;
$params[] = !empty ($this->password) ? $this->password : NULL;
@ibase_timefmt ("%Y-%m-%d %H:%M:%S", IBASE_TIMESTAMP );
@ibase_timefmt ("%Y-%m-%d", IBASE_DATE );
if (isset ($php_errormsg)) {
$error_msg = $php_errormsg;
$error_msg = 'Could not connect to FireBird/InterBase server';
'doConnect: '. $error_msg));
* Connect to the database
* @return TRUE on success, MDB_Error on failure
$port = (isset ($this->options['port']) ? $this->options['port'] : '');
$this->affected_rows = -1;
$connection = $this->_doConnect ($database_file, $this->options['persistent']);
//the if below was added after PEAR::DB. Review me!!
if ($this->dbsyntax == 'fbird') {
$this->supported['limit'] = 'alter';
if (!$this->auto_commit && MDB::isError($trans_result = $this->_doQuery ('BEGIN'))) {
$this->affected_rows = -1;
* Close the database connection
if (!$this->auto_commit) {
$this->affected_rows = -1;
unset ($GLOBALS['_MDB_databases'][$this->database]);
* @param string $query the SQL query
* @return mixed result identifier if query executed, else MDB_error
function _doQuery ($query, $first=0 , $limit=0 , $prepared_query=0 ) // function _doQuery($query)
$result = @ibase_query ($connection, $query);
while (@ibase_errmsg () == 'Query argument missed') { //ibase_errcode() only available in PHP5
//connection lost, try again...
//rollback the failed transaction to prevent deadlock and execute the query again
$result = @ibase_query ($this->connection, $query);
$result_value = intval($result);
$this->limits[$result_value] = array ($first, $limit, 0 );
$this->affected_rows = -1;
'_doQuery: Could not execute query ("'. $query. '"): ' . @ibase_errmsg ()));
* 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 result identifier if query executed, else MDB_error
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, 0 ))) {
// {{{ _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 (!is_array(@ibase_fetch_row ($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 = @ibase_num_fields ($result);
for ($column=0; $column < $columns; $column++ ) {
$column_info = @ibase_field_info ($result, $column);
$field_name = $column_info['name'];
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
'Number of columns: it was specified an inexisting result set'));
return @ibase_num_fields ($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))
* 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 $field field number where the data can be found
* @return mixed string on success, a MDB error on failure
function fetch($result, $rownum, $field)
$row = $this->fetchInto($result, $fetchmode, $rownum);
* 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])
&& is_array($buffer = @ibase_fetch_row ($result))
// 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 ($row as $key => $value_with_space) {
$row[$key] = rtrim($value_with_space, ' ');
foreach ($column_names as $name => $i) {
$column_names[$name] = $row[$i];
if (isset ($this->result_types[$result_value])) {
* 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'])) {
$this->lobs[$lob]['Value'] = $this->fetch($this->lobs[$lob]['Result'],
$this->lobs[$lob]['Row'],
$this->lobs[$lob]['Field']);
if (!$this->lobs[$lob]['Handle'] = @ibase_blob_open ($this->lobs[$lob]['Value'])) {
unset ($this->lobs[$lob]['Value']);
'Retrieve LOB: Could not open fetched large object field' . @ibase_errmsg ()));
* Determine whether it was reached the end of the large object and
* therefore there is no more data to be read for the its input stream.
* @param int $lob handle to a lob created by the createLob() function
* @return mixed TRUE or FALSE on success, a MDB error on failure
if (MDB::isError($lobresult = $this->_retrieveLob ($lob))) {
return(isset ($this->lobs[$lob]['EndOfLOB']));
* Read data from large object input stream.
* @param int $lob handle to a lob created by the createLob() function
* @param blob $data reference to a variable that will hold data to be
* read from the large object input stream
* @param int $length integer value that indicates the largest ammount of
* data to be read from the large object input stream.
* @return mixed length on success, a MDB error on failure
function _readResultLob ($lob, &$data, $length)
if (MDB::isError($lobresult = $this->_retrieveLob ($lob))) {
$data = @ibase_blob_get ($this->lobs[$lob]['Handle'], $length);
'Read Result LOB: ' . @ibase_errmsg ());
if (($length = strlen($data)) == 0 ) {
$this->lobs[$lob]['EndOfLOB'] = 1;
// {{{ _destroyResultLob()
* Free any resources allocated during the lifetime of the large object
* @param int $lob handle to a lob created by the createLob() function
function _destroyResultLob ($lob)
if (isset ($this->lobs[$lob])) {
if (isset ($this->lobs[$lob]['Value'])) {
@ibase_blob_close ($this->lobs[$lob]['Handle']);
* 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);
* 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 or a MDB error on failure
return $this->_baseConvertResult ($value, $type);
* 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);
* 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))) {
//$this->rows[$result_value] = 0;
while ((!isset ($this->limits[$result_value])
&& (is_array($buffer = @ibase_fetch_row ($result)))
* Free the internal resources associated with $result.
* @param $result result identifier
* @return boolean 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->rows[$result_value])) {
unset ($this->rows[$result_value]);
if (isset ($this->result_types[$result_value])) {
unset ($this->result_types[$result_value]);
return @ibase_free_result ($result);
// {{{ getTypeDeclaration()
* Obtain DBMS specific SQL code portion needed to declare an text type
* field to be used in statements like CREATE TABLE.
* @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.
return('VARCHAR ('. (isset ($field['length']) ? $field['length'] : (isset ($this->options['DefaultTextFieldLength']) ? $this->options['DefaultTextFieldLength'] : 4000 )). ')');
return 'BLOB SUB_TYPE 1';
return 'BLOB SUB_TYPE 0';
return 'DOUBLE PRECISION';
return 'DECIMAL(18,'. $this->decimal_places. ')';
// {{{ 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.
return($name. ' '. $this->getTypeDeclaration($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. ' '. $this->getTypeDeclaration($field). (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. ' '. $this->getTypeDeclaration($field). (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.
return($name. ' '. $this->getTypeDeclaration($field). (isset ($field['default']) ? ' DEFAULT "'. $field['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.
return($name. ' '. $this->getTypeDeclaration($field). (isset ($field['default']) ? ' DEFAULT "'. $field['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.
return($name. ' '. $this->getTypeDeclaration($field). (isset ($field['default']) ? ' DEFAULT '. $this->getFloatValue($field['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.
return($name. ' '. $this->getTypeDeclaration($field). (isset ($field['default']) ? ' DEFAULT '. $this->getDecimalValue($field['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.
function _getLobValue ($prepared_query, $parameter, $lob)
$value = ''; // DEAL WITH ME
return($this->raiseError(MDB_ERROR, NULL , NULL , '_getLobValue: Could not start a new transaction: '. @ibase_errmsg ()));
if (MDB::isError($result = $this->readLob($lob, $data, $this->options['lob_buffer_length']))) {
if (@ibase_blob_add ($lo, $data) === false ) {
'_getLobValue - Could not add data to a large object: ' . @ibase_errmsg ());
$value = @ibase_blob_close ($lo);
'Get LOB field value' . @ibase_errmsg ());
if (!$this->auto_commit) {
* 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.
return $this->_getLobValue ($prepared_query, $parameter, $clob);
* @param resource $prepared_query query handle from prepare()
* 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.
return $this->_getLobValue ($prepared_query, $parameter, $blob);
* 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' : $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.
* returns the affected rows of a query
* @return mixed MDB Error Object or number of rows
$affected_rows = @ibase_affected_rows ($this->connection);
if ($affected_rows === false ) {
* 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 )
//$sequence_name = $this->getSequenceName($seq_name);
$query = " SELECT GEN_ID($sequence_name, 1) as the_value FROM RDB\$DATABASE";
$result = $this->_doQuery ($query);
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
//$sequence_name = $this->getSequenceName($seq_name);
$query = " SELECT RDB\$GENERATOR_ID FROM RDB\$GENERATORS WHERE RDB\$GENERATOR_NAME='$sequence_name'";
'currId: Unable to select from ' . $seqname) );
//var_dump($result); ==> null
'currId: could not find value in sequence table'));
* Move the internal ibase result pointer to the next available result
* @param $result a valid ibase result resource
* @return TRUE if a result is available otherwise return FALSE
* returns meta data about the result set
* @param mixed $resource FireBird/InterBase result identifier or table name
* @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]['flags'] field flags
* - mode is MDB_TABLEINFO_ORDER
* ['num_fields'] number of metadata records
* [0]['table'] table name
* [0]['len'] field length
* [0]['flags'] field flags
* ['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['meta']['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 MDB_TABLEINFO_ORDER and
* MDB_TABLEINFO_ORDERTABLE with MDB_TABLEINFO_ORDER |
* MDB_TABLEINFO_ORDERTABLE * or with MDB_TABLEINFO_FULL
// if $result is a string, then we want information about a
// table without a resultset
$id = @ibase_query ($this->connection," SELECT * FROM $result" );
} else { // else we want information about a resultset
$count = @ibase_num_fields ($id);
// made this IF due to performance (one if is faster than $count if's)
for ($i=0; $i< $count; $i++ ) {
$info = @ibase_field_info ($id, $i);
//$res[$i]['table'] = (is_string($result)) ? $result : '';
$res[$i]['table'] = (is_string($result)) ? $result : $info['relation'];
$res[$i]['name'] = $info['name'];
$res[$i]['type'] = $info['type'];
$res[$i]['len'] = $info['length'];
//$res[$i]['flags'] = (is_string($result)) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
$res[$i]['flags'] = (is_string($result)) ? $this->_ibaseFieldFlags ($id, $i, $result) : '';
$res['num_fields'] = $count;
for ($i=0; $i< $count; $i++ ) {
$info = @ibase_field_info ($id, $i);
//$res[$i]['table'] = (is_string($result)) ? $result : '';
$res[$i]['table'] = (is_string($result)) ? $result : $info['relation'];
$res[$i]['name'] = $info['name'];
$res[$i]['type'] = $info['type'];
$res[$i]['len'] = $info['length'];
//$res[$i]['flags'] = (is_string($result)) ? $this->_ibaseFieldFlags($info['name'], $result) : '';
$res[$i]['flags'] = (is_string($result)) ? $this->_ibaseFieldFlags ($id, $i, $result) : '';
$res['order'][$res[$i]['name']] = $i;
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
// free the result only if we were called on a table
// {{{ _ibaseFieldFlags()
* get the Flags of a Field
* @param int $resource FireBird/InterBase result identifier
* @param int $num_field the field number
* @return string The flags of the field ('not_null', 'default_xx', 'primary_key',
* 'unique' and 'multiple_key' are supported)
function _ibaseFieldFlags ($resource, $num_field, $table_name)
$field_name = @ibase_field_info ($resource, $num_field);
$field_name = @$field_name['name'];
$sql = 'SELECT R.RDB$CONSTRAINT_TYPE CTYPE'
. ' FROM RDB$INDEX_SEGMENTS I'
. ' JOIN RDB$RELATION_CONSTRAINTS R ON I.RDB$INDEX_NAME=R.RDB$INDEX_NAME'
. ' WHERE I.RDB$FIELD_NAME=\''. $field_name. '\''
. ' AND UPPER(R.RDB$RELATION_NAME)=\''. strtoupper($table_name). '\'';
if ($obj = @ibase_fetch_object ($result)) {
@ibase_free_result ($result);
if (isset ($obj->CTYPE ) && trim($obj->CTYPE ) == 'PRIMARY KEY') {
if (isset ($obj->CTYPE ) && trim($obj->CTYPE ) == 'UNIQUE') {
$sql = 'SELECT R.RDB$NULL_FLAG AS NFLAG,'
. ' R.RDB$DEFAULT_SOURCE AS DSOURCE,'
. ' F.RDB$FIELD_TYPE AS FTYPE,'
. ' F.RDB$COMPUTED_SOURCE AS CSOURCE'
. ' FROM RDB$RELATION_FIELDS R '
. ' JOIN RDB$FIELDS F ON R.RDB$FIELD_SOURCE=F.RDB$FIELD_NAME'
. ' WHERE UPPER(R.RDB$RELATION_NAME)=\''. strtoupper($table_name). '\''
. ' AND R.RDB$FIELD_NAME=\''. $field_name. '\'';
if ($obj = @ibase_fetch_object ($result)) {
@ibase_free_result ($result);
if (isset ($obj->NFLAG )) {
if (isset ($obj->DSOURCE )) {
if (isset ($obj->CSOURCE )) {
if (isset ($obj->FTYPE ) && $obj->FTYPE == 261 ) {
Documentation generated on Mon, 11 Mar 2019 10:15:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|