We are using jruby 1.6.4 and Sequel 4.2.0 and recently upgraded from 
ojdbc14 to ojdbc6 in our Sinatra app. This has caused all the Date columns 
to come back as Timestamps, so the format of our query results has changed. 
We know we can force the behavior to mirror old behavior by setting the 
jdbc property 'oracle.jdbc.mapDateToTimestamp' to 'false', but we have not 
been able to do so using the :jdbc_properties element in the connection 
options. It seems that we have to enter the rescue block in Jdbc.connect in 
order for our property to be set, which we do not execute.

We were able to make it work as expected by editing the connect method in 
jdbc to include the explicit property setting before creating the 
connection. Our changes are highlighted:

# Connect to the database using JavaSQL::DriverManager.getConnection.
      def connect(server)
        opts = server_opts(server)
        conn = if jndi?
          get_connection_from_jndi
        else
          begin
            props = java.util.Properties.new
            if opts && opts[:user] && opts[:password]
              props.setProperty("user", opts[:user])
              props.setProperty("password", opts[:password])
            end
            opts[:jdbc_properties].each{|k,v| props.setProperty(k.to_s, v)} 
if opts[:jdbc_properties]
            JavaSQL::DriverManager.setLoginTimeout(opts[:login_timeout]) if 
opts[:login_timeout]
            JavaSQL::DriverManager.getConnection(uri(opts), props)
          rescue JavaSQL::SQLException, NativeException, StandardError => e
            raise e unless driver
            # If the DriverManager can't get the connection - use the 
connect
            # method of the driver. (This happens under Tomcat for instance)
            props = java.util.Properties.new
            if opts && opts[:user] && opts[:password]
              props.setProperty("user", opts[:user])
              props.setProperty("password", opts[:password])
            end
            opts[:jdbc_properties].each{|k,v| props.setProperty(k.to_s, v)} 
if opts[:jdbc_properties]
            begin
              c = driver.new.connect(args[0], props)
              raise(Sequel::DatabaseError, 'driver.new.connect returned 
nil: probably bad JDBC connection string') unless c
              c
            rescue JavaSQL::SQLException, NativeException, StandardError => 
e2
              unless e2.message == e.message
                e2.message << "\n#{e.class.name}: #{e.message}"
              end
              raise e2
            end
          end
        end
        setup_connection(conn)
      end

Is there a proper way to achieve the same results without making any 
modifications?

Thanks,
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to