Bugs: Browse | Submit New | Admin

[#27499] smallint, mediumint, bigint converted to varchar

Date:
2009-12-01 01:28
Priority:
3
Submitted By:
C H (centrx)
Assigned To:
Nobody (None)
Category:
None
State:
Open
Summary:
smallint, mediumint, bigint converted to varchar

Detailed description
DBI::TypeUtil.type_name_to_module('smallint')
=> DBI::Type::Varchar

because these types do not match /^int(?:\d+|eger)?$/i

Add A Comment: Notepad

Please login


Followup

Message
Date: 2009-12-13 19:13
Sender: Erik Hollensbe

Hi Chris,

I know I promised to have a patch out this weekend, but my VM
is being, for lack of a polite word, "pissy".

I hope to have everything sorted out later this week, and perhaps
then I can fix this issue.
Date: 2009-12-02 22:15
Sender: C H

I have been overriding DBI::TypeUtil#type_name_to_module, as
in the following diff. This works in SQL Server 2005, but is
not tested for other databases.

Thanks for your help! Take your time.

--- typeutil.rb 2009-12-02 16:36:38.000000000 -0500
+++ typeutil_sqlserver.rb       2009-12-02
17:05:59.000000000 -0500
@@ -63,13 +63,13 @@
         #
         def self.type_name_to_module(type_name)
             case type_name
-            when /^int(?:\d+|eger)?$/i
+            when /^(?:tiny|small)?int(?:\d+|eger)?$/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, /^bit$/i
                 DBI::Type::Boolean
             when /^time(?:stamp(?:tz)?)?$/i
                 DBI::Type::Timestamp
Date: 2009-12-02 21:54
Sender: Erik Hollensbe

If you need an immediate solution, please look into turning type
conversion off via DBI.convert_types= (it also works on statement
and database handles for those scopes)
Date: 2009-12-02 21:53
Sender: Erik Hollensbe

Alright... Getting to it this weekend is unlikely, but next week
should be probable. Alternatively, you can author a patch and
I can get it integrated and released quickly.

The tinyint-as-boolean issue is a separate one, but shouldn't
be working like that for non-mysql databases (mysql's 'bool'
type macros to tinyint(1)). I'll see if I can make that DBD-dependent
as well.
Date: 2009-12-02 21:46
Sender: C H

SQL Server 2005, through FreeTDS 0.82 and unixODBC 2.2.11 on
Debian testing.

I tested printing out the type_name parameter in
DBI::TypeUtil#type_name_to_module, and the row[0].class.to_s
resulting from dbh.select_one

These data types did not have sensible results:

type_name: ruby class
TINYINT: TrueClass/FalseClass (see #27283)
SMALLINT: String
BIT: String (supposed to be boolean)
Date: 2009-12-01 01:29
Sender: Erik Hollensbe

Yep. What database are you using? These kinds of types are usually
macros; they aren't actually used by the database for purposes
beyond DDL, which will convert them to an integer or number type
with a specific precision/scale.

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item