@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | list($schemaName, $tableName) = $this->getSchemaTableName($table); |
83 | 83 | $find = $schemaName === null ? "`{$tableName}`" : "`{$schemaName}`.`{$tableName}`"; |
84 | 84 | $colCase = $this->getDbConnection()->getColumnCase(); |
85 | - if ($colCase != TDbColumnCaseMode::Preserved) { |
|
85 | + if($colCase != TDbColumnCaseMode::Preserved) { |
|
86 | 86 | $this->getDbConnection()->setColumnCase('Preserved'); |
87 | 87 | } |
88 | 88 | $this->getDbConnection()->setActive(true); |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | $command = $this->getDbConnection()->createCommand($sql); |
91 | 91 | $tableInfo = $this->createNewTableInfo($table); |
92 | 92 | $index = 0; |
93 | - foreach ($command->query() as $col) { |
|
93 | + foreach($command->query() as $col) { |
|
94 | 94 | $col['index'] = $index++; |
95 | 95 | $this->processColumn($tableInfo, $col); |
96 | 96 | } |
97 | - if ($index === 0) { |
|
97 | + if($index === 0) { |
|
98 | 98 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
99 | 99 | } |
100 | - if ($colCase != TDbColumnCaseMode::Preserved) { |
|
100 | + if($colCase != TDbColumnCaseMode::Preserved) { |
|
101 | 101 | $this->getDbConnection()->setColumnCase($colCase); |
102 | 102 | } |
103 | 103 | return $tableInfo; |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | protected function getServerVersion() |
110 | 110 | { |
111 | - if (!$this->_serverVersion) { |
|
111 | + if(!$this->_serverVersion) { |
|
112 | 112 | $version = $this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION); |
113 | 113 | $digits = []; |
114 | 114 | preg_match('/(\d+)\.(\d+)\.(\d+)/', $version, $digits); |
@@ -128,40 +128,40 @@ discard block |
||
128 | 128 | $info['ColumnName'] = "`$columnId`"; //quote the column names! |
129 | 129 | $info['ColumnId'] = $columnId; |
130 | 130 | $info['ColumnIndex'] = $col['index']; |
131 | - if ($col['Null'] === 'YES') { |
|
131 | + if($col['Null'] === 'YES') { |
|
132 | 132 | $info['AllowNull'] = true; |
133 | 133 | } |
134 | - if (is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) { |
|
134 | + if(is_int(strpos(strtolower($col['Extra']), 'auto_increment'))) { |
|
135 | 135 | $info['AutoIncrement'] = true; |
136 | 136 | } |
137 | - if ($col['Default'] !== "") { |
|
137 | + if($col['Default'] !== "") { |
|
138 | 138 | $info['DefaultValue'] = $col['Default']; |
139 | 139 | } |
140 | 140 | |
141 | - if ($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
141 | + if($col['Key'] === 'PRI' || in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
142 | 142 | $info['IsPrimaryKey'] = true; |
143 | 143 | } |
144 | - if ($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
144 | + if($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
145 | 145 | $info['IsForeignKey'] = true; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $info['DbType'] = $col['Type']; |
149 | 149 | $match = []; |
150 | 150 | //find SET/ENUM values, column size, precision, and scale |
151 | - if (preg_match('/\((.*)\)/', $col['Type'], $match)) { |
|
151 | + if(preg_match('/\((.*)\)/', $col['Type'], $match)) { |
|
152 | 152 | $info['DbType'] = preg_replace('/\(.*\)/', '', $col['Type']); |
153 | 153 | |
154 | 154 | //find SET/ENUM values |
155 | - if ($this->isEnumSetType($info['DbType'])) { |
|
155 | + if($this->isEnumSetType($info['DbType'])) { |
|
156 | 156 | $info['DbTypeValues'] = preg_split("/[',]/S", $match[1], -1, PREG_SPLIT_NO_EMPTY); |
157 | 157 | } |
158 | 158 | |
159 | 159 | //find column size, precision and scale |
160 | 160 | $pscale = []; |
161 | - if (preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) { |
|
162 | - if ($this->isPrecisionType($info['DbType'])) { |
|
161 | + if(preg_match('/(\d+)(?:,(\d+))?+/', $match[1], $pscale)) { |
|
162 | + if($this->isPrecisionType($info['DbType'])) { |
|
163 | 163 | $info['NumericPrecision'] = intval($pscale[1]); |
164 | - if (count($pscale) > 2) { |
|
164 | + if(count($pscale) > 2) { |
|
165 | 165 | $info['NumericScale'] = intval($pscale[2]); |
166 | 166 | } |
167 | 167 | } else { |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | { |
203 | 203 | //remove the back ticks and separate out the "database.table" |
204 | 204 | $result = explode('.', str_replace('`', '', $table)); |
205 | - foreach ($result as $name) { |
|
206 | - if (!$this->isValidIdentifier($name)) { |
|
205 | + foreach($result as $name) { |
|
206 | + if(!$this->isValidIdentifier($name)) { |
|
207 | 207 | $ref = 'http://dev.mysql.com/doc/refman/5.0/en/identifiers.html'; |
208 | 208 | throw new TDbException('dbcommon_invalid_identifier_name', $table, $ref); |
209 | 209 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | list($schemaName, $tableName) = $this->getSchemaTableName($table); |
232 | 232 | $info['SchemaName'] = $schemaName; |
233 | 233 | $info['TableName'] = $tableName; |
234 | - if ($this->getIsView($schemaName, $tableName)) { |
|
234 | + if($this->getIsView($schemaName, $tableName)) { |
|
235 | 235 | $info['IsView'] = true; |
236 | 236 | } |
237 | 237 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
@@ -251,10 +251,10 @@ discard block |
||
251 | 251 | */ |
252 | 252 | protected function getIsView($schemaName, $tableName) |
253 | 253 | { |
254 | - if ($this->getServerVersion() < 5.01) { |
|
254 | + if($this->getServerVersion() < 5.01) { |
|
255 | 255 | return false; |
256 | 256 | } |
257 | - if ($schemaName !== null) { |
|
257 | + if($schemaName !== null) { |
|
258 | 258 | $sql = "SHOW FULL TABLES FROM `{$schemaName}` LIKE :table"; |
259 | 259 | } else { |
260 | 260 | $sql = "SHOW FULL TABLES LIKE :table"; |
@@ -282,19 +282,19 @@ discard block |
||
282 | 282 | $sql = "SHOW INDEX FROM {$table}"; |
283 | 283 | $command = $this->getDbConnection()->createCommand($sql); |
284 | 284 | $primary = []; |
285 | - foreach ($command->query() as $row) { |
|
286 | - if ($row['Key_name'] === 'PRIMARY') { |
|
285 | + foreach($command->query() as $row) { |
|
286 | + if($row['Key_name'] === 'PRIMARY') { |
|
287 | 287 | $primary[] = $row['Column_name']; |
288 | 288 | } |
289 | 289 | } |
290 | 290 | // MySQL version was increased to >=5.1.21 instead of 5.x |
291 | 291 | // due to a MySQL bug (http://bugs.mysql.com/bug.php?id=19588) |
292 | - if ($this->getServerVersion() >= 5.121) { |
|
292 | + if($this->getServerVersion() >= 5.121) { |
|
293 | 293 | $foreign = $this->getForeignConstraints($schemaName, $tableName); |
294 | 294 | } else { |
295 | 295 | $foreign = $this->findForeignConstraints($schemaName, $tableName); |
296 | 296 | } |
297 | - return [$primary,$foreign]; |
|
297 | + return [$primary, $foreign]; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | EOD; |
323 | 323 | $command = $this->getDbConnection()->createCommand($sql); |
324 | 324 | $command->bindValue(':table', $tableName); |
325 | - if ($schemaName !== null) { |
|
325 | + if($schemaName !== null) { |
|
326 | 326 | $command->bindValue(':schema', $schemaName); |
327 | 327 | } |
328 | 328 | $fkeys = []; |
329 | - foreach ($command->query() as $col) { |
|
329 | + foreach($command->query() as $col) { |
|
330 | 330 | $fkeys[$col['con']]['keys'][$col['col']] = $col['fkcol']; |
331 | 331 | $fkeys[$col['con']]['table'] = $col['fktable']; |
332 | 332 | } |
@@ -341,13 +341,13 @@ discard block |
||
341 | 341 | */ |
342 | 342 | protected function getShowCreateTable($schemaName, $tableName) |
343 | 343 | { |
344 | - if (version_compare(PHP_VERSION, '5.1.3', '<')) { |
|
344 | + if(version_compare(PHP_VERSION, '5.1.3', '<')) { |
|
345 | 345 | throw new TDbException('dbmetadata_requires_php_version', 'Mysql 4.1.x', '5.1.3'); |
346 | 346 | } |
347 | 347 | |
348 | 348 | //See http://netevil.org/node.php?nid=795&SC=1 |
349 | 349 | $this->getDbConnection()->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); |
350 | - if ($schemaName !== null) { |
|
350 | + if($schemaName !== null) { |
|
351 | 351 | $sql = "SHOW CREATE TABLE `{$schemaName}`.`{$tableName}`"; |
352 | 352 | } else { |
353 | 353 | $sql = "SHOW CREATE TABLE `{$tableName}`"; |
@@ -370,11 +370,11 @@ discard block |
||
370 | 370 | $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+`?([^`]+)`?\s\(([^\)]+)\)/mi'; |
371 | 371 | preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER); |
372 | 372 | $foreign = []; |
373 | - foreach ($matches as $match) { |
|
373 | + foreach($matches as $match) { |
|
374 | 374 | $fields = array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
375 | 375 | $fk_fields = array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
376 | 376 | $keys = []; |
377 | - foreach ($fields as $k => $v) { |
|
377 | + foreach($fields as $k => $v) { |
|
378 | 378 | $keys[$v] = $fk_fields[$k]; |
379 | 379 | } |
380 | 380 | $foreign[] = ['keys' => $keys, 'table' => trim($match[2])]; |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | */ |
390 | 390 | protected function isForeignKeyColumn($columnId, $tableInfo) |
391 | 391 | { |
392 | - foreach ($tableInfo->getForeignKeys() as $fk) { |
|
393 | - if (in_array($columnId, array_keys($fk['keys']))) { |
|
392 | + foreach($tableInfo->getForeignKeys() as $fk) { |
|
393 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
394 | 394 | return true; |
395 | 395 | } |
396 | 396 | } |
@@ -405,11 +405,11 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function findTableNames($schema = '') |
407 | 407 | { |
408 | - if ($schema === '') { |
|
408 | + if($schema === '') { |
|
409 | 409 | return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn(); |
410 | 410 | } |
411 | 411 | $names = $this->getDbConnection()->createCommand('SHOW TABLES FROM ' . $this->quoteTableName($schema))->queryColumn(); |
412 | - foreach ($names as &$name) { |
|
412 | + foreach($names as &$name) { |
|
413 | 413 | $name = $schema . '.' . $name; |
414 | 414 | } |
415 | 415 | return $names; |
@@ -38,12 +38,12 @@ |
||
38 | 38 | */ |
39 | 39 | public function getPHPType() |
40 | 40 | { |
41 | - $dbtype = trim(str_replace(['unsigned', 'zerofill'], ['','',], strtolower($this->getDbType()))); |
|
42 | - if ($dbtype === 'tinyint' && $this->getColumnSize() === 1) { |
|
41 | + $dbtype = trim(str_replace(['unsigned', 'zerofill'], ['', '', ], strtolower($this->getDbType()))); |
|
42 | + if($dbtype === 'tinyint' && $this->getColumnSize() === 1) { |
|
43 | 43 | return 'boolean'; |
44 | 44 | } |
45 | - foreach (self::$types as $type => $dbtypes) { |
|
46 | - if (in_array($dbtype, $dbtypes)) { |
|
45 | + foreach(self::$types as $type => $dbtypes) { |
|
46 | + if(in_array($dbtype, $dbtypes)) { |
|
47 | 47 | return $type; |
48 | 48 | } |
49 | 49 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | { |
65 | 65 | $conn->setActive(true); //must be connected before retrieving driver name |
66 | 66 | $driver = $conn->getDriverName(); |
67 | - switch (strtolower($driver)) { |
|
67 | + switch(strtolower($driver)) { |
|
68 | 68 | case 'pgsql': |
69 | 69 | return new TPgsqlMetaData($conn); |
70 | 70 | case 'mysqli': |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | public function getTableInfo($tableName = null) |
95 | 95 | { |
96 | 96 | $key = $tableName === null ? $this->getDbConnection()->getConnectionString() : $tableName; |
97 | - if (!isset($this->_tableInfoCache[$key])) { |
|
97 | + if(!isset($this->_tableInfoCache[$key])) { |
|
98 | 98 | $class = $this->getTableInfoClass(); |
99 | 99 | $tableInfo = $tableName === null ? new $class : $this->createTableInfo($tableName); |
100 | 100 | $this->_tableInfoCache[$key] = $tableInfo; |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | $rgt = $lft = isset($args[1]) ? $args[1] : ''; |
142 | 142 | $rgt = isset($args[2]) ? $args[2] : $rgt; |
143 | 143 | |
144 | - if (strpos($name, '.') === false) { |
|
144 | + if(strpos($name, '.') === false) { |
|
145 | 145 | return $lft . $name . $rgt; |
146 | 146 | } |
147 | 147 | $names = explode('.', $name); |
148 | - foreach ($names as &$n) { |
|
148 | + foreach($names as &$n) { |
|
149 | 149 | $n = $lft . $n . $rgt; |
150 | 150 | } |
151 | 151 | return implode('.', $names); |
@@ -83,30 +83,30 @@ discard block |
||
83 | 83 | WHERE t.table_name = c.table_name |
84 | 84 | AND t.table_name = :table |
85 | 85 | EOD; |
86 | - if ($schemaName !== null) { |
|
86 | + if($schemaName !== null) { |
|
87 | 87 | $sql .= ' AND t.table_schema = :schema'; |
88 | 88 | } |
89 | - if ($catalogName !== null) { |
|
89 | + if($catalogName !== null) { |
|
90 | 90 | $sql .= ' AND t.table_catalog = :catalog'; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $command = $this->getDbConnection()->createCommand($sql); |
94 | 94 | $command->bindValue(':table', $tableName); |
95 | - if ($schemaName !== null) { |
|
95 | + if($schemaName !== null) { |
|
96 | 96 | $command->bindValue(':schema', $schemaName); |
97 | 97 | } |
98 | - if ($catalogName !== null) { |
|
98 | + if($catalogName !== null) { |
|
99 | 99 | $command->bindValue(':catalog', $catalogName); |
100 | 100 | } |
101 | 101 | |
102 | 102 | $tableInfo = null; |
103 | - foreach ($command->query() as $col) { |
|
104 | - if ($tableInfo === null) { |
|
103 | + foreach($command->query() as $col) { |
|
104 | + if($tableInfo === null) { |
|
105 | 105 | $tableInfo = $this->createNewTableInfo($col); |
106 | 106 | } |
107 | 107 | $this->processColumn($tableInfo, $col); |
108 | 108 | } |
109 | - if ($tableInfo === null) { |
|
109 | + if($tableInfo === null) { |
|
110 | 110 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
111 | 111 | } |
112 | 112 | return $tableInfo; |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | { |
121 | 121 | //remove possible delimiters |
122 | 122 | $result = explode('.', preg_replace('/\[|\]|"/', '', $table)); |
123 | - if (count($result) === 1) { |
|
124 | - return [null,null,$result[0]]; |
|
123 | + if(count($result) === 1) { |
|
124 | + return [null, null, $result[0]]; |
|
125 | 125 | } |
126 | - if (count($result) === 2) { |
|
127 | - return [null,$result[0],$result[1]]; |
|
126 | + if(count($result) === 2) { |
|
127 | + return [null, $result[0], $result[1]]; |
|
128 | 128 | } |
129 | - if (count($result) > 2) { |
|
130 | - return [$result[0],$result[1],$result[2]]; |
|
129 | + if(count($result) > 2) { |
|
130 | + return [$result[0], $result[1], $result[2]]; |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
@@ -142,31 +142,31 @@ discard block |
||
142 | 142 | $info['ColumnName'] = "[$columnId]"; //quote the column names! |
143 | 143 | $info['ColumnId'] = $columnId; |
144 | 144 | $info['ColumnIndex'] = intval($col['ORDINAL_POSITION']) - 1; //zero-based index |
145 | - if ($col['IS_NULLABLE'] !== 'NO') { |
|
145 | + if($col['IS_NULLABLE'] !== 'NO') { |
|
146 | 146 | $info['AllowNull'] = true; |
147 | 147 | } |
148 | - if ($col['COLUMN_DEFAULT'] !== null) { |
|
148 | + if($col['COLUMN_DEFAULT'] !== null) { |
|
149 | 149 | $info['DefaultValue'] = $col['COLUMN_DEFAULT']; |
150 | 150 | } |
151 | 151 | |
152 | - if (in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
152 | + if(in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
153 | 153 | $info['IsPrimaryKey'] = true; |
154 | 154 | } |
155 | - if ($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
155 | + if($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
156 | 156 | $info['IsForeignKey'] = true; |
157 | 157 | } |
158 | 158 | |
159 | - if ($col['IsIdentity'] === '1') { |
|
159 | + if($col['IsIdentity'] === '1') { |
|
160 | 160 | $info['AutoIncrement'] = true; |
161 | 161 | } |
162 | 162 | $info['DbType'] = $col['DATA_TYPE']; |
163 | - if ($col['CHARACTER_MAXIMUM_LENGTH'] !== null) { |
|
163 | + if($col['CHARACTER_MAXIMUM_LENGTH'] !== null) { |
|
164 | 164 | $info['ColumnSize'] = intval($col['CHARACTER_MAXIMUM_LENGTH']); |
165 | 165 | } |
166 | - if ($col['NUMERIC_PRECISION'] !== null) { |
|
166 | + if($col['NUMERIC_PRECISION'] !== null) { |
|
167 | 167 | $info['NumericPrecision'] = intval($col['NUMERIC_PRECISION']); |
168 | 168 | } |
169 | - if ($col['NUMERIC_SCALE'] !== null) { |
|
169 | + if($col['NUMERIC_SCALE'] !== null) { |
|
170 | 170 | $info['NumericScale'] = intval($col['NUMERIC_SCALE']); |
171 | 171 | } |
172 | 172 | $tableInfo->Columns[$columnId] = new TMssqlTableColumn($info); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | $info['CatalogName'] = $col['TABLE_CATALOG']; |
183 | 183 | $info['SchemaName'] = $col['TABLE_SCHEMA']; |
184 | 184 | $info['TableName'] = $col['TABLE_NAME']; |
185 | - if ($col['TABLE_TYPE'] === 'VIEW') { |
|
185 | + if($col['TABLE_TYPE'] === 'VIEW') { |
|
186 | 186 | $info['IsView'] = true; |
187 | 187 | } |
188 | 188 | list($primary, $foreign) = $this->getConstraintKeys($col); |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | $command = $this->getDbConnection()->createCommand($sql); |
213 | 213 | $command->bindValue(':table', $col['TABLE_NAME']); |
214 | 214 | $primary = []; |
215 | - foreach ($command->query()->readAll() as $field) { |
|
215 | + foreach($command->query()->readAll() as $field) { |
|
216 | 216 | $primary[] = $field['field_name']; |
217 | 217 | } |
218 | 218 | $foreign = $this->getForeignConstraints($col); |
219 | - return [$primary,$foreign]; |
|
219 | + return [$primary, $foreign]; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | $command->bindValue(':table', $col['TABLE_NAME']); |
258 | 258 | $fkeys = []; |
259 | 259 | $catalogSchema = "[{$col['TABLE_CATALOG']}].[{$col['TABLE_SCHEMA']}]"; |
260 | - foreach ($command->query() as $info) { |
|
260 | + foreach($command->query() as $info) { |
|
261 | 261 | $fkeys[$info['FK_CONSTRAINT_NAME']]['keys'][$info['FK_COLUMN_NAME']] = $info['UQ_COLUMN_NAME']; |
262 | 262 | $fkeys[$info['FK_CONSTRAINT_NAME']]['table'] = $info['UQ_TABLE_NAME']; |
263 | 263 | } |
@@ -271,8 +271,8 @@ discard block |
||
271 | 271 | */ |
272 | 272 | protected function isForeignKeyColumn($columnId, $tableInfo) |
273 | 273 | { |
274 | - foreach ($tableInfo->getForeignKeys() as $fk) { |
|
275 | - if (in_array($columnId, array_keys($fk['keys']))) { |
|
274 | + foreach($tableInfo->getForeignKeys() as $fk) { |
|
275 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
276 | 276 | return true; |
277 | 277 | } |
278 | 278 | } |
@@ -296,8 +296,8 @@ discard block |
||
296 | 296 | $command->bindParam(":schema", $schema); |
297 | 297 | $rows = $command->queryAll(); |
298 | 298 | $names = []; |
299 | - foreach ($rows as $row) { |
|
300 | - if ($schema == self::DEFAULT_SCHEMA) { |
|
299 | + foreach($rows as $row) { |
|
300 | + if($schema == self::DEFAULT_SCHEMA) { |
|
301 | 301 | $names[] = $row['TABLE_NAME']; |
302 | 302 | } else { |
303 | 303 | $names[] = $schema . '.' . $row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']; |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function getLastInsertID() |
32 | 32 | { |
33 | - foreach ($this->getTableInfo()->getColumns() as $column) { |
|
34 | - if ($column->hasSequence()) { |
|
33 | + foreach($this->getTableInfo()->getColumns() as $column) { |
|
34 | + if($column->hasSequence()) { |
|
35 | 35 | $command = $this->getDbConnection()->createCommand('SELECT @@Identity'); |
36 | 36 | return intval($command->queryScalar()); |
37 | 37 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | { |
83 | 83 | $limit = $limit !== null ? intval($limit) : -1; |
84 | 84 | $offset = $offset !== null ? intval($offset) : -1; |
85 | - if ($limit > 0 && $offset <= 0) { //just limit |
|
85 | + if($limit > 0 && $offset <= 0) { //just limit |
|
86 | 86 | $sql = preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', "\\1SELECT\\2 TOP $limit", $sql); |
87 | - } elseif ($limit > 0 && $offset > 0) { |
|
87 | + } elseif($limit > 0 && $offset > 0) { |
|
88 | 88 | $sql = $this->rewriteLimitOffsetSql($sql, $limit, $offset); |
89 | 89 | } |
90 | 90 | return $sql; |
@@ -118,18 +118,18 @@ discard block |
||
118 | 118 | */ |
119 | 119 | protected function findOrdering($sql) |
120 | 120 | { |
121 | - if (!preg_match('/ORDER BY/i', $sql)) { |
|
121 | + if(!preg_match('/ORDER BY/i', $sql)) { |
|
122 | 122 | return []; |
123 | 123 | } |
124 | 124 | $matches = []; |
125 | 125 | $ordering = []; |
126 | 126 | preg_match_all('/(ORDER BY)[\s"\[](.*)(ASC|DESC)?(?:[\s"\[]|$|COMPUTE|FOR)/i', $sql, $matches); |
127 | - if (count($matches) > 1 && count($matches[2]) > 0) { |
|
127 | + if(count($matches) > 1 && count($matches[2]) > 0) { |
|
128 | 128 | $parts = explode(',', $matches[2][0]); |
129 | - foreach ($parts as $part) { |
|
129 | + foreach($parts as $part) { |
|
130 | 130 | $subs = []; |
131 | - if (preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs)) { |
|
132 | - if (count($subs) > 1 && count($subs[2]) > 0) { |
|
131 | + if(preg_match_all('/(.*)[\s"\]](ASC|DESC)$/i', trim($part), $subs)) { |
|
132 | + if(count($subs) > 1 && count($subs[2]) > 0) { |
|
133 | 133 | $ordering[$subs[1][0]] = $subs[2][0]; |
134 | 134 | } |
135 | 135 | //else what? |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function joinOrdering($orders) |
149 | 149 | { |
150 | - if (count($orders) > 0) { |
|
150 | + if(count($orders) > 0) { |
|
151 | 151 | $str = []; |
152 | - foreach ($orders as $column => $direction) { |
|
152 | + foreach($orders as $column => $direction) { |
|
153 | 153 | $str[] = $column . ' ' . $direction; |
154 | 154 | } |
155 | 155 | return 'ORDER BY ' . implode(', ', $str); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | protected function reverseDirection($orders) |
164 | 164 | { |
165 | - foreach ($orders as $column => $direction) { |
|
165 | + foreach($orders as $column => $direction) { |
|
166 | 166 | $orders[$column] = strtolower(trim($direction)) === 'desc' ? 'ASC' : 'DESC'; |
167 | 167 | } |
168 | 168 | return $orders; |
@@ -60,17 +60,17 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function init($xml) |
62 | 62 | { |
63 | - if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { |
|
64 | - if (isset($xml['database']) && is_array($xml['database'])) { |
|
63 | + if($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) { |
|
64 | + if(isset($xml['database']) && is_array($xml['database'])) { |
|
65 | 65 | $db = $this->getDbConnection(); |
66 | - foreach ($xml['database'] as $name => $value) { |
|
66 | + foreach($xml['database'] as $name => $value) { |
|
67 | 67 | $db->setSubProperty($name, $value); |
68 | 68 | } |
69 | 69 | } |
70 | 70 | } else { |
71 | - if ($prop = $xml->getElementByTagName('database')) { |
|
71 | + if($prop = $xml->getElementByTagName('database')) { |
|
72 | 72 | $db = $this->getDbConnection(); |
73 | - foreach ($prop->getAttributes() as $name => $value) { |
|
73 | + foreach($prop->getAttributes() as $name => $value) { |
|
74 | 74 | $db->setSubproperty($name, $value); |
75 | 75 | } |
76 | 76 | } |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function getDbConnection() |
106 | 106 | { |
107 | - if ($this->_conn === null) { |
|
108 | - if ($this->_connID !== '') { |
|
107 | + if($this->_conn === null) { |
|
108 | + if($this->_connID !== '') { |
|
109 | 109 | $this->_conn = $this->findConnectionByID($this->getConnectionID()); |
110 | 110 | } else { |
111 | 111 | $this->_conn = Prado::createComponent($this->getConnectionClass()); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function setConnectionClass($value) |
144 | 144 | { |
145 | - if ($this->_conn !== null) { |
|
145 | + if($this->_conn !== null) { |
|
146 | 146 | throw new TConfigurationException('datasource_dbconnection_exists', $value); |
147 | 147 | } |
148 | 148 | $this->_connClass = $value; |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | protected function findConnectionByID($id) |
158 | 158 | { |
159 | 159 | $conn = $this->getApplication()->getModule($id); |
160 | - if ($conn instanceof TDbConnection) { |
|
160 | + if($conn instanceof TDbConnection) { |
|
161 | 161 | return $conn; |
162 | - } elseif ($conn instanceof TDataSourceConfig) { |
|
162 | + } elseif($conn instanceof TDataSourceConfig) { |
|
163 | 163 | return $conn->getDbConnection(); |
164 | 164 | } else { |
165 | 165 | throw new TConfigurationException('datasource_dbconnection_invalid', $id); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function prepare() |
114 | 114 | { |
115 | - if ($this->_statement == null) { |
|
115 | + if($this->_statement == null) { |
|
116 | 116 | try { |
117 | 117 | $this->_statement = $this->getConnection()->getPdoInstance()->prepare($this->getText()); |
118 | 118 | } catch (Exception $e) { |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | public function bindParameter($name, &$value, $dataType = null, $length = null) |
146 | 146 | { |
147 | 147 | $this->prepare(); |
148 | - if ($dataType === null) { |
|
148 | + if($dataType === null) { |
|
149 | 149 | $this->_statement->bindParam($name, $value); |
150 | - } elseif ($length === null) { |
|
150 | + } elseif($length === null) { |
|
151 | 151 | $this->_statement->bindParam($name, $value, $dataType); |
152 | 152 | } else { |
153 | 153 | $this->_statement->bindParam($name, $value, $dataType, $length); |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | public function bindValue($name, $value, $dataType = null) |
168 | 168 | { |
169 | 169 | $this->prepare(); |
170 | - if ($dataType === null) { |
|
170 | + if($dataType === null) { |
|
171 | 171 | $this->_statement->bindValue($name, $value); |
172 | 172 | } else { |
173 | 173 | $this->_statement->bindValue($name, $value, $dataType); |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | try { |
187 | 187 | // Do not trace because it will remain even in Performance mode |
188 | 188 | // Prado::trace('Execute Command: '.$this->getDebugStatementText(), 'Prado\Data'); |
189 | - if ($this->_statement instanceof PDOStatement) { |
|
189 | + if($this->_statement instanceof PDOStatement) { |
|
190 | 190 | $this->_statement->execute(); |
191 | 191 | return $this->_statement->rowCount(); |
192 | 192 | } else { |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | { |
219 | 219 | try { |
220 | 220 | // Prado::trace('Query: '.$this->getDebugStatementText(), 'Prado\Data'); |
221 | - if ($this->_statement instanceof PDOStatement) { |
|
221 | + if($this->_statement instanceof PDOStatement) { |
|
222 | 222 | $this->_statement->execute(); |
223 | 223 | } else { |
224 | 224 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | { |
242 | 242 | try { |
243 | 243 | // Prado::trace('Query Row: '.$this->getDebugStatementText(), 'Prado\Data'); |
244 | - if ($this->_statement instanceof PDOStatement) { |
|
244 | + if($this->_statement instanceof PDOStatement) { |
|
245 | 245 | $this->_statement->execute(); |
246 | 246 | } else { |
247 | 247 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
@@ -265,14 +265,14 @@ discard block |
||
265 | 265 | { |
266 | 266 | try { |
267 | 267 | // Prado::trace('Query Scalar: '.$this->getDebugStatementText(), 'Prado\Data'); |
268 | - if ($this->_statement instanceof PDOStatement) { |
|
268 | + if($this->_statement instanceof PDOStatement) { |
|
269 | 269 | $this->_statement->execute(); |
270 | 270 | } else { |
271 | 271 | $this->_statement = $this->getConnection()->getPdoInstance()->query($this->getText()); |
272 | 272 | } |
273 | 273 | $result = $this->_statement->fetchColumn(); |
274 | 274 | $this->_statement->closeCursor(); |
275 | - if (is_resource($result) && get_resource_type($result) === 'stream') { |
|
275 | + if(is_resource($result) && get_resource_type($result) === 'stream') { |
|
276 | 276 | return stream_get_contents($result); |
277 | 277 | } else { |
278 | 278 | return $result; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | { |
295 | 295 | $rows = $this->query()->readAll(); |
296 | 296 | $column = []; |
297 | - foreach ($rows as $row) { |
|
297 | + foreach($rows as $row) { |
|
298 | 298 | $column[] = current($row); |
299 | 299 | } |
300 | 300 | return $column; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function bindColumn($column, &$value, $dataType = null) |
69 | 69 | { |
70 | - if ($dataType === null) { |
|
70 | + if($dataType === null) { |
|
71 | 71 | $this->_statement->bindColumn($column, $value); |
72 | 72 | } else { |
73 | 73 | $this->_statement->bindColumn($column, $value, $dataType); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function setFetchMode($mode) |
81 | 81 | { |
82 | 82 | $params = func_get_args(); |
83 | - call_user_func_array([$this->_statement,'setFetchMode'], $params); |
|
83 | + call_user_func_array([$this->_statement, 'setFetchMode'], $params); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function rewind() |
179 | 179 | { |
180 | - if ($this->_index < 0) { |
|
180 | + if($this->_index < 0) { |
|
181 | 181 | $this->_row = $this->_statement->fetch(); |
182 | 182 | $this->_index = 0; |
183 | 183 | } else { |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function __construct($condition = null, $parameters = []) |
55 | 55 | { |
56 | - if (!is_array($parameters) && func_num_args() > 1) { |
|
56 | + if(!is_array($parameters) && func_num_args() > 1) { |
|
57 | 57 | $parameters = array_slice(func_get_args(), 1); |
58 | 58 | } |
59 | 59 | $this->_parameters = new TAttributeCollection; |
60 | 60 | $this->_parameters->setCaseSensitive(true); |
61 | - $this->_parameters->copyFrom((array)$parameters); |
|
61 | + $this->_parameters->copyFrom((array) $parameters); |
|
62 | 62 | $this->_ordersBy = new TAttributeCollection; |
63 | 63 | $this->_ordersBy->setCaseSensitive(true); |
64 | 64 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function setCondition($value) |
134 | 134 | { |
135 | - if (empty($value)) { |
|
135 | + if(empty($value)) { |
|
136 | 136 | // reset the condition |
137 | 137 | $this->_condition = null; |
138 | 138 | return; |
@@ -144,32 +144,32 @@ discard block |
||
144 | 144 | // [LIMIT {[offset,] row_count | row_count OFFSET offset}] |
145 | 145 | // See: http://dev.mysql.com/doc/refman/5.0/en/select.html |
146 | 146 | |
147 | - if (preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
147 | + if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { |
|
148 | 148 | // condition contains ORDER BY |
149 | 149 | $value = str_replace($matches[0], '', $value); |
150 | - if (strlen($matches[1]) > 0) { |
|
150 | + if(strlen($matches[1]) > 0) { |
|
151 | 151 | $this->setOrdersBy($matches[1]); |
152 | - } elseif (strlen($matches[2]) > 0) { |
|
152 | + } elseif(strlen($matches[2]) > 0) { |
|
153 | 153 | $this->setOrdersBy($matches[2]); |
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
157 | - if (preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
157 | + if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { |
|
158 | 158 | // condition contains limit |
159 | 159 | $value = str_replace($matches[0], '', $value); // remove limit from query |
160 | - if (strpos($matches[1], ',')) { // both offset and limit given |
|
160 | + if(strpos($matches[1], ',')) { // both offset and limit given |
|
161 | 161 | list($offset, $limit) = explode(',', $matches[1]); |
162 | - $this->_limit = (int)$limit; |
|
163 | - $this->_offset = (int)$offset; |
|
162 | + $this->_limit = (int) $limit; |
|
163 | + $this->_offset = (int) $offset; |
|
164 | 164 | } else { // only limit given |
165 | - $this->_limit = (int)$matches[1]; |
|
165 | + $this->_limit = (int) $matches[1]; |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - if (preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
169 | + if(preg_match('/OFFSET\s+(\d+)/i', $value, $matches) > 0) { |
|
170 | 170 | // condition contains offset |
171 | 171 | $value = str_replace($matches[0], '', $value); // remove offset from query |
172 | - $this->_offset = (int)$matches[1]; // set offset in criteria |
|
172 | + $this->_offset = (int) $matches[1]; // set offset in criteria |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | $this->_condition = trim($value); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function setParameters($value) |
190 | 190 | { |
191 | - if (!(is_array($value) || $value instanceof \ArrayAccess)) { |
|
191 | + if(!(is_array($value) || $value instanceof \ArrayAccess)) { |
|
192 | 192 | throw new TException('value must be array or \ArrayAccess'); |
193 | 193 | } |
194 | 194 | $this->_parameters->copyFrom($value); |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function getIsNamedParameters() |
201 | 201 | { |
202 | - foreach ($this->getParameters() as $k => $v) { |
|
202 | + foreach($this->getParameters() as $k => $v) { |
|
203 | 203 | return is_string($k); |
204 | 204 | } |
205 | 205 | } |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function setOrdersBy($value) |
219 | 219 | { |
220 | - if (is_array($value) || $value instanceof Traversable) { |
|
220 | + if(is_array($value) || $value instanceof Traversable) { |
|
221 | 221 | $this->_ordersBy->copyFrom($value); |
222 | 222 | } else { |
223 | - $value = trim(preg_replace('/\s+/', ' ', (string)$value)); |
|
223 | + $value = trim(preg_replace('/\s+/', ' ', (string) $value)); |
|
224 | 224 | $orderBys = []; |
225 | - foreach (explode(',', $value) as $orderBy) { |
|
225 | + foreach(explode(',', $value) as $orderBy) { |
|
226 | 226 | $vs = explode(' ', trim($orderBy)); |
227 | 227 | $orderBys[$vs[0]] = isset($vs[1]) ? $vs[1] : 'asc'; |
228 | 228 | } |
@@ -268,27 +268,27 @@ discard block |
||
268 | 268 | public function __toString() |
269 | 269 | { |
270 | 270 | $str = ''; |
271 | - if (strlen((string)$this->getCondition()) > 0) { |
|
272 | - $str .= '"' . (string)$this->getCondition() . '"'; |
|
271 | + if(strlen((string) $this->getCondition()) > 0) { |
|
272 | + $str .= '"' . (string) $this->getCondition() . '"'; |
|
273 | 273 | } |
274 | 274 | $params = []; |
275 | - foreach ($this->getParameters() as $k => $v) { |
|
275 | + foreach($this->getParameters() as $k => $v) { |
|
276 | 276 | $params[] = "{$k} => ${v}"; |
277 | 277 | } |
278 | - if (count($params) > 0) { |
|
278 | + if(count($params) > 0) { |
|
279 | 279 | $str .= ', "' . implode(', ', $params) . '"'; |
280 | 280 | } |
281 | 281 | $orders = []; |
282 | - foreach ($this->getOrdersBy() as $k => $v) { |
|
282 | + foreach($this->getOrdersBy() as $k => $v) { |
|
283 | 283 | $orders[] = "{$k} => ${v}"; |
284 | 284 | } |
285 | - if (count($orders) > 0) { |
|
285 | + if(count($orders) > 0) { |
|
286 | 286 | $str .= ', "' . implode(', ', $orders) . '"'; |
287 | 287 | } |
288 | - if ($this->_limit !== null) { |
|
288 | + if($this->_limit !== null) { |
|
289 | 289 | $str .= ', ' . $this->_limit; |
290 | 290 | } |
291 | - if ($this->_offset !== null) { |
|
291 | + if($this->_offset !== null) { |
|
292 | 292 | $str .= ', ' . $this->_offset; |
293 | 293 | } |
294 | 294 | return $str; |