@@ -36,11 +36,11 @@ |
||
36 | 36 | { |
37 | 37 | $limit = $limit !== null ? intval($limit) : -1; |
38 | 38 | $offset = $offset !== null ? intval($offset) : -1; |
39 | - if($limit > 0 || $offset > 0) |
|
39 | + if ($limit > 0 || $offset > 0) |
|
40 | 40 | { |
41 | - $limitStr = ' LIMIT ' . $limit; |
|
42 | - $offsetStr = $offset >= 0 ? ' OFFSET ' . $offset : ''; |
|
43 | - return $sql . $limitStr . $offsetStr; |
|
41 | + $limitStr = ' LIMIT '.$limit; |
|
42 | + $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; |
|
43 | + return $sql.$limitStr.$offsetStr; |
|
44 | 44 | } |
45 | 45 | else |
46 | 46 | return $sql; |
@@ -41,9 +41,9 @@ |
||
41 | 41 | $limitStr = ' LIMIT ' . $limit; |
42 | 42 | $offsetStr = $offset >= 0 ? ' OFFSET ' . $offset : ''; |
43 | 43 | return $sql . $limitStr . $offsetStr; |
44 | + } else { |
|
45 | + return $sql; |
|
44 | 46 | } |
45 | - else |
|
46 | - return $sql; |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 |
@@ -82,18 +82,18 @@ discard block |
||
82 | 82 | $index = 0; |
83 | 83 | $columns = []; |
84 | 84 | $primary = []; |
85 | - foreach($command->query() as $col) |
|
85 | + foreach ($command->query() as $col) |
|
86 | 86 | { |
87 | 87 | $col['index'] = $index++; |
88 | 88 | $column = $this->processColumn($col, $foreign); |
89 | 89 | $columns[$col['name']] = $column; |
90 | - if($column->getIsPrimaryKey()) |
|
90 | + if ($column->getIsPrimaryKey()) |
|
91 | 91 | $primary[] = $col['name']; |
92 | 92 | } |
93 | 93 | $info['TableName'] = $tableName; |
94 | - if($this->getIsView($tableName)) |
|
94 | + if ($this->getIsView($tableName)) |
|
95 | 95 | $info['IsView'] = true; |
96 | - if(count($columns) === 0) |
|
96 | + if (count($columns) === 0) |
|
97 | 97 | throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
98 | 98 | $class = $this->getTableInfoClass(); |
99 | 99 | $tableInfo = new $class($info, $primary, $foreign); |
@@ -123,19 +123,19 @@ discard block |
||
123 | 123 | { |
124 | 124 | $columnId = $col['name']; //use column name as column Id |
125 | 125 | |
126 | - $info['ColumnName'] = '"' . $columnId . '"'; //quote the column names! |
|
126 | + $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
127 | 127 | $info['ColumnId'] = $columnId; |
128 | 128 | $info['ColumnIndex'] = $col['index']; |
129 | 129 | |
130 | - if($col['notnull'] !== '99') |
|
130 | + if ($col['notnull'] !== '99') |
|
131 | 131 | $info['AllowNull'] = true; |
132 | 132 | |
133 | - if($col['pk'] === '1') |
|
133 | + if ($col['pk'] === '1') |
|
134 | 134 | $info['IsPrimaryKey'] = true; |
135 | - if($this->isForeignKeyColumn($columnId, $foreign)) |
|
135 | + if ($this->isForeignKeyColumn($columnId, $foreign)) |
|
136 | 136 | $info['IsForeignKey'] = true; |
137 | 137 | |
138 | - if($col['dflt_value'] !== null) |
|
138 | + if ($col['dflt_value'] !== null) |
|
139 | 139 | $info['DefaultValue'] = $col['dflt_value']; |
140 | 140 | |
141 | 141 | $type = strtolower($col['type']); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | |
144 | 144 | $info['DbType'] = $type; |
145 | 145 | $match = []; |
146 | - if(is_int($pos = strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
|
146 | + if (is_int($pos = strpos($type, '(')) && preg_match('/\((.*)\)/', $type, $match)) |
|
147 | 147 | { |
148 | 148 | $ps = explode(',', $match[1]); |
149 | - if(count($ps) === 2) |
|
149 | + if (count($ps) === 2) |
|
150 | 150 | { |
151 | 151 | $info['NumericPrecision'] = intval($ps[0]); |
152 | 152 | $info['NumericScale'] = intval($ps[1]); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | $sql = "PRAGMA foreign_key_list({$table})"; |
171 | 171 | $command = $this->getDbConnection()->createCommand($sql); |
172 | 172 | $fkeys = []; |
173 | - foreach($command->query() as $col) |
|
173 | + foreach ($command->query() as $col) |
|
174 | 174 | { |
175 | 175 | $fkeys[$col['table']]['keys'][$col['from']] = $col['to']; |
176 | 176 | $fkeys[$col['table']]['table'] = $col['table']; |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | */ |
186 | 186 | protected function isForeignKeyColumn($columnId, $foreign) |
187 | 187 | { |
188 | - foreach($foreign as $fk) |
|
188 | + foreach ($foreign as $fk) |
|
189 | 189 | { |
190 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
190 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
191 | 191 | return true; |
192 | 192 | } |
193 | 193 | return false; |
@@ -87,14 +87,17 @@ discard block |
||
87 | 87 | $col['index'] = $index++; |
88 | 88 | $column = $this->processColumn($col, $foreign); |
89 | 89 | $columns[$col['name']] = $column; |
90 | - if($column->getIsPrimaryKey()) |
|
91 | - $primary[] = $col['name']; |
|
90 | + if($column->getIsPrimaryKey()) { |
|
91 | + $primary[] = $col['name']; |
|
92 | + } |
|
92 | 93 | } |
93 | 94 | $info['TableName'] = $tableName; |
94 | - if($this->getIsView($tableName)) |
|
95 | - $info['IsView'] = true; |
|
96 | - if(count($columns) === 0) |
|
97 | - throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
|
95 | + if($this->getIsView($tableName)) { |
|
96 | + $info['IsView'] = true; |
|
97 | + } |
|
98 | + if(count($columns) === 0) { |
|
99 | + throw new TDbException('dbmetadata_invalid_table_view', $tableName); |
|
100 | + } |
|
98 | 101 | $class = $this->getTableInfoClass(); |
99 | 102 | $tableInfo = new $class($info, $primary, $foreign); |
100 | 103 | $tableInfo->getColumns()->copyFrom($columns); |
@@ -127,16 +130,20 @@ discard block |
||
127 | 130 | $info['ColumnId'] = $columnId; |
128 | 131 | $info['ColumnIndex'] = $col['index']; |
129 | 132 | |
130 | - if($col['notnull'] !== '99') |
|
131 | - $info['AllowNull'] = true; |
|
133 | + if($col['notnull'] !== '99') { |
|
134 | + $info['AllowNull'] = true; |
|
135 | + } |
|
132 | 136 | |
133 | - if($col['pk'] === '1') |
|
134 | - $info['IsPrimaryKey'] = true; |
|
135 | - if($this->isForeignKeyColumn($columnId, $foreign)) |
|
136 | - $info['IsForeignKey'] = true; |
|
137 | + if($col['pk'] === '1') { |
|
138 | + $info['IsPrimaryKey'] = true; |
|
139 | + } |
|
140 | + if($this->isForeignKeyColumn($columnId, $foreign)) { |
|
141 | + $info['IsForeignKey'] = true; |
|
142 | + } |
|
137 | 143 | |
138 | - if($col['dflt_value'] !== null) |
|
139 | - $info['DefaultValue'] = $col['dflt_value']; |
|
144 | + if($col['dflt_value'] !== null) { |
|
145 | + $info['DefaultValue'] = $col['dflt_value']; |
|
146 | + } |
|
140 | 147 | |
141 | 148 | $type = strtolower($col['type']); |
142 | 149 | $info['AutoIncrement'] = $type === 'integer' && $col['pk'] === '1'; |
@@ -150,9 +157,9 @@ discard block |
||
150 | 157 | { |
151 | 158 | $info['NumericPrecision'] = intval($ps[0]); |
152 | 159 | $info['NumericScale'] = intval($ps[1]); |
160 | + } else { |
|
161 | + $info['ColumnSize'] = intval($match[1]); |
|
153 | 162 | } |
154 | - else |
|
155 | - $info['ColumnSize'] = intval($match[1]); |
|
156 | 163 | $info['DbType'] = substr($type, 0, $pos); |
157 | 164 | } |
158 | 165 | |
@@ -187,8 +194,9 @@ discard block |
||
187 | 194 | { |
188 | 195 | foreach($foreign as $fk) |
189 | 196 | { |
190 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
191 | - return true; |
|
197 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
198 | + return true; |
|
199 | + } |
|
192 | 200 | } |
193 | 201 | return false; |
194 | 202 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function getPdoType() |
70 | 70 | { |
71 | - switch($this->getPHPType()) |
|
71 | + switch ($this->getPHPType()) |
|
72 | 72 | { |
73 | 73 | case 'boolean': return PDO::PARAM_BOOL; |
74 | 74 | case 'integer': return PDO::PARAM_INT; |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | |
152 | 152 | public function getMaxiumNumericConstraint() |
153 | 153 | { |
154 | - if(($precision = $this->getNumericPrecision()) !== null) |
|
154 | + if (($precision = $this->getNumericPrecision()) !== null) |
|
155 | 155 | { |
156 | 156 | $scale = $this->getNumericScale(); |
157 | 157 | return $scale === null ? pow(10, $precision) : pow(10, $precision - $scale); |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function getSchemaTableName($table) |
92 | 92 | { |
93 | - if(count($parts = explode('.', str_replace('"', '', $table))) > 1) |
|
93 | + if (count($parts = explode('.', str_replace('"', '', $table))) > 1) |
|
94 | 94 | return [$parts[0], $parts[1]]; |
95 | 95 | else |
96 | - return [$this->getDefaultSchema(),$parts[0]]; |
|
96 | + return [$this->getDefaultSchema(), $parts[0]]; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | $command->bindValue(':schema', $schemaName); |
145 | 145 | $tableInfo = $this->createNewTableInfo($schemaName, $tableName); |
146 | 146 | $index = 0; |
147 | - foreach($command->query() as $col) |
|
147 | + foreach ($command->query() as $col) |
|
148 | 148 | { |
149 | 149 | $col['index'] = $index++; |
150 | 150 | $this->processColumn($tableInfo, $col); |
151 | 151 | } |
152 | - if($index === 0) |
|
152 | + if ($index === 0) |
|
153 | 153 | throw new TDbException('dbmetadata_invalid_table_view', $table); |
154 | 154 | return $tableInfo; |
155 | 155 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | { |
164 | 164 | $info['SchemaName'] = $this->assertIdentifier($schemaName); |
165 | 165 | $info['TableName'] = $this->assertIdentifier($tableName); |
166 | - if($this->getIsView($schemaName, $tableName)) |
|
166 | + if ($this->getIsView($schemaName, $tableName)) |
|
167 | 167 | $info['IsView'] = true; |
168 | 168 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
169 | 169 | $class = $this->getTableInfoClass(); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | */ |
178 | 178 | protected function assertIdentifier($name) |
179 | 179 | { |
180 | - if(strpos($name, '"') !== false) |
|
180 | + if (strpos($name, '"') !== false) |
|
181 | 181 | { |
182 | 182 | $ref = 'http://www.postgresql.org/docs/7.4/static/sql-syntax.html#SQL-SYNTAX-IDENTIFIERS'; |
183 | 183 | throw new TDbException('dbcommon_invalid_identifier_name', $name, $ref); |
@@ -213,36 +213,36 @@ discard block |
||
213 | 213 | { |
214 | 214 | $columnId = $col['attname']; //use column name as column Id |
215 | 215 | |
216 | - $info['ColumnName'] = '"' . $columnId . '"'; //quote the column names! |
|
216 | + $info['ColumnName'] = '"'.$columnId.'"'; //quote the column names! |
|
217 | 217 | $info['ColumnId'] = $columnId; |
218 | 218 | $info['ColumnIndex'] = $col['index']; |
219 | - if(!$col['attnotnull']) |
|
219 | + if (!$col['attnotnull']) |
|
220 | 220 | $info['AllowNull'] = true; |
221 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
221 | + if (in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
222 | 222 | $info['IsPrimaryKey'] = true; |
223 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
223 | + if ($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
224 | 224 | $info['IsForeignKey'] = true; |
225 | 225 | |
226 | - if($col['atttypmod'] > 0) |
|
226 | + if ($col['atttypmod'] > 0) |
|
227 | 227 | $info['ColumnSize'] = $col['atttypmod'] - 4; |
228 | - if($col['atthasdef']) |
|
228 | + if ($col['atthasdef']) |
|
229 | 229 | $info['DefaultValue'] = $col['adsrc']; |
230 | - if($col['attisserial'] || substr($col['adsrc'], 0, 8) === 'nextval(') |
|
230 | + if ($col['attisserial'] || substr($col['adsrc'], 0, 8) === 'nextval(') |
|
231 | 231 | { |
232 | - if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc'])) !== null) |
|
232 | + if (($sequence = $this->getSequenceName($tableInfo, $col['adsrc'])) !== null) |
|
233 | 233 | { |
234 | 234 | $info['SequenceName'] = $sequence; |
235 | 235 | unset($info['DefaultValue']); |
236 | 236 | } |
237 | 237 | } |
238 | 238 | $matches = []; |
239 | - if(preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
239 | + if (preg_match('/\((\d+)(?:,(\d+))?+\)/', $col['type'], $matches)) |
|
240 | 240 | { |
241 | 241 | $info['DbType'] = preg_replace('/\(\d+(?:,\d+)?\)/', '', $col['type']); |
242 | - if($this->isPrecisionType($info['DbType'])) |
|
242 | + if ($this->isPrecisionType($info['DbType'])) |
|
243 | 243 | { |
244 | 244 | $info['NumericPrecision'] = intval($matches[1]); |
245 | - if(count($matches) > 2) |
|
245 | + if (count($matches) > 2) |
|
246 | 246 | $info['NumericScale'] = intval($matches[2]); |
247 | 247 | } |
248 | 248 | else |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | protected function getSequenceName($tableInfo, $src) |
261 | 261 | { |
262 | 262 | $matches = []; |
263 | - if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
263 | + if (preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
|
264 | 264 | { |
265 | - if(is_int(strpos($matches[1], '.'))) |
|
265 | + if (is_int(strpos($matches[1], '.'))) |
|
266 | 266 | return $matches[1]; |
267 | 267 | else |
268 | - return $tableInfo->getSchemaName() . '.' . $matches[1]; |
|
268 | + return $tableInfo->getSchemaName().'.'.$matches[1]; |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -339,20 +339,20 @@ discard block |
||
339 | 339 | $command->bindValue(':schema', $schemaName); |
340 | 340 | $primary = []; |
341 | 341 | $foreign = []; |
342 | - foreach($command->query() as $row) |
|
342 | + foreach ($command->query() as $row) |
|
343 | 343 | { |
344 | - switch($row['contype']) |
|
344 | + switch ($row['contype']) |
|
345 | 345 | { |
346 | 346 | case 'p': |
347 | 347 | $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
348 | 348 | break; |
349 | 349 | case 'f': |
350 | - if(($fkey = $this->getForeignKeys($row['consrc'])) !== null) |
|
350 | + if (($fkey = $this->getForeignKeys($row['consrc'])) !== null) |
|
351 | 351 | $foreign[] = $fkey; |
352 | 352 | break; |
353 | 353 | } |
354 | 354 | } |
355 | - return [$primary,$foreign]; |
|
355 | + return [$primary, $foreign]; |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $command->bindValue(':schema', $schemaName); |
379 | 379 | // $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex))); |
380 | 380 | $primary = []; |
381 | - foreach($command->query() as $row) |
|
381 | + foreach ($command->query() as $row) |
|
382 | 382 | { |
383 | 383 | $primary[] = $row['attname']; |
384 | 384 | } |
@@ -396,11 +396,11 @@ discard block |
||
396 | 396 | $matches = []; |
397 | 397 | $brackets = '\(([^\)]+)\)'; |
398 | 398 | $find = "/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i"; |
399 | - if(preg_match($find, $src, $matches)) |
|
399 | + if (preg_match($find, $src, $matches)) |
|
400 | 400 | { |
401 | 401 | $keys = preg_split('/,\s+/', $matches[1]); |
402 | 402 | $fkeys = []; |
403 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
403 | + foreach (preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
404 | 404 | $fkeys[$keys[$i]] = $fkey; |
405 | 405 | return ['table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys]; |
406 | 406 | } |
@@ -413,9 +413,9 @@ discard block |
||
413 | 413 | */ |
414 | 414 | protected function isForeignKeyColumn($columnId, $tableInfo) |
415 | 415 | { |
416 | - foreach($tableInfo->getForeignKeys() as $fk) |
|
416 | + foreach ($tableInfo->getForeignKeys() as $fk) |
|
417 | 417 | { |
418 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
418 | + if (in_array($columnId, array_keys($fk['keys']))) |
|
419 | 419 | return true; |
420 | 420 | } |
421 | 421 | return false; |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | public function findTableNames($schema = 'public') |
431 | 431 | { |
432 | - if($schema === '') |
|
432 | + if ($schema === '') |
|
433 | 433 | $schema = self::DEFAULT_SCHEMA; |
434 | 434 | $sql = <<<EOD |
435 | 435 | SELECT table_name, table_schema FROM information_schema.tables |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | $command->bindParam(':schema', $schema); |
440 | 440 | $rows = $command->queryAll(); |
441 | 441 | $names = []; |
442 | - foreach($rows as $row) |
|
442 | + foreach ($rows as $row) |
|
443 | 443 | { |
444 | - if($schema === self::DEFAULT_SCHEMA) |
|
444 | + if ($schema === self::DEFAULT_SCHEMA) |
|
445 | 445 | $names[] = $row['table_name']; |
446 | 446 | else |
447 | - $names[] = $row['table_schema'] . '.' . $row['table_name']; |
|
447 | + $names[] = $row['table_schema'].'.'.$row['table_name']; |
|
448 | 448 | } |
449 | 449 | return $names; |
450 | 450 | } |
@@ -90,10 +90,11 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function getSchemaTableName($table) |
92 | 92 | { |
93 | - if(count($parts = explode('.', str_replace('"', '', $table))) > 1) |
|
94 | - return [$parts[0], $parts[1]]; |
|
95 | - else |
|
96 | - return [$this->getDefaultSchema(),$parts[0]]; |
|
93 | + if(count($parts = explode('.', str_replace('"', '', $table))) > 1) { |
|
94 | + return [$parts[0], $parts[1]]; |
|
95 | + } else { |
|
96 | + return [$this->getDefaultSchema(),$parts[0]]; |
|
97 | + } |
|
97 | 98 | } |
98 | 99 | |
99 | 100 | /** |
@@ -149,8 +150,9 @@ discard block |
||
149 | 150 | $col['index'] = $index++; |
150 | 151 | $this->processColumn($tableInfo, $col); |
151 | 152 | } |
152 | - if($index === 0) |
|
153 | - throw new TDbException('dbmetadata_invalid_table_view', $table); |
|
153 | + if($index === 0) { |
|
154 | + throw new TDbException('dbmetadata_invalid_table_view', $table); |
|
155 | + } |
|
154 | 156 | return $tableInfo; |
155 | 157 | } |
156 | 158 | |
@@ -163,8 +165,9 @@ discard block |
||
163 | 165 | { |
164 | 166 | $info['SchemaName'] = $this->assertIdentifier($schemaName); |
165 | 167 | $info['TableName'] = $this->assertIdentifier($tableName); |
166 | - if($this->getIsView($schemaName, $tableName)) |
|
167 | - $info['IsView'] = true; |
|
168 | + if($this->getIsView($schemaName, $tableName)) { |
|
169 | + $info['IsView'] = true; |
|
170 | + } |
|
168 | 171 | list($primary, $foreign) = $this->getConstraintKeys($schemaName, $tableName); |
169 | 172 | $class = $this->getTableInfoClass(); |
170 | 173 | return new $class($info, $primary, $foreign); |
@@ -216,17 +219,22 @@ discard block |
||
216 | 219 | $info['ColumnName'] = '"' . $columnId . '"'; //quote the column names! |
217 | 220 | $info['ColumnId'] = $columnId; |
218 | 221 | $info['ColumnIndex'] = $col['index']; |
219 | - if(!$col['attnotnull']) |
|
220 | - $info['AllowNull'] = true; |
|
221 | - if(in_array($columnId, $tableInfo->getPrimaryKeys())) |
|
222 | - $info['IsPrimaryKey'] = true; |
|
223 | - if($this->isForeignKeyColumn($columnId, $tableInfo)) |
|
224 | - $info['IsForeignKey'] = true; |
|
222 | + if(!$col['attnotnull']) { |
|
223 | + $info['AllowNull'] = true; |
|
224 | + } |
|
225 | + if(in_array($columnId, $tableInfo->getPrimaryKeys())) { |
|
226 | + $info['IsPrimaryKey'] = true; |
|
227 | + } |
|
228 | + if($this->isForeignKeyColumn($columnId, $tableInfo)) { |
|
229 | + $info['IsForeignKey'] = true; |
|
230 | + } |
|
225 | 231 | |
226 | - if($col['atttypmod'] > 0) |
|
227 | - $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
228 | - if($col['atthasdef']) |
|
229 | - $info['DefaultValue'] = $col['adsrc']; |
|
232 | + if($col['atttypmod'] > 0) { |
|
233 | + $info['ColumnSize'] = $col['atttypmod'] - 4; |
|
234 | + } |
|
235 | + if($col['atthasdef']) { |
|
236 | + $info['DefaultValue'] = $col['adsrc']; |
|
237 | + } |
|
230 | 238 | if($col['attisserial'] || substr($col['adsrc'], 0, 8) === 'nextval(') |
231 | 239 | { |
232 | 240 | if(($sequence = $this->getSequenceName($tableInfo, $col['adsrc'])) !== null) |
@@ -242,14 +250,15 @@ discard block |
||
242 | 250 | if($this->isPrecisionType($info['DbType'])) |
243 | 251 | { |
244 | 252 | $info['NumericPrecision'] = intval($matches[1]); |
245 | - if(count($matches) > 2) |
|
246 | - $info['NumericScale'] = intval($matches[2]); |
|
253 | + if(count($matches) > 2) { |
|
254 | + $info['NumericScale'] = intval($matches[2]); |
|
255 | + } |
|
256 | + } else { |
|
257 | + $info['ColumnSize'] = intval($matches[1]); |
|
247 | 258 | } |
248 | - else |
|
249 | - $info['ColumnSize'] = intval($matches[1]); |
|
259 | + } else { |
|
260 | + $info['DbType'] = $col['type']; |
|
250 | 261 | } |
251 | - else |
|
252 | - $info['DbType'] = $col['type']; |
|
253 | 262 | |
254 | 263 | $tableInfo->Columns[$columnId] = new TPgsqlTableColumn($info); |
255 | 264 | } |
@@ -262,10 +271,11 @@ discard block |
||
262 | 271 | $matches = []; |
263 | 272 | if(preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i', $src, $matches)) |
264 | 273 | { |
265 | - if(is_int(strpos($matches[1], '.'))) |
|
266 | - return $matches[1]; |
|
267 | - else |
|
268 | - return $tableInfo->getSchemaName() . '.' . $matches[1]; |
|
274 | + if(is_int(strpos($matches[1], '.'))) { |
|
275 | + return $matches[1]; |
|
276 | + } else { |
|
277 | + return $tableInfo->getSchemaName() . '.' . $matches[1]; |
|
278 | + } |
|
269 | 279 | } |
270 | 280 | } |
271 | 281 | |
@@ -347,8 +357,9 @@ discard block |
||
347 | 357 | $primary = $this->getPrimaryKeys($tableName, $schemaName, $row['indkey']); |
348 | 358 | break; |
349 | 359 | case 'f': |
350 | - if(($fkey = $this->getForeignKeys($row['consrc'])) !== null) |
|
351 | - $foreign[] = $fkey; |
|
360 | + if(($fkey = $this->getForeignKeys($row['consrc'])) !== null) { |
|
361 | + $foreign[] = $fkey; |
|
362 | + } |
|
352 | 363 | break; |
353 | 364 | } |
354 | 365 | } |
@@ -400,8 +411,9 @@ discard block |
||
400 | 411 | { |
401 | 412 | $keys = preg_split('/,\s+/', $matches[1]); |
402 | 413 | $fkeys = []; |
403 | - foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) |
|
404 | - $fkeys[$keys[$i]] = $fkey; |
|
414 | + foreach(preg_split('/,\s+/', $matches[3]) as $i => $fkey) { |
|
415 | + $fkeys[$keys[$i]] = $fkey; |
|
416 | + } |
|
405 | 417 | return ['table' => str_replace('"', '', $matches[2]), 'keys' => $fkeys]; |
406 | 418 | } |
407 | 419 | } |
@@ -415,8 +427,9 @@ discard block |
||
415 | 427 | { |
416 | 428 | foreach($tableInfo->getForeignKeys() as $fk) |
417 | 429 | { |
418 | - if(in_array($columnId, array_keys($fk['keys']))) |
|
419 | - return true; |
|
430 | + if(in_array($columnId, array_keys($fk['keys']))) { |
|
431 | + return true; |
|
432 | + } |
|
420 | 433 | } |
421 | 434 | return false; |
422 | 435 | } |
@@ -429,8 +442,9 @@ discard block |
||
429 | 442 | */ |
430 | 443 | public function findTableNames($schema = 'public') |
431 | 444 | { |
432 | - if($schema === '') |
|
433 | - $schema = self::DEFAULT_SCHEMA; |
|
445 | + if($schema === '') { |
|
446 | + $schema = self::DEFAULT_SCHEMA; |
|
447 | + } |
|
434 | 448 | $sql = <<<EOD |
435 | 449 | SELECT table_name, table_schema FROM information_schema.tables |
436 | 450 | WHERE table_schema=:schema AND table_type='BASE TABLE' |
@@ -441,10 +455,11 @@ discard block |
||
441 | 455 | $names = []; |
442 | 456 | foreach($rows as $row) |
443 | 457 | { |
444 | - if($schema === self::DEFAULT_SCHEMA) |
|
445 | - $names[] = $row['table_name']; |
|
446 | - else |
|
447 | - $names[] = $row['table_schema'] . '.' . $row['table_name']; |
|
458 | + if($schema === self::DEFAULT_SCHEMA) { |
|
459 | + $names[] = $row['table_name']; |
|
460 | + } else { |
|
461 | + $names[] = $row['table_schema'] . '.' . $row['table_name']; |
|
462 | + } |
|
448 | 463 | } |
449 | 464 | return $names; |
450 | 465 | } |
@@ -35,9 +35,9 @@ |
||
35 | 35 | public function getPHPType() |
36 | 36 | { |
37 | 37 | $dbtype = strtolower($this->getDbType()); |
38 | - foreach(self::$types as $type => $dbtypes) |
|
38 | + foreach (self::$types as $type => $dbtypes) |
|
39 | 39 | { |
40 | - if(in_array($dbtype, $dbtypes)) |
|
40 | + if (in_array($dbtype, $dbtypes)) |
|
41 | 41 | return $type; |
42 | 42 | } |
43 | 43 | return 'string'; |
@@ -39,8 +39,9 @@ |
||
39 | 39 | $dbtype = strtolower($this->getDbType()); |
40 | 40 | foreach(self::$types as $type => $dbtypes) |
41 | 41 | { |
42 | - if(in_array($dbtype, $dbtypes)) |
|
43 | - return $type; |
|
42 | + if(in_array($dbtype, $dbtypes)) { |
|
43 | + return $type; |
|
44 | + } |
|
44 | 45 | } |
45 | 46 | return 'string'; |
46 | 47 | } |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | public function getSearchExpression($fields, $keywords) |
36 | 36 | { |
37 | 37 | $columns = []; |
38 | - foreach($fields as $field) |
|
38 | + foreach ($fields as $field) |
|
39 | 39 | { |
40 | - if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
40 | + if ($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
41 | 41 | $columns[] = $field; |
42 | 42 | } |
43 | 43 | return parent::getSearchExpression($columns, $keywords); |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | protected function getSearchCondition($column, $words) |
63 | 63 | { |
64 | 64 | $conditions = []; |
65 | - foreach($words as $word) |
|
66 | - $conditions[] = $column . ' ILIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%'); |
|
67 | - return '(' . implode(' AND ', $conditions) . ')'; |
|
65 | + foreach ($words as $word) |
|
66 | + $conditions[] = $column.' ILIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); |
|
67 | + return '('.implode(' AND ', $conditions).')'; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | } |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | $columns = []; |
38 | 38 | foreach($fields as $field) |
39 | 39 | { |
40 | - if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
41 | - $columns[] = $field; |
|
40 | + if($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) { |
|
41 | + $columns[] = $field; |
|
42 | + } |
|
42 | 43 | } |
43 | 44 | return parent::getSearchExpression($columns, $keywords); |
44 | 45 | } |
@@ -62,8 +63,9 @@ discard block |
||
62 | 63 | protected function getSearchCondition($column, $words) |
63 | 64 | { |
64 | 65 | $conditions = []; |
65 | - foreach($words as $word) |
|
66 | - $conditions[] = $column . ' ILIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%'); |
|
66 | + foreach($words as $word) { |
|
67 | + $conditions[] = $column . ' ILIKE ' . $this->getDbConnection()->quoteString('%' . $word . '%'); |
|
68 | + } |
|
67 | 69 | return '(' . implode(' AND ', $conditions) . ')'; |
68 | 70 | } |
69 | 71 |
@@ -40,8 +40,8 @@ |
||
40 | 40 | */ |
41 | 41 | public function getTableFullName() |
42 | 42 | { |
43 | - if(($schema = $this->getSchemaName()) !== null) |
|
44 | - return $schema . '.' . $this->getTableName(); |
|
43 | + if (($schema = $this->getSchemaName()) !== null) |
|
44 | + return $schema.'.'.$this->getTableName(); |
|
45 | 45 | else |
46 | 46 | return $this->getTableName(); |
47 | 47 | } |
@@ -40,10 +40,11 @@ |
||
40 | 40 | */ |
41 | 41 | public function getTableFullName() |
42 | 42 | { |
43 | - if(($schema = $this->getSchemaName()) !== null) |
|
44 | - return $schema . '.' . $this->getTableName(); |
|
45 | - else |
|
46 | - return $this->getTableName(); |
|
43 | + if(($schema = $this->getSchemaName()) !== null) { |
|
44 | + return $schema . '.' . $this->getTableName(); |
|
45 | + } else { |
|
46 | + return $this->getTableName(); |
|
47 | + } |
|
47 | 48 | } |
48 | 49 | |
49 | 50 | /** |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function getTableFullName() |
89 | 89 | { |
90 | - return $this->_info['SchemaName'] . '.' . $this->getTableName(); |
|
90 | + return $this->_info['SchemaName'].'.'.$this->getTableName(); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -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 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | public function getColumnNames() |
125 | 125 | { |
126 | - foreach($this->getColumns() as $column) |
|
126 | + foreach ($this->getColumns() as $column) |
|
127 | 127 | $names[] = $column->getColumnName(); |
128 | 128 | return $names; |
129 | 129 | } |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function getLowerCaseColumnNames() |
151 | 151 | { |
152 | - if($this->_lowercase === null) |
|
152 | + if ($this->_lowercase === null) |
|
153 | 153 | { |
154 | 154 | $this->_lowercase = []; |
155 | - foreach($this->getColumns()->getKeys() as $key) |
|
155 | + foreach ($this->getColumns()->getKeys() as $key) |
|
156 | 156 | $this->_lowercase[strtolower($key)] = $key; |
157 | 157 | } |
158 | 158 | return $this->_lowercase; |
@@ -112,8 +112,9 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getColumn($name) |
114 | 114 | { |
115 | - if(($column = $this->_columns->itemAt($name)) !== null) |
|
116 | - return $column; |
|
115 | + if(($column = $this->_columns->itemAt($name)) !== null) { |
|
116 | + return $column; |
|
117 | + } |
|
117 | 118 | throw new TDbException('dbtableinfo_invalid_column_name', $name, $this->getTableFullName()); |
118 | 119 | } |
119 | 120 | |
@@ -123,8 +124,9 @@ discard block |
||
123 | 124 | */ |
124 | 125 | public function getColumnNames() |
125 | 126 | { |
126 | - foreach($this->getColumns() as $column) |
|
127 | - $names[] = $column->getColumnName(); |
|
127 | + foreach($this->getColumns() as $column) { |
|
128 | + $names[] = $column->getColumnName(); |
|
129 | + } |
|
128 | 130 | return $names; |
129 | 131 | } |
130 | 132 | |
@@ -152,8 +154,9 @@ discard block |
||
152 | 154 | if($this->_lowercase === null) |
153 | 155 | { |
154 | 156 | $this->_lowercase = []; |
155 | - foreach($this->getColumns()->getKeys() as $key) |
|
156 | - $this->_lowercase[strtolower($key)] = $key; |
|
157 | + foreach($this->getColumns()->getKeys() as $key) { |
|
158 | + $this->_lowercase[strtolower($key)] = $key; |
|
159 | + } |
|
157 | 160 | } |
158 | 161 | return $this->_lowercase; |
159 | 162 | } |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | $nfimDoSelect = (strpos($sql, 'FROM') !== false ? strpos($sql, 'FROM') : $nfimDaSQL); |
90 | 90 | |
91 | 91 | $WhereInSubSelect = ""; |
92 | - if(strpos($sql, 'WHERE') !== false) |
|
93 | - $WhereInSubSelect = "WHERE " . substr($sql, strpos($sql, 'WHERE') + 5, $nfimDoWhere - $niniDoWhere); |
|
92 | + if (strpos($sql, 'WHERE') !== false) |
|
93 | + $WhereInSubSelect = "WHERE ".substr($sql, strpos($sql, 'WHERE') + 5, $nfimDoWhere - $niniDoWhere); |
|
94 | 94 | |
95 | 95 | $sORDERBY = ''; |
96 | 96 | if (stripos($sql, 'ORDER') !== false) { |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $fields = ''; |
108 | 108 | $arr = $this->getTableInfo()->getColumns(); |
109 | 109 | foreach ($arr as $field) { |
110 | - $fields .= strtolower($field->getColumnName()) . ', '; |
|
110 | + $fields .= strtolower($field->getColumnName()).', '; |
|
111 | 111 | } |
112 | 112 | $fields = str_replace('"', '', $fields); |
113 | 113 | $fields = trim($fields); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $field = strtolower($field); |
120 | 120 | $existAS = str_ireplace(' as ', '-as-', $field); |
121 | 121 | if (strpos($existAS, '-as-') === false) |
122 | - $aliasedFields .= "{$fieldsALIAS}." . trim($field) . ", "; |
|
122 | + $aliasedFields .= "{$fieldsALIAS}.".trim($field).", "; |
|
123 | 123 | else |
124 | 124 | $aliasedFields .= "{$field}, "; |
125 | 125 | } |
@@ -138,17 +138,17 @@ discard block |
||
138 | 138 | ") WHERE {$pradoNUMLIN} >= {$offset} "; |
139 | 139 | |
140 | 140 | ************************* */ |
141 | - $offset = (int)$offset; |
|
142 | - $toReg = $offset + $limit ; |
|
141 | + $offset = (int) $offset; |
|
142 | + $toReg = $offset + $limit; |
|
143 | 143 | $fullTableName = $this->getTableInfo()->getTableFullName(); |
144 | 144 | if (empty($sORDERBY)) |
145 | 145 | $sORDERBY = "ROWNUM"; |
146 | 146 | |
147 | - $newSql = " SELECT $fields FROM " . |
|
148 | - "( " . |
|
149 | - " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} " . |
|
150 | - " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" . |
|
151 | - ") nn " . |
|
147 | + $newSql = " SELECT $fields FROM ". |
|
148 | + "( ". |
|
149 | + " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} ". |
|
150 | + " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect". |
|
151 | + ") nn ". |
|
152 | 152 | " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} < {$toReg} "; |
153 | 153 | //echo $newSql."\n<br>\n"; |
154 | 154 | return $newSql; |
@@ -36,8 +36,9 @@ discard block |
||
36 | 36 | public function getSearchExpression($fields, $keywords) { |
37 | 37 | $columns = []; |
38 | 38 | foreach ($fields as $field) { |
39 | - if ($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) |
|
40 | - $columns[] = $field; |
|
39 | + if ($this->isSearchableColumn($this->getTableInfo()->getColumn($field))) { |
|
40 | + $columns[] = $field; |
|
41 | + } |
|
41 | 42 | } |
42 | 43 | return parent :: getSearchExpression($columns, $keywords); |
43 | 44 | } |
@@ -77,8 +78,9 @@ discard block |
||
77 | 78 | * @return string SQL with limit and offset in Oracle way. |
78 | 79 | */ |
79 | 80 | public function applyLimitOffset($sql, $limit = -1, $offset = -1) { |
80 | - if ((int) $limit <= 0 && (int) $offset <= 0) |
|
81 | - return $sql; |
|
81 | + if ((int) $limit <= 0 && (int) $offset <= 0) { |
|
82 | + return $sql; |
|
83 | + } |
|
82 | 84 | |
83 | 85 | $pradoNUMLIN = 'pradoNUMLIN'; |
84 | 86 | $fieldsALIAS = 'xyz'; |
@@ -89,8 +91,9 @@ discard block |
||
89 | 91 | $nfimDoSelect = (strpos($sql, 'FROM') !== false ? strpos($sql, 'FROM') : $nfimDaSQL); |
90 | 92 | |
91 | 93 | $WhereInSubSelect = ""; |
92 | - if(strpos($sql, 'WHERE') !== false) |
|
93 | - $WhereInSubSelect = "WHERE " . substr($sql, strpos($sql, 'WHERE') + 5, $nfimDoWhere - $niniDoWhere); |
|
94 | + if(strpos($sql, 'WHERE') !== false) { |
|
95 | + $WhereInSubSelect = "WHERE " . substr($sql, strpos($sql, 'WHERE') + 5, $nfimDoWhere - $niniDoWhere); |
|
96 | + } |
|
94 | 97 | |
95 | 98 | $sORDERBY = ''; |
96 | 99 | if (stripos($sql, 'ORDER') !== false) { |
@@ -118,17 +121,19 @@ discard block |
||
118 | 121 | foreach ($arr as $field) { |
119 | 122 | $field = strtolower($field); |
120 | 123 | $existAS = str_ireplace(' as ', '-as-', $field); |
121 | - if (strpos($existAS, '-as-') === false) |
|
122 | - $aliasedFields .= "{$fieldsALIAS}." . trim($field) . ", "; |
|
123 | - else |
|
124 | - $aliasedFields .= "{$field}, "; |
|
124 | + if (strpos($existAS, '-as-') === false) { |
|
125 | + $aliasedFields .= "{$fieldsALIAS}." . trim($field) . ", "; |
|
126 | + } else { |
|
127 | + $aliasedFields .= "{$field}, "; |
|
128 | + } |
|
125 | 129 | } |
126 | 130 | $aliasedFields = trim($aliasedFields); |
127 | 131 | $aliasedFields = substr($aliasedFields, 0, strlen($aliasedFields) - 1); |
128 | 132 | } |
129 | 133 | } |
130 | - if ($aliasedFields == ', ') |
|
131 | - $aliasedFields = " , $fieldsALIAS.* "; |
|
134 | + if ($aliasedFields == ', ') { |
|
135 | + $aliasedFields = " , $fieldsALIAS.* "; |
|
136 | + } |
|
132 | 137 | |
133 | 138 | /* ************************ |
134 | 139 | $newSql = " SELECT $fields FROM ". |
@@ -141,8 +146,9 @@ discard block |
||
141 | 146 | $offset = (int)$offset; |
142 | 147 | $toReg = $offset + $limit ; |
143 | 148 | $fullTableName = $this->getTableInfo()->getTableFullName(); |
144 | - if (empty($sORDERBY)) |
|
145 | - $sORDERBY = "ROWNUM"; |
|
149 | + if (empty($sORDERBY)) { |
|
150 | + $sORDERBY = "ROWNUM"; |
|
151 | + } |
|
146 | 152 | |
147 | 153 | $newSql = " SELECT $fields FROM " . |
148 | 154 | "( " . |