minor bugfix: don't drop identical query components in WhereClause (thanks Alexander!)
This commit is contained in:
@@ -790,12 +790,11 @@ class WhereClause {
|
||||
}
|
||||
|
||||
function textAndArgs() {
|
||||
$sql = '';
|
||||
$sql = array();
|
||||
$args = array();
|
||||
|
||||
if (count($this->clauses) == 0) return array('(1)', $args);
|
||||
|
||||
$sql = array();
|
||||
foreach ($this->clauses as $clause) {
|
||||
if ($clause instanceof WhereClause) {
|
||||
list($clause_sql, $clause_args) = $clause->textAndArgs();
|
||||
@@ -808,7 +807,6 @@ class WhereClause {
|
||||
$args = array_merge($args, $clause_args);
|
||||
}
|
||||
|
||||
$sql = array_unique($sql);
|
||||
if ($this->type == 'and') $sql = implode(' AND ', $sql);
|
||||
else $sql = implode(' OR ', $sql);
|
||||
|
||||
|
||||
@@ -58,6 +58,15 @@ class WhereClauseTest extends SimpleTest {
|
||||
$this->assert($result[0]['age'] === '15');
|
||||
}
|
||||
|
||||
function test_6_or() {
|
||||
$where = new WhereClause('or');
|
||||
$where->add('username=%s', 'Bart');
|
||||
$where->add('username=%s', 'Abe');
|
||||
|
||||
$result = DB::query("SELECT * FROM accounts WHERE %l", $where);
|
||||
$this->assert(count($result) === 2);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user