something strange with sqlite ?

18 views
Skip to first unread message

Joe Guerra

unread,
Sep 17, 2018, 4:20:37 PM9/17/18
to Ruby on Rails: Talk
I have an active record query (for my categories) that check for the date ( .where( 'enddate > ?', todaydate )).

Today's date get's wrapped in quotes, and it fails to produce any records, but it's perfectly fine in postgres.


Rob Zolkos

unread,
Sep 17, 2018, 5:18:48 PM9/17/18
to rubyonra...@googlegroups.com
I think you will need to wrap todaydate in strftime for sqlite.   Away from computer to check but google ‘date arithmetic sqlite’

On Tue, 18 Sep 2018 at 6:20 am, Joe Guerra <JGu...@jginfosys.com> wrote:
I have an active record query (for my categories) that check for the date ( .where( 'enddate > ?', todaydate )).

Today's date get's wrapped in quotes, and it fails to produce any records, but it's perfectly fine in postgres.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/394a0f57-7d77-4d73-82ce-fd9730bc90b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Guerra

unread,
Sep 17, 2018, 6:24:51 PM9/17/18
to rubyonra...@googlegroups.com
Thanks, I'll try that.

Hopefully it works for postgres and sqlite.

Rob Zolkos

unread,
Sep 17, 2018, 6:45:34 PM9/17/18
to rubyonra...@googlegroups.com
doubtful.  They are very different.  Any reason you can't stick with one of them?

Hassan Schroeder

unread,
Sep 17, 2018, 7:34:00 PM9/17/18
to rubyonrails-talk
What exactly is "todaydate"? What's the column definition of "enddate"?

And are you sure you have identical records in both DBs you're testing
this with?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Joe Guerra

unread,
Sep 18, 2018, 8:59:27 AM9/18/18
to Ruby on Rails: Talk
Hi, I defined time like this --->

  require 'time'

    todaydate = Time.new

    todaydate = todaydate.year.to_s + "-" + todaydate.month.to_s + "-" + todaydate.day.to_s

and the column for enddate is a date type.   It had worked previously, I just updated the dates in a populate rake file and stopped working (on the development env (sqlite)).

Thanks,
Joe

Hassan Schroeder

unread,
Sep 18, 2018, 10:27:20 AM9/18/18
to rubyonrails-talk
On Tue, Sep 18, 2018 at 5:59 AM, Joe Guerra <JGu...@jginfosys.com> wrote:

> todaydate = Time.new
>
> todaydate = todaydate.year.to_s + "-" + todaydate.month.to_s + "-" +
> todaydate.day.to_s
>
> and the column for enddate is a date type.

Aside from the potential problem of redefining the same variable,
I'd avoid trying to compare a DB `date` with a String, but in this case --

Sqlite3 doesn't have a `date` type so you might want to spend a few
minutes here: https://www.sqlite.org/datatype3.html

HTH!
Reply all
Reply to author
Forward
0 new messages