? 284392-simplify-db_distinct_fields-rev2.D6.patch ? 284392-simplify-db_distinct_fields-rev3.D6.patch ? 284392-simplify-db_distinct_fields-rev4.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.mysql-common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/Attic/database.mysql-common.inc,v retrieving revision 1.17.2.3 diff -u -p -r1.17.2.3 database.mysql-common.inc --- includes/database.mysql-common.inc 14 Sep 2009 10:49:34 -0000 1.17.2.3 +++ includes/database.mysql-common.inc 17 Dec 2009 21:12:42 -0000 @@ -531,3 +531,21 @@ function db_change_field(&$ret, $table, function db_last_insert_id($table, $field) { return db_result(db_query('SELECT LAST_INSERT_ID()')); } + +/** + * 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; +} 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 17 Dec 2009 21:12:42 -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*)(?