0

I have a list of strings. They are all absolute paths (no relative at the moment) and they all start with \ (windows folder separator)

When I do a query with a like using

select * from list where name like @foo

and foo is

@"\a" + %

I get no results. If I use %\a% I get results. I then tried using mysql command line and wrote

where name like '\a%' limit 10;

I get no results there as well unless i write %\a%. Why doesn't it like \? and how do i have a string start with \a? I don't want to get \random\apples\file when I am expecting \apples\file

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    It sounds like an escaping issue. Have you tried doubling the backslash, i.e. `@"\\a" + %`? – ruakh Nov 28 '12 at 20:43
  • 3
    You should know that the backslash is used for escaping... – rekire Nov 28 '12 at 20:43
  • @rekire: Shouldnt the fact that i'm putting the value through a parameter escape the value for me? –  Nov 28 '12 at 20:54

2 Answers2

8

Because \ is the escaping character .

Try replacing it with \\ instead

Special Character Escape Sequences

Ibu
  • 42,752
  • 13
  • 76
  • 103
  • 1
    See - http://dev.mysql.com/doc/refman/5.0/en/string-literals.html#character-escape-sequences – danielrsmith Nov 28 '12 at 20:44
  • seriously what the hell!? Very relevant. http://stackoverflow.com/questions/13614291/how-do-i-escape-mysql-properly –  Nov 28 '12 at 20:59
1

try this

\ is a sign which escapes the next sign.. sometimes used to escape a \" quote or the backslash itself

where name like '\\a%' limit 10;

Mik
  • 1,705
  • 1
  • 14
  • 26
  • oops i forgot that its \ in the cli however wtf i thought parameter values would escape this –  Nov 28 '12 at 21:00