mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Merge branch 'dewekk/fix-dbquery' into develop
This commit is contained in:
commit
fe7833698a
3 changed files with 11 additions and 5 deletions
|
|
@ -326,7 +326,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, true, false);
|
||||||
if ($tables !== '')
|
if ($tables !== '')
|
||||||
{
|
{
|
||||||
$result .= $tables;
|
$result .= $tables;
|
||||||
|
|
@ -419,9 +419,10 @@ class Query extends VariableBase
|
||||||
*
|
*
|
||||||
* @param array $tables
|
* @param array $tables
|
||||||
* @param bool $use_aliases
|
* @param bool $use_aliases
|
||||||
|
* @param bool $use_default_aliases
|
||||||
* @return string
|
* @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.
|
// Initialize the result.
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
@ -439,6 +440,7 @@ class Query extends VariableBase
|
||||||
if ($table instanceof self)
|
if ($table instanceof self)
|
||||||
{
|
{
|
||||||
$tabledef = '(' . $table->getQueryString($this->_prefix, $this->_args) . ')';
|
$tabledef = '(' . $table->getQueryString($this->_prefix, $this->_args) . ')';
|
||||||
|
$table->alias = $table->alias ?: $table->name;
|
||||||
if ($table->alias)
|
if ($table->alias)
|
||||||
{
|
{
|
||||||
$tabledef .= ' AS `' . $table->alias . '`';
|
$tabledef .= ' AS `' . $table->alias . '`';
|
||||||
|
|
@ -453,6 +455,10 @@ class Query extends VariableBase
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tabledef = self::quoteName($this->_prefix . $table->name);
|
$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))
|
if ($use_aliases && $table->alias && $table->alias !== ($this->_prefix . $table->name))
|
||||||
{
|
{
|
||||||
$tabledef .= ' AS `' . $table->alias . '`';
|
$tabledef .= ' AS `' . $table->alias . '`';
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class DBQueryParser extends BaseParser
|
||||||
{
|
{
|
||||||
$table = new DBQuery\Table;
|
$table = new DBQuery\Table;
|
||||||
$table->name = trim($tag['name']);
|
$table->name = trim($tag['name']);
|
||||||
$table->alias = trim($tag['alias']) ?: $table->name;
|
$table->alias = trim($tag['alias']) ?: null;
|
||||||
$table->ifvar = trim($tag['if']) ?: null;
|
$table->ifvar = trim($tag['if']) ?: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ class DBQueryParser extends BaseParser
|
||||||
$table->join_conditions = self::_parseConditions($tag->conditions);
|
$table->join_conditions = self::_parseConditions($tag->conditions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$query->tables[$table->alias] = $table;
|
$query->tables[$table->alias ?: $table->name] = $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load index hints.
|
// Load index hints.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class DBQueryParserTest extends \Codeception\TestCase\Test
|
||||||
$this->assertTrue($query->select_distinct);
|
$this->assertTrue($query->select_distinct);
|
||||||
|
|
||||||
$this->assertTrue($query->tables['documents'] instanceof Rhymix\Framework\Parsers\DBQuery\Table);
|
$this->assertTrue($query->tables['documents'] instanceof Rhymix\Framework\Parsers\DBQuery\Table);
|
||||||
$this->assertEquals('documents', $query->tables['documents']->alias);
|
$this->assertEquals('documents', $query->tables['documents']->name);
|
||||||
|
|
||||||
$this->assertEquals(1, count($query->columns));
|
$this->assertEquals(1, count($query->columns));
|
||||||
$this->assertEquals('*', $query->columns[0]->name);
|
$this->assertEquals('*', $query->columns[0]->name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue