0

I use MySQL C Connector. My prepared statement looks like this:

"SELECT x FROM y WHERE z REGEXP '^BLA?$'"

The problem is that ? character is treated like part of REGEXP, when I need to insert parameter there later. How can I make ? to be treated like placeholder for data?

user3237732
  • 1,976
  • 2
  • 21
  • 28

1 Answers1

2

REGEXP CONCAT('^BLA', ?, '$') this should work. However, if you need that parameter AND a '?', like this CONCAT('^BLAH', ?, '?$'), I am not sure if that latter ? will need escaped, but according to this it should be fine without escaping it.

Community
  • 1
  • 1
Uueerdo
  • 15,723
  • 1
  • 16
  • 21
  • as a note, this is applicable for pretty much ANY situation where you need to embed a placeholder some other string. `'?'` is a question mark to mysql, so you need to "extract" the `?` from the string, which is where concat() comes in handy. – Marc B Sep 29 '15 at 19:57