Sounds reasonable to me. I assume that adding the ALTER SESSION code
to the connect method is also thread and disconnect safe? I'll try it
out.

On Mar 18, 2:35 pm, Jeremy Evans <[email protected]> wrote:
> On Mar 18, 1:01 pm, Jason Thomas <[email protected]> wrote:
>
>
>
> > I've been battling time since trying to use Sequel with Oracle and I
> > think I finally found the issue. The ruby-oci8 gem handles all the
> > ruby date / time creation from the database. Thus I think Sequel
> > simply uses whatever the adapter returns. The problem is nothing you
> > set in Sequel will affect what oci8 does. I was setting
> > Sequel.default_timezone=:utc and expecting to get back UTC times but
> > was always getting back local timezone times. I tracked this down to
> > how oci8 is creating the times and it is using the Oracle session
> > timezone. Thus to get it to return UTC times I had to do the
> > following:
>
> > DB.run "ALTER SESSION SET TIME_ZONE='-00:00'"
>
> > Now all accesses from the DB instance return times with that timezone
> > and everything works! I'd like to see this incorporated into Sequel
> > such that setting Sequel.default_timezone does this.
>
> That's unlikely to happen.  It's too ugly to add adapter dependent
> code to Sequel.default_timezone=.  Connection-level settings like this
> cannot be handled correctly by DB.run except in simple cases.  You can
> use the DB.run command safely only if you are single threaded and
> never get disconnected.
>
> > Obviously this is
> > Oracle specific and when I looked at timezones.rb I didn't see
> > anything specific to an adapter. Let me know the best way to make this
> > patch and I'll be happy to implement and test it.
>
> Currently, the best way to handle this is to use an after_connect
> proc:
>
>   DB.connect(..., :after_connect=>proc{|c| c.exec("ALTER SESSION SET
> TIME_ZONE='-00:00'")})
>
> This is the only thread-safe and disconnect-handling friendly way to
> change connection-level settings.
>
> I would be willing to accept a patch to the Oracle adapter (inside
> Database#connect) that checks the value of Sequel.database_timezone
> and issues that query if it is :utc.  That way, as long as the user
> sets Sequel.default_timezone before a connection to the database is
> made, it will use that.
>
> 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