Project

General

Profile

Bug #19494 » 9620_v2.diff

Administrator Admin, 2009-08-15 17:32

View differences:

t3lib/class.t3lib_db.php (working copy)
* @see exec_SELECTquery()
*/
function exec_SELECT_mm_query($select,$local_table,$mm_table,$foreign_table,$whereClause='',$groupBy='',$orderBy='',$limit='') {
if($foreign_table == $local_table) {
$foreign_table_as = $foreign_table.uniqid('_join');
$query = $this->SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause, $groupBy, $orderBy, $limit);
$res = mysql_query($query, $this->link);
if ($this->debugOutput) {
$this->debug('exec_SELECT_mm_query');
}
$mmWhere = $local_table ? $local_table.'.uid='.$mm_table.'.uid_local' : '';
$mmWhere.= ($local_table AND $foreign_table) ? ' AND ' : '';
$mmWhere.= $foreign_table ? ($foreign_table_as ? $foreign_table_as : $foreign_table).'.uid='.$mm_table.'.uid_foreign' : '';
return $this->exec_SELECTquery(
$select,
($local_table ? $local_table.',' : '').$mm_table.($foreign_table ? ','. $foreign_table.($foreign_table_as ? ' AS '.$foreign_table_as : '') : ''),
$mmWhere.' '.$whereClause, // whereClauseMightContainGroupOrderBy
$groupBy,
$orderBy,
$limit
);
return $res;
}
/**
......
}
/**
* Creates a SELECT query, selecting fields ($select) from two/three tables joined
* Use $mm_table together with $local_table or $foreign_table to select over two tables. Or use all three tables to select the full MM-relation.
* The JOIN is done with [$local_table].uid <--> [$mm_table].uid_local / [$mm_table].uid_foreign <--> [$foreign_table].uid
* The function is very useful for selecting MM-relations between tables adhering to the MM-format used by TCE (TYPO3 Core Engine). See the section on $TCA in Inside TYPO3 for more details.
*
*
* @param string Field list for SELECT
* @param string Tablename, local table
* @param string Tablename, relation table
* @param string Tablename, foreign table
* @param string Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT! You have to prepend 'AND ' to this parameter yourself!
* @param string Optional GROUP BY field(s), if none, supply blank string.
* @param string Optional ORDER BY field(s), if none, supply blank string.
* @param string Optional LIMIT value ([begin,]max), if none, supply blank string.
* @return string Full SQL query for SELECT
* @see exec_SELECTquery()
*/
function SELECT_mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause='', $groupBy='', $orderBy='', $limit='') {
if($foreign_table == $local_table) {
$foreign_table_as = $foreign_table.uniqid('_join');
}
$mmWhere = $local_table ? $local_table . '.uid=' . $mm_table . '.uid_local' : '';
$mmWhere.= ($local_table AND $foreign_table) ? ' AND ' : '';
$mmWhere.= $foreign_table ? ($foreign_table_as ? $foreign_table_as : $foreign_table) . '.uid=' . $mm_table . '.uid_foreign' : '';
return $GLOBALS['TYPO3_DB']->SELECTquery(
$select,
($local_table ? $local_table.',' : '') . $mm_table . ($foreign_table ? ',' . $foreign_table . ($foreign_table_as ? ' AS ' . $foreign_table_as : '') : ''),
$mmWhere . ' ' . $whereClause, // whereClauseMightContainGroupOrderBy
$groupBy,
$orderBy,
$limit
);
}
/**
* Returns a WHERE clause that can find a value ($value) in a list field ($field)
* For instance a record in the database might contain a list of numbers, "34,234,5" (with no spaces between). This query would be able to select that record based on the value "34", "234" or "5" regardless of their positioni in the list (left, middle or right).
* Is nice to look up list-relations to records or files in TYPO3 database tables.
(2-2/2)