diff options
Diffstat (limited to 'framework/Data/Common/Oracle/TOracleTableInfo.php')
-rw-r--r-- | framework/Data/Common/Oracle/TOracleTableInfo.php | 148 |
1 files changed, 124 insertions, 24 deletions
diff --git a/framework/Data/Common/Oracle/TOracleTableInfo.php b/framework/Data/Common/Oracle/TOracleTableInfo.php index 0f163df3..b3c1ff0a 100644 --- a/framework/Data/Common/Oracle/TOracleTableInfo.php +++ b/framework/Data/Common/Oracle/TOracleTableInfo.php @@ -1,4 +1,5 @@ <?php + /** * TOracleTableInfo class file. * @@ -7,31 +8,75 @@ * @copyright Copyright © 2005-2007 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ - * @package System.Data.Common.Oracle + * @package System.Data.Common */ /** - * Loads the base TDbTableInfo class and TOracleTableColumn class. - */ -Prado::using('System.Data.Common.TDbTableInfo'); -Prado::using('System.Data.Common.Oracle.TOracleTableColumn'); - -/** - * TOracleTableInfo class provides additional table information for ORACLE database. + * TDbTableInfo class describes the meta data of a database table. * - * @author Marcos Nobre <marconobre[at]gmail[dot]com> + * @author Wei Zhuo <weizho[at]gmail[dot]com> * @version $Id$ - * @package System.Data.Common.Oracle - * @since 3.1.1 + * @package System.Data.Common + * @since 3.1 */ -class TOracleTableInfo extends TDbTableInfo +class TOracleTableInfo extends TComponent { + private $_info=array(); + + private $_primaryKeys; + private $_foreignKeys; + + private $_columns; + + private $_lowercase; + /** - * @return string name of the schema this column belongs to. + * Sets the database table meta data information. + * @param array table column information. */ - public function getSchemaName() + public function __construct($tableInfo=array(),$primary=array(),$foreign=array()) { - return $this->getInfo('SchemaName'); + $this->_info=$tableInfo; + $this->_primaryKeys=$primary; + $this->_foreignKeys=$foreign; + $this->_columns=new TMap; + } + + /** + * @param TDbConnection database connection. + * @return TDbCommandBuilder new command builder + */ + public function createCommandBuilder($connection) + { + Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder'); + return new TOracleCommandBuilder($connection,$this); + } + + /** + * @param string information array key name + * @param mixed default value if information array value is null + * @return mixed information array value. + */ + public function getInfo($name,$default=null) + { + return isset($this->_info[$name]) ? $this->_info[$name] : $default; + } + + /** + * @param string information array key name + * @param mixed new information array value. + */ + protected function setInfo($name,$value) + { + $this->_info[$name]=$value; + } + + /** + * @return string name of the table this column belongs to. + */ + public function getTableName() + { + return $this->getInfo('TableName'); } /** @@ -39,20 +84,75 @@ class TOracleTableInfo extends TDbTableInfo */ public function getTableFullName() { - if(($schema=$this->getSchemaName())!==null) - return $schema.'.'.$this->getTableName(); - else - $this->getTableName(); + return $this->_info['SchemaName'].'.'.$this->getTableName(); } /** - * @param TDbConnection database connection. - * @return TDbCommandBuilder new command builder + * @return boolean whether the table is a view, default is false. */ - public function createCommandBuilder($connection) + public function getIsView() { - Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder'); - return new TOracleCommandBuilder($connection,$this); + return $this->getInfo('IsView',false); + } + + /** + * @return TMap TDbTableColumn column meta data. + */ + public function getColumns() + { + return $this->_columns; + } + + /** + * @param string column id + * @return TDbTableColumn column information. + */ + public function getColumn($name) + { + if(($column = $this->_columns->itemAt($name))!==null) + return $column; + throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); + } + + /** + * @param array list of column Id, empty to get all columns. + * @return array table column names (identifier quoted) + */ + public function getColumnNames() + { + foreach($this->getColumns() as $column) + $names[] = $column->getColumnName(); + return $names; + } + + /** + * @return string[] names of primary key columns. + */ + public function getPrimaryKeys() + { + return $this->_primaryKeys; + } + + /** + * @return array tuples of foreign table and column name. + */ + public function getForeignKeys() + { + return $this->_foreignKeys; + } + + /** + * @return array lowercased column key names mapped to normal column ids. + */ + public function getLowerCaseColumnNames() + { + if($this->_lowercase===null) + { + $this->_lowercase=array(); + foreach($this->getColumns()->getKeys() as $key) + $this->_lowercase[strtolower($key)] = $key; + } + return $this->_lowercase; } } |