On Feb 12, 12:24 am, Simon Arnaud <[email protected]> wrote:
> 2010/2/11 Jeremy Evans <[email protected]>:
>
> > On Feb 11, 9:14 am, Simon Arnaud <[email protected]> wrote:
> >> Hi
>
> >> Followinghttp://groups.google.com/group/sequel-talk/browse_thread/thread/6138e...
>
> > Sequel uses IS08601 dates on SQLite:
>
> >  $ sequel sqlite:/
> >  Your database is stored in DB...
> >  irb(main):001:0> DB.literal Date.today
> >  => "'2010-02-11'"
>
> I'm referering to the part where you use Date#to_s to format the date
> as ISO8601, and to_s is not anymore outputting ISO8601.
>
> $ sequel sqlite:/
> Your database is stored in DB...
> ruby-1.9.1-p376 > class Date
> ruby-1.9.1-p376 ?>  def to_s
> ruby-1.9.1-p376 ?>    strftime("%d/%m/%Y")
> ruby-1.9.1-p376 ?>    end
> ruby-1.9.1-p376 ?>  end
>  => nil
> ruby-1.9.1-p376 > DB.literal Date.today
>  => "'12/02/2010'"
> ruby-1.9.1-p376 >
>
> I understand it's a bad practice to rewrite core methods, but as you
> agreed back then, 'to_s' is a borderline case, and should not be
> relied on anything else than outputting a String.

True. I guess I forgot about that.

> here is literal_date from sequel 3.8.0:
> # SQL fragment for Date, using the ISO8601 format.
> def literal_date(v)
>   requires_sql_standard_datetimes? ? v.strftime("DATE '%Y-%m-%d'") : "'#{v}'"
> end
>
> Something like this might be better
> def literal_date(v)
>   iso8601_date = v.strftime("'%Y-%m-%d'")
>   requires_sql_standard_datetimes? ? "DATE " + iso8601_date: iso8601_date
> end

Try the patch at http://pastie.org/822124.txt.

> You forgot my first question also :) :
> How am I supposed to change 'requires_sql_standard_datetimes?' ? Just
> overwriting the method ?

Why does it matter, since SQLite doesn't require them?  But yes, you
would have to just override the method.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to