Skip to content
Permalink
Browse files

[debug:database:table] Sqlite support (#4073)

  • Loading branch information...
harold20 authored and enzolutions committed May 31, 2019
1 parent ee79d2e commit 46fb9ebb4ab369dc117ea3b4a975d62717bbcefd
Showing with 12 additions and 7 deletions.
  1. +11 −6 src/Command/Debug/DatabaseTableCommand.php
  2. +1 −1 src/Command/Shared/ConnectTrait.php
@@ -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(
@@ -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'],
];
}
@@ -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(
@@ -11,7 +11,7 @@
trait ConnectTrait
{
protected $supportedDrivers = ['mysql', 'pgsql'];
protected $supportedDrivers = ['mysql', 'pgsql', 'sqlite'];
public function resolveConnection($key = 'default', $target = 'default')
{

0 comments on commit 46fb9eb

Please sign in to comment.
You can’t perform that action at this time.