mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-04 17:44:38 +09:00
Use constants to control alias handling (#1956 보완)
This commit is contained in:
parent
fe7833698a
commit
b8641c3501
1 changed files with 15 additions and 9 deletions
|
|
@ -44,6 +44,13 @@ class Query extends VariableBase
|
||||||
protected $_column_list = array();
|
protected $_column_list = array();
|
||||||
protected $_params = array();
|
protected $_params = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants for alias handling.
|
||||||
|
*/
|
||||||
|
const ALIAS_NONE = 0;
|
||||||
|
const ALIAS_SPECIFIED = 1;
|
||||||
|
const ALIAS_ALWAYS = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the query string for this query.
|
* Generate the query string for this query.
|
||||||
*
|
*
|
||||||
|
|
@ -184,7 +191,7 @@ class Query extends VariableBase
|
||||||
// Compose the FROM clause.
|
// Compose the FROM clause.
|
||||||
if (count($this->tables))
|
if (count($this->tables))
|
||||||
{
|
{
|
||||||
$tables = $this->_arrangeTables($this->tables);
|
$tables = $this->_arrangeTables($this->tables, self::ALIAS_ALWAYS);
|
||||||
if ($tables !== '')
|
if ($tables !== '')
|
||||||
{
|
{
|
||||||
$result .= ' FROM ' . $tables;
|
$result .= ' FROM ' . $tables;
|
||||||
|
|
@ -274,7 +281,7 @@ class Query extends VariableBase
|
||||||
// Compose the INTO clause.
|
// Compose the INTO clause.
|
||||||
if (count($this->tables))
|
if (count($this->tables))
|
||||||
{
|
{
|
||||||
$tables = $this->_arrangeTables($this->tables, false);
|
$tables = $this->_arrangeTables($this->tables, self::ALIAS_NONE);
|
||||||
if ($tables !== '')
|
if ($tables !== '')
|
||||||
{
|
{
|
||||||
$result .= ' INTO ' . $tables;
|
$result .= ' INTO ' . $tables;
|
||||||
|
|
@ -326,7 +333,7 @@ class Query extends VariableBase
|
||||||
// Compose the INTO clause.
|
// Compose the INTO clause.
|
||||||
if (count($this->tables))
|
if (count($this->tables))
|
||||||
{
|
{
|
||||||
$tables = $this->_arrangeTables($this->tables, true, false);
|
$tables = $this->_arrangeTables($this->tables, self::ALIAS_SPECIFIED);
|
||||||
if ($tables !== '')
|
if ($tables !== '')
|
||||||
{
|
{
|
||||||
$result .= $tables;
|
$result .= $tables;
|
||||||
|
|
@ -377,7 +384,7 @@ class Query extends VariableBase
|
||||||
// Compose the FROM clause.
|
// Compose the FROM clause.
|
||||||
if (count($this->tables))
|
if (count($this->tables))
|
||||||
{
|
{
|
||||||
$tables = $this->_arrangeTables($this->tables, false);
|
$tables = $this->_arrangeTables($this->tables, self::ALIAS_NONE);
|
||||||
if ($tables !== '')
|
if ($tables !== '')
|
||||||
{
|
{
|
||||||
$result .= ' FROM ' . $tables;
|
$result .= ' FROM ' . $tables;
|
||||||
|
|
@ -418,11 +425,10 @@ class Query extends VariableBase
|
||||||
* Generate a FROM clause from a list of tables.
|
* Generate a FROM clause from a list of tables.
|
||||||
*
|
*
|
||||||
* @param array $tables
|
* @param array $tables
|
||||||
* @param bool $use_aliases
|
* @param int $use_aliases
|
||||||
* @param bool $use_default_aliases
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function _arrangeTables(array $tables, bool $use_aliases = true, bool $use_default_aliases = true): string
|
protected function _arrangeTables(array $tables, int $use_aliases = self::ALIAS_SPECIFIED): string
|
||||||
{
|
{
|
||||||
// Initialize the result.
|
// Initialize the result.
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
@ -455,11 +461,11 @@ class Query extends VariableBase
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tabledef = self::quoteName($this->_prefix . $table->name);
|
$tabledef = self::quoteName($this->_prefix . $table->name);
|
||||||
if ($use_default_aliases)
|
if ($use_aliases === self::ALIAS_ALWAYS)
|
||||||
{
|
{
|
||||||
$table->alias = $table->alias ?: $table->name;
|
$table->alias = $table->alias ?: $table->name;
|
||||||
}
|
}
|
||||||
if ($use_aliases && $table->alias && $table->alias !== ($this->_prefix . $table->name))
|
if ($use_aliases !== self::ALIAS_NONE && $table->alias && $table->alias !== ($this->_prefix . $table->name))
|
||||||
{
|
{
|
||||||
$tabledef .= ' AS `' . $table->alias . '`';
|
$tabledef .= ' AS `' . $table->alias . '`';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue