blib/lib/DBIx/DBO/DBD/Pg.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 21 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 95 SCAR 42.8
CC
8
Cov
0%
_get_table_schema
20.0
_get_column_info
12.0
_set_table_key_info
6.0
CRAP 72.0
1 use strict;
2 use warnings;
3  
4 package # hide from PAUSE
5 DBIx::DBO::DBD::Pg;
6 use Carp 'croak';
7  
8 sub _get_table_schema {
9 my($class, $me, $schema, $table) = @_;
10  
11 my $q_schema = $schema;
12 my $q_table = $table;
13 $q_schema =~ s/([\\_%])/\\$1/g if defined $q_schema;
14 $q_table =~ s/([\\_%])/\\$1/g;
15  
16 # First try just these types
17 my $info = $me->rdbh->table_info(undef, $q_schema, $q_table,
18 'TABLE,VIEW,GLOBAL TEMPORARY,LOCAL TEMPORARY,SYSTEM TABLE')->fetchall_arrayref({});
19 # Then if we found nothing, try any type
20 $info = $me->rdbh->table_info(undef, $q_schema, $q_table)->fetchall_arrayref({}) if $info and @$info == 0;
21 croak 'Invalid table: '.$class->_qi($me, $schema, $table) unless $info and @$info == 1 and $info->[0]{pg_table} eq $table;
22 return $info->[0]{pg_schema};
23 }
24  
25 sub _get_column_info {
26 my($class, $me, $schema, $table) = @_;
27  
28 my $q_schema = $schema;
29 my $q_table = $table;
30 $q_schema =~ s/([\\_%])/\\$1/g if defined $q_schema;
31 $q_table =~ s/([\\_%])/\\$1/g;
32  
33 my $cols = $me->rdbh->column_info(undef, $q_schema, $q_table, '%')->fetchall_arrayref({});
34 croak 'Invalid table: '.$class->_qi($me, $schema, $table) unless @$cols;
35  
36 map { $_->{pg_column} => $_->{ORDINAL_POSITION} } @$cols;
37 }
38  
39 sub _set_table_key_info {
40 my($class, $me, $schema, $table, $h) = @_;
41  
42 if (my $keys = $me->rdbh->primary_key_info(undef, $schema, $table)) {
43 # In Pg the KEY_SEQ is actually the column index! Rows returned are in key seq order
44 # And the column names are quoted so we use the pg_column names instead
45 $h->{PrimaryKeys} = [ map $h->{Columns}[$_->{KEY_SEQ} - 1], @{$keys->fetchall_arrayref({})} ];
46 }
47 }
48  
49 sub _save_last_insert_id {
50 my($class, $me, $sth) = @_;
51  
52 return $sth->{Database}->last_insert_id(undef, @$me{qw(Schema Name)}, undef);
53 }
54  
55 # Pg doesn't allow the use of aliases in the WHERE, GROUP BY or HAVING clause
56 sub _alias_preference {
57 my($class, $me, $method) = @_;
58 $method ||= ((caller(2))[3] =~ /\b(\w+)$/);
59 return 0 if $method eq 'join_on' or $method eq 'where' or $method eq 'group_by' or $method eq 'having';
60 return 1;
61 }
62  
63 sub _bulk_insert {
64 shift->_fast_bulk_insert(@_);
65 }
66  
67 1;