X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FInformix.pm;h=9dab49215d4c1de3f5d895b1558a36bb08bfbc4f;hb=c8845f2e67c636fbfb597a4562847cc80c4e5f28;hp=53b49f100a7c7dba621758dfb05edde29d49d096;hpb=a60e0f45aec9bb5f08951f73f0082f6e526bb1ef;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm index 53b49f1..9dab492 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Informix.pm @@ -2,13 +2,13 @@ package DBIx::Class::Schema::Loader::DBI::Informix; use strict; use warnings; -use Class::C3; +use mro 'c3'; use base qw/DBIx::Class::Schema::Loader::DBI/; -use namespace::autoclean; use Carp::Clan qw/^DBIx::Class/; use Scalar::Util 'looks_like_number'; +use namespace::clean; -our $VERSION = '0.07000'; +our $VERSION = '0.07009'; =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 { @@ -150,6 +154,31 @@ EOF return \@rels; } +# This is directly from http://www.ibm.com/developerworks/data/zones/informix/library/techarticle/0305parker/0305parker.html +# it doesn't work at all +sub _informix_datetime_precision { + my @date_type = qw/DUMMY year month day hour minute second fraction(1) fraction(2) fraction(3) fraction(4) fraction(5)/; + my @start_end = ( [], [1,5],[5,7],[7,9],[9,11],[11,13],[13,15],[15,16], [16,17], [17,18], [18,19], [19,20] ); + + my ($self, $collength) = @_; + + my $i = ($collength % 16) + 1; + my $j = int(($collength % 256) / 16) + 1; + my $k = int($collength / 256); + + my $len = $start_end[$i][1] - $start_end[$j][0]; + $len = $k - $len; + + if ($len == 0 || $j > 11) { + return $date_type[$j] . ' to ' . $date_type[$i]; + } + + $k = $start_end[$j][1] - $start_end[$j][0]; + $k += $len; + + return $date_type[$j] . "($k) to " . $date_type[$i]; +} + sub _columns_info_for { my $self = shift; my ($table) = @_; @@ -157,10 +186,9 @@ sub _columns_info_for { my $result = $self->next::method(@_); my $dbh = $self->schema->storage->dbh; - 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 +199,105 @@ 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; } + elsif ($type == 7) { + $result->{$col}{data_type} = 'date'; + } + elsif ($type == 10) { + $result->{$col}{data_type} = 'datetime year to fraction(5)'; + # this doesn't work yet +# $result->{$col}{data_type} = 'datetime ' . $self->_informix_datetime_precision($info->{collength}); + } + 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' unless $result->{$col}{data_type} eq 'smallint'; + } + elsif ($type == 21) { + $result->{$col}{data_type} = 'list'; + } + elsif ($type == 20) { + $result->{$col}{data_type} = 'multiset'; + } + elsif ($type == 19) { + $result->{$col}{data_type} = 'set'; + } + elsif ($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'; + } + + my $data_type = $result->{$col}{data_type}; - if (looks_like_number $result->{$col}{data_type}) { - if ($type == 7) { - $result->{$col}{data_type} = 'date'; + if ($data_type !~ /^(?:[nl]?(?:var)?char|decimal)\z/i) { + delete $result->{$col}{size}; + } + + if (lc($data_type) eq 'decimal') { + no warnings 'uninitialized'; + + $result->{$col}{data_type} = 'numeric'; + + my @size = @{ $result->{$col}{size} || [] }; + + if ($size[0] == 16 && $size[1] == -4) { + delete $result->{$col}{size}; } - elsif ($type == 10) { - $result->{$col}{data_type} = 'datetime'; + elsif ($size[0] == 16 && $size[1] == 2) { + $result->{$col}{data_type} = 'money'; + delete $result->{$col}{size}; } } + elsif (lc($data_type) eq 'smallfloat') { + $result->{$col}{data_type} = 'real'; + } + elsif (lc($data_type) eq 'float') { + $result->{$col}{data_type} = 'double precision'; + } + elsif ($data_type =~ /^n?(?:var)?char\z/i) { + $result->{$col}{size} = $result->{$col}{size}[0]; + } + # 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 {