- Patch #106370 by naquah and chx: fixed query rewriting in presence of OR-clause.

5.x
Dries Buytaert 2007-01-03 10:59:02 +00:00
parent a7d58587cb
commit c3c8d7f13d
1 changed files with 9 additions and 9 deletions

View File

@ -269,30 +269,30 @@ function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $
if (!empty($where) || !empty($join)) {
if (!empty($where)) {
$new = " WHERE $where ";
$new = "WHERE $where ";
}
$new = " $join $new";
if (strpos($query, 'WHERE')) {
$replace = 'WHERE';
$add = 'AND';
$query = str_replace('WHERE', $new .'AND (', $query);
$insert = ') ';
}
elseif (strpos($query, 'GROUP')) {
else {
$insert = $new;
}
if (strpos($query, 'GROUP')) {
$replace = 'GROUP';
$add = 'GROUP';
}
elseif (strpos($query, 'ORDER')) {
$replace = 'ORDER';
$add = 'ORDER';
}
elseif (strpos($query, 'LIMIT')) {
$replace = 'LIMIT';
$add = 'LIMIT';
}
else {
$query .= $new;
$query .= $insert;
}
if (isset($replace)) {
$query = str_replace($replace, "$new $add ", $query);
$query = str_replace($replace, $insert . $replace, $query);
}
}