How would i translate these mysql queries to work with sqlite3?:
self.find(:first, :conditions => ['concat(first_name, \' \', middle_names, \' \', last_name) = ?', name])
self.find(:all, :conditions => ['(concat(first_name, \' \', last_name) L开发者_StackOverflow中文版IKE ?) OR (concat(first_name, \' \', middle_names, \' \', last_name) LIKE ?)', "%#{name}%", "%#{name}%"])
A little google search could have helped: http://www.google.com/search?q=sqlite+concat
In SQLite the concat operator is ||
. and for easier reading of string with single quotes '
I would enclose these strings with double quotes "
, so you don't need so much escaping:
self.find(:first, :conditions => ["first_name || ' ' || middle_names || ' ' || last_name = ?", name])
self.find(:all, :conditions => ["(first_name || ' ' || last_name LIKE ?) OR (first_name, ' ', middle_names || ' ' || last_name LIKE ?)", "%#{name}%", "%#{name}%"])
|| is the SQLite concatenation operator. So this'll probably work:
self.find(:first, :conditions => ['first_name || \' \' || middle_names || \' \' || last_name = ?', name])
self.find(:all, :conditions => ['(first_name || \' \' || last_name LIKE ?) OR (first_name || \' \' || middle_names || \' \' || last_name LIKE ?)', "%#{name}%", "%#{name}%"])
精彩评论