* this is not used as a dataprovider for testGetColumnType to speed up the test
* when used as dataprovider every single line will cause a reconnect with the database which is not needed here
*/
...
...
@@ -142,16 +155,16 @@ class QueryBuilderTest extends DatabaseTestCase
[['or not like','name',[]],'',[]],
// simple like
[['like','name','heyho'],'"name" LIKE :qp0',[':qp0'=>'%heyho%']],
[['not like','name','heyho'],'"name" NOT LIKE :qp0',[':qp0'=>'%heyho%']],
[['or like','name','heyho'],'"name" LIKE :qp0',[':qp0'=>'%heyho%']],
[['or not like','name','heyho'],'"name" NOT LIKE :qp0',[':qp0'=>'%heyho%']],
[['like','name','heyho'],'`name` LIKE :qp0',[':qp0'=>'%heyho%']],
[['not like','name','heyho'],'`name` NOT LIKE :qp0',[':qp0'=>'%heyho%']],
[['or like','name','heyho'],'`name` LIKE :qp0',[':qp0'=>'%heyho%']],
[['or not like','name','heyho'],'`name` NOT LIKE :qp0',[':qp0'=>'%heyho%']],
// like for many values
[['like','name',['heyho','abc']],'"name" LIKE :qp0 AND "name" LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['not like','name',['heyho','abc']],'"name" NOT LIKE :qp0 AND "name" NOT LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['or like','name',['heyho','abc']],'"name" LIKE :qp0 OR "name" LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['or not like','name',['heyho','abc']],'"name" NOT LIKE :qp0 OR "name" NOT LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['like','name',['heyho','abc']],'`name` LIKE :qp0 AND `name` LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['not like','name',['heyho','abc']],'`name` NOT LIKE :qp0 AND `name` NOT LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['or like','name',['heyho','abc']],'`name` LIKE :qp0 OR `name` LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
[['or not like','name',['heyho','abc']],'`name` NOT LIKE :qp0 OR `name` NOT LIKE :qp1',[':qp0'=>'%heyho%',':qp1'=>'%abc%']],
// not
[['not','name'],'NOT (name)',[]],
...
...
@@ -166,48 +179,41 @@ class QueryBuilderTest extends DatabaseTestCase
// between
[['between','id',1,10],'"id" BETWEEN :qp0 AND :qp1',[':qp0'=>1,':qp1'=>10]],
[['not between','id',1,10],'"id" NOT BETWEEN :qp0 AND :qp1',[':qp0'=>1,':qp1'=>10]],
[['between','id',1,10],'`id` BETWEEN :qp0 AND :qp1',[':qp0'=>1,':qp1'=>10]],
[['not between','id',1,10],'`id` NOT BETWEEN :qp0 AND :qp1',[':qp0'=>1,':qp1'=>10]],
// 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]],
[['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]],
// 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]],
[['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]],
[['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]],
$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)";
"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)";
"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)"
@@ -401,10 +390,9 @@ class QueryBuilderTest extends DatabaseTestCase
*/
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 )";
"(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 )"
);
$query=newQuery();
$secondQuery=newQuery();
$secondQuery->select('id')
...
...
@@ -421,6 +409,7 @@ class QueryBuilderTest extends DatabaseTestCase