| Message: 97025 |
 |
BY: Yasuo Honda (yahonda) DATE: 2011-10-04 18:27 SUBJECT: IBM_DB with ActiveRecord unit test errors. Hi,
As I sometimes make commits ActiveRecord Oracle enhanced adapters,
then try to exeute ActiveRecord unit tests when any commits made
not to cause regressions other databases such as PostgreSQL and MySQL.
Recently, IBM_DB-2.5.7 gem supports Rails 3.1.0,
I'd like to test ActiveRecord unit tests with IBM DB2(LUW), then got some errors.
I'd like to hear from IBM DB2 professional point of view for these errors.
- Environment
Rails master branch
ruby 1.9.2 p 290(Linux 64-bit)
DB2 Express-C 9.7.4 for Linux 64-bit.
- Commands executed
$ cd rails/activerecord
$ rake test_db2
- 3 errors I've met
#1 SQL0604N: when it tries to create table with decimal(55,0) column
/var/lib/jenkins/.rvm/gems/ruby-1.9.2-p290@rails_master/gems/ibm_db-2.5.7/lib/active_record/connection_adapters/ibm_db_adapter.rb:1910:in `rescue in execute': RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0604N The length, precision, or scale attribute for column, distinct type, structured type, array type, attribute of structured type, routine, cast target type, type mapping, or global variable "decimal(55,0)" is not valid. SQLSTATE=42611 SQLCODE=-604: CREATE TABLE numeric_data (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, bank_balance decimal(10,2), big_bank_balance decimal(15,2), world_population decimal(10,0), my_house_population decimal(2,0), decimal_number_with_default decimal(3,2) DEFAULT 2.78, temperature float, atoms_in_universe decimal(55,0)) (ActiveRecord::StatementInvalid)
According to the IBM DB2 manual,
Table 2. Numeric Limits
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.sql.ref.doc%2Fdoc%2Fr0001029.html
Description Limit
Largest decimal precision 31
The largest decimal precision is 31, I made a following modification has made at my repository.
it has not pushed to the upstream one yet.
https://github.com/yahonda/rails/commit/575e8d7e3bf5f2a9e6c043cc6fac6a8c5247516d
--
395 + # IBM DB2 supports precision up to 31
396 + elsif current_adapter?(:IBM_DBAdapter)
397 + t.decimal :atoms_in_universe, :precision => 31, :scale => 0
--
Now I'm planning to do push request for this commit after addressing error #2 and #3 also.
#2 SQL0601N: when recreating CamelCase table when it exists as CAMELCASE
At 2nd time execution of "rake test_db2", the following error happend.
/var/lib/jenkins/.rvm/gems/ruby-1.9.2-p290@rails_master/gems/ibm_db-2.5.7/lib/active_record/connection_adapters/ibm_db_adapter.rb:1910:in `rescue in execute': RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0601N The name of the object to be created is identical to the existing name "ARUNIT.CAMELCASE" of type "TABLE". SQLSTATE=42710 SQLCODE=-601: CREATE TABLE CamelCase (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, name varchar(255)) (ActiveRecord::StatementInvalid)
"rake test_db2" will create each tables described in schema.rb. "CamelCase" table will be created as follows.
https://github.com/rails/rails/blob/master/activerecord/test/schema/schema.rb
--
101 create_table "CamelCase", :force => true do |t|
102 t.string :name
103 end
--
Here is my assuption based on trace files captured during rake test_db2.
- Trace files were captured with following commands.
$ db2 UPDATE CLI CFG FOR SECTION COMMON USING TRACE 1
$ db2 UPDATE CLI CFG FOR SECTION COMMON USING TRACEPATHNAME /var/tmp/db2
1st execution - arunit user does not have any tables.
Following SQL executed, then the "CAMELCASE" table created.
--
p25845t87348992.cli:( StmtOut="CREATE TABLE CamelCase (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, name varchar(255))" )
--
2nd execution of rake test_db2 with arunit user has their tables.
As :force => true option specified within create_table method,
rake test would try to drop the table if already exists by table_exists,
but it did not drop "CAMELCASE" table for some reason.
I tried to investigate the reason from IBM_DB modules but I gave it up when I reached to the" ibm_db.c".
I'd be happy if anyone has an idea how to investigate or handle this error.
#3 SQL0104N: when creating 'warehouse-things' table
/var/lib/jenkins/.rvm/gems/ruby-1.9.3-rc1@rails_master/gems/ibm_db-2.5.7/lib/active_record/connection_adapters/ibm_db_adapter.rb:1910:in `rescue in execute': RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "-" was found following "EATE TABLE warehouse". Expected tokens may include: ".". SQLSTATE=42601 SQLCODE=-104: CREATE TABLE warehouse-things (id INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY, value integer) (ActiveRecord::StatementInvalid)
At 1st execution of rake test_db2,
https://github.com/yahonda/rails/blob/master/activerecord/test/schema/schema.rb
--
656 create_table 'warehouse-things', :force => true do |t|
657 t.integer :value
658 end
--
Accoriding to the following manual, It looks hypens are not allowed for table names
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.db2.luw.admin.dbobj.doc%2Fdoc%2Fc0007246.html
>>
DB2 object naming rules
Table 2. Database object naming rules
... snip ...
Package names and package versions can also include periods (.), hyphens (-), and colons (:).
<<
Same as #2, I'd be happy if anyone has an idea how to investigate or handle this error.
Thanks in advance,
| |