Source for file dbtables.inc.php
Documentation is available at dbtables.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
use_unit('adodb/adodb-exceptions.inc.php');
* A component that represents a database
while(list ($key, $val)= each($fd))
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); }
//Calls inherited constructor
* Specifies if the database is connected or not
function readConnected() { return ($this->_connection!= null); }
function getConnected() { return $this->readconnected(); }
function setConnected($value) { $this->writeconnected($value); }
* Specifies if the database is in debug mode or not
function getDebug() { return $this->_debug; }
function setDebug($value) { $this->_debug= $value; }
function defaultDebug() { return 0; }
* Specifies the type of database you want to access
function getDriverName() { return $this->_drivername; }
function setDriverName($value) { $this->_drivername= $value; }
* Specifies the dictionary table you want to use
function getDictionary() { return $this->_dictionary; }
function setDictionary($value) { $this->_dictionary= $value; }
* Specifies the name of the database you want to access
function setDatabaseName($value) { $this->_databasename= $value; }
* Specifies the host where your database resides
function getHost() { return $this->_host; }
function setHost($value) { $this->_host= $value; }
* Specifies the username used to acces the database
function getUserName() { return $this->_username; }
function setUserName($value) { $this->_username= $value; }
* Specifies the password to access the database
function setUserPassword($value) { $this->_userpassword= $value; }
* @param string $query Query to execute
function execute($query,$params= array())
* Executes a limited query
* @param string $query SQL sentence to execute
* @param integer $numrows Numrows to retrieve
* @param integer $offset Starting row to retrieve
$rs= $this->_connection->SelectLimit($query,$numrows,$offset);
global $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE= ADODB_FETCH_ASSOC;
$this->_connection = ADONewConnection($this->DriverName);
if (($this->DriverName== 'borland_ibase') || ($this->DriverName== 'ibase'))
$result= $this->_connection->PConnect($this->DatabaseName,$this->UserName,$this->UserPassword);
$result= $this->_connection->Connect($this->Host,$this->UserName,$this->UserPassword,$this->DatabaseName);
* Return properties for a field
global $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE= ADODB_FETCH_ASSOC;
$q= "select * from $this->_dictionary where dict_tablename='$table' and dict_fieldname='$field'";
while ($r->fetchInto($arow))
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
return($this->_connection->MetaIndexes($table,$primary));
* Return an array with dictionary properties
* 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";
$q.= " `dict_id` int(11) unsigned NOT NULL auto_increment,";
$q.= " `dict_tablename` varchar(60) NULL,";
$q.= " `dict_fieldname` varchar(60) NULL,";
$q.= " `dict_property` varchar(60) NULL,";
$q.= " `dict_value1` varchar(60) NULL,";
$q.= " `dict_value2` text NULL,";
$q.= " PRIMARY KEY (`dict_id`)";
function getDebug() { return $this->_debug; }
function setDebug($value) { $this->_debug=$value; }
function defaultDebug() { return 0; }
function getDriverName() { return $this->_drivername; }
function setDriverName($value) { $this->_drivername=$value; }
function getDictionary() { return $this->_dictionary; }
function setDictionary($value) { $this->_dictionary=$value; }
function getDatabaseName() { return $this->_databasename; }
function setDatabaseName($value) { $this->_databasename=$value; }
function getHost() { return $this->_host; }
function setHost($value) { $this->_host=$value; }
function getUser() { return $this->_user; }
function setUser($value) { $this->_user=$value; }
function getPassword() { return $this->_password; }
function setPassword($value) { $this->_password=$value; }
function getConnected() { return $this->_connected; }
function setConnected($value)
if ($value!=$this->_connected)
$this->_connected=$value;
if (($this->ControlState & csLoading)!=csLoading)
if ($this->_connected) $this->open();
if ($this->_connected) $this->open();
if (($this->ControlState & csDesigning)!=csDesigning)
global $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE=ADODB_FETCH_ASSOC;
$this->_connection = ADONewConnection($this->DriverName);
$this->_connection->debug=$this->Debug;
if (($this->DriverName=='borland_ibase') || ($this->DriverName=='ibase'))
$result=$this->_connection->PConnect($this->DatabaseName,$this->User,$this->Password);
$result=$this->_connection->Connect($this->Host,$this->User,$this->Password,$this->DatabaseName);
* Return all the databases using the connection information
if ($this->_connection==null)
return($this->_connection->MetaDatabases());
* Return tables on this database
if ($this->_connection!=null)
$this->_connection->Close();
// $this->_connection->debug=true;
$rs=$this->_connection->Execute($query);
throw new Exception("Query error: $query ".$this->_connection->ErrorMsg());
//Dump here connection code if any
* Base Class for datasets linked to a database
* Specifies the database object to be used to connect to the server
* @return CustomConnection
function readDatabase() { return $this->_database; }
function defaultDatabase() { return null; }
* Field array (name=>value) of the current record
return($this->_rs->fields);
* Number of fields on the current record
function readFieldCount() { return count($this->_rs->_numOfFields); }
* Number of records in the dataset
function readRecordCount()
return($this->_rs->RecordCount());
else return(parent::readRecordCount());
for($i= 0;$i<= $distance- 1;$i++ )
* If true, the pointer is at the end of the dataset
$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);
if ($this->_tablename!= '')
$fd= $this->Database->MetaFields($this->_tablename);
if ($this->_tablename!= '')
$fd= $this->Database->MetaFields($this->_tablename);
* Overriden to allow get field values as properties
return ($this->_rs->fields[$nm]);
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
* Name of the table you want to access
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);
$updateSQL = $this->Database->_connection->AutoExecute($this->TableName, $buffer, 'UPDATE', $where);
$insertSQL = $this->Database->_connection->AutoExecute($this->TableName, $this->fieldbuffer, 'INSERT');
* Builds the query to execute
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!= "") $result.= " where $where ";
* Return an array containg the row values
function readAssociativeFieldValues()
return($this->_rs->fields);
* 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))
* Dump hidden html fields with the key fields of this dataset
* @param string $basename Prefix to be used to generate hidden key field names
* @param array $values Array with the values to generate
$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 to order this table for
function readOrderField() { return $this->_orderfield; }
function writeOrderField($value) { $this->_orderfield= $value; }
function defaultOrderField() { return ""; }
* Specifies the ordering of the query, ascendant or descendant
function readOrder() { return $this->_order; }
function writeOrder($value) { $this->_order= $value; }
function defaultOrder() { return "asc"; }
* A class to encapsulate a database 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); }
* A class to encapsulate a database table
* Specifies the query property to be executed
function readSQL() { return $this->_sql; }
function writeSQL($value)
function defaultSQL() { return ""; }
* Prepares the query to be executed
* Specifies the parameters to be used in a parametrized query
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
* Name of the stored procedure to execute
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)";
|