00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 abstract class DatabaseInfo {
00031
00032 protected $tables = array();
00033
00034 protected $sequences = array();
00035
00037 protected $tablesLoaded = false;
00038
00040 protected $seqsLoaded = false;
00041
00043 private $vendorSpecificInfo = array();
00044
00049 protected $conn;
00050
00052 protected $dbname;
00053
00058 protected $dblink;
00059
00063 public function __construct(Connection $conn, $vendorInfo = array())
00064 {
00065 $this->conn = $conn;
00066 $this->dblink = $conn->getResource();
00067 $dsn = $conn->getDSN();
00068 $this->dbname = $dsn['database'];
00069 $this->vendorSpecificInfo = $vendorInfo;
00070 }
00071
00076 public function getName()
00077 {
00078 return $this->dbname;
00079 }
00080
00087 function __sleep()
00088 {
00089 return array('tables','sequences','conn');
00090 }
00091
00096 function __wakeup()
00097 {
00098
00099 $this->dbname = $conn->database;
00100 $this->dblink = $conn->connection;
00101
00102
00103 foreach($this->tables as $tbl) {
00104 $tbl->database = $this;
00105 $tbl->dbname = $this->dbname;
00106 $tbl->dblink = $this->dblink;
00107 $tbl->schema = $this->schema;
00108 }
00109 }
00110
00115 public function getConnection()
00116 {
00117 return $this->conn;
00118 }
00119
00126 public function getTable($name)
00127 {
00128 if(!$this->tablesLoaded) $this->initTables();
00129 if (!isset($this->tables[strtoupper($name)])) {
00130 throw new SQLException("Database `".$this->dbname."` has no table `".$name."`");
00131 }
00132 return $this->tables[ strtoupper($name) ];
00133 }
00134
00140 public function hasTable($name)
00141 {
00142 return isset($this->tables[strtoupper($name)]);
00143 }
00144
00149 public function getTables()
00150 {
00151 if(!$this->tablesLoaded) $this->initTables();
00152 return array_values($this->tables);
00153 }
00154
00160 public function addTable(TableInfo $table)
00161 {
00162 $this->tables[strtoupper($table->getName())] = $table;
00163 }
00164
00169 abstract protected function initTables();
00170
00175 abstract protected function initSequences();
00176
00181 public function isSequence($key)
00182 {
00183 if(!$this->seqsLoaded) $this->initSequences();
00184 return isset($this->sequences[ strtoupper($key) ]);
00185 }
00186
00191 public function getSequences()
00192 {
00193 if(!$this->seqsLoaded) $this->initSequences();
00194 return array_values($this->sequences);
00195 }
00196
00201 public function getVendorSpecificInfo()
00202 {
00203 return $this->vendorSpecificInfo;
00204 }
00205 }
00206