Source for file ibase.php
Documentation is available at ibase.php
// +----------------------------------------------------------------------+
// | PHP versions 4 and 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1998-2005 Manuel Lemos, Tomas V.V.Cox, |
// | Stig. S. Bakken, Lukas Smith, Frank M. Kromann, Lorenzo Alberton |
// | All rights reserved. |
// +----------------------------------------------------------------------+
// | MDB2 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.35 2006/01/13 20:39:05 quipo Exp $
require_once 'MDB2/Driver/Reverse/Common.php';
* MDB2 InterbaseBase driver for the reverse engineering module
* @author Lorenzo Alberton <l.alberton@quipo.it>
* Array for converting constant values to text values
12 => 'date', //dialect 3 DATE
35 => 'timestamp', //DATE in older versions
* Array for converting constant values to text values
1 => 'fixed', //BINARY data
2 => 'BLR', //Binary Language Representation
3 => 'access control list',
4 => 'reserved for future use',
5 => 'encoded description of a table\'s current metadata',
6 => 'description of multi-database transaction that finished irregularly',
// {{{ getTableFieldDefinition()
* get the stucture of a field into an array
* @param string $table name of table that should be used in method
* @param string $field_name name of field that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $this->getDBInstance ();
if (PEAR ::isError ($db)) {
$result = $db->loadModule ('Datatype', null , true );
if (PEAR ::isError ($result)) {
$query = " SELECT RDB\$RELATION_FIELDS.RDB\$FIELD_NAME AS name,
RDB\$FIELDS.RDB\$FIELD_LENGTH AS \"length\",
RDB\$FIELDS.RDB\$FIELD_TYPE AS field_type_code,
RDB\$FIELDS.RDB\$FIELD_SUB_TYPE AS field_sub_type_code,
RDB\$RELATION_FIELDS.RDB\$DESCRIPTION AS description,
RDB\$RELATION_FIELDS.RDB\$NULL_FLAG AS null_flag,
RDB\$RELATION_FIELDS.RDB\$DEFAULT_SOURCE AS default_source
LEFT JOIN RDB\$RELATION_FIELDS ON RDB\$FIELDS.RDB\$FIELD_NAME = RDB\$RELATION_FIELDS.RDB\$FIELD_SOURCE
WHERE UPPER(RDB\$RELATION_FIELDS.RDB\$RELATION_NAME)='$table'
AND UPPER(RDB\$RELATION_FIELDS.RDB\$FIELD_NAME)='$field_name';";
$column = $db->queryRow ($query, null , MDB2_FETCHMODE_ASSOC );
if (PEAR ::isError ($column)) {
return $db->raiseError (MDB2_ERROR , null , null ,
'getTableFieldDefinition: it was not specified an existing table column');
if ($db->options ['portability'] & MDB2_PORTABILITY_FIX_CASE ) {
if ($db->options ['field_case'] == CASE_LOWER ) {
? $this->types[(int) $column['field_type_code']] : 'undefined';
if ($column['field_sub_type_code']
$column['field_sub_type'] = $this->subtypes[(int) $column['field_type_code']][$column['field_sub_type_code']];
$column['field_sub_type'] = null;
list ($types, $length, $unsigned) = $db->datatype ->mapNativeDatatype ($column);
$notnull = !empty ($column['null_flag']);
$default = $column['default_source'];
if (is_null($default) && $notnull) {
$default = ($types[0 ] == 'integer') ? 0 : '';
foreach ($types as $key => $type) {
$definition[$key] = array (
$definition[$key]['length'] = $length;
$definition[$key]['unsigned'] = true;
$definition[$key]['default'] = $default;
// {{{ getTableIndexDefinition()
* get the stucture of an index into an array
* @param string $table name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $this->getDBInstance ();
if (PEAR ::isError ($db)) {
$index_name = strtoupper($db->getIndexName ($index_name));
$query = " SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name,
RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag,
RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key,
RDB\$INDICES.RDB\$DESCRIPTION AS description,
RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE as constraint_type
LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)='$table'
AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)='$index_name'
AND (RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE IS NULL OR
RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE <> 'PRIMARY KEY')
ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;";
$result = $db->query ($query);
if (PEAR ::isError ($result)) {
$index = $row = $result->fetchRow (MDB2_FETCHMODE_ASSOC );
return $db->raiseError (MDB2_ERROR_NOT_FOUND , null , null ,
'getTableIndexDefinition: it was not specified an existing table index');
$fields[] = $row['field_name'];
} while (is_array($row = $result->fetchRow (MDB2_FETCHMODE_ASSOC )));
if ($db->options ['portability'] & MDB2_PORTABILITY_FIX_CASE ) {
$fields = array_map(($db->options ['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $fields);
if ($index['unique_flag']) {
$definition['unique'] = true;
foreach ($fields as $field) {
$definition['fields'][$field] = array ();
if (array_key_exists('collation', $row)) {
$definition['fields'][$field]['sorting'] = ($row['collation'] == 'A'
? 'ascending' : 'descending');
// {{{ getTableConstraintDefinition()
* get the stucture of a constraint into an array
* @param string $table name of table that should be used in method
* @param string $index_name name of index that should be used in method
* @return mixed data array on success, a MDB2 error on failure
$db = & $this->getDBInstance ();
if (PEAR ::isError ($db)) {
$index_name = strtoupper($db->getIndexName ($index_name));
$query = " SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name,
RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag,
RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key,
RDB\$INDICES.RDB\$DESCRIPTION AS description,
RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE as constraint_type
LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME
WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)='$table'
AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)='$index_name'
ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;";
$result = $db->query ($query);
if (PEAR ::isError ($result)) {
$index = $row = $result->fetchRow (MDB2_FETCHMODE_ASSOC );
return $db->raiseError (MDB2_ERROR_NOT_FOUND , null , null ,
'getTableConstraintDefinition: it was not specified an existing table constraint');
$fields[] = $row['field_name'];
} while (is_array($row = $result->fetchRow (MDB2_FETCHMODE_ASSOC )));
if ($db->options ['portability'] & MDB2_PORTABILITY_FIX_CASE ) {
$fields = array_map(($db->options ['field_case'] == CASE_LOWER ? 'strtolower' : 'strtoupper'), $fields);
if ($index['constraint_type'] == 'PRIMARY KEY') {
$definition['primary'] = true;
if (!$index['unique_flag'] && !$index['foreign_key']) {
return $db->raiseError (MDB2_ERROR_NOT_FOUND , null , null ,
'getTableConstraintDefinition: it was not specified an existing table constraint');
foreach ($fields as $field) {
$definition['fields'][$field] = array ();
if (array_key_exists('collation', $row)) {
$definition['fields'][$field]['sorting'] = ($row['collation'] == 'A'
? 'ascending' : 'descending');
* Returns information about a table or a result set
* NOTE: only supports 'table' and 'flags' if <var>$result</var>
* @param object|string $result MDB2_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
* @param int $mode a valid tableInfo mode
* @return array an associative array with the information requested.
* A MDB2_Error object on failure.
* @see MDB2_Driver_Common::tableInfo()
$db = & $this->getDBInstance ();
if (PEAR ::isError ($db)) {
* Probably received a table name.
* Create a result resource identifier.
$id = $db->_doQuery (" SELECT * FROM $result WHERE 1=0" , false );
if (PEAR ::isError ($id)) {
} elseif (MDB2 ::isResultCommon ($result)) {
* Probably received a result object.
* Extract the result resource identifier.
$id = $result->getResource ();
* Probably received a result resource identifier.
* Deprecated. Here for compatibility only.
return $db->raiseError (MDB2_ERROR_NEED_MORE_DATA );
if ($db->options ['portability'] & MDB2_PORTABILITY_FIX_CASE ) {
if ($db->options ['field_case'] == CASE_LOWER ) {
$case_func = 'strtolower';
$case_func = 'strtoupper';
$count = @ibase_num_fields ($id);
$res['num_fields'] = $count;
$db->loadModule ('Datatype', null , true );
for ($i = 0; $i < $count; $i++ ) {
$info = @ibase_field_info ($id, $i);
if (($pos = strpos($info['type'], '(')) !== false ) {
$info['type'] = substr($info['type'], 0 , $pos);
'table' => $got_string ? $case_func($result) : '',
'name' => $case_func($info['name']),
'length' => $info['length'],
$mdb2type_info = $db->datatype ->mapNativeDatatype ($res[$i]);
if (PEAR ::isError ($mdb2type_info)) {
$res[$i]['mdb2type'] = $mdb2type_info[0 ][0 ];
if ($mode & MDB2_TABLEINFO_ORDER ) {
$res['order'][$res[$i]['name']] = $i;
if ($mode & MDB2_TABLEINFO_ORDERTABLE ) {
$res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;
// free the result only if we were called on a table
// {{{ _ibaseFieldFlags()
* Supports "primary_key", "unique_key", "not_null", "default",
* @param string $field_name the name of the field
* @param string $table_name the name of the table
* @return string the flags
$db = & $this->getDBInstance ();
if (PEAR ::isError ($db)) {
$query = '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) . '\'';
$result = $db->_doQuery ($query, false );
if (PEAR ::isError ($result)) {
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') {
$query = '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 . '\'';
$result = $db->_doQuery ($query, false );
if (PEAR ::isError ($result)) {
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 14:36:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|