Skip to content
Open
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
24 changes: 20 additions & 4 deletions src/Sql/SqlPgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Drush\Drush;

define('PSQL_SHOW_TABLES', "SELECT tablename FROM pg_tables WHERE schemaname='public';");

class SqlPgsql extends SqlBase
{
public string $queryExtra = "--no-align --field-separator=\"\t\" --pset tuples_only=on";
Expand Down Expand Up @@ -130,14 +128,14 @@ public function dbExists(): bool
public function queryFormat($query)
{
if (strtolower($query) === 'show tables;') {
return PSQL_SHOW_TABLES;
return $this->showTablesSql();
}
return $query;
}

public function listTables(): array
{
$this->alwaysQuery(PSQL_SHOW_TABLES);
$this->alwaysQuery($this->showTablesSql());
$tables = explode(PHP_EOL, trim($this->getProcess()->getOutput()));
return array_filter($tables);
}
Expand Down Expand Up @@ -199,4 +197,22 @@ public function getPasswordFile(): ?string
{
return $this->password_file;
}

private function schemaName(): string
{
$dbSpec = $this->getDbSpec();

return $dbSpec['schema']
?? $dbSpec['database']
?? 'public';
}

private function showTablesSql(): string
{
$schema = str_replace("'", "''", $this->schemaName());

return "SELECT quote_ident(schemaname) || '.' || quote_ident(tablename)
FROM pg_tables
WHERE schemaname='{$schema}';";
}
}