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 SQLiteTableInfo extends TableInfo {
00032
00034 protected function initColumns()
00035 {
00036
00037 include_once 'creole/metadata/ColumnInfo.php';
00038 include_once 'creole/metadata/PrimaryKeyInfo.php';
00039 include_once 'creole/drivers/sqlite/SQLiteTypes.php';
00040
00041
00042
00043
00044
00045 $sql = 'PRAGMA table_info('.$this->name.')';
00046
00047 $res = sqlite_query($this->conn->getResource(), $sql);
00048
00049
00050 while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
00051
00052 $name = $row['name'];
00053
00054 $fulltype = $row['type'];
00055 $size = null;
00056 $precision = null;
00057 $scale = null;
00058
00059 if (preg_match('/^([^\(]+)\(\s*(\d+)\s*,\s*(\d+)\s*\)$/', $fulltype, $matches)) {
00060 $type = $matches[1];
00061 $precision = $matches[2];
00062 $scale = $matches[3];
00063 } elseif (preg_match('/^([^\(]+)\(\s*(\d+)\s*\)$/', $fulltype, $matches)) {
00064 $type = $matches[1];
00065 $size = $matches[2];
00066 } else {
00067 $type = $fulltype;
00068 }
00069
00070 $not_null = $row['notnull'];
00071 $is_nullable = !$not_null;
00072
00073 $default_val = $row['dflt_value'];
00074
00075 $this->columns[$name] = new ColumnInfo($this, $name, SQLiteTypes::getType($type), $type, $size, $precision, $scale, $is_nullable, $default_val);
00076
00077 if (($row['pk'] == 1) || (strtolower($type) == 'integer primary key')) {
00078 if ($this->primaryKey === null) {
00079 $this->primaryKey = new PrimaryKeyInfo($name);
00080 }
00081 $this->primaryKey->addColumn($this->columns[ $name ]);
00082 }
00083
00084 }
00085
00086 $this->colsLoaded = true;
00087 }
00088
00090 protected function initPrimaryKey()
00091 {
00092
00093 if (!$this->colsLoaded) $this->initColumns();
00094
00095 $this->pkLoaded = true;
00096 }
00097
00099 protected function initIndexes() {
00100
00101 include_once 'creole/metadata/IndexInfo.php';
00102
00103
00104 if (!$this->colsLoaded) $this->initColumns();
00105
00106 $sql = 'PRAGMA index_list('.$this->name.')';
00107 $res = sqlite_query($this->conn->getResource(), $sql);
00108
00109 while($row = sqlite_fetch_array($res, SQLITE_ASSOC)) {
00110 $name = $row['name'];
00111 $this->indexes[$name] = new IndexInfo($name);
00112
00113
00114 $res2 = sqlite_query($this->conn->getResource(), 'PRAGMA index_info('.$name.')');
00115 while($row2 = sqlite_fetch_array($res2, SQLITE_ASSOC)) {
00116 $colname = $row2['name'];
00117 $this->indexes[$name]->addColumn($this->columns[ $colname ]);
00118 }
00119 }
00120
00121 $this->indexesLoaded = true;
00122 }
00123
00125 protected function initForeignKeys() {
00126
00127
00128 if (!$this->colsLoaded) $this->initColumns();
00129
00130
00131
00132 $this->fksLoaded = true;
00133 }
00134
00135 }