Update 쿼리에서 alias 기본 값 사용 안 함

This commit is contained in:
dewekk 2022-06-02 17:21:28 +09:00
parent e0514110af
commit ecda6ddcb8
2 changed files with 10 additions and 4 deletions

View file

@ -326,7 +326,7 @@ class Query extends VariableBase
// Compose the INTO clause.
if (count($this->tables))
{
$tables = $this->_arrangeTables($this->tables);
$tables = $this->_arrangeTables($this->tables, true, false);
if ($tables !== '')
{
$result .= $tables;
@ -419,9 +419,10 @@ class Query extends VariableBase
*
* @param array $tables
* @param bool $use_aliases
* @param bool $use_default_aliases
* @return string
*/
protected function _arrangeTables(array $tables, bool $use_aliases = true): string
protected function _arrangeTables(array $tables, bool $use_aliases = true, bool $use_default_aliases = true): string
{
// Initialize the result.
$result = array();
@ -439,6 +440,7 @@ class Query extends VariableBase
if ($table instanceof self)
{
$tabledef = '(' . $table->getQueryString($this->_prefix, $this->_args) . ')';
$table->alias = $table->alias ?: $table->name;
if ($table->alias)
{
$tabledef .= ' AS `' . $table->alias . '`';
@ -453,6 +455,10 @@ class Query extends VariableBase
else
{
$tabledef = self::quoteName($this->_prefix . $table->name);
if ($use_default_aliases)
{
$table->alias = $table->alias ?: $table->name;
}
if ($use_aliases && $table->alias && $table->alias !== ($this->_prefix . $table->name))
{
$tabledef .= ' AS `' . $table->alias . '`';

View file

@ -65,7 +65,7 @@ class DBQueryParser extends BaseParser
{
$table = new DBQuery\Table;
$table->name = trim($tag['name']);
$table->alias = trim($tag['alias']) ?: $table->name;
$table->alias = trim($tag['alias']) ?: null;
$table->ifvar = trim($tag['if']) ?: null;
}
@ -78,7 +78,7 @@ class DBQueryParser extends BaseParser
$table->join_conditions = self::_parseConditions($tag->conditions);
}
}
$query->tables[$table->alias] = $table;
$query->tables[$table->alias ?: $table->name] = $table;
}
// Load index hints.