X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FDBI%2FDB2.pm;h=8ed1ff6246dbce1c7fe422e48eaac2d672c1557e;hb=478f608d9028508396da37bb5df10b3057b96981;hp=56af605b8bdf9d2ba0bb7c2863d87eedda0353b7;hpb=4c41d371fe2e3b4a1f217135eddf3045fbf89491;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/DBI/DB2.pm b/lib/SQL/Translator/Parser/DBI/DB2.pm index 56af605..8ed1ff6 100644 --- a/lib/SQL/Translator/Parser/DBI/DB2.pm +++ b/lib/SQL/Translator/Parser/DBI/DB2.pm @@ -18,10 +18,10 @@ delegates to DBD::DB2. use strict; use DBI; use Data::Dumper; +use SQL::Translator::Parser::DB2; use SQL::Translator::Schema::Constants; -use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; +use vars qw[ $DEBUG @EXPORT_OK ]; $DEBUG = 0 unless defined $DEBUG; # ------------------------------------------------------------------- @@ -41,9 +41,18 @@ sub parse { $dbh->{ChopBlanks} = 1; } - $sth = $dbh->table_info(); - - @tables = @{$sth->fetchall_arrayref({})}; + my $tabsth = $dbh->prepare(<table_info(); +# @tables = @{$sth->fetchall_arrayref({})}; my $colsth = $dbh->prepare(<prepare(<prepare(<execute(); + @tables = @{$tabsth->fetchall_arrayref({})}; + foreach my $table_info (@tables) { next - unless (defined($table_info->{TABLE_TYPE})); + unless (defined($table_info->{TYPE})); # Why are we not getting system tables, maybe a parameter should decide? - if ($table_info->{TABLE_TYPE} eq 'TABLE'&& - $table_info->{TABLE_SCHEM} !~ /^SYS/) { + if ($table_info->{TYPE} eq 'T'&& + $table_info->{TABSCHEMA} !~ /^SYS/) { print Dumper($table_info) if($DEBUG); - print $table_info->{TABLE_NAME} if($DEBUG); + print $table_info->{TABNAME} if($DEBUG); my $table = $schema->add_table( - name => $table_info->{TABLE_NAME}, - type => $table_info->{TABLE_TYPE}, + name => $table_info->{TABNAME}, + type => 'TABLE', ) || die $schema->error; + $table->options("TABLESPACE", $table_info->{TBSPACE}); - $colsth->execute($table_info->{TABLE_NAME}); + $colsth->execute($table_info->{TABNAME}); my $cols = $colsth->fetchall_hashref("COLNAME"); foreach my $c (values %{$cols}) { @@ -123,7 +150,7 @@ SQL $f->is_nullable($c->{NULLS} eq 'Y'); } - $consth->execute($table_info->{TABLE_NAME}); + $consth->execute($table_info->{TABNAME}); my $cons = $consth->fetchall_hashref("COLNAME"); next if(!%$cons); @@ -142,7 +169,7 @@ SQL $con->deferrable($c->{CHECKEXISTINGDATA} eq 'D'); - $indsth->execute($table_info->{TABLE_NAME}); + $indsth->execute($table_info->{TABNAME}); my $inds = $indsth->fetchall_hashref("INDNAME"); print Dumper($inds) if($DEBUG); next if(!%$inds); @@ -150,7 +177,7 @@ SQL foreach my $ind (keys %$inds) { print $ind if($DEBUG); - $indsth->execute($table_info->{TABLE_NAME}); + $indsth->execute($table_info->{TABNAME}); my $indcols = $indsth->fetchall_hashref("COLNAME"); next if($inds->{$ind}{UNIQUERULE} eq 'P'); @@ -170,6 +197,33 @@ SQL } + + $trigsth->execute($table_info->{TABNAME}); + my $trigs = $trigsth->fetchall_hashref("TRIGNAME"); + print Dumper($trigs); + next if(!%$trigs); + + foreach my $t (values %$trigs) + { + print $t->{TRIGNAME} if($DEBUG); + my $trig = $schema->add_trigger( + name => $t->{TRIGNAME}, + # fields => \@fields, + perform_action_when => $t->{TRIGTIME} eq 'A' ? 'after' : + $t->{TRIGTIME} eq 'B' ? 'before': + 'instead', + database_event => $t->{TRIGEVENT} eq 'I' ? 'insert' + : $t->{TRIGEVENT} eq 'D' ? 'delete' + : 'update', + action => $t->{TEXT}, + on_table => $t->{TABNAME} + ) || die $schema->error; + +# $trig->extra( reference => $def->{'reference'}, +# condition => $def->{'condition'}, +# granularity => $def->{'granularity'} ); + } + } }