summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGábor Hojtsy2008-02-08 22:44:59 (GMT)
committerGábor Hojtsy2008-02-08 22:44:59 (GMT)
commitba74c7ce25f40d95e028aa9dc0e66c5c64a9788b (patch)
treeb8a37535193dc65bd5935ed845dbfe6ca7820679
parent32ed1f9a63abe5bcb1279b8637ca43176e630543 (diff)
#219380 by chx: bring back support for queries without WHERE clause to db_rewrite_sql() (regression)
-rw-r--r--includes/database.inc33
1 files changed, 22 insertions, 11 deletions
diff --git a/includes/database.inc b/includes/database.inc
index d3de06c..d97a4e5 100644
--- a/includes/database.inc
+++ b/includes/database.inc
@@ -328,22 +328,30 @@ function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $
)[^()]+WHERE)
}x';
preg_match($pattern, $query, $matches);
- if ($where) {
+ if (!$where) {
+ $where = '1 = 1';
+ }
+ if ($matches) {
$n = strlen($matches[1]);
$second_part = substr($query, $n);
$first_part = substr($matches[1], 0, $n - 5) ." $join WHERE $where AND ( ";
// PHP 4 does not support strrpos for strings. We emulate it.
$haystack_reverse = strrev($second_part);
- // No need to use strrev on the needle, we supply GROUP, ORDER, LIMIT
- // reversed.
- foreach (array('PUORG', 'REDRO', 'TIMIL') as $needle_reverse) {
- $pos = strpos($haystack_reverse, $needle_reverse);
- if ($pos !== FALSE) {
- // All needles are five characters long.
- $pos += 5;
- break;
- }
+ }
+ else {
+ $haystack_reverse = strrev($query);
+ }
+ // No need to use strrev on the needle, we supply GROUP, ORDER, LIMIT
+ // reversed.
+ foreach (array('PUORG', 'REDRO', 'TIMIL') as $needle_reverse) {
+ $pos = strpos($haystack_reverse, $needle_reverse);
+ if ($pos !== FALSE) {
+ // All needles are five characters long.
+ $pos += 5;
+ break;
}
+ }
+ if ($matches) {
if ($pos === FALSE) {
$query = $first_part . $second_part .')';
}
@@ -351,8 +359,11 @@ function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $
$query = $first_part . substr($second_part, 0, -$pos) .')'. substr($second_part, -$pos);
}
}
+ elseif ($pos === FALSE) {
+ $query .= " $join WHERE $where";
+ }
else {
- $query = $matches[1] ." $join ". substr($query, strlen($matches[1]));
+ $query = substr($query, 0, -$pos) . " $join WHERE $where " . substr($query, -$pos);
}
}