[bug] DBD::ODBC

J

jc

I've run into a small bug with DBD::ODBC. The following code:

require 'dbi'
dbh = DBI.connect("DBI:ODBC:dsn", "user", "pass")
puts dbh.columns('table').collect { |c| c.name }

produced the following error:

/ruby/lib/ruby/site_ruby/1.8/DBD/ODBC/ODBC.rb:127 in 'columns'
undefined method '-' for nil:NilClass (NoMethodError

This relates to the following line in ODBC.rb (line 127)

info['precision'] = row['COLUMN_SIZE'] - (row['DECIMAL_DIGITS'] || 0)

It appears this needs to be changed to the following:

info['precision'] = (row['COLUMN_SIZE'] || 0) - (row['DECIMAL_DIGITS']
|| 0)

In case of situations where COLUMN_SIZE is undefined.
 
M

Michael Neumann

jc said:
I've run into a small bug with DBD::ODBC. The following code:

require 'dbi'
dbh = DBI.connect("DBI:ODBC:dsn", "user", "pass")
puts dbh.columns('table').collect { |c| c.name }

produced the following error:

/ruby/lib/ruby/site_ruby/1.8/DBD/ODBC/ODBC.rb:127 in 'columns'
undefined method '-' for nil:NilClass (NoMethodError

This relates to the following line in ODBC.rb (line 127)

info['precision'] = row['COLUMN_SIZE'] - (row['DECIMAL_DIGITS'] || 0)

It appears this needs to be changed to the following:

info['precision'] = (row['COLUMN_SIZE'] || 0) - (row['DECIMAL_DIGITS']
|| 0)

maybe it's even better to return nil, if column_size is not set.
because, imagine decimal_digits is set, then a negative value is returned.

The following is now commited to SVN (see patch below).u

Regards,

Michael

Index: ODBC.rb
===================================================================
--- ODBC.rb (revision 415)
+++ ODBC.rb (working copy)
@@ -124,7 +124,8 @@
info['type_name'] = row['TYPE_NAME']
info['sql_type'] = row['DATA_TYPE']
info['nullable'] = row['NULLABLE']
- info['precision'] = row['COLUMN_SIZE'] - (row['DECIMAL_DIGITS'] || 0)
+ cs = row['COLUMN_SIZE']
+ info['precision'] = cs ? (cs - (row['DECIMAL_DIGITS'] || 0)) : nil
info['scale'] = row['DECIMAL_DIGITS']
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top