From bc49d84555dead4ce4b41415d0c0e1314e7d57ab Mon Sep 17 00:00:00 2001 From: BOIVIN Jonathan Date: Fri, 10 Dec 2021 16:00:53 +0100 Subject: [PATCH] fix(builder): fix getColumnListing --- src/Database/Schema/Builder.php | 40 ++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Database/Schema/Builder.php b/src/Database/Schema/Builder.php index fc7eab6..751df0f 100644 --- a/src/Database/Schema/Builder.php +++ b/src/Database/Schema/Builder.php @@ -12,11 +12,10 @@ */ class Builder extends \Illuminate\Database\Schema\Builder { - /** * Determine if the given table exists. * - * @param string $table + * @param string $table * * @return bool */ @@ -27,19 +26,22 @@ public function hasTable($table) if (count($schemaTable) > 1) { $schema = $schemaTable[0]; - $table = $this->connection->getTablePrefix().$schemaTable[1]; + $table = $this->connection->getTablePrefix() . $schemaTable[1]; } else { $schema = $this->connection->getDefaultSchema(); - $table = $this->connection->getTablePrefix().$table; + $table = $this->connection->getTablePrefix() . $table; } - return count($this->connection->select($sql, [$schema, $table])) > 0; + return count($this->connection->select($sql, [ + $schema, + $table, + ])) > 0; } /** * Get the column listing for a given table. * - * @param string $table + * @param string $table * * @return array */ @@ -47,10 +49,26 @@ public function getColumnListing($table) { $sql = $this->grammar->compileColumnExists(); $database = $this->connection->getDatabaseName(); - $table = $this->connection->getTablePrefix().$table; - $results = $this->connection->select($sql, [$database, $table]); + $table = $this->connection->getTablePrefix() . $table; + + $tableExploded = explode('.', $table); + + if (count($tableExploded) > 1) { + $database = $tableExploded[0]; + $table = $tableExploded[1]; + } + + $results = $this->connection->select($sql, [ + $database, + $table, + ]); + + $res = $this->connection->getPostProcessor() + ->processColumnListing($results); - return $this->connection->getPostProcessor()->processColumnListing($results); + return array_values(array_map(function($r) { + return $r->column_name; + }, $res)); } /** @@ -73,8 +91,8 @@ protected function build(Blueprint $blueprint) /** * Create a new command set with a Closure. * - * @param string $table - * @param \Closure $callback + * @param string $table + * @param \Closure $callback * * @return \Cooperl\DB2\Database\Schema\Blueprint */