Skip to content

Commit

Permalink
[debug:database:table] Sqlite support (#4073)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuarez20 authored and enzolutions committed May 31, 2019
1 parent ee79d2e commit 46fb9eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/Command/Debug/DatabaseTableCommand.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 46fb9eb

Please sign in to comment.