[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: ODBCTableInfo.php,v 1.2 2006/01/17 19:44:39 hlellelid Exp $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://creole.phpdb.org>. 20 */ 21 22 require_once 'creole/metadata/TableInfo.php'; 23 24 /** 25 * ODBC implementation of TableInfo. 26 * 27 * @author Dave Lawson <dlawson@masterytech.com> 28 * @version $Revision: 1.2 $ 29 * @package creole.drivers.odbc.metadata 30 */ 31 class ODBCTableInfo extends TableInfo { 32 33 /** 34 * @see TableInfo::initColumns() 35 */ 36 protected function initColumns() 37 { 38 include_once 'creole/metadata/ColumnInfo.php'; 39 include_once 'creole/drivers/odbc/ODBCTypes.php'; 40 41 ODBCTypes::loadTypeMap($this->conn); 42 43 $result = @odbc_columns($this->conn->getResource(), $this->dbname, '', $this->name); 44 45 if (!$result) 46 throw new SQLException('Could not get column names', $this->conn->nativeError()); 47 48 while (odbc_fetch_row($result)) 49 { 50 $name = odbc_result($result, 'COLUMN_NAME'); 51 $type = odbc_result($result, 'TYPE_NAME'); 52 $length = odbc_result($result, 'LENGTH'); 53 $is_nullable = odbc_result($result, 'NULLABLE'); 54 $default = ''; 55 $precision = odbc_result($result, 'PRECISION'); 56 $scale = odbc_result($result, 'SCALE'); 57 $this->columns[$name] = new ColumnInfo($this, $name, ODBCTypes::getType($type), $type, $length, $precision, $scale, $is_nullable, $default); 58 } 59 60 @odbc_free_result($result); 61 62 $this->colsLoaded = true; 63 } 64 65 /** 66 * @see TableInfo::initPrimaryKey() 67 */ 68 protected function initPrimaryKey() 69 { 70 include_once 'creole/metadata/PrimaryKeyInfo.php'; 71 72 // columns have to be loaded first 73 if (!$this->colsLoaded) $this->initColumns(); 74 75 $result = @odbc_primarykeys($this->conn->getResource(), $this->dbname, '', $this->name); 76 77 while (odbc_fetch_row($result)) 78 { 79 $name = odbc_result($result, 'COLUMN_NAME'); 80 81 if (!isset($this->primaryKey)) 82 $this->primaryKey = new PrimaryKeyInfo($name); 83 84 $this->primaryKey->addColumn($this->columns[$name]); 85 } 86 87 @odbc_free_result($result); 88 89 $this->pkLoaded = true; 90 } 91 92 /** 93 * @see TableInfo::initIndexes() 94 */ 95 protected function initIndexes() 96 { 97 // Not sure if this can be implemented in a driver-independent way. 98 } 99 100 /** 101 * @see TableInfo::initForeignKeys() 102 */ 103 protected function initForeignKeys() 104 { 105 // columns have to be loaded first 106 if (!$this->colsLoaded) $this->initColumns(); 107 108 $result = @odbc_foreignkeys($this->conn->getResource(), '', '', '', $this->dbname, '', $this->name); 109 110 while (odbc_fetch_row($result)) 111 { 112 $name = odbc_result($result, 'COLUMN_NAME'); 113 $ftbl = odbc_result($result, 'FKTABLE_NAME'); 114 $fcol = odbc_result($result, 'FKCOLUMN_NAME'); 115 116 if (!isset($this->foreignKeys[$name])) 117 { 118 $this->foreignKeys[$name] = new ForeignKeyInfo($name); 119 120 if (($foreignTable = $this->database->getTable($ftbl)) === null) 121 { 122 $foreignTable = new TableInfo($ltbl); 123 $this->database->addTable($foreignTable); 124 } 125 126 if (($foreignCol = $foreignTable->getColumn($name)) === null) 127 { 128 $foreignCol = new ColumnInfo($foreignTable, $name); 129 $foreignTable->addColumn($foreignCol); 130 } 131 132 $this->foreignKeys[$name]->addReference($this->columns[$name], $foreignCol); 133 } 134 } 135 136 @odbc_free_result($result); 137 138 $this->fksLoaded = true; 139 } 140 141 }
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 |