Skip to content

Commit 0a978f9

Browse files
committedJan 5, 2017
Fix fetching schema information for pgsql when PDO::ATTR_CASE is set
1 parent 1bcdcde commit 0a978f9

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed
 

‎framework/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Yii Framework 2 Change Log
4040
- Bug #13159: Fixed `destroy` method in `yii.captcha.js` which did not work as expected (arogachev)
4141
- Bug #13198: Fixed order of checks in `yii\validators\IpValidator` that sometimes caused wrong error message (silverfire)
4242
- Bug #13200: Creating URLs for routes specified in `yii\rest\UrlRule::$extraPatterns` did not work if no HTTP verb was specified (cebe)
43-
- Bug #13229: Fix fetching table schema for `pgsql` when `PDO::ATTR_CASE` is set (klimov-paul)
43+
- Bug #13229: Fix fetching schema information for `pgsql` when `PDO::ATTR_CASE` is set (klimov-paul)
4444
- Bug #13231: Fixed `destroy` method in `yii.gridView.js` which did not work as expected (arogachev)
4545
- Bug #13232: Event handlers were not detached with changed selector in `yii.gridView.js` (arogachev)
4646
- Bug #12969: Improved unique ID generation for `yii\widgets\Pjax` widgets (dynasource, samdark, rob006)

‎framework/db/pgsql/Schema.php

+8-18
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public function loadTableSchema($name)
167167
$this->resolveTableNames($table, $name);
168168
if ($this->findColumns($table)) {
169169
$this->findConstraints($table);
170-
171170
return $table;
172171
} else {
173172
return null;
@@ -209,14 +208,7 @@ protected function findTableNames($schema = '')
209208
WHERE ns.nspname = :schemaName AND c.relkind IN ('r','v','m','f')
210209
ORDER BY c.relname
211210
SQL;
212-
$command = $this->db->createCommand($sql, [':schemaName' => $schema]);
213-
$rows = $command->queryAll();
214-
$names = [];
215-
foreach ($rows as $row) {
216-
$names[] = $row['table_name'];
217-
}
218-
219-
return $names;
211+
return $this->db->createCommand($sql, [':schemaName' => $schema])->queryColumn();
220212
}
221213

222214
/**
@@ -237,14 +229,7 @@ protected function findViewNames($schema = '')
237229
WHERE ns.nspname = :schemaName AND c.relkind = 'v'
238230
ORDER BY c.relname
239231
SQL;
240-
$command = $this->db->createCommand($sql, [':schemaName' => $schema]);
241-
$rows = $command->queryAll();
242-
$names = [];
243-
foreach ($rows as $row) {
244-
$names[] = $row['table_name'];
245-
}
246-
247-
return $names;
232+
return $this->db->createCommand($sql, [':schemaName' => $schema])->queryColumn();
248233
}
249234

250235
/**
@@ -271,7 +256,6 @@ public function getViewNames($schema = '', $refresh = false)
271256
*/
272257
protected function findConstraints($table)
273258
{
274-
275259
$tableName = $this->quoteValue($table->name);
276260
$tableSchema = $this->quoteValue($table->schemaName);
277261

@@ -305,6 +289,9 @@ protected function findConstraints($table)
305289

306290
$constraints = [];
307291
foreach ($this->db->createCommand($sql)->queryAll() as $constraint) {
292+
if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_UPPER) {
293+
$constraint = array_change_key_case($constraint, CASE_LOWER);
294+
}
308295
if ($constraint['foreign_table_schema'] !== $this->defaultSchema) {
309296
$foreignTable = $constraint['foreign_table_schema'] . '.' . $constraint['foreign_table_name'];
310297
} else {
@@ -373,6 +360,9 @@ public function findUniqueIndexes($table)
373360

374361
$rows = $this->getUniqueIndexInformation($table);
375362
foreach ($rows as $row) {
363+
if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_UPPER) {
364+
$row = array_change_key_case($row, CASE_LOWER);
365+
}
376366
$column = $row['columnname'];
377367
if (!empty($column) && $column[0] === '"') {
378368
// postgres will quote names that are not lowercase-only

0 commit comments

Comments
 (0)
Please sign in to comment.