Skip to content

[5.5] Fix column listing for postgres db driver. #19553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Jun 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ public function compileTableExists()
/**
* Compile the query to determine the list of columns.
*
* @param string $table
* @return string
*/
public function compileColumnListing($table)
public function compileColumnListing()
{
return "select column_name from information_schema.columns where table_name = '$table'";
return 'select column_name from information_schema.columns where table_schema = ? and table_name = ?';
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/Illuminate/Database/Schema/PostgresBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,27 @@ protected function getAllTables()
$this->grammar->compileGetAllTables($this->connection->getConfig('schema'))
);
}

/**
* Get the column listing for a given table.
*
* @param string $table
* @return array
*/
public function getColumnListing($table)
{
if (is_array($schema = $this->connection->getConfig('schema'))) {
$schema = head($schema);
}

$schema = $schema ? $schema : 'public';

$table = $this->connection->getTablePrefix().$table;

$results = $this->connection->select(
$this->grammar->compileColumnListing(), [$schema, $table]
);

return $this->connection->getPostProcessor()->processColumnListing($results);
}
}