I created my custom DQL function for Doctrine DQL:
class Translate extends FunctionNode {
public $field;
public function getSql(SqlWalker $sqlWalker) {
$query = "TRANSLATE(" . $this->field->dispatch($sqlWalker) . ", 'àâäãáåÀÁÂÃÄÅçÇéèêëÉÈÊËîïìíÌÍÎÏñÑôöðòóÒÓÔÕÖùúûüÙÚÛÜýÿÝ', 'AAAAAAAAAAAACCEEEEEEEEIIIIIIIINNOOOOOOOOOOUUUUUUUUYYY')";
return $query;
}
public function parse(Parser $parser) {
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
It seems to work well when using it.
But if the string parameter contains more than 307 chars, it is not working. There is no error but the script is ending.
$query = $this->createQueryBuilder('...');
$query->addSelect("TRANSLATE('less than 307 chars')"); // working
$query->addSelect("TRANSLATE('more than 307 chars')"); // NOT working
How can I use more than 307 chars?
iconv
to ASCII would do about the same thing without needing to provide all characters seperately. – MorentzDoctrineExtensions
as possible solution for your original problem, which might be related to "slugification". See also https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/sluggable.md#transliterator – Nonplus:substitution_variable
rather than injecting text into your SQL. You'll probably get a more debuggable error message. – Nitid$this->field->dispatch($sqlWalker)
returned in single quotes? – Suiting