1 package DBIx::Class::Loader::DB2;
4 use base 'DBIx::Class::Loader::Generic';
10 DBIx::Class::Loader::DB2 - DBIx::Class::Loader DB2 Implementation.
14 use DBIx::Class::Loader;
16 # $loader is a DBIx::Class::Loader::DB2
17 my $loader = DBIx::Class::Loader->new(
18 dsn => "dbi:DB2:dbname",
25 my $class = $loader->find_class('film'); # $class => Data::Film
26 my $obj = $class->retrieve(1);
30 See L<DBIx::Class::Loader>.
41 my $schema = uc ($args{schema} || '');
42 my $dbh = DBI->connect( @{ $self->{_datasource} } ) or croak($DBI::errstr);
44 # this is split out to avoid version parsing errors...
45 my $is_dbd_db2_gte_114 = ( $DBD::DB2::VERSION >= 1.14 );
46 my @tables = $is_dbd_db2_gte_114 ?
47 $dbh->tables( { TABLE_SCHEM => '%', TABLE_TYPE => 'TABLE,VIEW' } )
50 # People who use table or schema names that aren't identifiers deserve
51 # what they get. Still, FIXME?
53 @tables = grep {!/^SYSIBM\./ and !/^SYSCAT\./ and !/^SYSSTAT\./} @tables;
54 @tables = grep {/^$schema\./} @tables if($schema);
59 my ( $self, $table ) = @_;
61 # print "_table_info($table)\n";
62 my ($schema, $tabname) = split /\./, $table, 2;
63 # print "Schema: $schema, Table: $tabname\n";
65 # FIXME: Horribly inefficient and just plain evil. (JMM)
66 my $dbh = DBI->connect( @{ $self->{_datasource} } ) or croak($DBI::errstr);
67 $dbh->{RaiseError} = 1;
69 my $sth = $dbh->prepare(<<'SQL') or die;
71 FROM SYSCAT.COLUMNS as c
72 WHERE c.TABSCHEMA = ? and c.TABNAME = ?
75 $sth->execute($schema, $tabname) or die;
76 my @cols = map { @$_ } @{$sth->fetchall_arrayref};
78 $sth = $dbh->prepare(<<'SQL') or die;
80 FROM SYSCAT.TABCONST as tc
81 JOIN SYSCAT.KEYCOLUSE as kcu ON tc.constname = kcu.constname
82 WHERE tc.TABSCHEMA = ? and tc.TABNAME = ? and tc.TYPE = 'P'
85 $sth->execute($schema, $tabname) or die;
88 my @pri = map { @$_ } @{$sth->fetchall_arrayref};
90 return ( \@cols, \@pri );
95 L<DBIx::Class::Loader>