From ac68bbe1f9dded0d855765aaedae89f5cecaac30 Mon Sep 17 00:00:00 2001 From: Nikola Chingoski Date: Thu, 5 Mar 2020 13:35:49 +0100 Subject: [PATCH] PostgreSQL query fix --- src/Console/GenerateCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Console/GenerateCommand.php b/src/Console/GenerateCommand.php index 57f814e..579c118 100644 --- a/src/Console/GenerateCommand.php +++ b/src/Console/GenerateCommand.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; - class GenerateCommand extends Command { /** @@ -368,9 +367,11 @@ public static function enumValues($table, $name) if ($table === null) { return "[]"; } - - $type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type; - + if (env('DB_HOST') == 'postgres') { + $type = DB::select(DB::raw('SELECT column_name,data_type FROM information_schema.columns WHERE table_name = \'' . $table . '\' AND column_name = \'' . $name . '\''))[0]->data_type; + } else { + $type = DB::select(DB::raw('SHOW COLUMNS FROM ' . $table . ' WHERE Field = "' . $name . '"'))[0]->Type; + } preg_match_all("/'([^']+)'/", $type, $matches); $values = isset($matches[1]) ? $matches[1] : array(); @@ -394,5 +395,4 @@ protected function createFactory($class) return $content; } - }