使用 SQLite 在本地运行,但在 Heroku 上运行:PGError: ERROR: 语法错误位于或接近“NULL”
我的代码在本地 sqllite 上运行良好,但是当我推送到 heroku 时,我得到:
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):
ruby 代码是:
Beep.last(:conditions => [ "(widget_id NOT NULL) AND (updated_at > ?) AND (userphone = ?) AND (beeper = ?) AND (inbound = ?)", 5.minutes.ago, aphone, beeper, inboundflag ])
顺便说一句,有没有办法使用纯活动记录来构造此查询,这样我们就可以(希望)避免特定于数据库的查询字符串?
My code runs fine for sqllite locally, but when I push to heroku I get:
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):
the ruby code is :
Beep.last(:conditions => [ "(widget_id NOT NULL) AND (updated_at > ?) AND (userphone = ?) AND (beeper = ?) AND (inbound = ?)", 5.minutes.ago, aphone, beeper, inboundflag ])
By the way, is there any way to structure this query using pure active record, so we can (hopefully) avoid database-specific query strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您在 Heroku 上使用 SQLLite 而不是 MySQL 吗?不管怎样,查询语法似乎有点不正确。我会将您的查询修改为:
如果您使用的是 Rails3,您可以将您的条件链接在一起,如下所示:
Are you sure you are using SQLLite on Heroku and not MySQL? Either way the query syntax seems a little incorrect. I would modify your query to this:
If you are using Rails3 you can chain your conditions together like this: