From 58ae36d23a5ec915a263282dd84187c82a5600c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Mon, 1 May 2023 14:38:52 +0200 Subject: [PATCH] use the table name is column names if table is not specified --- src/Database/Query/Select.php | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Database/Query/Select.php b/src/Database/Query/Select.php index 8acbb0d..4eb53a0 100644 --- a/src/Database/Query/Select.php +++ b/src/Database/Query/Select.php @@ -276,13 +276,12 @@ class Select return [(string) $table, $params]; } - if ($table instanceof Select) - { + if ($table instanceof Select) { return $table->generateQuery(); } if (isset($this->tableAliases[$table])) { - $queryString = ($defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table)); + $queryString = $defineAlias ? Utils::backtick($this->tableAliases[$table]) . ' ' . Utils::backtick($table) : Utils::backtick($table); return [$queryString, $params]; } @@ -295,24 +294,17 @@ class Select return (string) $column; } - if (is_array($column)) { - $out = ''; - - if ($column[0]) { - list($tableName, $params) = $this->generateTable($column[0]); - $out .= $tableName . '.'; - } - - $out .= Utils::backtick($column[1]); - - if (!empty($column[2])) { - $out .= ' ' . Utils::backtick($column[2]); - } - - return $out; - } else { - return Utils::backtick($column); + if (!is_array($column)) { + $column = [$this->table, $column]; } + + list($tableName, $params) = $this->generateTable($column[0]); + $out = $tableName . '.' . Utils::backtick($column[1]); + if (!empty($column[2])) { + $out .= ' ' . Utils::backtick($column[2]); + } + + return $out; } private function generateColumns(): string