| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: DatabaseInfo.php,v 1.15 2005/11/08 04:24:50 hlellelid Exp $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://creole.phpdb.org>. 21 */ 22 23 /** 24 * "Info" metadata class for a database. 25 * 26 * @author Hans Lellelid <hans@xmpl.org> 27 * @version $Revision: 1.15 $ 28 * @package creole.metadata 29 */ 30 abstract class DatabaseInfo { 31 32 protected $tables = array(); 33 34 protected $sequences = array(); 35 36 /** have tables been loaded */ 37 protected $tablesLoaded = false; 38 39 /** have sequences been loaded */ 40 protected $seqsLoaded = false; 41 42 /** additional vendor specific information */ 43 private $vendorSpecificInfo = array(); 44 45 /** 46 * The database Connection. 47 * @var Connection 48 */ 49 protected $conn; 50 51 /** Database name. */ 52 protected $dbname; 53 54 /** 55 * Database link 56 * @var resource 57 */ 58 protected $dblink; 59 60 /** 61 * @param Connection $dbh 62 */ 63 public function __construct(Connection $conn, $vendorInfo = array()) 64 { 65 $this->conn = $conn; 66 $this->dblink = $conn->getResource(); 67 $dsn = $conn->getDSN(); 68 $this->dbname = $dsn['database']; 69 $this->vendorSpecificInfo = $vendorInfo; 70 } 71 72 /** 73 * Get name of database. 74 * @return string 75 */ 76 public function getName() 77 { 78 return $this->dbname; 79 } 80 81 /** 82 * This method is invoked upon serialize(). 83 * Because the Info class hierarchy is recursive, we must handle 84 * the serialization and unserialization of this object. 85 * @return array The class variables that should be serialized (all must be public!). 86 */ 87 function __sleep() 88 { 89 return array('tables','sequences','conn'); 90 } 91 92 /** 93 * This method is invoked upon unserialize(). 94 * This method re-hydrates the object and restores the recursive hierarchy. 95 */ 96 function __wakeup() 97 { 98 // Re-init vars from serialized connection 99 $this->dbname = $conn->database; 100 $this->dblink = $conn->connection; 101 102 // restore chaining 103 foreach($this->tables as $tbl) { 104 $tbl->database = $this; 105 $tbl->dbname = $this->dbname; 106 $tbl->dblink = $this->dblink; 107 $tbl->schema = $this->schema; 108 } 109 } 110 111 /** 112 * Returns Connection being used. 113 * @return Connection 114 */ 115 public function getConnection() 116 { 117 return $this->conn; 118 } 119 120 /** 121 * Get the TableInfo object for specified table name. 122 * @param string $name The name of the table to retrieve. 123 * @return TableInfo 124 * @throws SQLException - if table does not exist in this db. 125 */ 126 public function getTable($name) 127 { 128 if(!$this->tablesLoaded) $this->initTables(); 129 if (!isset($this->tables[strtoupper($name)])) { 130 throw new SQLException("Database `".$this->dbname."` has no table `".$name."`"); 131 } 132 return $this->tables[ strtoupper($name) ]; 133 } 134 135 /** 136 * Return whether database contains specified table. 137 * @param string $name The table name. 138 * @return boolean 139 */ 140 public function hasTable($name) 141 { 142 if(!$this->tablesLoaded) $this->initTables(); 143 return isset($this->tables[strtoupper($name)]); 144 } 145 146 /** 147 * Gets array of TableInfo objects. 148 * @return array TableInfo[] 149 */ 150 public function getTables() 151 { 152 if(!$this->tablesLoaded) $this->initTables(); 153 return array_values($this->tables); //re-key [numerically] 154 } 155 156 /** 157 * Adds a table to this db. 158 * Table name is case-insensitive. 159 * @param TableInfo $table 160 */ 161 public function addTable(TableInfo $table) 162 { 163 $this->tables[strtoupper($table->getName())] = $table; 164 } 165 166 /** 167 * @return void 168 * @throws SQLException 169 */ 170 abstract protected function initTables(); 171 172 /** 173 * @return void 174 * @throws SQLException 175 */ 176 abstract protected function initSequences(); 177 178 /** 179 * @return boolean 180 * @throws SQLException 181 */ 182 public function isSequence($key) 183 { 184 if(!$this->seqsLoaded) $this->initSequences(); 185 return isset($this->sequences[ strtoupper($key) ]); 186 } 187 188 /** 189 * Gets array of ? objects. 190 * @return array ?[] 191 */ 192 public function getSequences() 193 { 194 if(!$this->seqsLoaded) $this->initSequences(); 195 return array_values($this->sequences); //re-key [numerically] 196 } 197 198 /** 199 * Get vendor specific optional information for this primary key. 200 * @return array vendorSpecificInfo[] 201 */ 202 public function getVendorSpecificInfo() 203 { 204 return $this->vendorSpecificInfo; 205 } 206 } 207
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |