#24 ✓resolved
extcake

Datetime modifiers don't work with Sqlite3

Reported by extcake | November 12th, 2008 @ 02:52 PM

Modifiers like day_of_month, month, year.. don't work with sqlite3. Problem is their return type. Sqlite's strftime return string and this modifiers return type is :integer. After change to :string, they works like expected.

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson November 12th, 2008 @ 10:51 PM

    • State changed from “new” to “open”
    • Tag set to modifiers, sqlite3

    I will look into this some more, regardless, when using these in ruby they should be returned as :integers, not strings.

  • Ben Johnson

    Ben Johnson November 14th, 2008 @ 01:01 AM

    Can you give me an example that causes the problem. Is there an error or a backtrace. I am not having any issues in SQLite3.

  • extcake

    extcake November 14th, 2008 @ 02:27 AM

    I doesn't work at all. Example, i have user that is activate at in year 2008 now:

    
    >> User.last
    => #<User id: 4, login: "extcake", name: "mr.", surname: "Black", email: "user@localhost.com", crypted_password: "444181fe8782a833869c65325b185d2d9d8370c1", salt: "93f29fa3a69a409519e0c0e50fef590b9814510f", created_at: "2008-11-12 12:33:57", updated_at: "20
    08-11-13 08:23:15", remember_token: nil, remember_token_expires_at: nil, activation_code: nil, activated_at: "2008-11-13 08:22:08", state: "deleted", deleted_at: nil, type: "User">
    >> User.find(:all, :conditions => {:year_of_activated_at => 2008})
    => []
    

    now sql generated by this find: User Load (0.000456) SELECT * FROM "users" WHERE (strftime('%Y', "users"."activated_at") = 2008)

    If select would looks like: SELECT * FROM "users" WHERE (strftime('%Y', "users"."activated_at") = '2008') then it works like expected.

    Changing find so it get year as string like: User.find(:all, :conditions => {:year_of_activated_at => '2008'}) don't help because generated sql is the same.

  • Ben Johnson

    Ben Johnson November 14th, 2008 @ 04:15 AM

    Well the return type deals with the type of value the condition accepts as well as type casting. I also doubt some of the comparison conditions like "greater than", "less than", etc will work with strings. I wonder if there is a way to convert a string to an integer in SQLite. Something like:

    strftime('%Y', "created_at") * 1

    This would be a very simple solution if that above works. I will test this out and see what I can come up with. If you know off the top of your head how to do this please let me know, this will fix the problem.

    Thanks.

  • extcake

    extcake November 14th, 2008 @ 04:25 AM

    strftime('%Y', "created_at") * 1 works great :)

  • Ben Johnson

    Ben Johnson November 14th, 2008 @ 04:26 AM

    • State changed from “open” to “resolved”

    Alright, I pushed the changes. Update from the repo, let me know if you have any issues. Thanks!

  • extcake

    extcake November 14th, 2008 @ 04:44 AM

    Now everything works nicely. Thanks for this great plugin!

  • rareki

    rareki July 3rd, 2019 @ 08:14 AM

    The search is the basic component in the study and the research purpose because the person gets the close exposure of the issue by searching. The topic is by the name of the proper set of research paper writing service with the modified date time and the date sense.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages