00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 require_once 'creole/metadata/TableInfo.php';
00023
00031 class ODBCTableInfo extends TableInfo {
00032
00036 protected function initColumns()
00037 {
00038 include_once 'creole/metadata/ColumnInfo.php';
00039 include_once 'creole/drivers/odbc/ODBCTypes.php';
00040
00041 ODBCTypes::loadTypeMap($this->conn);
00042
00043 $result = @odbc_columns($this->conn->getResource(), $this->dbname, '', $this->name);
00044
00045 if (!$result)
00046 throw new SQLException('Could not get column names', $this->conn->nativeError());
00047
00048 while (odbc_fetch_row($result))
00049 {
00050 $name = odbc_result($result, 'COLUMN_NAME');
00051 $type = odbc_result($result, 'TYPE_NAME');
00052 $length = odbc_result($result, 'LENGTH');
00053 $is_nullable = odbc_result($result, 'NULLABLE');
00054 $default = '';
00055 $precision = odbc_result($result, 'PRECISION');
00056 $scale = odbc_result($result, 'SCALE');
00057 $this->columns[$name] = new ColumnInfo($this, $name, ODBCTypes::getType($type), $type, $length, $precision, $scale, $is_nullable, $default);
00058 }
00059
00060 @odbc_free_result($result);
00061
00062 $this->colsLoaded = true;
00063 }
00064
00068 protected function initPrimaryKey()
00069 {
00070 include_once 'creole/metadata/PrimaryKeyInfo.php';
00071
00072
00073 if (!$this->colsLoaded) $this->initColumns();
00074
00075 $result = @odbc_primarykeys($this->conn->getResource(), $this->dbname, '', $this->name);
00076
00077 while (odbc_fetch_row($result))
00078 {
00079 $name = odbc_result($result, 'COLUMN_NAME');
00080
00081 if (!isset($this->primaryKey))
00082 $this->primaryKey = new PrimaryKeyInfo($name);
00083
00084 $this->primaryKey->addColumn($this->columns[$name]);
00085 }
00086
00087 @odbc_free_result($result);
00088
00089 $this->pkLoaded = true;
00090 }
00091
00095 protected function initIndexes()
00096 {
00097
00098 }
00099
00103 protected function initForeignKeys()
00104 {
00105
00106 if (!$this->colsLoaded) $this->initColumns();
00107
00108 $result = @odbc_foreignkeys($this->conn->getResource(), '', '', '', $this->dbname, '', $this->name);
00109
00110 while (odbc_fetch_row($result))
00111 {
00112 $name = odbc_result($result, 'COLUMN_NAME');
00113 $ftbl = odbc_result($result, 'FKTABLE_NAME');
00114 $fcol = odbc_result($result, 'FKCOLUMN_NAME');
00115
00116 if (!isset($this->foreignKeys[$name]))
00117 {
00118 $this->foreignKeys[$name] = new ForeignKeyInfo($name);
00119
00120 if (($foreignTable = $this->database->getTable($ftbl)) === null)
00121 {
00122 $foreignTable = new TableInfo($ltbl);
00123 $this->database->addTable($foreignTable);
00124 }
00125
00126 if (($foreignCol = $foreignTable->getColumn($name)) === null)
00127 {
00128 $foreignCol = new ColumnInfo($foreignTable, $name);
00129 $foreignTable->addColumn($foreignCol);
00130 }
00131
00132 $this->foreignKeys[$name]->addReference($this->columns[$name], $foreignCol);
00133 }
00134 }
00135
00136 @odbc_free_result($result);
00137
00138 $this->fksLoaded = true;
00139 }
00140
00141 }