Skip to content

Commit

Permalink
fix(builder): fix getColumnListing
Browse files Browse the repository at this point in the history
  • Loading branch information
boivinj committed Dec 10, 2021
1 parent f5cad53 commit bc49d84
Showing 1 changed file with 29 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -27,30 +26,49 @@ 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
*/
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));
}

/**
Expand All @@ -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
*/
Expand Down

0 comments on commit bc49d84

Please sign in to comment.