本地运行的SQLite,但在Heroku:PGError:错误:语法错误或接近“NULL”

问题描述:

我的代码运行罚款sqllite地方,但是当我推到Heroku上我得到:本地运行的SQLite,但在Heroku:PGError:错误:语法错误或接近“NULL”

ActiveRecord::StatementInvalid (PGError: ERROR: syntax error at or near "NULL" 
LINE 1: ...LECT "beeps".* FROM "beeps" WHERE ((widget_id NOT NULL) AND ... 
                  ^
: SELECT "beeps".* FROM "beeps" WHERE ((widget_id NOT NULL) AND (updated_at > '2011-02-06 02:27:59.867809') AND (userphone = '0000000xxxx') AND (beeper 
= '0000000zzzz') AND (inbound = 't')) ORDER BY beeps.id DESC LIMIT 1): 

红宝石代码:

Beep.last(:conditions => [ "(widget_id NOT NULL) AND (updated_at > ?) AND (userphone = ?) AND (beeper = ?) AND (inbound = ?)", 5.minutes.ago, aphone, beeper, inboundflag ]) 

顺便说一句,有没有什么办法来构建使用纯活动记录本查询,所以我们可以(希望)避免特定数据库的查询字符串?

你确定你在Heroku上使用SQLLite而不是MySQL吗?无论哪种方式查询语法似乎有点不正确。我将修改您的查询到这一点:

 
Beep.last(:conditions => [ "(widget_id IS NOT NULL) AND (updated_at > ?) AND (userphone = ?) AND (beeper = ?) AND (inbound = ?)", 5.minutes.ago, aphone, beeper, inboundflag ]) 

如果您正在使用Rails3中,你可以链的条件这样在一起:

 
Beep.where('widget_id IS NOT NULL) 
    .where('updated_at > ?', 5.minutes.ago) 
    .where(userphone: aphone) 
    .where(beeper: beeper) 
    .where(inbound: inboundflag) 
    .last 
+0

谢谢! “xxx NOT NULL”在sqllite上正常工作,但我看到它应该有“IS”:“xxx IS NOT NULL” – jpwynn 2011-02-06 03:12:08