Skip to content

Commit

Permalink
MySqlDriver: Fix PDO::ATTR_CASE (#199)
Browse files Browse the repository at this point in the history
fixed Cannot read an undeclared column 'Type', did you mean 'type'? when you used PDO::ATTR_CASE option
  • Loading branch information
dennydanek authored and dg committed Jun 19, 2018
1 parent edc3648 commit 40e48b1
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Database/Drivers/MySqlDriver.php
Expand Up @@ -143,17 +143,18 @@ public function getColumns($table)
{
$columns = [];
foreach ($this->connection->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table)) as $row) {
$type = explode('(', $row['Type']);
$row = array_change_key_case((array) $row, CASE_LOWER);
$type = explode('(', $row['type']);
$columns[] = [
'name' => $row['Field'],
'name' => $row['field'],
'table' => $table,
'nativetype' => strtoupper($type[0]),
'size' => isset($type[1]) ? (int) $type[1] : null,
'unsigned' => (bool) strstr($row['Type'], 'unsigned'),
'nullable' => $row['Null'] === 'YES',
'default' => $row['Default'],
'autoincrement' => $row['Extra'] === 'auto_increment',
'primary' => $row['Key'] === 'PRI',
'unsigned' => (bool) strstr($row['type'], 'unsigned'),
'nullable' => $row['null'] === 'YES',
'default' => $row['default'],
'autoincrement' => $row['extra'] === 'auto_increment',
'primary' => $row['key'] === 'PRI',
'vendor' => (array) $row,
];
}
Expand All @@ -165,10 +166,11 @@ public function getIndexes($table)
{
$indexes = [];
foreach ($this->connection->query('SHOW INDEX FROM ' . $this->delimite($table)) as $row) {
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
$indexes[$row['Key_name']]['primary'] = $row['Key_name'] === 'PRIMARY';
$indexes[$row['Key_name']]['columns'][$row['Seq_in_index'] - 1] = $row['Column_name'];
$row = array_change_key_case((array) $row, CASE_LOWER);
$indexes[$row['key_name']]['name'] = $row['key_name'];
$indexes[$row['key_name']]['unique'] = !$row['non_unique'];
$indexes[$row['key_name']]['primary'] = $row['key_name'] === 'PRIMARY';
$indexes[$row['key_name']]['columns'][$row['seq_in_index'] - 1] = $row['column_name'];
}
return array_values($indexes);
}
Expand All @@ -181,10 +183,11 @@ public function getForeignKeys($table)
. 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table);

foreach ($this->connection->query($query) as $id => $row) {
$keys[$id]['name'] = $row['CONSTRAINT_NAME']; // foreign key name
$keys[$id]['local'] = $row['COLUMN_NAME']; // local columns
$keys[$id]['table'] = $row['REFERENCED_TABLE_NAME']; // referenced table
$keys[$id]['foreign'] = $row['REFERENCED_COLUMN_NAME']; // referenced columns
$row = array_change_key_case((array) $row, CASE_LOWER);
$keys[$id]['name'] = $row['constraint_name']; // foreign key name
$keys[$id]['local'] = $row['column_name']; // local columns
$keys[$id]['table'] = $row['referenced_table_name']; // referenced table
$keys[$id]['foreign'] = $row['referenced_column_name']; // referenced columns
}

return array_values($keys);
Expand Down

0 comments on commit 40e48b1

Please sign in to comment.