Created
September 9, 2011 12:40
-
-
Save josepjaume/1206106 to your computer and use it in GitHub Desktop.
Time comparison inconsistency with SQLite, PostgreSQL and MySQL with ActiveRecord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pending_notifications | |
notifications = self.notifications | |
if last_notification_read_at | |
# Sqlite doesn't properly compare dates because doesn't have a dedicated | |
# type for it. | |
# TODO: Investigate further and find a better solution for this. | |
# | |
time_restriction = if connection.class.name.demodulize =~ /SQLite/ | |
["datetime(notifications.created_at) >= ?", last_notification_read_at] | |
elsif connection.class.name.demodulize =~ /PostgreSQL/ | |
["notifications.created_at >= ?", last_notification_read_at.to_time] | |
else | |
["notifications.created_at >= ?", last_notification_read_at] | |
end | |
notifications = notifications.where(time_restriction) | |
end | |
notifications | |
end | |
Author
josepjaume
commented
Sep 9, 2011
via email
```
X'323031312D30392D30392031363A32353A34342E333233393433'","blob"
```
Wow, that's true. But it seems that BLOB is what SQLite3Adapter uses when
dealing with datetimes
Josep Jaume
…On Fri, Sep 9, 2011 at 5:57 PM, Francesc Esplugas < ***@***.***>wrote:
How do you store stuff in `SQLite3`? Run this in the `SQLite3` console.
SELECT created_at, typeof(created_at) FROM entries;
I guess you have a `BLOB` there when it should be `text`.
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1206106
See this commit: rails/rails@20c07170
And this rails/rails#2892
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment