RSS

(root)/drupal/6 : 11 : includes/database.mysqli.inc

Ā« back to all changes in this revision

Viewing changes to includes/database.mysqli.inc

David Strauss
2010-03-04 01:32:05
Revision ID: david@fourkitchens.com-20100304013205-rzm7nzx405tybf1o
Tags: DRUPAL-6-16
DrupalĀ 6.16

Show diffs side-by-side

added added

removed removed

1
1
<?php
2
 
// $Id: database.mysqli.inc,v 1.54.2.1 2009/07/21 08:52:30 goba Exp $
 
2
// $Id: database.mysqli.inc,v 1.54.2.2 2010/02/01 16:32:10 goba Exp $
3
3
 
4
4
/**
5
5
 * @file
352
352
}
353
353
 
354
354
/**
355
 
 * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
356
 
 * the SELECT list entry of the given query and the resulting query is returned.
357
 
 * This function only applies the wrapper if a DISTINCT doesn't already exist in
358
 
 * the query.
359
 
 *
360
 
 * @param $table Table containing the field to set as DISTINCT
361
 
 * @param $field Field to set as DISTINCT
362
 
 * @param $query Query to apply the wrapper to
363
 
 * @return SQL query with the DISTINCT wrapper surrounding the given table.field.
364
 
 */
365
 
function db_distinct_field($table, $field, $query) {
366
 
  $field_to_select = 'DISTINCT('. $table .'.'. $field .')';
367
 
  $matches = array();
368
 
  if (preg_match('/^SELECT(.*?)FROM(.*)/is', $query, $matches)) {
369
 
    $select = preg_replace(
370
 
      '/((?:^|,)\s*)(?<!DISTINCT\()(?:'. $table .'\.)?'. $field .'(\s*(?:,|$))/is',
371
 
      '\1'. $field_to_select .'\2', $matches[1], 1
372
 
    );
373
 
    
374
 
    return 'SELECT'. $select .'FROM'.$matches[2];
375
 
  }
376
 
  return $query;
377
 
}
378
 
 
379
 
/**
380
355
 * @} End of "ingroup database".
381
356
 */
382
357
 

Loggerhead 1.17 is a web-based interface for Bazaar branches