1: <?php
2: /**
3: * CDbTableSchema class file.
4: *
5: * @author Qiang Xue <qiang.xue@gmail.com>
6: * @link http://www.yiiframework.com/
7: * @copyright 2008-2013 Yii Software LLC
8: * @license http://www.yiiframework.com/license/
9: */
10:
11: /**
12: * CDbTableSchema is the base class for representing the metadata of a database table.
13: *
14: * It may be extended by different DBMS driver to provide DBMS-specific table metadata.
15: *
16: * CDbTableSchema provides the following information about a table:
17: * <ul>
18: * <li>{@link name}</li>
19: * <li>{@link rawName}</li>
20: * <li>{@link columns}</li>
21: * <li>{@link primaryKey}</li>
22: * <li>{@link foreignKeys}</li>
23: * <li>{@link sequenceName}</li>
24: * </ul>
25: *
26: * @property array $columnNames List of column names.
27: *
28: * @author Qiang Xue <qiang.xue@gmail.com>
29: * @package system.db.schema
30: * @since 1.0
31: */
32: class CDbTableSchema extends CComponent
33: {
34: /**
35: * @var string name of this table.
36: */
37: public $name;
38: /**
39: * @var string raw name of this table. This is the quoted version of table name with optional schema name. It can be directly used in SQLs.
40: */
41: public $rawName;
42: /**
43: * @var string|array primary key name of this table. If composite key, an array of key names is returned.
44: */
45: public $primaryKey;
46: /**
47: * @var string sequence name for the primary key. Null if no sequence.
48: */
49: public $sequenceName;
50: /**
51: * @var array foreign keys of this table. The array is indexed by column name. Each value is an array of foreign table name and foreign column name.
52: */
53: public $foreignKeys=array();
54: /**
55: * @var array column metadata of this table. Each array element is a CDbColumnSchema object, indexed by column names.
56: */
57: public $columns=array();
58:
59: /**
60: * Gets the named column metadata.
61: * This is a convenient method for retrieving a named column even if it does not exist.
62: * @param string $name column name
63: * @return CDbColumnSchema metadata of the named column. Null if the named column does not exist.
64: */
65: public function getColumn($name)
66: {
67: return isset($this->columns[$name]) ? $this->columns[$name] : null;
68: }
69:
70: /**
71: * @return array list of column names
72: */
73: public function getColumnNames()
74: {
75: return array_keys($this->columns);
76: }
77: }
78: