Skip to content
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

[debug:database:table] Sqlite support #4073

Merged
merged 1 commit into from May 31, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Command/Debug/DatabaseTableCommand.php
Expand Up @@ -76,9 +76,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$table = $input->getArgument('table');
$databaseConnection = $this->resolveConnection($database);
if ($table) {
$result = $this->database
->query('DESCRIBE ' . $table . ';')
->fetchAll();

$result = $databaseConnection['driver'] == 'sqlite' ? $this->database->query('PRAGMA table_info('.$table.');') :
$this->database
->query('DESCRIBE ' . $table . ';')
->fetchAll();

if (!$result) {
throw new \Exception(
sprintf(
Expand All @@ -96,8 +99,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
foreach ($result as $record) {
$column = json_decode(json_encode($record), true);
$tableRows[] = [
'column' => $column['Field'],
'type' => $column['Type'],
'column' => $column[$databaseConnection['driver'] == 'sqlite' ? 'name': 'Field'],
'type' => $column[$databaseConnection['driver'] == 'sqlite' ? 'type': 'Type'],
];
}

Expand All @@ -107,7 +110,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$schema = $this->database->schema();
$tables = $schema->findTables('%');

$tables = $databaseConnection['driver'] == 'sqlite' ? array_keys($this->database->query('SELECT name FROM sqlite_master WHERE type = "table" AND name NOT LIKE "sqlite_%";')
->fetchAllAssoc('name')) : $schema->findTables('%');

$this->getIo()->comment(
sprintf(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Shared/ConnectTrait.php
Expand Up @@ -11,7 +11,7 @@

trait ConnectTrait
{
protected $supportedDrivers = ['mysql', 'pgsql'];
protected $supportedDrivers = ['mysql', 'pgsql', 'sqlite'];

public function resolveConnection($key = 'default', $target = 'default')
{
Expand Down