Update of /cvsroot/php-blog/serendipity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10889
Modified Files:
serendipity_functions.inc.php
Log Message:
changed DISTINCT/GROUP BY issues. See mailinglist.
Index: serendipity_functions.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/serendipity_functions.inc.php,v
retrieving revision 1.333
retrieving revision 1.334
diff -u -d -r1.333 -r1.334
--- serendipity_functions.inc.php 15 Jul 2004 03:59:07 -0000 1.333
+++ serendipity_functions.inc.php 15 Jul 2004 07:54:13 -0000 1.334
@@ -727,11 +727,14 @@
}
}
- ##Query modified to remove GROUP BY clause. If Distinct doesn't work
- ##for mysql, please see the serendipity_mailSubscribers function in
- ##this file for an example of how to fix it.
+ if (strtolower($serendipity['dbType']) == 'postgres') {
+ $group = 'DISTINCT ON (e.id)';
+ } else {
+ $group = 'GROUP BY e.id';
+ }
+
$query = "SELECT
- DISTINCT(e.id),
+ e.id,
e.title,
e.timestamp,
e.comments,
@@ -755,11 +758,10 @@
ON e.id = ec.entryid
LEFT JOIN {$serendipity['dbPrefix']}category c
ON ec.categoryid = c.categoryid $and
+ $group
ORDER BY
$orderby
$limit";
- #GROUP BY
- # e.id
$ret = serendipity_db_query($query);
@@ -911,11 +913,14 @@
function serendipity_searchEntries($term) {
global $serendipity;
- ##Query modified to remove GROUP BY clause. If Distinct doesn't work
- ##for mysql, please see the serendipity_mailSubscribers function in
- ##this file for an example of how to fix it.
+ if (strtolower($serendipity['dbType']) == 'postgres') {
+ $group = 'DISTINCT ON (e.id)';
+ } else {
+ $group = 'GROUP BY e.id';
+ }
+
$querystring = "SELECT
- DISTINCT(e.id),
+ e.id,
e.author,
a.username,
a.email,
@@ -936,10 +941,9 @@
AND e.id = ec.entryid
AND MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($term) . "')
AND isdraft = 'false'
+ $group
ORDER BY
timestamp DESC";
- #GROUP BY
- # e.id
return serendipity_db_query($querystring);
}
@@ -1394,8 +1398,14 @@
$and = 'AND co.entry_id=' . $id;
}
+ if (strtolower($serendipity['dbType']) == 'postgres') {
+ $group = 'DISTINCT ON (co.id)';
+ } else {
+ $group = 'GROUP BY co.id';
+ }
+
$query = "SELECT
- DISTINCT(co.id),
+ co.id,
co.entry_id, co.timestamp, co.title, co.email, co.url, co.ip, co.body, co.type, co.subscribed,
co.author AS username,
e.title,
@@ -1409,11 +1419,11 @@
LEFT JOIN {$serendipity['dbPrefix']}entries e ON (co.entry_id = e.id)
LEFT JOIN {$serendipity['dbPrefix']}entrycat ec ON (e.id = ec.entryid)
LEFT JOIN {$serendipity['dbPrefix']}category c ON (ec.categoryid = c.categoryid)
- WHERE co.type LIKE 'NORMAL' AND entry_id > 0 $and
- ORDER BY
- co.id " . ($order != '' ? $order : '') . "
+ WHERE co.type LIKE 'NORMAL' AND entry_id > 0 $and
+ $group
+ ORDER BY
+ co.id " . ($order != '' ? $order : '') . "
$limit";
- #GROUP BY co.id
$comments = serendipity_db_query($query);
|