Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB2 Rails 4.1 support #581

Closed
bbozo opened this issue Sep 2, 2014 · 2 comments
Closed

DB2 Rails 4.1 support #581

bbozo opened this issue Sep 2, 2014 · 2 comments
Labels

Comments

@bbozo
Copy link

bbozo commented Sep 2, 2014

Hi all :)

Docs say that the following YAML should be used for DB2:

development:
  adapter: jdbc
  url: jdbc:db2j:net://mightyzoshost:446/RAILS_DBT1
  driver: com.ibm.db2.jcc.DB2Driver
  schema: DB2XB12
  database: RAILS_DB1
  tablespace: TSDE911
  lob_tablespaces:
    first_table: TSDE912
  username: business
  password: machines
  encoding: unicode
  # you can force a (DB2) dialect using:
  #dialect: as400

However, the following database.yml snippet

default: &default
  adapter: jdbc
  url: jdbc:db2j:net://localhost:50000/BBOZO
  driver: com.ibm.db2.jcc.DB2Driver
  database: BBOZO
  encoding: unicode
  host: localhost
  port: 50000
  #connection_alive_sql: SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY

development:
  username: username
  password: password
  <<: *default

yields an abstract method error:

WARN: driver does not support checking if connection isValid() please make sure you're using a JDBC 4.0 compilant driver or set `connection_alive_sql: ...` in your database configuration
rake aborted!
Java::JavaLang::AbstractMethodError: com.ibm.db2.jcc.t4.b.isValid(I)Z
arjdbc.jdbc.RubyJdbcConnection.isConnectionValid(RubyJdbcConnection.java:2696)
arjdbc.jdbc.RubyJdbcConnection.active_p(RubyJdbcConnection.java:478)

I can tell that the driver at least seems to handle this https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/db2/connection_methods.rb#L17 but for some reason it doesn't seem to "sink in"

Quick workaround was to add connection_alive_sql: SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY to the default section, however then this blows up:

wrong number of arguments calling `initialize` (1 for 4)/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/db2/adapter.rb:200:in `zos_create_table'
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/db2/adapter.rb:192:in `create_table'

And sure enough, there's a line saying NOTE: this won't work for 4.0 - need to pass different initialize args on https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/db2/adapter.rb#L199 so I guessed that's mistery solved because all I need to do is make it to not be zos? :)

OK, zos? is defined on https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/db2/adapter.rb#L620 and I find #546 so things seem clear - zos? support (whatever it is) didn't get updated with rails 4 and the thing doesn't work with the outdated url: parameter, all I need to do is switch from url: to jdbc_url: or define host, port etc in separate tags and all will be fine once I update README.md, however:

ActiveRecord::ConnectionNotEstablished: jdbc adapter requires :driver and :url (got :driver = com.ibm.db2.jcc.DB2Driver)
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/jdbc/connection.rb:80:in `setup_jdbc_factory'
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/jdbc/connection.rb:63:in `setup_connection_factory'
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/jdbc/connection.rb:14:in `initialize'
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/jdbc/adapter.rb:68:in `initialize'
/home/bbozo/dev/activerecord-jdbc-adapter/lib/arjdbc/jdbc/connection_methods.rb:12:in `jdbc_connection'

In the end I cargo culted the IBM data admin connection string url: jdbc:db2://localhost:50000/BBOZO instead of one from README.md just to get around the zos? regexp condition (https://github.com/jruby/activerecord-jdbc-adapter/blob/master/lib/arjdbc/db2/adapter.rb#L625), but I have no idea what the implications of this are, rake db:migrate went through which I guess is enough to start development YAY :)

I guess, however, that this isn't an optimal setting to go to production? And that at least the docs need to be updated as well as possibly several other issues as well, I'll push my test DB2 rails app to github in a minute

@bbozo
Copy link
Author

bbozo commented Sep 2, 2014

Here: https://github.com/bbozo/db2_test

@kares
Copy link
Member

kares commented Sep 3, 2014

@bbozo great detail ... I tihnk you'll definitely crack this down. you assumed the config[:url] wrong - it still works (with Rails 4.x) Rails core incorporated a work-around for JRuby - they simply do not parse.

I'll recommend keeping the JDBC url as is and instead concentrate on making a 4.x compatible zos_create_table ... you should also try using adapter: db2 but you will still hit the create table thing!

@kares kares added the db2 label Sep 3, 2014
kares added a commit that referenced this issue Nov 26, 2014
@kares kares closed this as completed Nov 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants