开发者

Broken query using MySQL module with Ruby?

开发者 https://www.devze.com 2023-01-06 12:57 出处:网络
Any idea what is broken about my query here? irb(main):010:0> dbh.query(\'SELECT foo FROM bar\') Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL

Any idea what is broken about my query here?

irb(main):010:0> dbh.query('SELECT foo FROM bar')
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 1
    from (irb):10:in `query'
    from (irb):10
    from /usr/bin/irb1.9:12:in `<main>'

the table bar definitely exists as does the column 开发者_如何学Gofoo.

also dbh is a legit object:

irb(main):012:0> dbh
=> #<Mysql:0x91149c4>

irb(main):011:0> dbh.methods.grep(/query/)
=> [:query, :real_query, :query_with_result, :query_with_result=]


Paste a real query, maybe table name or field name is a reserved keyword in mysql.

Try using delimiters:

dbh.query('SELECT `foo` FROM `bar`')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号