Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Found mistake in Doctrine\ORM\Query->_parse()
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gennady  
View profile  
 More options Apr 28 2012, 4:12 am
From: Gennady <gennady...@gmail.com>
Date: Sat, 28 Apr 2012 01:12:46 -0700 (PDT)
Local: Sat, Apr 28 2012 4:12 am
Subject: Found mistake in Doctrine\ORM\Query->_parse()
I construct by QueryBuilder next query:
SELECT * FROM resulttable
where name like '%\'s tom%'

$name = addslashes($this->_request->getPost('name'));
$qb = $this->em->getRepository('resulttable')-

>createQueryBuilder('vb')

$qb->andWhere('vb.name like \'%'.$name.'%\'');

Message: [Syntax Error] line 0, col 101: Error: Expected end of
string, got 's'

\library\Doctrine\ORM\Query\Parser.php(380): Doctrine\ORM\Query
\QueryException::syntaxError('line 0, col 101...')
#1 \library\Doctrine\ORM\Query\Parser.php(745): Doctrine\ORM\Query
\Parser->syntaxError('end of string')
#2 \library\Doctrine\ORM\Query\Parser.php(213): Doctrine\ORM\Query
\Parser->QueryLanguage()
#3 \library\Doctrine\ORM\Query\Parser.php(288): Doctrine\ORM\Query
\Parser->getAST()
#4 \library\Doctrine\ORM\Query.php(230): Doctrine\ORM\Query\Parser-

>parse()

#5 \library\Doctrine\ORM\Query.php(176): Doctrine\ORM\Query->_parse()

MySQL executes this query successfull.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Pivetta  
View profile  
 More options Apr 28 2012, 9:14 am
From: Marco Pivetta <ocram...@gmail.com>
Date: Sat, 28 Apr 2012 15:14:15 +0200
Local: Sat, Apr 28 2012 9:14 am
Subject: Re: [doctrine-dev] Found mistake in Doctrine\ORM\Query->_parse()

Hi there!

Could you please also tell what version of Doctrine ORM you are using? It
may be caused by some wrong merge.

Anyway, your approach is basically incorrect, you should instead do
`->andWhere('vb.name LIKE :nameParameter')->setParameter('nameParameter',
'%' . $name . '%')`, which is much safer, uses query cache and avoids SQL
injections.

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com

On 28 April 2012 10:12, Gennady <gennady...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Benjamin Eberlei  
View profile  
 More options Apr 28 2012, 9:31 am
From: Benjamin Eberlei <kont...@beberlei.de>
Date: Sat, 28 Apr 2012 15:31:16 +0200
Local: Sat, Apr 28 2012 9:31 am
Subject: Re: [doctrine-dev] Found mistake in Doctrine\ORM\Query->_parse()

DQL does not support escaping of ' in strings. As Marco explained, you
should do this in a parameter and it will work.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gennady  
View profile  
 More options May 3 2012, 2:30 am
From: Gennady <gennady...@gmail.com>
Date: Wed, 2 May 2012 23:30:58 -0700 (PDT)
Local: Thurs, May 3 2012 2:30 am
Subject: Re: Found mistake in Doctrine\ORM\Query->_parse()
Thank you all!
I'm using Doctrine 2. For MySQL, I found another solution

$name = str_replace("'", "''", $this->_request->getPost('name'));
$qb->andWhere('vb.name like \'%'.$name.'%\'');

this work. But I think the decision Marco is more correct for future
use.
Developers can think about the internal escaping for security purpose.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Pivetta  
View profile  
 More options May 3 2012, 3:16 am
From: Marco Pivetta <ocram...@gmail.com>
Date: Thu, 3 May 2012 09:16:14 +0200
Local: Thurs, May 3 2012 3:16 am
Subject: Re: [doctrine-dev] Re: Found mistake in Doctrine\ORM\Query->_parse()

Gennay: do _NOT_ use that method! That is just wrong and unsafe!
$qb->andWhere('vb.name LIKE :nameParam')->setParameter('nameParam',
$this->_request->getPost('name')); works just fine! Don't use what you
wrote!
Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com

On 3 May 2012 08:30, Gennady <gennady...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lee Davis  
View profile  
 More options May 3 2012, 3:51 am
From: Lee Davis <leedavi...@gmail.com>
Date: Thu, 3 May 2012 08:51:42 +0100
Local: Thurs, May 3 2012 3:51 am
Subject: Re: [doctrine-dev] Re: Found mistake in Doctrine\ORM\Query->_parse()

Gennay, I'm only iterating what Marco said. Don't use that implementation.
Doctrine sits on top of PDO which handles all your escaping for you. Using
that implementation is dangerous.

Lee


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gennady  
View profile  
 More options May 3 2012, 5:19 am
From: Gennady <gennady...@gmail.com>
Date: Thu, 3 May 2012 02:19:01 -0700 (PDT)
Local: Thurs, May 3 2012 5:19 am
Subject: Re: Found mistake in Doctrine\ORM\Query->_parse()
Thanks Marco and Lee.

I've been using version Marco.

On 3 май, 10:51, Lee Davis <leedavi...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »