Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/**
4
 * TOracleTableInfo class file.
5
 *
6
 * @author Marcos Nobre <marconobre[at]gmail[dot]com>
7
 * @link http://www.pradosoft.com/
8
 * @copyright Copyright &copy; 2005-2008 PradoSoft
9
 * @license http://www.pradosoft.com/license/
10
 * @version $Id: TOracleTableInfo.php 2482 2008-07-30 02:07:13Z knut $
11
 * @package System.Data.Common
12
 */
13
 
14
/**
15
 * TDbTableInfo class describes the meta data of a database table.
16
 *
17
 * @author Wei Zhuo <weizho[at]gmail[dot]com>
18
 * @version $Id: TOracleTableInfo.php 2482 2008-07-30 02:07:13Z knut $
19
 * @package System.Data.Common
20
 * @since 3.1
21
 */
22
class TOracleTableInfo extends TComponent
23
{
24
	private $_info=array();
25
 
26
	private $_primaryKeys;
27
	private $_foreignKeys;
28
 
29
	private $_columns;
30
 
31
	private $_lowercase;
32
 
33
	/**
34
	 * Sets the database table meta data information.
35
	 * @param array table column information.
36
	 */
37
	public function __construct($tableInfo=array(),$primary=array(),$foreign=array())
38
	{
39
		$this->_info=$tableInfo;
40
		$this->_primaryKeys=$primary;
41
		$this->_foreignKeys=$foreign;
42
		$this->_columns=new TMap;
43
	}
44
 
45
	/**
46
	 * @param TDbConnection database connection.
47
	 * @return TDbCommandBuilder new command builder
48
	 */
49
	public function createCommandBuilder($connection)
50
	{
51
		Prado::using('System.Data.Common.Oracle.TOracleCommandBuilder');
52
		return new TOracleCommandBuilder($connection,$this);
53
	}
54
 
55
	/**
56
	 * @param string information array key name
57
	 * @param mixed default value if information array value is null
58
	 * @return mixed information array value.
59
	 */
60
	public function getInfo($name,$default=null)
61
	{
62
		return isset($this->_info[$name]) ? $this->_info[$name] : $default;
63
	}
64
 
65
	/**
66
	 * @param string information array key name
67
	 * @param mixed new information array value.
68
	 */
69
	protected function setInfo($name,$value)
70
	{
71
		$this->_info[$name]=$value;
72
	}
73
 
74
	/**
75
	 * @return string name of the table this column belongs to.
76
	 */
77
	public function getTableName()
78
	{
79
		return $this->getInfo('TableName');
80
	}
81
 
82
	/**
83
	 * @return string full name of the table, database dependent.
84
	 */
85
	public function getTableFullName()
86
	{
87
		return $this->_info['SchemaName'].'.'.$this->getTableName();
88
	}
89
 
90
	/**
91
	 * @return boolean whether the table is a view, default is false.
92
	 */
93
	public function getIsView()
94
	{
95
		return $this->getInfo('IsView',false);
96
	}
97
 
98
	/**
99
	 * @return TMap TDbTableColumn column meta data.
100
	 */
101
	public function getColumns()
102
	{
103
		return $this->_columns;
104
	}
105
 
106
	/**
107
	 * @param string column id
108
	 * @return TDbTableColumn column information.
109
	 */
110
	public function getColumn($name)
111
	{
112
		if(($column = $this->_columns->itemAt($name))!==null)
113
			return $column;
114
		throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName());
115
	}
116
 
117
	/**
118
	 * @param array list of column Id, empty to get all columns.
119
	 * @return array table column names (identifier quoted)
120
	 */
121
	public function getColumnNames()
122
	{
123
		foreach($this->getColumns() as $column)
124
			$names[] = $column->getColumnName();
125
		return $names;
126
	}
127
 
128
	/**
129
	 * @return string[] names of primary key columns.
130
	 */
131
	public function getPrimaryKeys()
132
	{
133
		return $this->_primaryKeys;
134
	}
135
 
136
	/**
137
	 * @return array tuples of foreign table and column name.
138
	 */
139
	public function getForeignKeys()
140
	{
141
		return $this->_foreignKeys;
142
	}
143
 
144
	/**
145
	 * @return array lowercased column key names mapped to normal column ids.
146
	 */
147
	public function getLowerCaseColumnNames()
148
	{
149
		if($this->_lowercase===null)
150
		{
151
			$this->_lowercase=array();
152
			foreach($this->getColumns()->getKeys() as $key)
153
				$this->_lowercase[strtolower($key)] = $key;
154
		}
155
		return $this->_lowercase;
156
	}
157
}
158
 
159
?>