mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-16 22:39:52 +08:00
allow passing a single Expression object to select() and addSelect()
fixes #9883
This commit is contained in:
@@ -505,6 +505,27 @@ class QueryBuilderTest extends DatabaseTestCase
|
||||
$this->assertEmpty($params);
|
||||
}
|
||||
|
||||
public function testSelectExpression()
|
||||
{
|
||||
$query = (new Query())
|
||||
->select(new Expression("1 AS ab"))
|
||||
->from('tablename');
|
||||
list ($sql, $params) = $this->getQueryBuilder()->build($query);
|
||||
$expected = $this->replaceQuotes("SELECT 1 AS ab FROM `tablename`");
|
||||
$this->assertEquals($expected, $sql);
|
||||
$this->assertEmpty($params);
|
||||
|
||||
$query = (new Query())
|
||||
->select(new Expression("1 AS ab"))
|
||||
->addSelect(new Expression("2 AS cd"))
|
||||
->addSelect(['ef' => new Expression("3")])
|
||||
->from('tablename');
|
||||
list ($sql, $params) = $this->getQueryBuilder()->build($query);
|
||||
$expected = $this->replaceQuotes("SELECT 1 AS ab, 2 AS cd, 3 AS `ef` FROM `tablename`");
|
||||
$this->assertEquals($expected, $sql);
|
||||
$this->assertEmpty($params);
|
||||
}
|
||||
|
||||
public function testCompositeInCondition()
|
||||
{
|
||||
$condition = [
|
||||
|
||||
Reference in New Issue
Block a user