@@ -171,8 +171,19 @@ class QueryBuilderTest extends DatabaseTestCase
// in
[['in','id',[1,2,3]],'"id" IN (:qp0, :qp1, :qp2)',[':qp0'=>1,':qp1'=>2,':qp2'=>3]],
[['not in','id',[1,2,3]],'"id" NOT IN (:qp0, :qp1, :qp2)',[':qp0'=>1,':qp1'=>2,':qp2'=>3]],
[['in','id',(newQuery())->select('id')->from('users')->where(['active'=>1])],'("id") IN (SELECT "id" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
[['not in','id',(newQuery())->select('id')->from('users')->where(['active'=>1])],'("id") NOT IN (SELECT "id" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
// TODO: exists and not exists
// composite in
[['in',['id','name'],[['id'=>1,'name'=>'foo'],['id'=>2,'name'=>'bar']]],'("id", "name") IN ((:qp0, :qp1), (:qp2, :qp3))',[':qp0'=>1,':qp1'=>'foo',':qp2'=>2,':qp3'=>'bar']],
[['not in',['id','name'],[['id'=>1,'name'=>'foo'],['id'=>2,'name'=>'bar']]],'("id", "name") NOT IN ((:qp0, :qp1), (:qp2, :qp3))',[':qp0'=>1,':qp1'=>'foo',':qp2'=>2,':qp3'=>'bar']],
[['in',['id','name'],(newQuery())->select(['id','name'])->from('users')->where(['active'=>1])],'("id", "name") IN (SELECT "id", "name" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
[['not in',['id','name'],(newQuery())->select(['id','name'])->from('users')->where(['active'=>1])],'("id", "name") NOT IN (SELECT "id", "name" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
// exists
[['exists',(newQuery())->select('id')->from('users')->where(['active'=>1])],'EXISTS (SELECT "id" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
[['not exists',(newQuery())->select('id')->from('users')->where(['active'=>1])],'NOT EXISTS (SELECT "id" FROM "users" WHERE "active"=:qp0)',[':qp0'=>1]],
// simple conditions
[['=','a','b'],'"a" = :qp0',[':qp0'=>'b']],
...
...
@@ -229,8 +240,6 @@ class QueryBuilderTest extends DatabaseTestCase
[['in','id',[]],'',[]],
[['not in','id',[]],'',[]],
// TODO: exists and not exists
// simple conditions
[['=','a',''],'',[]],
[['>','a',''],'',[]],
...
...
@@ -262,8 +271,8 @@ class QueryBuilderTest extends DatabaseTestCase
$expectedQuerySql="SELECT `id` FROM `TotalExample` `t` WHERE (EXISTS (SELECT `1` FROM `Website` `w` WHERE (w.id = t.website_id) AND (w.merchant_id = :merchant_id))) AND (t.some_column = :some_value)";
$expectedQuerySql="SELECT `id` FROM `TotalExample` `t` WHERE (EXISTS (SELECT `1` FROM `Website` `w` WHERE (w.id = t.website_id) AND ((`w`.`merchant_id`=:qp0) AND (`w`.`user_id`=:qp1)))) AND (`t`.`some_column`=:qp2)";
This test contains three select queries connected with UNION and UNION ALL constructions.
It could be useful to use "phpunit --group=db --filter testBuildUnion" command for run it.
public function testBuildUnion()
{
$expectedQuerySql = "SELECT `id` FROM `TotalExample` `t1` WHERE (w > 0) AND (x < 2) UNION ( SELECT `id` FROM `TotalTotalExample` `t2` WHERE w > 5 ) UNION ALL ( SELECT `id` FROM `TotalTotalExample` `t3` WHERE w = 3 )";
* This test contains three select queries connected with UNION and UNION ALL constructions.
* It could be useful to use "phpunit --group=db --filter testBuildUnion" command for run it.
*/
publicfunctiontestBuildUnion()
{
$expectedQuerySql="(SELECT `id` FROM `TotalExample` `t1` WHERE (w > 0) AND (x < 2)) UNION ( SELECT `id` FROM `TotalTotalExample` `t2` WHERE w > 5 ) UNION ALL ( SELECT `id` FROM `TotalTotalExample` `t3` WHERE w = 3 )";