/***************************************************************
* Copyright notice
*
-* (c) 2004-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
+* (c) 2004-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* 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
+ * record based on the value "34", "234" or "5" regardless of their position in
* the list (left, middle or right).
+ * The value must not contain a comma (,)
* Is nice to look up list-relations to records or files in TYPO3 database tables.
*
* @param string Field name
* @param string Table in which we are searching (for DBAL detection of quoteStr() method)
* @return string WHERE clause for a query
*/
- function listQuery($field, $value, $table) {
+ public function listQuery($field, $value, $table) {
+ $value = (string)$value;
+ if (strpos(',', $value) !== FALSE) {
+ throw new InvalidArgumentException('$value must not contain a comma (,) in $this->listQuery() !');
+ }
$pattern = $this->quoteStr($value, $table);
- $patternForLike = $this->escapeStrForLike($pattern, $table);
- $where = '(' . $field . ' LIKE \'%,' . $patternForLike . ',%\' OR ' .
- $field . ' LIKE \'' . $patternForLike . ',%\' OR ' .
- $field . ' LIKE \'%,' . $patternForLike . '\' OR ' .
- $field . '=\'' . $pattern . '\')';
+ $where = 'FIND_IN_SET(\'' . $pattern . '\',' . $field . ')';
return $where;
}
4
);
} else {
- $setDBinit = t3lib_div::trimExplode(LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit'], TRUE);
+ $setDBinit = t3lib_div::trimExplode(LF, str_replace("' . LF . '", LF, $GLOBALS['TYPO3_CONF_VARS']['SYS']['setDBinit']), TRUE);
foreach ($setDBinit as $v) {
if (mysql_query($v, $this->link) === FALSE) {
t3lib_div::sysLog('Could not initialize DB connection with query "' . $v .