[TYPO3-mvc] complex queries

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed Apr 28 10:05:43 CEST 2010


Hey,

> what I need to do is something like this:
>
> |SELECT * FROM tx_ext_domain_model_m WHERE CONCAT_WS("", f1,f2,f3,f4)
> LIKE '%myString%'
>
> what I have so far is something like this:
> $query = $this->createQuery();
> $query->matching( $query->like('f1' , '%'.$piVars["name"].'%' ) );
>
> I tried a lot, but I am not making any progress. Any ideas.
> Thanks to all for the earlier advise and responses.

I'm afraid that CONCAT_WS is not directly supported by the persistence 
API, so you might have to write the statement by your own if you have to 
use CONCAT_WS.

$query->statement(SELECT * FROM tx_ext_domain_model_m WHERE 
CONCAT_WS("", f1,f2,f3,f4) LIKE '%myString%');

I haven't had a look if extbase is taking care of it, but please note 
that you should never ever use unescaped/unquoted POST/GET vars in 
queries due to the risk of SQL injections etc.


If you don't have to use CONCAT_WS but could also use concatenated OR 
statements (WHERE f1 LIKE '%foobar%' OR f2 LIKE '%foobar%'), than you 
could use $query->logicalOr to concatenate all the $query->like calls. 
(PS: I'm not sure, but I think it's by now easier to do this using an 
array with fieldnames as parameter. It's been a while since I used 
extbase the last time).

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list