? 284392-simplify-db_distinct_fields-rev2.D6.patch
? 284392-simplify-db_distinct_fields-rev3.D6.patch
? 284392-simplify-db_distinct_fields.D6.patch
? 336483-add-comment-count-index-d6.patch
? 336483-add-comment-count-index-rev2-d6.patch
? 582534-freetagging-fullwidth-comma-D6.patch
? node_load_caching_flag-D6.patch
Index: includes/database.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.inc,v
retrieving revision 1.92.2.8
diff -u -p -r1.92.2.8 database.inc
--- includes/database.inc	14 Sep 2009 10:49:34 -0000	1.92.2.8
+++ includes/database.inc	16 Dec 2009 23:43:08 -0000
@@ -389,6 +389,24 @@ function db_rewrite_sql($query, $primary
 }
 
 /**
+ * Adds the DISTINCT flag to the supplied query if a DISTINCT doesn't already
+ * exist in the query. Returns the altered query.
+ *
+ * @param $table Unused. Kept to remain API compatibility.
+ * @param $field Unused. Kept to remain API compatibility.
+ * @param $query Query to which the DISTINCT flag should be applied.
+ * @return SQL query with the DISTINCT flag set.
+ */
+function db_distinct_field($table, $field, $query) {
+  $matches = array();
+  // We use stristr() because stripos() is only available in PHP 5.
+  if (!stristr('DISTINCT', $query) && preg_match('/^SELECT/i', $query, $matches)) {
+    $query = preg_replace('/^SELECT/i', 'SELECT DISTINCT', $query);
+  }
+  return $query;
+}
+
+/**
  * Restrict a dynamic table, column or constraint name to safe characters.
  *
  * Only keeps alphanumeric and underscores.
Index: includes/database.mysql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.mysql.inc,v
retrieving revision 1.89.2.1
diff -u -p -r1.89.2.1 database.mysql.inc
--- includes/database.mysql.inc	21 Jul 2009 08:52:29 -0000	1.89.2.1
+++ includes/database.mysql.inc	16 Dec 2009 23:43:09 -0000
@@ -350,30 +350,5 @@ function db_column_exists($table, $colum
 }
 
 /**
- * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
- * the SELECT list entry of the given query and the resulting query is returned.
- * This function only applies the wrapper if a DISTINCT doesn't already exist in
- * the query.
- *
- * @param $table Table containing the field to set as DISTINCT
- * @param $field Field to set as DISTINCT
- * @param $query Query to apply the wrapper to
- * @return SQL query with the DISTINCT wrapper surrounding the given table.field.
- */
-function db_distinct_field($table, $field, $query) {
-  $field_to_select = 'DISTINCT('. $table .'.'. $field .')';
-  $matches = array();
-  if (preg_match('/^SELECT(.*?)FROM(.*)/is', $query, $matches)) {
-    $select = preg_replace(
-      '/((?:^|,)\s*)(?<!DISTINCT\()(?:'. $table .'\.)?'. $field .'(\s*(?:,|$))/is',
-      '\1'. $field_to_select .'\2', $matches[1], 1
-    );
-    
-    return 'SELECT'. $select .'FROM'. $matches[2];
-  }
-  return $query;
-}
-
-/**
  * @} End of "ingroup database".
  */
Index: includes/database.mysqli.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.mysqli.inc,v
retrieving revision 1.54.2.1
diff -u -p -r1.54.2.1 database.mysqli.inc
--- includes/database.mysqli.inc	21 Jul 2009 08:52:30 -0000	1.54.2.1
+++ includes/database.mysqli.inc	16 Dec 2009 23:43:09 -0000
@@ -352,31 +352,6 @@ function db_column_exists($table, $colum
 }
 
 /**
- * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
- * the SELECT list entry of the given query and the resulting query is returned.
- * This function only applies the wrapper if a DISTINCT doesn't already exist in
- * the query.
- *
- * @param $table Table containing the field to set as DISTINCT
- * @param $field Field to set as DISTINCT
- * @param $query Query to apply the wrapper to
- * @return SQL query with the DISTINCT wrapper surrounding the given table.field.
- */
-function db_distinct_field($table, $field, $query) {
-  $field_to_select = 'DISTINCT('. $table .'.'. $field .')';
-  $matches = array();
-  if (preg_match('/^SELECT(.*?)FROM(.*)/is', $query, $matches)) {
-    $select = preg_replace(
-      '/((?:^|,)\s*)(?<!DISTINCT\()(?:'. $table .'\.)?'. $field .'(\s*(?:,|$))/is',
-      '\1'. $field_to_select .'\2', $matches[1], 1
-    );
-    
-    return 'SELECT'. $select .'FROM'.$matches[2];
-  }
-  return $query;
-}
-
-/**
  * @} End of "ingroup database".
  */
 
Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/Attic/database.pgsql.inc,v
retrieving revision 1.68.2.7
diff -u -p -r1.68.2.7 database.pgsql.inc
--- includes/database.pgsql.inc	14 Sep 2009 10:49:34 -0000	1.68.2.7
+++ includes/database.pgsql.inc	16 Dec 2009 23:43:09 -0000
@@ -408,29 +408,6 @@ function db_check_setup() {
 }
 
 /**
- * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
- * the SELECT list entry of the given query and the resulting query is returned.
- * This function only applies the wrapper if a DISTINCT doesn't already exist in
- * the query.
- *
- * @param $table Table containing the field to set as DISTINCT
- * @param $field Field to set as DISTINCT
- * @param $query Query to apply the wrapper to
- * @return SQL query with the DISTINCT wrapper surrounding the given table.field.
- */
-function db_distinct_field($table, $field, $query) {
-  if (!preg_match('/FROM\s+\S+\s+AS/si', $query)
-  && !preg_match('/DISTINCT\s+ON\s*\(\s*(' . $table . '\s*\.\s*)?' . $field . '\s*\)/si', $query)
-  && !preg_match('/DISTINCT[ (]' . $field . '/si', $query)
-  && preg_match('/(.*FROM\s+)(.*?\s)(\s*(WHERE|GROUP|HAVING|ORDER|LIMIT|FOR).*)/Asi', $query, $m)) {
-    $query = $m[1];
-    $query .= preg_replace('/([\{\w+\}]+)\s+(' . $table . ')\s/Usi', '(SELECT DISTINCT ON (' . $field . ') * FROM \1) \2 ', $m[2]);
-    $query .= $m[3];
-  }
-  return $query;
-}
-
-/**
  * @} End of "ingroup database".
  */
 
