Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single quote escape inside double quotes using sequel fetch function in ruby

Tags:

ruby

sequel

using raw SQL when I use the IN statement inside a query using sequel's fetch function, I can't escape a single quote by writing where stuff IN ...

@values='stuff1\'','stuff2\''

db.fetch("query...where IN (?)", "#{@values}")

outputs query...where stuff IN ('stuff1'',''stuff2') instead of ('stuff1','stuff2')

Quite frustrating that I'd probably have to write a Sequel equivalent for the raw query or use a different ORM just because of this escape issue. Any thoughts?

like image 493
Nothing Avatar asked Mar 10 '26 10:03

Nothing


1 Answers

You should probably do something like:

@values = ['stuff1', 'stuff2']
db.fetch("query...where IN ?", @values)
like image 185
Jeremy Evans Avatar answered Mar 13 '26 10:03

Jeremy Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!