2010年12月30日星期四

RE: [fw-mvc] Zend_Db quote backslashes issue

Hello,

you know wrong, like it clearly says in the note in chapter
11.5.1. "String Comparison Functions" in the MySQL Reference Manual
under:
http://dev.mysql.com/doc/refman/5.5/en/string-comparison-functions.html

Because MySQL uses C escape syntax in strings (for example, "\n" to represent a newline character), you must double any "\" that you
use in LIKE strings. For example, to search for "\n", specify it as "\\n". To search for "\", specify it as "\\\\"; this is because
the backslashes are stripped once by the parser and again when the pattern match is made, leaving a single backslash to be matched
against.

This is the same for MySQL versions < 5.5

So this must be a bug in Zend_Db's quote mechanism.

Regards
Viktor

> -----Original Message-----
> From: Hector Virgen [mailto:djvirgen@gmail.com]
> Sent: Thursday, December 30, 2010 1:59 AM
> To: info@intelligibel.de
> Cc: fw-mvc@lists.zend.com
> Subject: Re: [fw-mvc] Zend_Db quote backslashes issue
>
> AFAIK the backslash character is not considered special in "like"
> comparisons, so you don't need to double-escape it. Only
> underscores and
> question marks need additional escaping.
>
> --
> Hector Virgen
> Sent from my Droid X
> On Dec 29, 2010 7:27 AM, "Viktor Grandgeorg"
> <info@intelligibel.de> wrote:
> > Hello,
> >
> > it seems that Zend_Db does not escape backslashes right -
> or I'm doing
> something wrong:
> >
> > in my db table "dir" I have a column named "path" with the
> folowing entry:
> >
> > C:\some\path\with\backslahes
> >
> > In my DbTable class I'm doing something like:
> >
> > $path = "C:\some\path\with\backslahes"; // in reality the
> value comes from
> a config.ini
> > $this->fetchAll(
> > $this->select()->where('path LIKE ?', $path));
> >
> > Now Zend_Db generates the following query:
> >
> > SELECT `dir`.* FROM `dir` WHERE (path LIKE
> 'C:\\some\\path\\with\\backslahes')
> >
> > This is wrong and the corresponding row never gets matched.
> > It must be the following SQL query to match the right row(s):
> >
> > SELECT `dir`.* FROM `dir` WHERE (path LIKE
> 'C:\\\\some\\\\path\\\\with\\\\backslahes')
> >
> > Can somebody confirm this issue?
> >
> > Regards
> > Viktor
> >
>

没有评论: