Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom DQL function to replicate MySQL CONV
    primarykey
    data
    text
    <p>I'm trying to create a custom DQL function to allow me to use the MySQL CONV string function within my DQL. My goal is to be able to perform bit checks against content which is being stored in hex. Previously I've just performed SQL query such as:</p> <pre><code>.... where conv(`myField`,16,10) &amp; 4096 = 4096 </code></pre> <p>However I want to convert these SQL queries into DQL format. What I cannot figure out is how to bring '&amp; 4096 = 4096' into parser. This is as far as I have been able to get:</p> <pre><code>namespace Acme\TestBundle\DQL; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\AST\Functions\FunctionNode; class MysqlConv extends FunctionNode { public $stringFirst; public $stringSecond; public $stringThird; public $stringFourth; public function parse(\Doctrine\ORM\Query\Parser $parser) { $parser-&gt;match(Lexer::T_IDENTIFIER); $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS); $this-&gt;stringFirst = $parser-&gt;StringPrimary(); $parser-&gt;match(Lexer::T_COMMA); $this-&gt;stringSecond = $parser-&gt;ArithmeticPrimary(); $parser-&gt;match(Lexer::T_COMMA); $this-&gt;stringThird = $parser-&gt;ArithmeticPrimary(); $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS); } public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) { return 'CONV(' . $this-&gt;stringFirst-&gt;dispatch($sqlWalker) . ',' . $this-&gt;stringSecond-&gt;dispatch($sqlWalker) . ',' . $this-&gt;stringThird-&gt;dispatch($sqlWalker) . ') &amp; 4096'; } } </code></pre> <p>Which I'm then using like this:</p> <pre><code> return $this-&gt;getEntityManager() -&gt;createQuery('SELECT c, h FROM AcmeTestBundle:Company c LEFT JOIN c.CompanyAssoc h WHERE CONV(c.myField,16,10) = 4096') -&gt;getResult(); </code></pre> <p>Any suggestions as to how best to complete the SQL to DQL transition for the MySQL CONV function?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload