当`where`子句中的哈希值传递字符串值时,`sequel` orm失败

时间:2015-01-08 18:15:57

标签: ruby sequel

当我使用.where(:status_name => 'Active')而不是.where("status_name = 'Active'")时,我不知道发生了什么事情当我使用字符串变量而不是对“活动”字符串进行编码时也会发生这种情况

[1] pry(#<DefenseFeature>)> @db[:defense_status_tbl].select(:defense_status_id).where(:status_name => 'Active').single_record
Sequel::DatabaseConnectionError: Mysql2::Error: Can't connect to MySQL server on '127.0.0.1' (61)
from /Users/calopez/.rvm/gems/ruby-2.1.5/gems/mysql2-0.3.17/lib/mysql2/client.rb:70:in `connect'
[2] pry(#<DefenseFeature>)> @db[:defense_status_tbl].select(:defense_status_id).where("status_name = 'Active'").single_record
=> {:defense_status_id=>2}

显示sql查询生成:

[3] pry(#<DefenseFeature>)> @db[:defense_status_tbl].select(:defense_status_id).where(:status_name => 'Active')
=> #<Sequel::Mysql2::Dataset:0x3fc29dcc5d2c>
[4] pry(#<DefenseFeature>)> @db[:defense_status_tbl].select(:defense_status_id).where("status_name = 'Active'")
=> #<Sequel::Mysql2::Dataset: "SELECT `defense_status_id` FROM `defense_status_tbl` WHERE (status_name = 'Active')">

0 个答案:

没有答案