Select SQL conditions based on database

I’d like to have database agnostic code, however I have been
unsuccessful writing conditions that work for both postgres and mysql
for the following:

postgres only

conditions = [“curtain_at + CAST (CAST (duration AS VARCHAR) || ’
SECOND’ AS INTERVAL) >= ? AND curtain_at < ?”, Time.now, Time.now +
2.hours]

MySQL only

conditions = [“curtain_at + INTERVAL duration SECOND >= ? and
curtain_at < ?”, Time.now, Time.now + 2.hours]

Concert.find(:all, :conditions => conditions)

Can anyone lend some SQL expertise?

As a last resort, how can I determine what the current database is so
I can selectively set conditions?

bump

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs