jc11
(jc)
1
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.
George5
(George)
2
jc wrote:
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