All pastes #641043 Raw Edit

Something

public php v1 · immutable
#641043 ·published 2007-07-31 21:48 UTC
rendered paste body
function project_find_alias($query, $table) {  // See if {$table} is already in the query.  $match = array();  // This regexp handles many cases:  // - {node} can be either in FROM or in a JOIN clause  // - Query might end immediately after {node}  // - Might not have a table alias for {node}  $pattern = "@.*(FROM|JOIN)\s+\{$table\}\s*(\S+)?@";  if (preg_match($pattern, $query, $match)) {    $keywords = '@(ON|INNER|LEFT|RIGHT|WHERE|ORDER|GROUP|HAVING|LIMIT)@';    if (!isset($match[2]) || preg_match($keywords, $match[2])) {      // No alias found, just use "node".      $alias = $table;    }    else {      $alias = $match[2];    }  }  else {    $alias = FALSE;  }  return $alias;}