/** * Resolve the list of values that will be required for PDO statement binding. * * @param \Titon\Db\Query $query * @return array */ public function resolveParams(Query $query) { $params = []; $schema = $query->getRepository()->getSchema()->getColumns(); foreach ($query->getGroupedBindings() as $groupedBinds) { foreach ($groupedBinds as $binds) { $params[] = $this->resolveBind($binds['field'], $binds['value'], $schema); } } foreach ($query->getCompounds() as $compound) { $params = array_merge($params, $this->resolveParams($compound)); } return $params; }
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())); }