Example #1
0
 public function testResolveParamsCompoundQueries()
 {
     $query1 = new Query(Query::SELECT, $this->table);
     $query1->where('username', 'like', '%foo%');
     $query2 = new Query(Query::SELECT, $this->table);
     $query2->where('username', 'like', '%bar%');
     $query1->union($query2);
     $this->assertEquals([['%foo%', PDO::PARAM_STR], ['%bar%', PDO::PARAM_STR]], $this->object->resolveParams($query1));
 }
Example #2
0
 public function testFormatCompounds()
 {
     // union
     $query = new Query(Query::INSERT, new User());
     $query->union($query->subQuery('id')->from('u1'));
     $this->assertRegExp('/UNION\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // union all
     $query->union($query->subQuery('id')->from('u2'), 'all');
     $this->assertRegExp('/UNION\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")? UNION ALL SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u2(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // union distinct
     $query = new Query(Query::INSERT, new User());
     $query->union($query->subQuery('id')->from('u1'), 'distinct');
     $this->assertRegExp('/UNION DISTINCT SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // intersects
     $query = new Query(Query::INSERT, new User());
     $query->intersect($query->subQuery('id')->from('u1'));
     $this->assertRegExp('/INTERSECT\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // intersects all
     $query->intersect($query->subQuery('id')->from('u2'), 'all');
     $this->assertRegExp('/INTERSECT\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")? INTERSECT ALL SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u2(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // excepts
     $query = new Query(Query::INSERT, new User());
     $query->except($query->subQuery('id')->from('u1'));
     $this->assertRegExp('/EXCEPT\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
     // excepts all
     $query->except($query->subQuery('id')->from('u2'), 'all');
     $this->assertRegExp('/EXCEPT\\s+SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u1(`|\\")? EXCEPT ALL SELECT\\s+(`|\\")?id(`|\\")? FROM (`|\\")?u2(`|\\")?/', $this->object->formatCompounds($query->getCompounds()));
 }