Source for file interbase.inc.php
Documentation is available at interbase.inc.php
* This file is part of the VCL for PHP project
* Copyright (c) 2004-2007 qadram software <support@qadram.com>
* Checkout AUTHORS file for more information on the developers
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* A database component for InterBase
$metaColumnsSQL = "select a.rdb\$field_name from rdb\$relation_fields a, rdb\$fields b where a.rdb\$field_source = b.rdb\$field_name and a.rdb\$relation_name = '%s' order by a.rdb\$field_position asc";
while ($row= ibase_fetch_row($rs))
function readConnected() { if ($this->_connection!= null) return("1"); else return("0"); }
function getConnected() { return $this->readconnected(); }
function setConnected($value) { $this->writeconnected($value); }
function getDebug() { return $this->_debug; }
function setDebug($value) { $this->_debug= $value; }
function defaultDebug() { return 0; }
function getDictionary() { return $this->_dictionary; }
function setDictionary($value) { $this->_dictionary= $value; }
function setDatabaseName($value) { $this->_databasename= $value; }
function getHost() { return $this->_host; }
function setHost($value) { $this->_host= $value; }
function getUserName() { return $this->_username; }
function setUserName($value) { $this->_username= $value; }
function setUserPassword($value) { $this->_userpassword= $value; }
function getOnAfterConnect() { return $this->readonafterconnect(); }
function setOnAfterConnect($value) { $this->writeonafterconnect($value); }
function getOnBeforeConnect() { return $this->readonbeforeconnect(); }
function setOnBeforeConnect($value) { $this->writeonbeforeconnect($value); }
function getOnAfterDisconnect() { return $this->readonafterdisconnect(); }
function setOnAfterDisconnect($value) { $this->writeonafterdisconnect($value); }
function getOnBeforeDisconnect() { return $this->readonbeforedisconnect(); }
function setOnBeforeDisconnect($value) { $this->writeonbeforedisconnect($value); }
* Specifies the dialect to be used when connecting to the server
function getDialect() { return $this->_dialect; }
function setDialect($value) { $this->_dialect= $value; }
function defaultDialect() { return 3; }
//Calls inherited constructor
function execute($query,$params= array())
DatabaseError("Error executing query: $query [". ibase_errmsg(). "]");
* Executes a limited query
if ($offset <= 0) $str = " ROWS $numrows ";
$str = " ROWS $a TO 999999999"; // 999 million
$this->_connection = ibase_pconnect ($this->DatabaseName, $this->UserName, $this->UserPassword,'ISO8859_1', '100', $this->Dialect);
* Return properties for a field
$q= "select * from $this->_dictionary where dict_tablename='$table' and dict_fieldname='$field'";
while ($arow= ibase_fetch_assoc($r))
while (list ($k,$v)= each($arow))
$props[$row['dict_property']]= array($row['dict_value1'],$row['dict_value2']);
if (!empty($props)) $result= $props;
* Return indexes for a table
* @param boolean $primary
$sql = "SELECT * FROM RDB\$INDICES WHERE RDB\$RELATION_NAME = '". $table. "'";
$sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$%'";
$sql .= " AND RDB\$INDEX_NAME NOT LIKE 'RDB\$FOREIGN%'";
while ($row = ibase_fetch_row($rs))
if (!isset ($indexes[$index]))
$indexes[$index] = array(
'unique' => ($row[3] == 1),
$sql = "SELECT * FROM RDB\$INDEX_SEGMENTS WHERE RDB\$INDEX_NAME = '". $index. "' ORDER BY RDB\$FIELD_POSITION ASC";
while ($row1 = ibase_fetch_row($rs1))
$indexes[$index]['columns'][$row1[2]] = $row1[1];
* Creates the dictionary table on the database
$q.= " DICT_ID INTEGER NOT NULL,\n";
$q.= " DICT_TABLENAME VARCHAR(60) CHARACTER SET NONE COLLATE NONE,\n";
$q.= " DICT_FIELDNAME VARCHAR(60) CHARACTER SET NONE COLLATE NONE,\n";
$q.= " DICT_PROPERTY VARCHAR(60) CHARACTER SET NONE COLLATE NONE,\n";
$q.= " DICT_VALUE1 VARCHAR(60) CHARACTER SET NONE COLLATE NONE,\n";
$q.= " DICT_VALUE2 VARCHAR(200) CHARACTER SET NONE COLLATE NONE);\n";
$q= "ALTER TABLE $this->_dictionary ADD PRIMARY KEY (DICT_ID);\n";
* Return all the databases using the connection information
* Return tables on this database
function tables($ttype= false,$showSchema= false,$mask= false)
$metaTablesSQL = "select rdb\$relation_name from rdb\$relations where rdb\$relation_name not like 'RDB\$%'";
$rs = $this->execute($metaTablesSQL);
if ($rs === false) return $false;
while ($arr = ibase_fetch_row($rs))
* Base Class for datasets linked to a database
function readDatabase() { return $this->_database; }
function defaultDatabase() { return null; }
function readFields() { return($this->_buffer); }
function readRecordCount()
else return(parent::readRecordCount());
for($i= 0;$i<= $distance- 1;$i++ )
$this->_eof= !($buff= ibase_fetch_assoc($this->_rs));
if ($lquery!= "") $query= $lquery;
else $query= $this->buildQuery();
$this->_rs= $this->Database->Execute($query,$this->_params);
if ($limitstart== '') $limitstart=- 1;
if ($limitcount== '') $limitcount=- 1;
$this->_rs= $this->Database->ExecuteLimit($query,$limitcount,$limitstart);
if ($this->_tablename!= '')
$fd= $this->Database->MetaFields($this->_tablename);
* Overriden to allow get field values as properties
else return(parent::__get($nm));
return(parent::__get($nm));
return(parent::__get($nm));
* Overriden to allow get field values as properties
else parent::__set($nm, $val);
parent::__set($nm, $val);
parent::__set($nm, $val);
* A class to encapsulate a database table
function readTableName() { return $this->_tablename; }
function writeTableName($value) { $this->_tablename= $value; }
function defaultTableName() { return ""; }
if (trim($val)== '') continue;
if ($where!= '') $where.= " and ";
$where.= " $fname = ". $this->Database->QuoteStr($val);
$query= "delete from $this->TableName where $where";
$this->Database->Execute($query);
* @param string $fieldname
if (trim($val)== '') continue;
if ($where!= '') $where.= " and ";
$where.= " $fname = ". $this->Database->QuoteStr($val);
while(list ($key, $fname)= each($buffer))
if ($set!= "") $set.= ", ";
$set.= " $key = '$fname' ";
$updateSQL= "update $this->TableName set $set where $where";
$this->Database->execute($updateSQL);
if ($fields!= '') $fields.= ',';
if ($values!= '') $values.= ',';
$values.= $this->Database->QuoteStr($val);
$insertSQL= "insert into $this->TableName($fields) values ($values)";
$this->Database->execute($insertSQL);
if ($this->Filter!= "") $where.= " $this->Filter ";
if ($this->MasterSource!= "")
if ($ms!= "") $ms.= " and ";
$ms.= " $thisfield=". $this->Database->QuoteStr($this->_mastersource->DataSet->$msfield). " ";
if ($where!= "") $where.= " and ";
if ($where!= "") $where= " where $where ";
$result= $qu. " $where $order ";
* Return an array containg the row values
function readAssociativeFieldValues()
* Return an array with Key fields for the table
//TODO: Check here for another indexes
$indexes= $this->Database->extractIndexes($this->_tablename,true);
list (,$primary)= each($indexes);
$result= $primary['columns'];
while (list ($k,$v)= each($result))
$keyfields= $this->readKeyFields();
$values= $this->readAssociativeFieldValues();
while (list ($k,$v)= each($keyfields))
echo "<input type=\"hidden\" name=\"". $basename. "[$v]\" value=\"$values[$v]\" />";
* Specifies the field by which the dataset will be ordered
function readOrderField() { return $this->_orderfield; }
function writeOrderField($value) { $this->_orderfield= $value; }
function defaultOrderField() { return ""; }
* Specifies the order (ascending/descending) to order the dataset
function readOrder() { return $this->_order; }
function writeOrder($value) { $this->_order= $value; }
function defaultOrder() { return "asc"; }
//**************************************************************
//TODO: Abstract more this class into Dataset (i.e. active, open, etc)
* A class to encapsulate an interbase table
function getMasterSource() { return $this->readmastersource(); }
function setMasterSource($value) { $this->writemastersource($value); }
function getMasterFields() { return $this->readmasterfields(); }
function setMasterFields($value) { $this->writemasterfields($value); }
function getTableName() { return $this->readtablename(); }
function setTableName($value) { $this->writetablename($value); }
function getActive() { return $this->readactive(); }
function setActive($value) { $this->writeactive($value); }
function getDatabase() { return $this->readdatabase(); }
function setDatabase($value) { $this->writedatabase($value); }
function getFilter() { return $this->readfilter(); }
function setFilter($value) { $this->writefilter($value); }
function getOrderField() { return $this->readorderfield(); }
function setOrderField($value) { $this->writeorderfield($value); }
function getOrder() { return $this->readorder(); }
function setOrder($value) { $this->writeorder($value); }
function getOnBeforeOpen() { return $this->readonbeforeopen(); }
function setOnBeforeOpen($value) { $this->writeonbeforeopen($value); }
function getOnAfterOpen() { return $this->readonafteropen(); }
function setOnAfterOpen($value) { $this->writeonafteropen($value); }
function getOnBeforeClose() { return $this->readonbeforeclose(); }
function setOnBeforeClose($value) { $this->writeonbeforeclose($value); }
function getOnAfterClose() { return $this->readonafterclose(); }
function setOnAfterClose($value) { $this->writeonafterclose($value); }
function getOnBeforeInsert() { return $this->readonbeforeinsert(); }
function setOnBeforeInsert($value) { $this->writeonbeforeinsert($value); }
function getOnAfterInsert() { return $this->readonafterinsert(); }
function setOnAfterInsert($value) { $this->writeonafterinsert($value); }
function getOnBeforeEdit() { return $this->readonbeforeedit(); }
function setOnBeforeEdit($value) { $this->writeonbeforeedit($value); }
function getOnAfterEdit() { return $this->readonafteredit(); }
function setOnAfterEdit($value) { $this->writeonafteredit($value); }
function getOnBeforePost() { return $this->readonbeforepost(); }
function setOnBeforePost($value) { $this->writeonbeforepost($value); }
function getOnAfterPost() { return $this->readonafterpost(); }
function setOnAfterPost($value) { $this->writeonafterpost($value); }
function getOnBeforeCancel() { return $this->readonbeforecancel(); }
function setOnBeforeCancel($value) { $this->writeonbeforecancel($value); }
function getOnAfterCancel() { return $this->readonaftercancel(); }
function setOnAfterCancel($value) { $this->writeonaftercancel($value); }
function getOnBeforeDelete() { return $this->readonbeforedelete(); }
function setOnBeforeDelete($value) { $this->writeonbeforedelete($value); }
function getOnAfterDelete() { return $this->readonafterdelete(); }
function setOnAfterDelete($value) { $this->writeonafterdelete($value); }
function getOnDeleteError() { return $this->readondeleteerror(); }
function setOnDeleteError($value) { $this->writeondeleteerror($value); }
* An array that specifies the query to be executed
function readSQL() { return $this->_sql; }
function writeSQL($value)
function defaultSQL() { return ""; }
* Parameters to be used on parametrized queries
function readParams() { return $this->_params; }
function writeParams($value) { $this->_params= $value; }
function defaultParams() { return ""; }
$result= $qu. " $filter $order ";
* A class to encapsulate a database table
function getSQL() { return $this->readsql(); }
function setSQL($value) { $this->writesql($value); }
function getParams() { return $this->readparams(); }
function setParams($value) { $this->writeparams($value); }
function getTableName() { return $this->readtablename(); }
function setTableName($value) { $this->writetablename($value); }
function getActive() { return $this->readactive(); }
function setActive($value) { $this->writeactive($value); }
function getDatabase() { return $this->readdatabase(); }
function setDatabase($value) { $this->writedatabase($value); }
function getFilter() { return $this->readfilter(); }
function setFilter($value) { $this->writefilter($value); }
function getOrderField() { return $this->readorderfield(); }
function setOrderField($value) { $this->writeorderfield($value); }
function getOrder() { return $this->readorder(); }
function setOrder($value) { $this->writeorder($value); }
* A component to call stored procedures
function defaultStoredProcName() { return ""; }
function getActive() { return $this->readactive(); }
function setActive($value) { $this->writeactive($value); }
function getDatabase() { return $this->readdatabase(); }
function setDatabase($value) { $this->writedatabase($value); }
function getFilter() { return $this->readfilter(); }
function setFilter($value) { $this->writefilter($value); }
function getOrderField() { return $this->readorderfield(); }
function setOrderField($value) { $this->writeorderfield($value); }
function getOrder() { return $this->readorder(); }
function setOrder($value) { $this->writeorder($value); }
function getParams() { return $this->readparams(); }
function setParams($value) { $this->writeparams($value); }
if ($pars!= "") $pars.= ', ';
if ($pars!= "") $pars= "($pars)";
|