Hi Gabriel,

Try as:
mysql > select * from forum where topoc like "%\\\\%";

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. (Exception: At the end of
the pattern string, backslash can be specified as '\\'. At the end of the
string, backslash stands for itself because there is nothing following to
escape.)

Ref: http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html

Thanks
ViSolve DB Team.

----- Original Message ----- From: "Gabriel Linder" <[EMAIL PROTECTED]>
To: "MySQL List" <mysql@lists.mysql.com>
Sent: Friday, January 19, 2007 9:43 PM
Subject: Request problem (with \\)


Hello list,

I am currently trying to fix a bug in a search function with a request like this one :
select * from forum where topic like '%[...]%' ;

where [...] is a string escaped by mysql_real_escape_string (C API) and topic is a varchar field (not null).

It works, but there is a bug if someone is searching the character backslash only ('\'), so the request become :
select * from forum where topic like '%\\%' ;

and it returns only topics who have a '%' in them, not a '\'. It is the same result as if I were doing :
select * from forum where topic like '%\%' ;

To get the topics with a '\' (but it returns only the topics that ends with a '\'), I must do :
select * from forum where topic like '%\\' ;

So it seems to me that the ending % is escaped even with '\\'. Is this a normal behaviour ? Or am I missing something ?

Here are some infos about the server version, might be useful :
version = 4.0.20-standard
version_comment = Official MySQL-standard binary
version_compile_os = linux

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to