public function select($exprs, $args = NULL) {
$exprs = (array) $exprs;
foreach ($exprs as $expr) {
- $this->selects[$expr] = $this->interpolate($expr, $args);
+ $this->selects[] = $this->interpolate($expr, $args);
}
return $this;
}
public function groupBy($exprs, $args = NULL) {
$exprs = (array) $exprs;
foreach ($exprs as $expr) {
- $this->groupBys[$expr] = $this->interpolate($expr, $args);
+ $evaluatedExpr = $this->interpolate($expr, $args);
+ $this->groupBys[$evaluatedExpr] = $evaluatedExpr;
}
return $this;
}
public function having($exprs, $args = NULL) {
$exprs = (array) $exprs;
foreach ($exprs as $expr) {
- $this->havings[$expr] = $this->interpolate($expr, $args);
+ $evaluatedExpr = $this->interpolate($expr, $args);
+ $this->havings[$evaluatedExpr] = $evaluatedExpr;
}
return $this;
}
public function orderBy($exprs, $args = NULL) {
$exprs = (array) $exprs;
foreach ($exprs as $expr) {
- $this->orderBys[$expr] = $this->interpolate($expr, $args);
+ $evaluatedExpr = $this->interpolate($expr, $args);
+ $this->orderBys[$evaluatedExpr] = $evaluatedExpr;
}
return $this;
}
$this->assertEquals('world', $select['hello']);
}
+ public function testInsertInto_WithDupes() {
+ $select = CRM_Utils_SQL_Select::from('foo')
+ ->insertInto('bar', array('first', 'second', 'third', 'fourth'))
+ ->select('fid')
+ ->select('1')
+ ->select('fid')
+ ->select('1')
+ ->where('!field = #value', array('field' => 'zoo', 'value' => 3))
+ ->where('!field = #value', array('field' => 'aviary', 'value' => 3))
+ ->where('!field = #value', array('field' => 'zoo', 'value' => 3))
+ ->groupBy('!colName', array('colName' => 'noodle'))
+ ->groupBy('!colName', array('colName' => 'sauce'))
+ ->groupBy('!colName', array('colName' => 'noodle'));
+ $this->assertLike('INSERT INTO bar (first, second, third, fourth) SELECT fid, 1, fid, 1 FROM foo WHERE (zoo = 3) AND (aviary = 3) GROUP BY noodle, sauce', $select->toSQL());
+ }
+
/**
* @param $expected
* @param $actual