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() {
|
function textAndArgs() {
|
||||||
$sql = '';
|
$sql = array();
|
||||||
$args = array();
|
$args = array();
|
||||||
|
|
||||||
if (count($this->clauses) == 0) return array('(1)', $args);
|
if (count($this->clauses) == 0) return array('(1)', $args);
|
||||||
|
|
||||||
$sql = array();
|
|
||||||
foreach ($this->clauses as $clause) {
|
foreach ($this->clauses as $clause) {
|
||||||
if ($clause instanceof WhereClause) {
|
if ($clause instanceof WhereClause) {
|
||||||
list($clause_sql, $clause_args) = $clause->textAndArgs();
|
list($clause_sql, $clause_args) = $clause->textAndArgs();
|
||||||
@@ -808,7 +807,6 @@ class WhereClause {
|
|||||||
$args = array_merge($args, $clause_args);
|
$args = array_merge($args, $clause_args);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = array_unique($sql);
|
|
||||||
if ($this->type == 'and') $sql = implode(' AND ', $sql);
|
if ($this->type == 'and') $sql = implode(' AND ', $sql);
|
||||||
else $sql = implode(' OR ', $sql);
|
else $sql = implode(' OR ', $sql);
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,15 @@ class WhereClauseTest extends SimpleTest {
|
|||||||
$this->assert(count($result) === 1);
|
$this->assert(count($result) === 1);
|
||||||
$this->assert($result[0]['age'] === '15');
|
$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