[ruby-dbi-users] find a bug for Real column for MS SQL Server

Oliver Peng oliver.peng at skywave.com
Wed Jul 6 11:36:33 EDT 2011


In MS SQL Server, create following test database and table:

CREATE DATABASE admin_test  COLLATE SQL_Latin1_General_Cp850_CI_AI

use admin_test;
GO

CREATE TABLE table5 (
  table5_id int NOT NULL,
  column8 REAL,

  CONSTRAINT PK_table5 PRIMARY KEY(table5_id),
);
go

insert into table5 values (1, -1.11)
go

select * from table5 where table5_id = 1
go

Connect to this database by using DBI and retrieve it:

irb(main):011:0> require 'rubygems'
=> true
irb(main):012:0> require 'dbi'
=> true
irb(main):012:0> connstr = "DBI:ODBC:Driver={SQL Server};Server=(local);Database=admin_test;UID=AdminTest;PWD=123"
=> "DBI:ODBC:Driver={SQL Server};Server=(local);Database=admin_test;UID=AdminTes
t;PWD=123"
irb(main):014:0> connection = DBI.connect(connstr)
=> #<DBI::DatabaseHandle:0x5902a88 @handle=#<DBI::DBD::ODBC::Database:0x5901bb8
@handle=#<ODBC::Database:0x5901d08>, @attr={}>, @convert_types=true, @driver_nam
e="odbc", @trace_output=nil, @trace_mode=nil>
irb(main):015:0> sql = 'select * from table5 where table5_id = 1'
=> "select * from table5 where table5_id = 1"
irb(main):016:0> sth = connection.execute(sql)
=> #<DBI::StatementHandle:0x58ba1a0 @handle=#<DBI::DBD::ODBC::Statement:0x58ba00
8 @handle=#<ODBC::Statement:0x58ba0b0>, @arr=[], @statement="select * from table
5 where table5_id = 1", @params=[]>, @dbh=#<DBI::DatabaseHandle:0x5902a88 @handl
e=#<DBI::DBD::ODBC::Database:0x5901bb8 @handle=#<ODBC::Database:0x5901d08>, @att
r={}>, @convert_types=true, @driver_name="odbc", @last_statement="select * from
table5 where table5_id = 1", @trace_output=nil, @trace_mode=nil>, @executed=true
, @convert_types=true, @row=[nil, nil], @prepared=true, @trace_output=nil, @colt
ypes=[DBI::Type::Integer, DBI::Type::Float], @fetchable=true, @raise_error=nil,
@trace_mode=nil, @cols=["table5_id", "column8"]>

irb(main):017:0> dbr = sth.fetch_all
=> [[1, -1.11000001430511]]

>From the result, the value of column8 is not correct.

I am using latest Ruby 1.8.7 and latest ODBC gem and here is the gem list:

*** LOCAL GEMS ***

dbd-mysql (0.4.4)
dbd-odbc (0.2.5)
dbi (0.4.5)
deprecated (2.0.1)
mysql (2.8.1 x86-mingw32)
ruby-oci8 (2.0.6 x86-mingw32)
ruby-odbc (0.99994)

Oliver
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ruby-dbi-users/attachments/20110706/314da737/attachment-0001.html>


More information about the ruby-dbi-users mailing list