RSS

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

Ā« back to all changes in this revision

Viewing changes to includes/database.pgsql.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.pgsql.inc,v 1.68.2.7 2009/09/14 10:49:34 goba Exp $
 
2
// $Id: database.pgsql.inc,v 1.68.2.8 2010/02/01 16:32:10 goba Exp $
3
3
 
4
4
/**
5
5
 * @file
408
408
}
409
409
 
410
410
/**
411
 
 * Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
412
 
 * the SELECT list entry of the given query and the resulting query is returned.
413
 
 * This function only applies the wrapper if a DISTINCT doesn't already exist in
414
 
 * the query.
415
 
 *
416
 
 * @param $table Table containing the field to set as DISTINCT
417
 
 * @param $field Field to set as DISTINCT
418
 
 * @param $query Query to apply the wrapper to
419
 
 * @return SQL query with the DISTINCT wrapper surrounding the given table.field.
420
 
 */
421
 
function db_distinct_field($table, $field, $query) {
422
 
  if (!preg_match('/FROM\s+\S+\s+AS/si', $query)
423
 
  && !preg_match('/DISTINCT\s+ON\s*\(\s*(' . $table . '\s*\.\s*)?' . $field . '\s*\)/si', $query)
424
 
  && !preg_match('/DISTINCT[ (]' . $field . '/si', $query)
425
 
  && preg_match('/(.*FROM\s+)(.*?\s)(\s*(WHERE|GROUP|HAVING|ORDER|LIMIT|FOR).*)/Asi', $query, $m)) {
426
 
    $query = $m[1];
427
 
    $query .= preg_replace('/([\{\w+\}]+)\s+(' . $table . ')\s/Usi', '(SELECT DISTINCT ON (' . $field . ') * FROM \1) \2 ', $m[2]);
428
 
    $query .= $m[3];
429
 
  }
430
 
  return $query;
431
 
}
432
 
 
433
 
/**
434
411
 * @} End of "ingroup database".
435
412
 */
436
413
 

Loggerhead 1.17 is a web-based interface for Bazaar branches