/usr/share/perl5/DBIx/Class/Schema/Loader/DBI/DB2.pm is in libdbix-class-schema-loader-perl 0.07048-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | package DBIx::Class::Schema::Loader::DBI::DB2;
use strict;
use warnings;
use base qw/
DBIx::Class::Schema::Loader::DBI::Component::QuotedDefault
DBIx::Class::Schema::Loader::DBI
/;
use mro 'c3';
use List::Util 'any';
use namespace::clean;
use DBIx::Class::Schema::Loader::Table ();
our $VERSION = '0.07048';
=head1 NAME
DBIx::Class::Schema::Loader::DBI::DB2 - DBIx::Class::Schema::Loader::DBI DB2 Implementation.
=head1 DESCRIPTION
See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base>.
=cut
sub _system_schemas {
my $self = shift;
return ($self->next::method(@_), qw/
SYSCAT SYSIBM SYSIBMADM SYSPUBLIC SYSSTAT SYSTOOLS
/);
}
sub _setup {
my $self = shift;
$self->next::method(@_);
my $ns = $self->name_sep;
$self->db_schema([ $self->dbh->selectrow_array(<<"EOF", {}) ]) unless $self->db_schema;
SELECT CURRENT_SCHEMA FROM sysibm${ns}sysdummy1
EOF
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($ns);
}
}
sub _table_uniq_info {
my ($self, $table) = @_;
my @uniqs;
my $sth = $self->{_cache}->{db2_uniq} ||= $self->dbh->prepare(<<'EOF');
SELECT kcu.colname, kcu.constname, kcu.colseq
FROM syscat.tabconst as tc
JOIN syscat.keycoluse as kcu
ON tc.constname = kcu.constname
AND tc.tabschema = kcu.tabschema
AND tc.tabname = kcu.tabname
WHERE tc.tabschema = ? and tc.tabname = ? and tc.type = 'U'
EOF
$sth->execute($table->schema, $table->name);
my %keydata;
while(my $row = $sth->fetchrow_arrayref) {
my ($col, $constname, $seq) = @$row;
push(@{$keydata{$constname}}, [ $seq, $self->_lc($col) ]);
}
foreach my $keyname (sort keys %keydata) {
my @ordered_cols = map { $_->[1] } sort { $a->[0] <=> $b->[0] }
@{$keydata{$keyname}};
push(@uniqs, [ $keyname => \@ordered_cols ]);
}
$sth->finish;
return \@uniqs;
}
sub _table_fk_info {
my ($self, $table) = @_;
my $sth = $self->{_cache}->{db2_fk} ||= $self->dbh->prepare(<<'EOF');
SELECT tc.constname, sr.reftabschema, sr.reftabname,
kcu.colname, rkcu.colname, kcu.colseq,
sr.deleterule, sr.updaterule
FROM syscat.tabconst tc
JOIN syscat.keycoluse kcu
ON tc.constname = kcu.constname
AND tc.tabschema = kcu.tabschema
AND tc.tabname = kcu.tabname
JOIN syscat.references sr
ON tc.constname = sr.constname
AND tc.tabschema = sr.tabschema
AND tc.tabname = sr.tabname
JOIN syscat.keycoluse rkcu
ON sr.refkeyname = rkcu.constname
AND sr.reftabschema = rkcu.tabschema
AND sr.reftabname = rkcu.tabname
AND kcu.colseq = rkcu.colseq
WHERE tc.tabschema = ?
AND tc.tabname = ?
AND tc.type = 'F';
EOF
$sth->execute($table->schema, $table->name);
my %rels;
my %rules = (
A => 'NO ACTION',
C => 'CASCADE',
N => 'SET NULL',
R => 'RESTRICT',
);
COLS: while (my @row = $sth->fetchrow_array) {
my ($fk, $remote_schema, $remote_table, $local_col, $remote_col,
$colseq, $delete_rule, $update_rule) = @row;
if (not exists $rels{$fk}) {
if ($self->db_schema && $self->db_schema->[0] ne '%'
&& (not any { $_ eq $remote_schema } @{ $self->db_schema })) {
next COLS;
}
$rels{$fk}{remote_table} = DBIx::Class::Schema::Loader::Table->new(
loader => $self,
name => $remote_table,
schema => $remote_schema,
);
}
$rels{$fk}{local_columns}[$colseq-1] = $self->_lc($local_col);
$rels{$fk}{remote_columns}[$colseq-1] = $self->_lc($remote_col);
$rels{$fk}{attrs} ||= {
on_delete => $rules{$delete_rule},
on_update => $rules{$update_rule},
is_deferrable => 1, # DB2 has no deferrable constraints
};
}
return [ values %rels ];
}
# DBD::DB2 doesn't follow the DBI API for ->tables (pre 1.85), but since its
# backwards compatible we don't change it.
# DBD::DB2 1.85 and beyond default TABLE_NAME to '', previously defaulted to
# '%'. so we supply it.
sub _dbh_tables {
my ($self, $schema) = @_;
return $self->dbh->tables($schema ? { TABLE_SCHEM => $schema, TABLE_NAME => '%' } : undef);
}
sub _dbh_table_info {
my $self = shift;
local $^W = 0; # shut up undef warning from DBD::DB2
$self->next::method(@_);
}
sub _columns_info_for {
my $self = shift;
my ($table) = @_;
my $result = $self->next::method(@_);
while (my ($col, $info) = each %$result) {
# check for identities
my $sth = $self->dbh->prepare_cached(
q{
SELECT COUNT(*)
FROM syscat.columns
WHERE tabschema = ? AND tabname = ? AND colname = ?
AND identity = 'Y' AND generated != ''
},
{}, 1);
$sth->execute($table->schema, $table->name, $self->_uc($col));
if ($sth->fetchrow_array) {
$info->{is_auto_increment} = 1;
}
my $data_type = $info->{data_type};
if ($data_type !~ /^(?:(?:var)?(?:char|graphic)|decimal)\z/i) {
delete $info->{size};
}
if ($data_type eq 'double') {
$info->{data_type} = 'double precision';
}
elsif ($data_type eq 'decimal') {
no warnings 'uninitialized';
$info->{data_type} = 'numeric';
my @size = @{ $info->{size} || [] };
if ($size[0] == 5 && $size[1] == 0) {
delete $info->{size};
}
}
elsif ($data_type =~ /^(?:((?:var)?char) \(\) for bit data|(long varchar) for bit data)\z/i) {
my $base_type = lc($1 || $2);
(my $original_type = $data_type) =~ s/[()]+ //;
$info->{original}{data_type} = $original_type;
if ($base_type eq 'long varchar') {
$info->{data_type} = 'blob';
}
else {
if ($base_type eq 'char') {
$info->{data_type} = 'binary';
}
elsif ($base_type eq 'varchar') {
$info->{data_type} = 'varbinary';
}
my ($size) = $self->dbh->selectrow_array(<<'EOF', {}, $table->schema, $table->name, $self->_uc($col));
SELECT length
FROM syscat.columns
WHERE tabschema = ? AND tabname = ? AND colname = ?
EOF
$info->{size} = $size if $size;
}
}
if ((eval { lc ${ $info->{default_value} } }||'') =~ /^current (date|time(?:stamp)?)\z/i) {
my $type = lc($1);
${ $info->{default_value} } = 'current_timestamp';
my $orig_deflt = "current $type";
$info->{original}{default_value} = \$orig_deflt;
}
}
return $result;
}
=head1 SEE ALSO
L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
L<DBIx::Class::Schema::Loader::DBI>
=head1 AUTHORS
See L<DBIx::Class::Schema::Loader/AUTHORS>.
=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:
|