使用转义字符时,Ruby SQLite适配器失败

时间:2014-06-05 18:02:58

标签: ruby-on-rails ruby sqlite

我正在使用sqlite3适配器来获取Ruby并获得一些奇怪的行为。我正在使用?来逃避对我的查询的输入。以下作品:

db.execute 'SELECT * FROM table_name WHERE id = ?', 1 
  => [{ "id"=> 1, "name" => "Hannah" }]
db.execute 'SELECT * FROM table_name WHERE name = ?, 'Hannah'
  => [{ "id"=> 1, "name" => "Hannah" }]
db.execute 'SELECT * FROM table_name WHERE id = 1 AND name = ?', 'Hannah' 
  => [{ "id"=> 1, "name" => "Hannah" }]

但是,以下内容不起作用:

db.execute 'SELECT * FROM table_name WHERE id = ? AND name = ?', 1, 'Hannah' 
  => []

为什么会这样?

0 个答案:

没有答案