what is the Ruby code equivalent to following mysql query? I'm trying to search for an exact match of a string eg.'MAIN' and 'Main' should be treat different.
SELECT UserID FROM sys_users WHERE BINARY UserID='MAIN'
what is the Ruby code equivalent to following mysql query? I'm trying to search for an exact match of a string eg.'MAIN' and 'Main' should be treat different.
SELECT UserID FROM sys_users WHERE BINARY UserID='MAIN'
It's just like:
SysUser.select('UserID').where('BINARY UserID=?', 'MAIN')
A very quick look at ActiveRecord guide gives the answer:
2.1 Pure String Conditions If you’d like to add conditions to your find, you could just specify them in there, just like
Client.where("orders_count = '2'")
. This will find all clients where the orders_count field’s value is 2.
You could have easily found this through google...
Also, case sensitivity is not Rails responsibility but depends on your database settings. Hint: You should switch default collation to UTF-8.
Ruby code equivalent to mysql query:
SysUser.where("UserID='MAIN'").select('UserID')