bump $VERSION
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / Informix.pm
index 0f1c3d7..b6db13a 100644 (file)
@@ -8,7 +8,7 @@ use namespace::autoclean;
 use Carp::Clan qw/^DBIx::Class/;
 use Scalar::Util 'looks_like_number';
 
-our $VERSION = '0.07000';
+our $VERSION = '0.07001';
 
 =head1 NAME
 
@@ -29,6 +29,10 @@ sub _setup {
     if (not defined $self->preserve_case) {
         $self->preserve_case(0);
     }
+    elsif ($self->preserve_case) {
+        $self->schema->storage->sql_maker->quote_char('"');
+        $self->schema->storage->sql_maker->name_sep('.');
+    }
 }
 
 sub _tables_list {
@@ -160,7 +164,7 @@ sub _columns_info_for {
     local $dbh->{FetchHashKeyName} = 'NAME_lc';
 
     my $sth = $dbh->prepare(<<'EOF');
-select c.colname, c.coltype, d.type deflt_type, d.default deflt
+select c.colname, c.coltype, c.collength, c.colmin, d.type deflt_type, d.default deflt
 from syscolumns c
 join systables t on c.tabid = t.tabid
 left join sysdefaults d on t.tabid = d.tabid and c.colno = d.colno
@@ -171,31 +175,78 @@ EOF
     $sth->finish;
 
     while (my ($col, $info) = each %$cols) {
+        $col = $self->_lc($col);
+
         my $type = $info->{coltype} % 256;
 
         if ($type == 6) { # SERIAL
             $result->{$col}{is_auto_increment} = 1;
         }
 
-        if (looks_like_number $result->{$col}{data_type}) {
+        my $data_type = $result->{$col}{data_type};
+
+        if (looks_like_number $data_type) {
             if ($type == 7) {
                 $result->{$col}{data_type} = 'date';
             }
             elsif ($type == 10) {
-                $result->{$col}{data_type} = 'datetime';
+                $result->{$col}{data_type} = 'datetime year to fraction(5)';
+            }
+            elsif ($type == 17 || $type == 52) {
+                $result->{$col}{data_type} = 'bigint';
+            }
+            elsif ($type == 40) {
+                $result->{$col}{data_type} = 'lvarchar';
+                $result->{$col}{size}      = $info->{collength};
+            }
+            elsif ($type == 12) {
+                $result->{$col}{data_type} = 'text';
+            }
+            elsif ($type == 11) {
+                $result->{$col}{data_type}           = 'bytea';
+                $result->{$col}{original}{data_type} = 'byte';
+            }
+            elsif ($type == 41) {
+                # XXX no way to distinguish opaque types boolean, blob and clob
+                $result->{$col}{data_type} = 'blob';
             }
+            elsif ($type == 21) {
+                $result->{$col}{data_type} = 'list';
+            }
+            elsif ($type == 20) {
+                $result->{$col}{data_type} = 'multiset';
+            }
+            elsif ($type == 19) {
+                $result->{$col}{data_type} = 'set';
+            }
+        }
+
+        if ($type == 15) {
+            $result->{$col}{data_type} = 'nchar';
+        }
+        elsif ($type == 16) {
+            $result->{$col}{data_type} = 'nvarchar';
+        }
+        # XXX untested!
+        elsif ($info->{coltype} == 2061) {
+            $result->{$col}{data_type} = 'idssecuritylabel';
         }
 
+        # XXX colmin doesn't work for min size of varchar columns, it's NULL
+#        if (lc($data_type) eq 'varchar') {
+#            $result->{$col}{size}[1] = $info->{colmin};
+#        }
+       
         my ($default_type, $default) = @{$info}{qw/deflt_type deflt/};
 
         next unless $default_type;
 
         if ($default_type eq 'C') {
-            my $current = 'CURRENT YEAR TO FRACTION(5)';
+            my $current = 'current year to fraction(5)';
             $result->{$col}{default_value} = \$current;
         }
         elsif ($default_type eq 'T') {
-            my $today = 'TODAY';
+            my $today = 'today';
             $result->{$col}{default_value} = \$today;
         }
         else {
@@ -204,12 +255,47 @@ EOF
             $default =~ s/\s+\z// if looks_like_number $default;
 
             # remove trailing 0s in floating point defaults
-            $default =~ s/0+\z// if $default =~ /^\d+\.\d+\z/;
+            # disabled, this is unsafe since it might be a varchar default
+            #$default =~ s/0+\z// if $default =~ /^\d+\.\d+\z/;
 
             $result->{$col}{default_value} = $default;
         }
     }
 
+    # fix up data_types some more
+    while (my ($col, $info) = each %$result) {
+        my $data_type = $info->{data_type};
+
+        if ($data_type !~ /^(?:[nl]?(?:var)?char|decimal)\z/i) {
+            delete $info->{size};
+        }
+
+        if (lc($data_type) eq 'decimal') {
+            no warnings 'uninitialized';
+
+            $info->{data_type} = 'numeric';
+
+            my @size = @{ $info->{size} || [] };
+
+            if ($size[0] == 16 && $size[1] == -4) {
+                delete $info->{size};
+            }
+            elsif ($size[0] == 16 && $size[1] == 2) {
+                $info->{data_type} = 'money';
+                delete $info->{size};
+            }
+        }
+        elsif (lc($data_type) eq 'smallfloat') {
+            $info->{data_type} = 'real';
+        }
+        elsif (lc($data_type) eq 'float') {
+            $info->{data_type} = 'double precision';
+        }
+        elsif ($data_type =~ /^n?(?:var)?char\z/i) {
+            $info->{size} = $info->{size}[0];
+        }
+    }
+
     return $result;
 }