Bugs: Browse | Submit New | Admin

[#27283] TINYINT incorrectly converted to BOOL

Date:
2009-10-13 21:19
Priority:
3
Submitted By:
Leslie Viljoen (lesliev)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
TINYINT incorrectly converted to BOOL

Detailed description
This is for DBI:ODBC, which activerecord-sqlserver-adapter uses.
Discussion here:
http://groups.google.com/group/rails-sqlserver-adapter/browse_thread/thread/7c75c7c87418d5e0

The change in dbi.rb here:
http://github.com/erikh/ruby-dbi/commit/e7f7fcbff57f79da9ff5b99c702ea9d77c06cedb

..coerces TINYINT to BOOL, even when the TINYINT is an 8-bit number. This is rarely what you'd want with MSSQL since
it has a BIT data type.

The MYSQL adapter makes use of an emulate_booleans option to control this kind of conversion, and turns it off
by default:
http://osdir.com/ml/RubyonRailsTalk/2009-10/msg00160.html

My Rails 2.3.4 is using DBI 0.4.1.

Here's a patch which treats TINYINT as an INTEGER, which works for my purposes.

For this file on my system: 
/usr/lib/ruby/gems/1.8/gems/dbi-0.4.1/lib/dbi/typeutil.rb 

--- typeutil.rb 2009-10-13 09:25:02.000000000 +0200 
+++ typeutil_les.rb     2009-10-13 09:27:50.000000000 +0200 
@@ -63,13 +63,13 @@ 
         # 
         def self.type_name_to_module(type_name) 
             case type_name 
-            when /^int(?:\d+|eger)?$/i 
+            when /^int(?:\d+|eger)?$/i, /^tinyint$/i 
                 DBI::Type::Integer 
             when /^varchar$/i, /^character varying$/i 
                 DBI::Type::Varchar 
             when /^(?:float|real)$/i 
                 DBI::Type::Float 
-            when /^bool(?:ean)?$/i, /^tinyint$/i 
+            when /^bool(?:ean)?$/i 
                 DBI::Type::Boolean 
             when /^time(?:stamp(?:tz)?)?$/i 
                 DBI::Type::Timestamp 


Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-10-15 19:37
Sender: Erik Hollensbe

Thanks Ken.

I'm going to leave this open, as this does seem to be a problem
that needs to be handled at a lower level. Since a plan of redoing
the type system seems imminent, it'll be important to have this
around when we consider how it should best be done.
Date: 2009-10-15 18:39
Sender: Ken Collins

Not sure this is right for core DBI since different DBs expect
tinyint to be something different. The SQL Server adapter method
chains this already and I just extended it to add our expected
behavior for tinyint.

http://github.com/rails-sqlserver/2000-2005-adapter/commit/dfc57d
3d68d10e58e7654126669ac5570d7dbe92

Attached Files:

Name Description Download
tinyint.patch Patch for typeutil.rb in DBI 0.4.1 Download

Changes:

Field Old Value Date By
File Added4761: tinyint.patch2009-10-13 21:29lesliev