From f3df7ecc9d527cdcaef1d5ad215511f304223901 Mon Sep 17 00:00:00 2001 From: Harold Date: Fri, 31 May 2019 14:10:20 -0600 Subject: [PATCH] [debug:database:table] Sqlite support --- src/Command/Debug/DatabaseTableCommand.php | 17 +++++++++++------ src/Command/Shared/ConnectTrait.php | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Command/Debug/DatabaseTableCommand.php b/src/Command/Debug/DatabaseTableCommand.php index e33d630be..88399381b 100644 --- a/src/Command/Debug/DatabaseTableCommand.php +++ b/src/Command/Debug/DatabaseTableCommand.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( diff --git a/src/Command/Shared/ConnectTrait.php b/src/Command/Shared/ConnectTrait.php index 517d93c93..24ddd8b40 100644 --- a/src/Command/Shared/ConnectTrait.php +++ b/src/Command/Shared/ConnectTrait.php @@ -11,7 +11,7 @@ trait ConnectTrait { - protected $supportedDrivers = ['mysql', 'pgsql']; + protected $supportedDrivers = ['mysql', 'pgsql', 'sqlite']; public function resolveConnection($key = 'default', $target = 'default') {