Mixing quoted and non quoted values with Ruby DBI prepared statements
Sorry for the somewhat long title, but I messed a bit with DBI in Ruby today, and I had some problems with prepared statements, as DBI quotes everything. I wanted to do something like the following:
sth = dbh.prepare(“UPDATE table SET ? = ? WHERE id = ‘1′”)
With a normal approach, both values would be quoted if I ran sth.execute(“field”, “value”), but as the sth.execute runs a quote function, which is just an ugly while loop, and the else part of it, is just value.to_s, you can do it quite smart:
sth.execute(:field, “value”)
Isn’t that nice? I think so.
About this entry
You’re currently reading “Mixing quoted and non quoted values with Ruby DBI prepared statements,” an entry on Blog noir
- Published:
- June 22, 2008 / 6:47 pm
- Category:
- Tips'n'Tricks, programming, ruby
- Tags:
1 Comment
Jump to comment form | comment rss [?] | trackback uri [?]