MySQL Lists are EOL. Please join:

List:General Discussion« Previous MessageNext Message »
From:Gabriel Linder Date:January 19 2007 4:13pm
Subject:Request problem (with \\)
View as plain text  
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
Thread
Request problem (with \\)Gabriel Linder19 Jan
  • Re: Request problem (with \\)ViSolve DB Team20 Jan
    • Re: Request problem (with \\)Gabriel Linder22 Jan