@@ -50,7 +50,7 @@ |
||
50 | 50 | public function createCommandBuilder($connection) |
51 | 51 | { |
52 | 52 | Prado::using('System.Data.Common.Mysql.TMysqlCommandBuilder'); |
53 | - return new TMysqlCommandBuilder($connection,$this); |
|
53 | + return new TMysqlCommandBuilder($connection, $this); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class TMysqlTableColumn extends TDbTableColumn |
25 | 25 | { |
26 | - private static $types = array( |
|
26 | + private static $types=array( |
|
27 | 27 | 'integer' => array('bit', 'tinyint', 'smallint', 'mediumint', 'int', 'integer', 'bigint'), |
28 | 28 | 'boolean' => array('boolean', 'bool'), |
29 | 29 | 'float' => array('float', 'double', 'double precision', 'decimal', 'dec', 'numeric', 'fixed') |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function getPHPType() |
37 | 37 | { |
38 | - $dbtype = trim(str_replace(array('unsigned', 'zerofill'),array('','',),strtolower($this->getDbType()))); |
|
38 | + $dbtype=trim(str_replace(array('unsigned', 'zerofill'), array('', '',), strtolower($this->getDbType()))); |
|
39 | 39 | if($dbtype==='tinyint' && $this->getColumnSize()===1) |
40 | 40 | return 'boolean'; |
41 | 41 | foreach(self::$types as $type => $dbtypes) |
@@ -74,24 +74,24 @@ discard block |
||
74 | 74 | */ |
75 | 75 | protected function createTableInfo($table) |
76 | 76 | { |
77 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
78 | - $find = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
79 | - $colCase = $this->getDbConnection()->getColumnCase(); |
|
80 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
77 | + list($schemaName, $tableName)=$this->getSchemaTableName($table); |
|
78 | + $find=$schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
79 | + $colCase=$this->getDbConnection()->getColumnCase(); |
|
80 | + if($colCase!=TDbColumnCaseMode::Preserved) |
|
81 | 81 | $this->getDbConnection()->setColumnCase('Preserved'); |
82 | 82 | $this->getDbConnection()->setActive(true); |
83 | - $sql = "SHOW FULL FIELDS FROM {$find}"; |
|
84 | - $command = $this->getDbConnection()->createCommand($sql); |
|
85 | - $tableInfo = $this->createNewTableInfo($table); |
|
83 | + $sql="SHOW FULL FIELDS FROM {$find}"; |
|
84 | + $command=$this->getDbConnection()->createCommand($sql); |
|
85 | + $tableInfo=$this->createNewTableInfo($table); |
|
86 | 86 | $index=0; |
87 | 87 | foreach($command->query() as $col) |
88 | 88 | { |
89 | - $col['index'] = $index++; |
|
90 | - $this->processColumn($tableInfo,$col); |
|
89 | + $col['index']=$index++; |
|
90 | + $this->processColumn($tableInfo, $col); |
|
91 | 91 | } |
92 | 92 | if($index===0) |
93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
94 | - if($colCase != TDbColumnCaseMode::Preserved) |
|
94 | + if($colCase!=TDbColumnCaseMode::Preserved) |
|
95 | 95 | $this->getDbConnection()->setColumnCase($colCase); |
96 | 96 | return $tableInfo; |
97 | 97 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | { |
104 | 104 | if(!$this->_serverVersion) |
105 | 105 | { |
106 | - $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
|
106 | + $version=$this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
|
107 | 107 | $digits=array(); |
108 | 108 | preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits); |
109 | 109 | $this->_serverVersion=floatval($digits[1].'.'.$digits[2].$digits[3]); |
@@ -117,50 +117,50 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function processColumn($tableInfo, $col) |
119 | 119 | { |
120 | - $columnId = $col['Field']; |
|
120 | + $columnId=$col['Field']; |
|
121 | 121 | |
122 | - $info['ColumnName'] = "`$columnId`"; //quote the column names! |
|
123 | - $info['ColumnId'] = $columnId; |
|
124 | - $info['ColumnIndex'] = $col['index']; |
|
122 | + $info['ColumnName']="`$columnId`"; //quote the column names! |
|
123 | + $info['ColumnId']=$columnId; |
|
124 | + $info['ColumnIndex']=$col['index']; |
|
125 | 125 | if($col['Null']==='YES') |
126 | - $info['AllowNull'] = true; |
|
126 | + $info['AllowNull']=true; |
|
127 | 127 | if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) |
128 | 128 | $info['AutoIncrement']=true; |
129 | 129 | if($col['Default']!=="") |
130 | - $info['DefaultValue'] = $col['Default']; |
|
130 | + $info['DefaultValue']=$col['Default']; |
|
131 | 131 | |
132 | 132 | if($col['Key']==='PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) |
133 | - $info['IsPrimaryKey'] = true; |
|
133 | + $info['IsPrimaryKey']=true; |
|
134 | 134 | if($this->isForeignKeyColumn($columnId, $tableInfo)) |
135 | - $info['IsForeignKey'] = true; |
|
135 | + $info['IsForeignKey']=true; |
|
136 | 136 | |
137 | - $info['DbType'] = $col['Type']; |
|
137 | + $info['DbType']=$col['Type']; |
|
138 | 138 | $match=array(); |
139 | 139 | //find SET/ENUM values, column size, precision, and scale |
140 | 140 | if(preg_match('/\((.*)\)/', $col['Type'], $match)) |
141 | 141 | { |
142 | - $info['DbType']= preg_replace('/\(.*\)/', '', $col['Type']); |
|
142 | + $info['DbType']=preg_replace('/\(.*\)/', '', $col['Type']); |
|
143 | 143 | |
144 | 144 | //find SET/ENUM values |
145 | 145 | if($this->isEnumSetType($info['DbType'])) |
146 | - $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
|
146 | + $info['DbTypeValues']=preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
|
147 | 147 | |
148 | 148 | //find column size, precision and scale |
149 | - $pscale = array(); |
|
149 | + $pscale=array(); |
|
150 | 150 | if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) |
151 | 151 | { |
152 | 152 | if($this->isPrecisionType($info['DbType'])) |
153 | 153 | { |
154 | - $info['NumericPrecision'] = intval($pscale[1]); |
|
154 | + $info['NumericPrecision']=intval($pscale[1]); |
|
155 | 155 | if(count($pscale) > 2) |
156 | - $info['NumericScale'] = intval($pscale[2]); |
|
156 | + $info['NumericScale']=intval($pscale[2]); |
|
157 | 157 | } |
158 | 158 | else |
159 | - $info['ColumnSize'] = intval($pscale[1]); |
|
159 | + $info['ColumnSize']=intval($pscale[1]); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - $tableInfo->Columns[$columnId] = new TMysqlTableColumn($info); |
|
163 | + $tableInfo->Columns[$columnId]=new TMysqlTableColumn($info); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | protected function isPrecisionType($type) |
170 | 170 | { |
171 | - $type = strtolower(trim($type)); |
|
171 | + $type=strtolower(trim($type)); |
|
172 | 172 | return $type==='decimal' || $type==='dec' |
173 | 173 | || $type==='float' || $type==='double' |
174 | 174 | || $type==='double precision' || $type==='real'; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function isEnumSetType($type) |
181 | 181 | { |
182 | - $type = strtolower(trim($type)); |
|
182 | + $type=strtolower(trim($type)); |
|
183 | 183 | return $type==='set' || $type==='enum'; |
184 | 184 | } |
185 | 185 | |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | protected function getSchemaTableName($table) |
192 | 192 | { |
193 | 193 | //remove the back ticks and separate out the "database.table" |
194 | - $result = explode('.', str_replace('`', '', $table)); |
|
194 | + $result=explode('.', str_replace('`', '', $table)); |
|
195 | 195 | foreach($result as $name) |
196 | 196 | { |
197 | 197 | if(!$this->isValidIdentifier($name)) |
198 | 198 | { |
199 | - $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
|
199 | + $ref='http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
|
200 | 200 | throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref); |
201 | 201 | } |
202 | 202 | } |
@@ -220,14 +220,14 @@ discard block |
||
220 | 220 | */ |
221 | 221 | protected function createNewTableInfo($table) |
222 | 222 | { |
223 | - list($schemaName,$tableName) = $this->getSchemaTableName($table); |
|
224 | - $info['SchemaName'] = $schemaName; |
|
225 | - $info['TableName'] = $tableName; |
|
226 | - if($this->getIsView($schemaName,$tableName)) |
|
227 | - $info['IsView'] = true; |
|
228 | - list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
|
229 | - $class = $this->getTableInfoClass(); |
|
230 | - return new $class($info,$primary,$foreign); |
|
223 | + list($schemaName, $tableName)=$this->getSchemaTableName($table); |
|
224 | + $info['SchemaName']=$schemaName; |
|
225 | + $info['TableName']=$tableName; |
|
226 | + if($this->getIsView($schemaName, $tableName)) |
|
227 | + $info['IsView']=true; |
|
228 | + list($primary, $foreign)=$this->getConstraintKeys($schemaName, $tableName); |
|
229 | + $class=$this->getTableInfoClass(); |
|
230 | + return new $class($info, $primary, $foreign); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -240,25 +240,25 @@ discard block |
||
240 | 240 | * @return boolean true if is view, false otherwise. |
241 | 241 | * @throws TDbException if table or view does not exist. |
242 | 242 | */ |
243 | - protected function getIsView($schemaName,$tableName) |
|
243 | + protected function getIsView($schemaName, $tableName) |
|
244 | 244 | { |
245 | - if($this->getServerVersion()<5.01) |
|
245 | + if($this->getServerVersion() < 5.01) |
|
246 | 246 | return false; |
247 | 247 | if($schemaName!==null) |
248 | - $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
|
248 | + $sql="SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
|
249 | 249 | else |
250 | - $sql = "SHOW FULL TABLES LIKE :table"; |
|
250 | + $sql="SHOW FULL TABLES LIKE :table"; |
|
251 | 251 | |
252 | - $command = $this->getDbConnection()->createCommand($sql); |
|
252 | + $command=$this->getDbConnection()->createCommand($sql); |
|
253 | 253 | $command->bindValue(':table', $tableName); |
254 | 254 | try |
255 | 255 | { |
256 | - return count($result = $command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
|
256 | + return count($result=$command->queryRow()) > 0 && $result['Table_type']==='VIEW'; |
|
257 | 257 | } |
258 | 258 | catch(TDbException $e) |
259 | 259 | { |
260 | - $table = $schemaName===null?$tableName:$schemaName.'.'.$tableName; |
|
261 | - throw new TDbException('dbcommon_invalid_table_name',$table,$e->getMessage()); |
|
260 | + $table=$schemaName===null ? $tableName : $schemaName.'.'.$tableName; |
|
261 | + throw new TDbException('dbcommon_invalid_table_name', $table, $e->getMessage()); |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
@@ -270,22 +270,22 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function getConstraintKeys($schemaName, $tableName) |
272 | 272 | { |
273 | - $table = $schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
274 | - $sql = "SHOW INDEX FROM {$table}"; |
|
275 | - $command = $this->getDbConnection()->createCommand($sql); |
|
276 | - $primary = array(); |
|
273 | + $table=$schemaName===null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
|
274 | + $sql="SHOW INDEX FROM {$table}"; |
|
275 | + $command=$this->getDbConnection()->createCommand($sql); |
|
276 | + $primary=array(); |
|
277 | 277 | foreach($command->query() as $row) |
278 | 278 | { |
279 | 279 | if($row['Key_name']==='PRIMARY') |
280 | - $primary[] = $row['Column_name']; |
|
280 | + $primary[]=$row['Column_name']; |
|
281 | 281 | } |
282 | 282 | // MySQL version was increased to >=5.1.21 instead of 5.x |
283 | 283 | // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588) |
284 | 284 | if($this->getServerVersion() >= 5.121) |
285 | - $foreign = $this->getForeignConstraints($schemaName,$tableName); |
|
285 | + $foreign=$this->getForeignConstraints($schemaName, $tableName); |
|
286 | 286 | else |
287 | - $foreign = $this->findForeignConstraints($schemaName,$tableName); |
|
288 | - return array($primary,$foreign); |
|
287 | + $foreign=$this->findForeignConstraints($schemaName, $tableName); |
|
288 | + return array($primary, $foreign); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | */ |
297 | 297 | protected function getForeignConstraints($schemaName, $tableName) |
298 | 298 | { |
299 | - $andSchema = $schemaName !== null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()'; |
|
300 | - $sql = <<<EOD |
|
299 | + $andSchema=$schemaName!==null ? 'AND TABLE_SCHEMA LIKE :schema' : 'AND TABLE_SCHEMA LIKE DATABASE()'; |
|
300 | + $sql=<<<EOD |
|
301 | 301 | SELECT |
302 | 302 | CONSTRAINT_NAME as con, |
303 | 303 | COLUMN_NAME as col, |
@@ -311,15 +311,15 @@ discard block |
||
311 | 311 | AND TABLE_NAME LIKE :table |
312 | 312 | $andSchema |
313 | 313 | EOD; |
314 | - $command = $this->getDbConnection()->createCommand($sql); |
|
314 | + $command=$this->getDbConnection()->createCommand($sql); |
|
315 | 315 | $command->bindValue(':table', $tableName); |
316 | 316 | if($schemaName!==null) |
317 | 317 | $command->bindValue(':schema', $schemaName); |
318 | 318 | $fkeys=array(); |
319 | 319 | foreach($command->query() as $col) |
320 | 320 | { |
321 | - $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol']; |
|
322 | - $fkeys[$col['con']]['table'] = $col['fktable']; |
|
321 | + $fkeys[$col['con']]['keys'][$col['col']]=$col['fkcol']; |
|
322 | + $fkeys[$col['con']]['table']=$col['fktable']; |
|
323 | 323 | } |
324 | 324 | return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; |
325 | 325 | } |
@@ -332,17 +332,17 @@ discard block |
||
332 | 332 | */ |
333 | 333 | protected function getShowCreateTable($schemaName, $tableName) |
334 | 334 | { |
335 | - if(version_compare(PHP_VERSION,'5.1.3','<')) |
|
335 | + if(version_compare(PHP_VERSION, '5.1.3', '<')) |
|
336 | 336 | throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3'); |
337 | 337 | |
338 | 338 | //See http://netevil.org/node.php?nid=795&SC=1 |
339 | 339 | $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
340 | 340 | if($schemaName!==null) |
341 | - $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
|
341 | + $sql="SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
|
342 | 342 | else |
343 | - $sql = "SHOW CREATE TABLE `{$tableName}`"; |
|
344 | - $command = $this->getDbConnection()->createCommand($sql); |
|
345 | - $result = $command->queryRow(); |
|
343 | + $sql="SHOW CREATE TABLE `{$tableName}`"; |
|
344 | + $command=$this->getDbConnection()->createCommand($sql); |
|
345 | + $result=$command->queryRow(); |
|
346 | 346 | return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : ''); |
347 | 347 | } |
348 | 348 | |
@@ -354,19 +354,19 @@ discard block |
||
354 | 354 | */ |
355 | 355 | protected function findForeignConstraints($schemaName, $tableName) |
356 | 356 | { |
357 | - $sql = $this->getShowCreateTable($schemaName, $tableName); |
|
358 | - $matches =array(); |
|
359 | - $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
|
360 | - preg_match_all($regexp,$sql,$matches,PREG_SET_ORDER); |
|
361 | - $foreign = array(); |
|
357 | + $sql=$this->getShowCreateTable($schemaName, $tableName); |
|
358 | + $matches=array(); |
|
359 | + $regexp='/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
|
360 | + preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER); |
|
361 | + $foreign=array(); |
|
362 | 362 | foreach($matches as $match) |
363 | 363 | { |
364 | - $fields = array_map('trim',explode(',',str_replace('`','',$match[1]))); |
|
365 | - $fk_fields = array_map('trim',explode(',',str_replace('`','',$match[3]))); |
|
364 | + $fields=array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
|
365 | + $fk_fields=array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
|
366 | 366 | $keys=array(); |
367 | 367 | foreach($fields as $k=>$v) |
368 | - $keys[$v] = $fk_fields[$k]; |
|
369 | - $foreign[] = array('keys' => $keys, 'table' => trim($match[2])); |
|
368 | + $keys[$v]=$fk_fields[$k]; |
|
369 | + $foreign[]=array('keys' => $keys, 'table' => trim($match[2])); |
|
370 | 370 | } |
371 | 371 | return $foreign; |
372 | 372 | } |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * @var null|array |
32 | 32 | * @since 3.1.7 |
33 | 33 | */ |
34 | - private $_names = null; |
|
34 | + private $_names=null; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Sets the database table meta data information. |
38 | 38 | * @param array table column information. |
39 | 39 | */ |
40 | - public function __construct($tableInfo=array(),$primary=array(),$foreign=array()) |
|
40 | + public function __construct($tableInfo=array(), $primary=array(), $foreign=array()) |
|
41 | 41 | { |
42 | 42 | $this->_info=$tableInfo; |
43 | 43 | $this->_primaryKeys=$primary; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function createCommandBuilder($connection) |
53 | 53 | { |
54 | 54 | Prado::using('System.Data.Common.TDbCommandBuilder'); |
55 | - return new TDbCommandBuilder($connection,$this); |
|
55 | + return new TDbCommandBuilder($connection, $this); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | * @param mixed default value if information array value is null |
61 | 61 | * @return mixed information array value. |
62 | 62 | */ |
63 | - protected function getInfo($name,$default=null) |
|
63 | + protected function getInfo($name, $default=null) |
|
64 | 64 | { |
65 | 65 | return isset($this->_info[$name]) ? $this->_info[$name] : $default; |
66 | 66 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string information array key name |
70 | 70 | * @param mixed new information array value. |
71 | 71 | */ |
72 | - protected function setInfo($name,$value) |
|
72 | + protected function setInfo($name, $value) |
|
73 | 73 | { |
74 | 74 | $this->_info[$name]=$value; |
75 | 75 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function getIsView() |
97 | 97 | { |
98 | - return $this->getInfo('IsView',false); |
|
98 | + return $this->getInfo('IsView', false); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getColumn($name) |
114 | 114 | { |
115 | - if(($column = $this->_columns->itemAt($name))!==null) |
|
115 | + if(($column=$this->_columns->itemAt($name))!==null) |
|
116 | 116 | return $column; |
117 | 117 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
118 | 118 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $this->_names=array(); |
129 | 129 | foreach($this->getColumns() as $column) |
130 | - $this->_names[] = $column->getColumnName(); |
|
130 | + $this->_names[]=$column->getColumnName(); |
|
131 | 131 | } |
132 | 132 | return $this->_names; |
133 | 133 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | $this->_lowercase=array(); |
159 | 159 | foreach($this->getColumns()->getKeys() as $key) |
160 | - $this->_lowercase[strtolower($key)] = $key; |
|
160 | + $this->_lowercase[strtolower($key)]=$key; |
|
161 | 161 | } |
162 | 162 | return $this->_lowercase; |
163 | 163 | } |
@@ -69,30 +69,30 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function createTableInfo($tableName) |
71 | 71 | { |
72 | - $tableName = str_replace("'",'',$tableName); |
|
72 | + $tableName=str_replace("'", '', $tableName); |
|
73 | 73 | $this->getDbConnection()->setActive(true); |
74 | - $table = $this->getDbConnection()->quoteString($tableName); |
|
75 | - $sql = "PRAGMA table_info({$table})"; |
|
76 | - $command = $this->getDbConnection()->createCommand($sql); |
|
77 | - $foreign = $this->getForeignKeys($table); |
|
74 | + $table=$this->getDbConnection()->quoteString($tableName); |
|
75 | + $sql="PRAGMA table_info({$table})"; |
|
76 | + $command=$this->getDbConnection()->createCommand($sql); |
|
77 | + $foreign=$this->getForeignKeys($table); |
|
78 | 78 | $index=0; |
79 | 79 | $columns=array(); |
80 | 80 | $primary=array(); |
81 | 81 | foreach($command->query() as $col) |
82 | 82 | { |
83 | - $col['index'] = $index++; |
|
84 | - $column = $this->processColumn($col, $foreign); |
|
85 | - $columns[$col['name']] = $column; |
|
83 | + $col['index']=$index++; |
|
84 | + $column=$this->processColumn($col, $foreign); |
|
85 | + $columns[$col['name']]=$column; |
|
86 | 86 | if($column->getIsPrimaryKey()) |
87 | - $primary[] = $col['name']; |
|
87 | + $primary[]=$col['name']; |
|
88 | 88 | } |
89 | - $info['TableName'] = $tableName; |
|
89 | + $info['TableName']=$tableName; |
|
90 | 90 | if($this->getIsView($tableName)) |
91 | - $info['IsView'] = true; |
|
91 | + $info['IsView']=true; |
|
92 | 92 | if(count($columns)===0) |
93 | 93 | throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
94 | - $class = $this->getTableInfoClass(); |
|
95 | - $tableInfo = new $class($info,$primary,$foreign); |
|
94 | + $class=$this->getTableInfoClass(); |
|
95 | + $tableInfo=new $class($info, $primary, $foreign); |
|
96 | 96 | $tableInfo->getColumns()->copyFrom($columns); |
97 | 97 | return $tableInfo; |
98 | 98 | } |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected function getIsView($tableName) |
105 | 105 | { |
106 | - $sql = 'SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table'; |
|
106 | + $sql='SELECT count(*) FROM sqlite_master WHERE type="view" AND name= :table'; |
|
107 | 107 | $this->getDbConnection()->setActive(true); |
108 | - $command = $this->getDbConnection()->createCommand($sql); |
|
108 | + $command=$this->getDbConnection()->createCommand($sql); |
|
109 | 109 | $command->bindValue(':table', $tableName); |
110 | - return intval($command->queryScalar()) === 1; |
|
110 | + return intval($command->queryScalar())===1; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -117,39 +117,39 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function processColumn($col, $foreign) |
119 | 119 | { |
120 | - $columnId = $col['name']; //use column name as column Id |
|
120 | + $columnId=$col['name']; //use column name as column Id |
|
121 | 121 | |
122 | - $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
123 | - $info['ColumnId'] = $columnId; |
|
124 | - $info['ColumnIndex'] = $col['index']; |
|
122 | + $info['ColumnName']='"'.$columnId.'"'; //quote the column names! |
|
123 | + $info['ColumnId']=$columnId; |
|
124 | + $info['ColumnIndex']=$col['index']; |
|
125 | 125 | |
126 | 126 | if($col['notnull']!=='99') |
127 | - $info['AllowNull'] = true; |
|
127 | + $info['AllowNull']=true; |
|
128 | 128 | |
129 | 129 | if($col['pk']==='1') |
130 | - $info['IsPrimaryKey'] = true; |
|
130 | + $info['IsPrimaryKey']=true; |
|
131 | 131 | if($this->isForeignKeyColumn($columnId, $foreign)) |
132 | - $info['IsForeignKey'] = true; |
|
132 | + $info['IsForeignKey']=true; |
|
133 | 133 | |
134 | 134 | if($col['dflt_value']!==null) |
135 | - $info['DefaultValue'] = $col['dflt_value']; |
|
135 | + $info['DefaultValue']=$col['dflt_value']; |
|
136 | 136 | |
137 | - $type = strtolower($col['type']); |
|
138 | - $info['AutoIncrement'] = $type==='integer' && $col['pk']==='1'; |
|
137 | + $type=strtolower($col['type']); |
|
138 | + $info['AutoIncrement']=$type==='integer' && $col['pk']==='1'; |
|
139 | 139 | |
140 | - $info['DbType'] = $type; |
|
140 | + $info['DbType']=$type; |
|
141 | 141 | $match=array(); |
142 | 142 | if(is_int($pos=strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
143 | 143 | { |
144 | - $ps = explode(',', $match[1]); |
|
144 | + $ps=explode(',', $match[1]); |
|
145 | 145 | if(count($ps)===2) |
146 | 146 | { |
147 | - $info['NumericPrecision'] = intval($ps[0]); |
|
148 | - $info['NumericScale'] = intval($ps[1]); |
|
147 | + $info['NumericPrecision']=intval($ps[0]); |
|
148 | + $info['NumericScale']=intval($ps[1]); |
|
149 | 149 | } |
150 | 150 | else |
151 | 151 | $info['ColumnSize']=intval($match[1]); |
152 | - $info['DbType'] = substr($type,0,$pos); |
|
152 | + $info['DbType']=substr($type, 0, $pos); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | return new TSqliteTableColumn($info); |
@@ -163,13 +163,13 @@ discard block |
||
163 | 163 | */ |
164 | 164 | protected function getForeignKeys($table) |
165 | 165 | { |
166 | - $sql = "PRAGMA foreign_key_list({$table})"; |
|
167 | - $command = $this->getDbConnection()->createCommand($sql); |
|
168 | - $fkeys = array(); |
|
166 | + $sql="PRAGMA foreign_key_list({$table})"; |
|
167 | + $command=$this->getDbConnection()->createCommand($sql); |
|
168 | + $fkeys=array(); |
|
169 | 169 | foreach($command->query() as $col) |
170 | 170 | { |
171 | - $fkeys[$col['table']]['keys'][$col['from']] = $col['to']; |
|
172 | - $fkeys[$col['table']]['table'] = $col['table']; |
|
171 | + $fkeys[$col['table']]['keys'][$col['from']]=$col['to']; |
|
172 | + $fkeys[$col['table']]['table']=$col['table']; |
|
173 | 173 | } |
174 | 174 | return count($fkeys) > 0 ? array_values($fkeys) : $fkeys; |
175 | 175 | } |
@@ -30,12 +30,12 @@ |
||
30 | 30 | */ |
31 | 31 | public function applyLimitOffset($sql, $limit=-1, $offset=-1) |
32 | 32 | { |
33 | - $limit = $limit!==null ? intval($limit) : -1; |
|
34 | - $offset = $offset!==null ? intval($offset) : -1; |
|
33 | + $limit=$limit!==null ? intval($limit) : -1; |
|
34 | + $offset=$offset!==null ? intval($offset) : -1; |
|
35 | 35 | if($limit > 0 || $offset > 0) |
36 | 36 | { |
37 | - $limitStr = ' LIMIT '.$limit; |
|
38 | - $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
37 | + $limitStr=' LIMIT '.$limit; |
|
38 | + $offsetStr=$offset >= 0 ? ' OFFSET '.$offset : ''; |
|
39 | 39 | return $sql.$limitStr.$offsetStr; |
40 | 40 | } |
41 | 41 | else |
@@ -31,7 +31,7 @@ |
||
31 | 31 | public function createCommandBuilder($connection) |
32 | 32 | { |
33 | 33 | Prado::using('System.Data.Common.Sqlite.TSqliteCommandBuilder'); |
34 | - return new TSqliteCommandBuilder($connection,$this); |
|
34 | + return new TSqliteCommandBuilder($connection, $this); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | /** |
27 | 27 | * @TODO add sqlite types. |
28 | 28 | */ |
29 | - private static $types = array(); |
|
29 | + private static $types=array(); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Overrides parent implementation, returns PHP type from the db type. |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function getPHPType() |
36 | 36 | { |
37 | - $dbtype = strtolower($this->getDbType()); |
|
37 | + $dbtype=strtolower($this->getDbType()); |
|
38 | 38 | foreach(self::$types as $type => $dbtypes) |
39 | 39 | { |
40 | 40 | if(in_array($dbtype, $dbtypes)) |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $db=$this->getDbConnection(); |
64 | 64 | foreach($xml['database'] as $name=>$value) |
65 | - $db->setSubProperty($name,$value); |
|
65 | + $db->setSubProperty($name, $value); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | else |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $db=$this->getDbConnection(); |
73 | 73 | foreach($prop->getAttributes() as $name=>$value) |
74 | - $db->setSubproperty($name,$value); |
|
74 | + $db->setSubproperty($name, $value); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | if($this->_conn===null) |
107 | 107 | { |
108 | 108 | if($this->_connID!=='') |
109 | - $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
|
109 | + $this->_conn=$this->findConnectionByID($this->getConnectionID()); |
|
110 | 110 | else |
111 | - $this->_conn = Prado::createComponent($this->getConnectionClass()); |
|
111 | + $this->_conn=Prado::createComponent($this->getConnectionClass()); |
|
112 | 112 | } |
113 | 113 | return $this->_conn; |
114 | 114 | } |
@@ -154,12 +154,12 @@ discard block |
||
154 | 154 | */ |
155 | 155 | protected function findConnectionByID($id) |
156 | 156 | { |
157 | - $conn = $this->getApplication()->getModule($id); |
|
157 | + $conn=$this->getApplication()->getModule($id); |
|
158 | 158 | if($conn instanceof TDbConnection) |
159 | 159 | return $conn; |
160 | 160 | else if($conn instanceof TDataSourceConfig) |
161 | 161 | return $conn->getDbConnection(); |
162 | 162 | else |
163 | - throw new TConfigurationException('datasource_dbconnection_invalid',$id); |
|
163 | + throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
|
164 | 164 | } |
165 | 165 | } |