The TYPE attribute is defined to be NUMERIC. Several databases do not
follow that definition, like SQLite and CSV

Luckily,  we control both DBD::CSV and the underlying DBD::File, se I
can "fix" that for at least DBD::CSV and probably all DBD's using the
DBD::File layer. I propose this change:

--8<---
diff --git a/lib/DBD/File.pm b/lib/DBD/File.pm
index 444c4d4..ffc5e84 100644
--- a/lib/DBD/File.pm
+++ b/lib/DBD/File.pm
@@ -280,6 +280,7 @@ my %supported_attrs = (
     PRECISION => 1,
     NULLABLE  => 1,
     );
+my $type_map;

 sub FETCH
 {
@@ -306,8 +307,23 @@ sub FETCH

            my @colnames = $sth->sql_get_colnames ();

+           unless ($type_map) {
+               $type_map = {   # Minimal type set (like CSV)
+                   BLOB    => -4,
+                   TEXT    => -1,
+                   CHAR    =>  1,
+                   INTEGER =>  4,
+                   REAL    =>  7,
+                   VARCHAR => 12,
+                   };
+               my $tia = $sth->{Database}->type_info_all ();
+               # TYPE_NAME => DATA_TYPE
+               $type_map->{$_->[0]} = $_->[1] for grep { ref $_ eq "ARRAY" } 
@$tia;
+               }
+
            $attr eq "TYPE"      and
-               return [ map { $sth->{f_overall_defs}{$_}{data_type}   || 
"CHAR" }
+               return [ map { $type_map->{$_} || $_ }
+                        map { $sth->{f_overall_defs}{$_}{data_type}   || 
"VARCHAR" }
                            @colnames ];

            $attr eq "PRECISION" and
-->8---

All DBI tests still pass, and several TODO tests in DBD::CSV now pass

If DBD::xxx provides GetInfo.pm and TypeInfo.pm, the conversions will
automatically be updated (once).

-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.19   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

Reply via email to