CDbTableSchema.php 2.1 KB

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