1

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?

demongolem
  • 9,474
  • 36
  • 90
  • 105
jpw
  • 18,697
  • 25
  • 111
  • 187

1 Answers1

2

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
Pan Thomakos
  • 34,082
  • 9
  • 88
  • 85
  • thank you! "xxx NOT NULL" worked fine on sqllite but I see it should have the "IS": "xxx IS NOT NULL" – jpw Feb 06 '11 at 03:12