X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FDB2.pm;h=2d36a1541cbf374152ecbc7e229c6af6ae7d807c;hb=701cd3e37c8b4119cf43454d22766c1196377a3c;hp=bdc8f0d3f066400600e143c02896175716517792;hpb=41ef22da3417549e4b5eedd025cca17278bd1d72;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm index bdc8f0d..2d36a15 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/DB2.pm @@ -2,11 +2,14 @@ package DBIx::Class::Schema::Loader::DBI::DB2; use strict; use warnings; -use base 'DBIx::Class::Schema::Loader::DBI'; +use base qw/ + DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault + DBIx::Class::Schema::Loader::DBI +/; use Carp::Clan qw/^DBIx::Class/; use Class::C3; -our $VERSION = '0.04999_06'; +our $VERSION = '0.07000'; =head1 NAME @@ -34,6 +37,10 @@ sub _setup { my $dbh = $self->schema->storage->dbh; $self->{db_schema} ||= $dbh->selectrow_array('VALUES(CURRENT_USER)', {}); + + if (not defined $self->preserve_case) { + $self->preserve_case(0); + } } sub _table_uniq_info { @@ -46,7 +53,8 @@ sub _table_uniq_info { my $sth = $self->{_cache}->{db2_uniq} ||= $dbh->prepare( q{SELECT kcu.COLNAME, kcu.CONSTNAME, kcu.COLSEQ FROM SYSCAT.TABCONST as tc - JOIN SYSCAT.KEYCOLUSE as kcu ON tc.CONSTNAME = kcu.CONSTNAME + JOIN SYSCAT.KEYCOLUSE as kcu + ON tc.CONSTNAME = kcu.CONSTNAME AND tc.TABSCHEMA = kcu.TABSCHEMA WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'U'} ) or die $DBI::errstr; @@ -70,7 +78,7 @@ sub _table_uniq_info { # DBD::DB2 doesn't follow the DBI API for ->tables sub _tables_list { - my $self = shift; + my ($self, $opts) = @_; my $dbh = $self->schema->storage->dbh; my @tables = map { lc } $dbh->tables( @@ -79,7 +87,7 @@ sub _tables_list { s/\Q$self->{_quoter}\E//g for @tables; s/^.*\Q$self->{_namesep}\E// for @tables; - return @tables; + return $self->_filter_tables(\@tables, $opts); } sub _table_pk_info { @@ -100,31 +108,38 @@ sub _table_fk_info { } sub _columns_info_for { - my ($self, $table) = @_; - return $self->next::method(uc $table); -} - -sub _extra_column_info { - my ($self, $info) = @_; - my %extra_info; + my $self = shift; + my ($table) = @_; - my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/}; + my $result = $self->next::method(uc $table); my $dbh = $self->schema->storage->dbh; - my $sth = $dbh->prepare_cached( - q{ - SELECT COUNT(*) - FROM syscat.columns - WHERE tabschema = ? AND tabname = ? AND colname = ? - AND identity = 'Y' AND generated != '' - }, - {}, 1); - $sth->execute($self->db_schema, $table, $column); - if ($sth->fetchrow_array) { - $extra_info{is_auto_increment} = 1; + + while (my ($col, $info) = each %$result) { + # check for identities + my $sth = $dbh->prepare_cached( + q{ + SELECT COUNT(*) + FROM syscat.columns + WHERE tabschema = ? AND tabname = ? AND colname = ? + AND identity = 'Y' AND generated != '' + }, + {}, 1); + $sth->execute($self->db_schema, uc $table, uc $col); + if ($sth->fetchrow_array) { + $info->{is_auto_increment} = 1; + } + + if ((eval { lc ${ $info->{default_value} } }||'') eq 'current timestamp') { + ${ $info->{default_value} } = 'current_timestamp'; + delete $info->{size}; + + my $orig_deflt = 'current timestamp'; + $info->{original}{default_value} = \$orig_deflt; + } } - return \%extra_info; + return $result; } =head1 SEE ALSO @@ -132,6 +147,16 @@ sub _extra_column_info { L, L, L +=head1 AUTHOR + +See L and L. + +=head1 LICENSE + +This library is free software; you can redistribute it and/or modify it under +the same terms as Perl itself. + =cut 1; +# vim:et sts=4 sw=4 tw=0: