V
V
Valery2013-07-01 16:02:46
symfony
Valery, 2013-07-01 16:02:46

How to add INSTR function to Doctrine2?

Good evening,

I'm using Symfony 2.3 with the underlying doctrine.
you must use the INSTR() function in queries.

I found how to add “my own” function, created a class, but the doctrine swears at the query syntax ...
In general, if someone has a ready-made example, let me see how it all should look.

For myself, I took an example from this function:
github.com/doctrine/doctrine2/blob/90b6d5e293147a0268ca005362ff50343bc6dc0f/lib/Doctrine/ORM/Query/AST/Functions/SubstringFunction.php

In fact, I just removed the third parameter, which I don’t have, but that’s all still doesn't work.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
bredmm, 2013-07-01
@Akuma

probably because the condition should have a comparison with something
and probably because the query should look something like this

SELECT count(*) FROM table1 WHERE INSTR(field1, 'bar') != 0;

V
Valery, 2013-07-01
@Akuma

Found an example: coolspamforeva.org/?p=292
I did everything as described, but nothing has changed.
My function is parsed, but swears at a further ORDER:

[Syntax Error] line 0, col 107: Error: Expected =, <, <=, <>, >, >=, !=, got 'ORDER'

The request itself:
SELECT n FROM QCoreBundle:Node n WHERE n.name IN (:names) AND n.level IN (:levels) AND INSTR(:path, n.url) ORDER BY n.left DESC

If you remove ORDER BY, then it will start swearing at the end of the line ...

V
Valery, 2013-07-01
@Akuma

Who cares - I got out with SUBSTRING(n.url, 1, :pathlen) = n.url
I still have only one such request - so there shouldn't be much difference

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question