使用 SQLite 在本地运行,但在 Heroku 上运行:PGError: ERROR: 语法错误位于或接近“NULL”

发布于 2024-10-16 08:09:17 字数 808 浏览 2 评论 0原文

我的代码在本地 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阿楠 2024-10-23 08:09:17

您确定您在 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

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:

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

If you are using Rails3 you can chain your conditions together like this:

Beep.where('widget_id IS NOT NULL)
  .where('updated_at > ?', 5.minutes.ago)
  .where(userphone: aphone)
  .where(beeper: beeper)
  .where(inbound: inboundflag)
  .last
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文