0

I need to make query like this:

SELECT p.pid, p.url FROM products as p WHERE url_crc IN (FNV_64("http://url1.com/"),FNV_64("http://url2.com/"))

I need to use FNV_64 hash function for every array variable. I CAN'T make hashes before passing variables to query builder. This hash functions is only avaliable as MySQL extension.

How can i make this using Symfony2 ? For example, using:

$qb = $em->createQueryBuilder();
$query = $qb->select('p.pid')
            ->from('SRC\MainBundle\Entity\Product', 'p')
            ->where('p.url_crc IN (FNV_64(:urls))') // error HERE
            ->setParameter('urls', $hashes_array)
            ->getQuery();

Wouldn't work. The only way i can this of is:

$query = $em->createNativeQuery('SELECT p.pid, p.url FROM products as p
                                WHERE url_crc IN (' . join(',', $tmp_array) . ')', $rsm);

Where tmp_array looks like this:

Array
(
    [0] => FNV_64("http://url1.com/")
    [1] => FNV_64("http://url2.com/")
)

Is there better way ?

1 Answer 1

1

You can always bypass DQL. However, Doctrine2 was designed to support various database engines, and allows you to add "vendor specific SQL functionalities in DQL". You can read This link to see how you could code in support for your mysql extension. There's also a link to a github repo with a number of extensions you can look at for examples.

One other thing-- I found at least one php implementation of the FNV hash here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.