我如何翻译这些mysql查询以使用sqlite3?:
self.find(:first, :conditions => ['concat(first_name, \' \', middle_names, \' \', last_name) = ?', name])
self.find(:all, :conditions => ['(concat(first_name, \' \', last_name) LIKE ?) OR (concat(first_name, \' \', middle_names, \' \', last_name) LIKE ?)', "%#{name}%", "%#{name}%"])
答案 0 :(得分:0)
||是SQLite连接运算符。所以这可能会奏效:
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}%"])
答案 1 :(得分:0)
谷歌搜索可能有所帮助:http://www.google.com/search?q=sqlite+concat
在SQLite中,concat运算符是||
。并且为了更容易阅读带有单引号'
的字符串,我会用双引号"
将这些字符串括起来,所以你不需要那么多的转义:
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}%"])