README for the IBM_DB Adapter (3.0.2) and Driver (3.0.2) (2016/05/24) For ActiveRecord Version >= 4.2.0 (and Rails >= 4.2.0)
Supported Operating Systems
- Linux 32/64 bit
- Microsoft Windows 32 bit
- IBM AIX 32/64 bit
- HP-UX 32/64 bit
- Sun Solaris 32/64 bit
Supported Databases
- IBM DB2 Universal Database on Linux/Unix/Windows versions 9 Fixpak2 and above
- Remote connections to IBM DB2 Universal Database on i5/OS versions V5R3 and V5R4.
Please ensure PTF SI27358 (includes SI27250) is installed in i5/OS version 5R3 and
and PTF SI27256 is installed while using i5/OS version 5R4.
- Remote connections to IBM DB2 Universal Database on z/OS version 8, 9 and 10
- Informix Dynamic Server 11.10 and beyond.
Please ensure that the IBM DataServer Viper 2 client is installed.
Installing the IBM_DB adapter and driver as a Ruby gem
The IBM_DB gem is an ActiveRecord adapter. Installing the IBM_DB adapter and driver as a gem enables any application in the Ruby environment, including Rails, to interact with IBM data servers.
Note : - 1) If using activerecord version below 2.0 then it requires that the ibm_db adapter be registered with the list of connection adapters by manually adding ibm_db at line 77 (approx) in the file activerecord.rb (GEM_HOMEactiverecord-<version>lib).
2) The IBM_DB driver can also be built separately (from source) and used in direct API calls.
-
Windows platforms:
INSTALL (as Ruby gem)
To remove previous gem version (optionally):
D:\>gem uninstall ibm_db
Successfully uninstalled ibm_db version 1.0.0
Example:
D:\>gem install ibm_db
Fetching: ibm_db-2.5.9-x86-mingw32.gem (100%)
Successfully installed ibm_db-2.5.9-x86-mingw32
1 gem installed
Installing ri documentation for ibm_db-2.5.9-x86-mingw32...
Installing RDoc documentation for ibm_db-2.5.9-x86-mingw32...
Note:
1) Currently Ruby-2.0 64-bit version on Windows is not supported as there are issues related to SQL definitions with the mingW compiler
[Details can be found here https://sourceforge.net/p/mingw/bugs/2041/ ].
Support will be enabled after the abive reported issue is resolved.
2)The manual step after install if using activerecord version below 2.0:
add ibm_db into GEM_HOME\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
-
Linux and Unix platforms:
INSTALL (as Ruby gem)
To remove previous gem version (optionally):
$ gem uninstall ibm_db
Successfully uninstalled ibm_db version 0.6.0
Note: DB2 environment is required while using an arbitrary user account
(other than the DB2 install user account)
$ . /home/db2inst1/sqllib/db2profile
$ export IBM_DB_HOME=DB2HOME (eg. /home/db2inst1/sqllib or /opt/ibm/db2/v9.5)
$ gem install ibm_db
Building native extensions. This could take a while...
Successfully installed ibm_db-2.5.9
1 gem installed
Installing ri documentation for ibm_db-2.5.9...
Installing RDoc documentation for ibm_db-2.5.9...
BUILD (optionally) ibm_db gem from sources (ibm_db-x.x.x.tar.gz):
1. Download source from Rubyforge
http://rubyforge.org/frs/?group_id=2361
2. Build gem from specification (IBM_DB.gemspec)
$ cd IBM_DB_Adapter/ibm_db
$ gem build IBM_DB.gemspec
Note: The manual step after install if using activerecord version below 2.0:
add ibm_db into GEM_HOME\1.8\gems\activerecord-1.15.3\lib\active_record.rb (Line 77)
TEST (simple gem install verification)
$ rails new myApp -d ibm_db
$ cd myApp
$ rails generate scaffold Wood name:string price:float
$ vi config/database.yml
$ rake db:migrate
$ rails console #rails server
Instructions for building and installing the IBM_DB driver from source
Building the driver manually as described below is not required if the install process above has been pursued. This manual procedure is in fact automated on Linux and UNIX platforms by the IBM_DB gem install, but is presented here only for reference.
Prerequisites:
Install Ruby from:
http://rubyforge.org
Setup the environment
Linux and Unix platforms:
Note: commands may vary depending on the shell used
- To setup DB2 environment while using an arbitrary user account
(other than the DB2 install user account):
Example:
$ . /home/db2inst1/sqllib/db2profile
- To compile and link with DB2 client libraries:
$ export IBM_DB_HOME=DB2HOME (eg. /home/db2inst1/sqllib or /opt/ibm/db2/v9.5)
Windows platforms:
- Set ruby devkit environment:
- To compile and link with DB2 client libraries:
$ set IBM_DB_HOME=DB2HOME (eg. C:\Program Files\IBM\SQLLIB)
Build the driver:
- $ cd rubyibm_source/IBM_DB_Adapter/ibm_db/ext
- $ ruby extconf.rb
- $ make
Build the ibm_db gem
- $ cp rubyibm_source/IBM_DB_Adapter/ibm_db/ext/ibm_db.so rubyibm_source/IBM_DB_Adapter/ibm_db/lib
# Not on windows separate binaries are generated for 1.8 and 1.9 version of ruby
# and placed under rb18x and rb19x directories respectively. The file ibm_db_mswin32.rb is renamed to ibm_db.rb to ensure proper binary is loaded based on runtime
# You will need to similarly ensure that the generated binary is placed on rb18x or rb19x directory under lib based on ruby version being used
- $ cd rubyibm_source/IBM_DB_Adapter/ibm_db
- $ gem build IBM_DB.gemspec
Running tests
Testing the IBM_DB Adapter
1) a) Copy the files under test directory of ibm_db gem to the test directory of Activerecord following the same directory structure. These files contain modifications in some test files of AR suite to handle ibm_db specifics. Hence make sure these files are replaced in the AR test suite properly.
b) Rename warhouse-things.yml to warehouse_things.yml under fixtures directory
2) Edit the Rakefile to include ibm_db in list of adapters %w( mysql mysql2 postgresql sqlite3 sqlite3_mem firebird db2 oracle sybase openbase ibm_db frontbase jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ) 3) Configure the connection information in test/config.yml for ibm_db 4) run the test suite - rake test_ibm_db
Running IBM_DB driver test suite
1) Copy over the test directory under source to lib directory of installed ibm_db under $GEM_HOME 2) Edit config.yml file to provide database connection information 3) Run the test suite $ rake onlytests 4) To run single test export SINGLE_RUBY_TEST=<test file name> #Eg: export SINGLE_RUBY_TEST=test_000_PrepareDb.rb rake onlytests
Limitations and known problems
- ActiveRecord remove_column method is not supported for DB2 zOS
- The driver returns an error when you try to insert a TIMESTAMP value into a DATE column.
To fix this, please ensure that the following configuration keyword PATCH2=58 is set
in the COMMON section of your DB2 CLI initialization file (db2cli.ini):
- set: db2 UPDATE CLI CFG FOR SECTION COMMON USING PATCH2 58
- verify: db2 GET CLI CFG FOR SECTION COMMON
Please refer to http://publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.apdv.cli.doc/doc/c0007882.htm
for more information.
- The behaviour of ActiveRecord::Base.find(:first) without an :order attribute can be unpredictable.
The first record (i.e. the record with the minimum id) may be not retrieved. In a relational model,
the order of the rows returned is unpredictable and independent of the order of insertion.
This issue may be addressed in a future release.
- Rails applications on DB2 9 require the APPLHEAPSZ database configuration parameter to be
set to or above 1024. You will need to set this parameter for each database for which you will be
running DB2 on Rails applications. Following is the command syntax for updating the
applheapsz parameter:
> db2 update db cfg for <database_name> using APPLHEAPSZ 1024
To enable this parameter, you need to restart your DB2 instance.
- If you see connectivity issues with Informix Dynamic Server, please ensure that the server is configured to accept DRDA connections.
Please refer to http://publib.boulder.ibm.com/infocenter/idshelp/v111/index.jsp?topic=/com.ibm.admin.doc/admin154.htm for more information.
- IBM_DB is not supported on JRuby. As stated in the JRuby Wiki, "Basics of Getting JRuby Running":
'You may install other gems, but keep in mind that libraries with C extension dependencies
will not work in JRuby.' http://www.headius.com/jrubywiki/index.php/Getting_Started
The IBM_DB adapter relies on IBM_DB driver (C extension) and the IBM Driver for ODBC and
CLI to access databases on IBM data servers. Alternatively, you can either use the regular C
implementation of Ruby, or use ActiveRecord-JDBC adapter to access databases.
- When using ActiveRecord-2.1.0 it requires that ActiveRecord be patched, with the patch in the link below:
http://rails.lighthouseapp.com/attachments/26975/association_preloading.diff
The patch is required because, ActiveRecord 2.1.0 generates a non-standard SQL identifier,while preloading has_and_belongs_to_many associations,
which standard compliant databases like DB2 do not support. The bug report, against ActiveRecord, can be found in the link below
http://rails.lighthouseapp.com/projects/8994/tickets/394-patch-fixed-non-standard-sql-generated-by-preloading-has_and_belongs_to_many-associations
- The following tests from the ActiveRecord 2.1.0 test suite with ibm_db gem 0.10.0 are expected to fail on DB2 LUW
- test_read_attributes_before_type_cast_on_datetime
- test_to_xml
- test_native_types
- test_counting
- test_counting_with_column_name_and_hash
- test_counting_with_empty_hash_conditions
- test_counting_with_single_conditions
- test_counting_with_single_hash
Note :- 1) The test cases from HasManyAssociations (4-8) above are found failing only when run as part of
the complete suite. However they pass when run standalone.
2) Also there are two test cases (test_validate_uniqueness_with_non_standard_table_names, test_update_all_with_non_standard_table_name)which run against table with non-standard name. Given that DB2/IDS is standard compliant these test cases are expected to fail.
To have these test cases passing rename the fixtures file warehouse-things to warehouse_things.
- Usage with Rails-3.0.3/Rails-3.0.4
- To use with Rails-3.0.3/4 patch latest Arel with the patch available at gist.github.com/814491 Unicode Support
- Available only with Ruby version 1.9 and above
- Data returned from the driver will be in UTF8 encoding format.
- The input data to the driver can be in any Ruby supported encoding format.
To Do
- Support ActiveRecord remove_column method for DB2 zOS version 9
Feedback
Your feedback is very much appreciated and expected through Rubyforge:
- rubyibm project: http://rubyforge.org/projects/rubyibm/
- rubyibm forum: http://rubyforge.org/forum/?group_id=2361
- rubyibm bug reports: http://rubyforge.org/tracker/?group_id=2361
- IBM_DB developers: [email protected]